Controlling DC Motor With Drivemall
by HorizonLab in Circuits > Arduino
129 Views, 0 Favorites, 0 Comments
Controlling DC Motor With Drivemall
A practical guide on how to control a DC motor using the Drivemall already prepared with the L298 driver.
This tutorial is valid both if we use the Arduino and both using the Drivemall Board
below the link to build the Drivemall.
The advantage of prefering the Drivemall over the classic Arduino board is that of reducing the complexity of the connections leading to a more tidy setup. However, this is optional: all the results are still valid with the arduino board, a breadboard and enough dupont jumpers for connections.
A DC motor driver is require If an Arduino board is adopted instead of the Drivemall.
Bill of Materials
- Drivemall / Arduino Mega
- 4 button
- 4 Resistor1Kohm
- 1 Motor in DC
- (Optional) DC Driver (i.e. L298N)
Wire Connections
We use the driver L298 for the following reasons
-
Motor direction control
-
Engine power control
-
Use of power greater than that which can be supplied by Arduino
The driver can be controlled via 3 pins
- Enable for the power
- IN1 and IN2 for the direction
-
IN1 and IN2 both high or low the motor is stopped
-
IN1 and IN2 discordant the motor turns in one direction or the other
-
Each motor is driven by three pins, In1,In2 to indicate the direction and EnableA for the engine power.
Let's start by preparing the breadboard with 4 buttons connected via 4 resistance to GND and the other pin to Vbat. We then connect the pins from A0 to A3 of the Drivemall to the 4 buttons as shown in photos (1 and two). Then we connect the motor as in photo 3.
Firmware
Since the control pins for the DC motor are not mapped, we manage them directly at the register level
the instructions. The mask
DDRD = DDRD | B11110000
is used to define PINs PD7 to PD4 at the output.
To set the logical level of the PIINs we use two instructions
PORTD = PORTD | B10100000; PORTD = PORTD & B10101111;
the first to set level 1 the second to set level 0
the motor is connected to PIN PE4 so it can be controlled with PINs PD7 and PD6.
To prevent the board from detecting more than one press while pressing the button, the instruction helps us
unsigned long currentMillis = millis ();
Acc = analogRead (PinAcc);
if (currentMillis - previousMillis> 100 and Acc> 500)
{
Vel ++;
Serial.print (Vel);
previousMillis = currentMillis;
}
Downloads
Control
As a last step we connect the power supply of the board, in what we wanted to use the USB power supply for the logic part and the 12 volt for the motor, we have to connect the GND in common
for the control we have:
- pin A0 to increase speed
- pin A1 to decrease the speed
- pin A2 to stop the motor
- pin A3 to change direction of rotation
Downloads
Disclaim
This tutorial has been produced as part of the Makerspace for Inclusion project, co-financed by the Erasmus + Programme of the European commission.
The project aims to promote an informal form of education as a means to foster the social inclusion of young people, informal education as can be found within makerspaces. This tutorial reflects the views only of the authors, and the European Commission cannot be held responsible for any use which may be made of the information contained therein