This article was translated to English, and was originally published for deviceplus.jp.
On Device Plus, a wide variety of applications for Arduino and examples of pieces were introduced, but knowing the basics is especially important whenever you’re creating something. So that’s why for today’s article, we’ll be going over the key foundations of Arduino. Teaching us this today will be expert and author of “Entry into the Basics of Arduino Electronic Crafts!” Kazuhiro Fukuda.
In this article, I would like to cover ways on how you can control motors with large electrical currents.
Motors are used to run a wide variety of machines such as drones and cars. Connecting motors to a power supply makes it possible for electronic components to generate rotational motion. Attaching tires or propellers to a motor also increases the rotation and movement of operations.
On Arduino, it’s possible to control the motor. As with the LED, you can control the motor to rotate or stop by turning the power supplied to the motor on and off. When combined with other sensors, it’s possible to set up automatic control, such as stopping the motor when an obstacle approaches.
The motor rotates in the opposite direction when the direction of the connected power supply is reversed. It is also possible to change the rotation speed by adjusting the amount of current to flow. As a result, this makes it possible to rotate at high speed when the motor is moving or to slowly stop at a desired position by gradually slowing down when stopping. Even if a projectile hits the fans, the motor can move backward and move in other directions. That being said, today we’ll be going over ways you can control a motor on Arduino.
[Table of Contents]
・Operating the Motor Requires a Driver
・Connecting the Motor to Arduino
・Controlling the Motor on a Program
・Changing the Rotation Speed of the Motor
On Arduino’s digital output, you can switch between High and Low to control the light flashes of the LED. Using this function, you should be able to supply electricity to the motor. However, even if you actually connect the motor directly to Arduino, it won’t be operable.
In order to move the motor, a large amount of electric current is necessary. For example, for today’s「RE-280RA」, you would need more than 1A of electrical current for it to move. However, Arduino’s digital output connector can only flow up to 20mA. Flowing any electrical current past this could potentially damage the Arduino. To do this, we need to connect the motor to Arduino’s output connector and control it.
What will be used here is a「Motor driver」. A motor driver is an electrical component used to control a motor. Prepare a circuit that connects the motor to the power supply for operating the motor and insert the motor driver inside. The motor driver can connect and disconnect the motor operation circuit by an external signal, and can control the rotation and stop of the motor. Since almost no current flows into the control signal, even if the Arduino is connected, it will be possible to control the motor without any problems.
Depending on the motor driver, the direction of the rotation can be switched by a control signal. Equipped with two control connectors, when one side is set to High, it will rotate normally while another side that is set to High will rotate in reverse. This allows forward, reverse and stop controls possible.
Now let’s try controlling the motor from Arduino. The following electronics will be used for this portion, so please make sure you have them prepared.
This is the motor body. These types of motors that use dry batteries are called「DC Motor」. For this article, we’ll be using「RE-280RA」. The RE-280RA battery can support electric voltage of up to 4.5V.
We’ll be using this to control the motor. Following signals from Arduino, you can control the supply of electricity to the motor and the rotational direction. We’ll be using「BA6956AN」made from ROHM. From the connector with cutouts (left side in the picture), they’re counted as Connector 1 and Connector 2.
A condenser is an electrical component that can store a small amount of electricity. When it is running on a motor, it will begin to make noise. This noise has potential negative effects on other operable electrical parts. So because of that, connect the condenser to both connectors to help reduce the noise.
In order to prevent electronic components from breaking due to sudden large electrical current flows, the current can be suppressed by using a resistor. This time, in order to specify the voltage being supplied to the motor, the Arduino 3.3V connector is connected to the motor driver. Normally, there are almost no current flows, but a large current may flow in some cases, so connect a 10kΩ resistor to prevent any large currents from flowing. A 10 kΩ resistor is printed with “Brown Black Orange Gold” along with a color code.
Batteries are used as the power source for rotating the motor. Here, a 006P that can supply up to 9V voltage will be used. It also uses battery snaps to connect the batteries to the breadboard.
For the motor, wiring for the connectors up to the breadboard is necessary. Usually, the conductor is soldered onto the connector. However, if you use the electrical clip jumper wire, you can just wire it by inserting the clip into the motor connector, eliminating the need for soldering.
Once you prepare each of the components, connect like below.
Connect the motor to Connectors 2 and 4 of the motor driver by pinching the connector with the electrical clip. Keep in mind that noise may be generated during motor operation, which may affect other devices. Therefore, connecting capacitors to both connectors of the motor will reduce the amount of noise.
The motor can be powered from a separately prepared battery. Therefore, power can be supplied from the battery by connecting the battery to the fifth and third connectors of the motor driver.
In addition, the motor used this time has a power supply range of up to 4.5V. For this reason, the voltage may be too high with a 9V battery, so there is the possibility that the motor may be damaged. Therefore, specify the maximum voltage of the output going into the motor at Connector 1 of the motor driver. This time, we will be able to supply up to 3.3V to the motor. Connect the Arduino 3.3V power supply to Connector 1 and specify the maximum voltage. Motor rotation can be controlled with the seventh and ninth connectors of the motor driver. This means connecting to Connectors 5 and 6 of Arduino allows you to control the motor via Arduino’s output.
Once connected, let’s actually try controlling the motor with a programming code. The rotation of the motor can be controlled by the output of Arduino Connectors 5 and 6. Rotation, stop and rotation direction can all be controlled by waning High or Low in these two connectors. In the case of BA6956AN, it can be controlled as follows.
For normal rotations, Connector 5’s output is set at High while the output for Connector 6 is set at Low. Writing the below programming code into Arduino should start the motors normal rotation.
At the tenth line, the output should be set at High, while at Connector 6 on the sixth line, output should be set at Low.
When you would like to make the motor rotate in the opposite direction, Connector 5’s output should be set at Low, while Connector 6’s output should be set at High.
The programming code should look like the following:
On the tenth line, Connector 5’s output should be set at Low while on the eleventh line, Connector 6 should be set at High. When you would like to stop the motor, both the output for Connectors 5 and 6 should set at Low.
The programming code should look like the following:
In addition, setting both outputs at High will cause it to turn on the breaker. Setting either of them at Low will cause it to stop in a short amount of time.
Last time, we were able to change the brightness by using an LED output method called PWM. Even on a motor, the rotational speed can be changed by controlling the motor with PWM. By switching between High and Low in a short amount of time, the motor alternatively switches between rotation and stop, with the rotation speed actually being slower than normal. The longer the High time, the faster the rotation speed will be, and vice versa.
For the motor, output the control connector of the direction you would like to rotate on PWM and always keep the other connector at Low. For normal rotations, output Connector 5 on PWM and keep Connector 6 at Low. For inverse rotation, output Connector 6 on PWM, and keep Connector 5 at Low. The programming code for controlling the speed of the normal rotation is listed below.
For the programming code, set output Connector 5 on line 10 to half the ratio of PWM (biggest at 255) and keep Connector 6 on line 11 at Low. If you change the number on line 10, the speed will also change. However, the motor will not rotate if High is less than a certain percentage. If the motor doesn’t rotate with a small value, try specifying a higher value. You can gradually change the speed by gradually increasing or decreasing the value output from Connector 5. In the next program, the rotation speed will gradually increase from the stop state, and once it reaches the maximum, the speed will gradually decrease and stop.
For today, we went over different ways you can operate electronic components on Arduino such as LED or motors. Next time, we’ll be talking about how to look up the condition of switches on Arduino.