Exercise 7 - Connecting a DC engine and decelerator DC engine
1. INTRODUCTION
A DC motor converts electrical energy into mechanical energy, is a reversible machine, this means that it can also converts mechanical energy into electrical energy.
BRUSHED MOTORS:
The principle of this motor is based on Ampère law, which relates magnetic fields to electric currents that produce them. In IMAGE 1, when coil is conducting current, a magnetic field is generated around it.
On IMAGE 2, you can see a simple motor with a pair of poles (one north and one south). The engine also has two coils which are connected to a generator by a pair of brushes. These brushes are separated from each other.
When a current is applied to the coils, they move the rotor and brushes because the stator poles attract them. When the rotor moves to a stability position the brushes which also rotate reversing their connections with the generator, what invert the magnetic field and move the rotor another time (Coils are attracted by stator poles another time because they change their produced magnetic field). This cycle is performed with high velocity what do the motor rotation.
On this exercise, you can use a brushed motor with and without decelerator engine.
2. HOW TO CONNECT?
Materials:
· Arduino UNO board
· Protoboard
· Some wire Jumpers
· DC engine
· Decelerator DC engine
· H-bridge
If the motor, which you want to connect, not is too small, you must not connect it directly to Arduino board because you can break it (the microcontroller can support 200mA of maximum charge). To avoid problems connect the motor to a H bridge (L298N on this exercise).
Connect motor and power supply to L298, and then connect it to PWM pins. It is important to connect ground of Arduino with ground of battery.
EXERCISE_A (Acceleration & Deceleration) |
![]()
|
EXERCISE_B (Change the direction of rotation) |
![]()
|
3. PROGRAMMING
EXERCISE_A (Acceleration & Deceleration)
These programs test a motor connected with a L298n H bridge
On L298N driver, you can control motor velocity with one pin to each direction. Associate a pin to motor and declare “i” variable.
On setup set motor pint as OUTPUT and start the serial communication at 9600 bauds.
int motor=9;
int i=0;
void setup() {
pinMode(motor,OUTPUT);
Serial.begin(9600);
}
On loop motor velocity are incremented one each 50 milliseconds, when i=200 velocity are decremented by analogWrite() function. Furthermore, “i” value is written on serial monitor.
void loop() {
for(i=0;i<=200;i++){
analogWrite(motor,i);
delay(50);
Serial.println(i);
}
for(i=200;i>=0;i--){
analogWrite(motor,i);
delay(50);
Serial.println(i);
}
}
EXERCISE_B (Change the direction of rotation)
These pins are connected to H Bridge.
int forward = 9;
int backward = 6;
void setup() {
pinMode(forward, OUTPUT);
pinMode(backward, OUTPUT);
}
To avoid break the motor, i value should not overcome 200. Go forward during 1 second, and then go backward 1 second. You also can brake the motor writing on backward when forward is active.
void loop() {
analogWrite(forward, 200);
analogWrite(backward, 0);
delay(3000);
analogWrite(forward, 0);
analogWrite(backward, 200);
delay(1000);}