Introduction
- In this article, I will explain about connecting simple DC motors in Arduino Mega 2560.
- It can work with the connection of the PN 2222 transistor.
Parts Of Lists
- Arduino Mega 2560
- DC Motor
- PN2222 Transistor
- Diode
- 270-ohm Resistor
- LED
- Bread Board.
PN2222 Transistor
Figure 1. PN 2222 Transistor
- It can be used for low-power and medium-power amplifying.
- It is frequently used as a small-signal transistor.
- It can have the following three pins.
- First pin: Collector
- Second pin: Base
- Third pin: Emitter
DC motor
- DC Motor that converts the direct current electrical power to the mechanical power.
- A DC motor's speed can be controlled over a wide range, using either a variable supply voltage or by changing the strength of current in its field windings.
- Small DC motors are used in tools, toys, and appliances.
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 the connection of a 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 at high speed, it will glow the LED.
- When the DC motor is in low speed, it cannot glow the LED.
Output
Figure 3. Output