R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E.
(2019Pattern), Electronic System Design
Roll No. Date:
Experiment No. 3
Name:
Title: Using Sensors & Actuators and their interfacing with Arduino (Motor Driver with relays,
Reversible motor).
Aim: To build and test motor controlling circuit with arduino
Apparatus: bread board, connecting wires, resistor, L298N DC motor, Motor driver
module, Arduino board, Arduino board serial cable, computer system, Arduino IDE,
Python3.6, etc.
Prior Concept:
1. Knowledge of basic electronic components
2. Implementing circuit on bread board
3. Fundamentals of programming in C/C++
4. Fundamentals of programming in python
Learning Objectives:
Intellectual Skills
1. To understand the construction of Arduino board and its use
2. To understand interfacing devices or machines to microcontrollers
3. To understand programming in python for Arduino boards.
Motor Skills
1. Set up electronic circuits interfacing motor driver module with Arduino
2. To write program for controlling motor
3. Set up the Firmata protocol on Arduino
Theory:
Text Instructions
Hardware:
1.) The controller can take up to 2 motors. Plug one motor into the terminal labelled
OUT1 and OUT2. Plug the second motor into the terminal labelled OUT3 and OUT4:
2.) The row of pins on the bottom right of the L298N control the speed and direction of
the motors. IN1 and IN2 control the direction of the motor connected to OUT1 and
OUT2. IN3 and IN4 control the direction of the motor connected to OUT3 and OUT4.
Here I plugged them into pins 2, 3, 4, and 5 on the Arduino.
Department of Electronics & Telecommunication Engineering
R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design
Fig.3 interfacing diagram of motor driver, DC motors with Arduino
Software:
4.) Write the code. Setting IN1 to HIGH and IN2 to LOW will cause the left motor to
turn a direction. Setting IN1 to LOW and IN2 to HIGH will cause the left motor to spin
the other direction. The same applies to IN3 and IN4. Here is a short example (You can
download the full code in the "Code" section at the bottom of the page):
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
Speed:
5.) You can change the speed with the EN pins using PWM. ENA controls the speed of
the left motor and ENB controls the speed of the right motor. Here I plugged them into
pins 9 and 10 on the Arduino.
Department of Electronics & Telecommunication Engineering
R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design
Code without speed control C/C++
int motor1pin1 = 2;
int motor1pin2 = 3;
int motor2pin1 = 4;
int motor2pin2 = 5;
void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
delay(1000);
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
delay(1000);
}
Conclusions:________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
Checked By:
Department of Electronics & Telecommunication Engineering
R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design
Name of Subject Teacher Sign with Date
Department of Electronics & Telecommunication Engineering