Skip to main content

How to control RGB LED using Arduino Uno

RGB LED is the abbreviation of ‘’Red Green Blue Light Emitting Diode’’. RGB LED is the most amazing type of LED which has the ability to create millions of different shades of light colors using red, green, and blue colors.

How to operate DC motor using Arduino


A direct current motor (DC motor) is a very basic type of motor. DC motor has amazing features like higher starting torque, variable speeds based on provided input voltage, rapid starting and stopping, cheaper controlling than AC motors.
The speed of the DC motor can be changed by varying the applied input voltage. If the applied voltage is high then the motor rotates with higher speed similarly if the applied voltage is low that means the motor will rotate at the lower speed. I have used 5 volt DC motor, for which applying 5-volt input voltage to DC motor will provide higher speed while applying the lower voltage will provide lower speed.

DC motor normally has two leads one is positive and the other one is negative. If these two leads are directly connected with the battery, the motor will rotate in a particular direction. If we exchange the leads, the motor will rotate in the opposite direction.

In this article, you will learn how a DC motor can be operated using Arduino Uno. DC motor should not be operated directly by the Arduino Uno pins. It will damage the board, to avoid this situation I will use the transistor as a switch to operate motor using Arduino. I am providing a very basic circuit connection example which will help you to understand how a DC motor can be turned on and off with the help of a transistor.

Required components:

  1. Arduino Uno board:............................. BUY
  2. 1 x 2N2222 transistor:.......................... BUY
  3. 1 x 1N4007 diode: ................................BUY
  4. 5 volt DC motor: ...................................BUY
  5. 1 x 220 ohm resistor: .............................BUY
  6. few jumper wires:.................................. BUY
  7. 1 x USB cable: .......................................BUY

Connection diagram:


Circuit description:

Transistor has three terminals with two side structure (flat and round). The flat side’s first terminal should be connected with the positive terminal of the diode (as shown in the connection diagram). The middle terminal is connected with the 220-ohm resistor and the third terminal is connected with ground. The 220-ohm resistor’s another terminal is connected with PWM pin 6 of the Arduino board. The motor is connected across the diode. The negative terminal of the diode is connected with the 5-volt power supply pin of the Arduino board. Transistor and diode should be connected in the proper manner otherwise you will not get exact output.

Code link: Click here

Output: 

The motor will turn on and rotate for specified millisecond time after that turn-off and this loop runs over and over again.


Some other important point to keep in mind:

  • The speed of the motor can be changed according to the need. analogWrite(pin, value) function is preferred in the code to generate PWM wave on PWM digital pins of Arduino Uno board (PWM pins are: 3, 5, 6, 9, 10 and 11). We can provide any value between 0 to 255 in the analogWrite function. The DC motor will rotate with different speeds according to the specified value (0 to 255) in the function.
  • The DC motor can rotate in a clockwise and anti-clockwise direction. If the motor is rotating in the clockwise direction and we need to change the direction of motor rotation into anticlockwise direction then the leads should be interchanged. The H-bridge is an electronic circuit that is used to drive DC motor in both the direction according to the requirement without changing the leads.

Application:


Water pump made up of 5 volt DC motor 

DC motor is most commonly used in multiple applications such as in toys, drones, home appliances and so on. I have used 5 volt DC motor to develop a mini water pump using the above-provided code which can be used for home-based automation systems (like for indoor plant watering system and automated fish tank water pump).

For outer structure, I used a small plastic box with a cap. I made a hole in the center of the box's cap to attach the DC motor and two other holes on the box to attach the water pipes (one in the center and the other one in verticle edge of the box). After that, I took a round shape plastic plate and attach five small plastic plates on it vertically and fix it with the motor rotator inside the box using the glue gun. In the end, I glued small water pipes in both the holes of the box and fixed all the stuff with the help of hot glue. (note: I used the soldering iron to make a hole in the plastic box) After that, I attached DC motor with the Arduino board as shown in the circuit diagram and uploaded the code and my water pump is ready to use.

Small plastic Box

After making holes

Small plates to make rotator

Disk to fix small plates

Water pipe

For more detail please visit this video: 



Note: Sometimes when you upload the code and try to run the DC motor while connected through the Laptop using a USB cable, at that time you may face the problem that DC motor is not rotating due to an insufficent power supply issue. In that case, you should use an external 5 volt DC charger (your smartphone charger) to provide power supply using the Arduino compatible USB cable.


Comments

  1. I am happy to find this post useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing.led screen

    ReplyDelete

Post a Comment

Popular posts from this blog

Smart Plant Watering System Using ARDUINO UNO

As we all know, plants play an important role in our life, there are countless benefits we get from plants but the most important is fresh air and the pleasant atmosphere on the earth. Hence,   It is not only our social duty as well as the responsibility that we should plant trees as much as we can and also take care of them. But  the biggest challenge we face, is, taking care of them,

How to use LCD with Arduino Uno

Liquid crystal Display 16x2 (LCD) is a widely used electronic device to establish communication between the real world and the electronics-based machine world.

How to operate soil moisture sensor with Arduino

The soil moisture sensor is the most amazing sensor used to measure the quantity of water present in the soil and defines the moisture level of the soil as the output. Because of its amazing operating principle, this sensor is used in applications such as automatic irrigation systems, agriculture research applications, landscape irrigation, indoor planting system, and lawns. I have also made an advanced level project  "Smart Plant Watering System" using a soil moisture sensor.

ad

ad