[Project 19] – Serial Communication with Computer Keyboard + DC Motor Direction Control

In this project we will do serial communiation example with computer keyboard and we use DC Motor and 2 LED's with the arduino. We need to use 2 commands for this project (Serial.avileble) and (Serial.Read). You need a battery according to your motor.  I use usually arduino mega 2560. You can use the other arduino cards. (serial monitor: Ctrl+Shift+M) Good Luck.

Circuit:


[Project 19] - Serial Communication with Computer Keyboard  + DC Motor Dİrection Control 777

Materials:


Arduino Mega/Uno  x1
Breadboard  x1
DC Motor  x1
L293D  x1
LED  x2
220 Ohm Res.  x2
Jumper Cable

 

Program:

//  letsarduino.com
//  [Project 19] - Serial Communication with Computer Keyboard  
//  DC Motor Dİrection Control

const int right_led=2;
const int left_led=3;

const int enablePin = 4;
const int motor_Pin1 = 5;
const int motor_Pin2 = 6;

char data;

void setup()
{
  Serial.begin(9600);
  pinMode(right_led,OUTPUT);
  pinMode(left_led,OUTPUT);
  pinMode(motor_Pin1, OUTPUT);
  pinMode(motor_Pin2, OUTPUT);
  pinMode(enablePin, OUTPUT);

}

void loop()
{

  if(Serial.available()>0)
  {
    data=Serial.read();
    if(data=='1')  
    {
      digitalWrite(motor_Pin1, HIGH);
      digitalWrite(motor_Pin2, LOW);
      digitalWrite(enablePin, HIGH);
      digitalWrite(right_led, HIGH);
      digitalWrite(left_led, LOW);
      
      Serial.println("motor turns left now");
    }
    else if (data=='2')
    {
      digitalWrite(motor_Pin1, LOW);
      digitalWrite(motor_Pin2, LOW);
      digitalWrite(enablePin, LOW);
      digitalWrite(right_led, LOW);
      digitalWrite(left_led, LOW);
      
      Serial.println("motor stopped turning ");
    }
     else if (data=='3')
    {
      digitalWrite(motor_Pin1, LOW);
      digitalWrite(motor_Pin2, HIGH);
      digitalWrite(enablePin, HIGH);
      digitalWrite(right_led, LOW);
      digitalWrite(left_led, HIGH);
      
      Serial.println("motor turns right now");
    }
  }
}

 

Serial Monitor Image:


serial monitor

L293D Pins:


[Project 16] - DC motor speed and direction control using arduino L293D datasheet  pins

Project Related Images:


[Project 19] - Serial Communication with Computer Keyboard  + DC Motor Dİrection Control 44

[Project 19] - Serial Communication with Computer Keyboard  + DC Motor Dİrection Control 32



 

You may also like...