This project is the beginning of Arduino Robotics. Here we control the direction of motor by pressing defined key from keyboard.
Component Required
- Arduino.
- Motor.
- Motor driver.
- computer.
- Jumper wires.
Project Objectives
- To understand about the direction of Motor.
Circuit Diagram
Fig:- Circuit Diagram
- Connect Motor to the Motor driver as Shown in figure.
- Connect the Controller to pin from Motor driver to 6 & 7 pin of Arduino
- Connect 5V pin of Motor Driver to 5V pin of Arduino and GND pin of Arduino To GND pin of Motor Driver.
Here the Function of Motor Driver is to drive the motor according to the instruction given by the user.
CODE
int lm1=6;
int lm2=7;
void setup()
{
// put your setup code here, to run once:
pinMode(lm1,OUTPUT);
pinMode(lm2,OUTPUT);
Serial.begin(9600);
Serial.println("press \n forward 8 \n backward 2 \n stop others pin");
}
void loop()
{
// put your main code here, to run repeatedly:
if(Serial.available());
{
int val= Serial.read();
Serial.print(val);
if(val==8)
{
digitalWrite(lm1,HIGH);
digitalWrite(lm2,LOW);
Serial.println(" \n now moving forward");
}
else if(val==2)
{
digitalWrite(lm1,LOW);
digitalWrite(lm2,HIGH);
Serial.println(" \n now moving backward");
}
else
{
digitalWrite(lm1,LOW);
digitalWrite(lm2,LOW);
Serial.println(" \n now stop");
}
}
}
Now Upload the Code to the Arduino.
Then if you press 8 :- Motor will Rotates in ClockWise Direction
if you press 2:- Motor will Rotates in Anti-Clock wise Direction.
Except these two key if we press any key Motor will stop.