PWM über Seriellen Monitor - AZ-Delivery

Ciao a tutti

abbiamo già alcuni prodotti nel nostro Portofolio che consentono di utilizzare motori step o DC con più canali sull'Arduino. Oggi voglio mostrare un motore 12V su un Arduino. In linea di principio, qualsiasi consumatore controllato tramite PWM può essere collegato, come un LED. La velocità o la luminosità possono essere controllate tramite il monitor seriale. Tuttavia, è anche possibile implementare il progetto senza una libreria. Un grosso problema con l'implementazione manuale è il carico sul controller, motivo per cui vorremmo introdurre questa libreria a voi oggi:

https://github.com/HobbyComponents/HCMotor

Queste (e altre autostrade) offrono la possibilità di far funzionare il motore "in background", cioè di non bloccare il controller in modo che le Nazioni Unite possano eseguire altre attività.

Abbiamo già mostrato come installare la libreria in molti post di blog.

Al fine di avere sufficiente potenza per il nostro ventilatore e non danneggiare l'ONU, usiamo il modulo MOS con IRF520.

Il cablaggio:

I tre pin del modulo MOS sono collegati all'ONU, alla fonte di alimentazione e alla ventola ai terminali a vite:

Un (Inst Modulo MOS Alimentazione Consumatori
5v Vcc
Gnd Gnd
D6 Sig
Vin 12v
Gnd Gnd
VERSIONE V +
V- -

 

Ecco il codice:

 

#include "HCMotor.h"
# define MOTOR_PIN 6 PWM Pin    Motore HC Motore HC;
 
Vuoto Installazione(){   Seriale.Iniziare(9600);   Motore HC.Init();   Motore HC.allegare(0, DCMOTOR, MOTOR_PIN);   Motore HC.Ciclo di lavoro(0, 100); minimo 0 e velocità massima 100
}    Vuoto Ciclo(){      Mentre(Seriale.Disponibile() > 0){          Int Valore = Seriale.Readstring().ToInt();     Int motorSpeed = Mappa(Valore, 0, 1024, 0, 100);     Motore HC.Ontime(0, motorSpeed);   }
}

 

Divertiti a sperimentare!

Für arduinoProjekte für anfänger

4 commenti

Moritz

Moritz

Hallo,
ich denke es ist immer schwierig das richtige Niveau für die Artikel zu finden. So wie ich das verstanden habe will AZ mit den Artikeln die Leute für Mikrocontroller begeistern und zur Umsetzung eigener Projekte anregen. Alle Sachen die ich hier im Blog gefunden habe funktionierten auf Anhieb, das ist recht selten. Interne Timer und Register sind nicht besonders anfängerfreundlich. Sieht einfach aus, ist es aber nicht….

Matthias Jacobsen

Matthias Jacobsen

Moin,
Prinzipiell finde ich ihren Beitrag sehr gut.
Erwähnenswert wäre, dass die Benutzung des internen Timermoduls. Dieser lässt sich als pwm Generator parametrisieren und dies benötigt auch nur ca. 3 Zeilen Code.
Damit läuft der pwm Generator im Hintergrund und blockiert die Main nicht.

Es ist zwar schön wenn einem Librarys die Arbeit abnehmen und Mann nicht weiß was diese tun.

Gruß
Matthias

Ljubomir Madzarac

Ljubomir Madzarac

Monitor ??? Motor :-)

Norbert

Norbert

Vielen Dank das Du dein Wissen mit uns teilst.
Jedoch wären im Programm einige Erklärungen hilfreich, da ich trotz ein wenig
Programmierkenntnis da nicht so viel verstehe.
Wo ist denn der Wert der den Motor (soll warscheinlich der erwähnte Lüfter sein) Steuert?

Ihr Programmierprofis setzen häufig zuviel als selbstverständlich voraus, und hängt dann die lernwilligen ab, schade.

Lascia un commento

Tutti i commenti vengono moderati prima della pubblicazione