Figure 2: Dc Motor
Connection:
Step 1 : Connection From DC motor to board
- Connect the red color wire to the positive of the diode pin
- Connect the black color wire to the negative of the diode pin.
- Connect the negative pin to the interconnect of the transistor of the emitter.
Step 2 : Connection From Transistor to Board
- Connect the base pin to the digital pin 05 of the Arduino Mega 2560.
- Connect the collector pin to the Gnd of the board.
Step 3 : LED Connection to Board
- Positive pin to the 12
- Negative pin to the Gnd.
Programming
- int motor=5;
- int led=12;
-
- void setup()
- {
- pinMode(led,OUTPUT);
- pinMode(motor,OUTPUT);
- Serial.begin(9600);
- if(! Serial);
- Serial.println("Speed up to 0 to 255");
- }
- void loop()
- {
- if(Serial.available())
- {
- int speed=Serial.parseInt();
- if(speed >=0 && speed <=255)
- {
- digitalWrite(led,HIGH);
- }
- else {
- digitalWrite(led,LOW);
- }
- analogWrite(motor,speed);
- }
- }
Explanation
- In this article I have explained about the connection of simple DC Motor using Arduino Mega 2560
- Normally the DC motor can run in the high, so it will control and give the limited speed.
- When the DC motor is in high speed, it will glow the LED.
- When the DC motor is in low speed, it cannot glow the LED.