Created
May 10, 2017 18:10
-
-
Save bha159/89c020a11d56afc3a7b371548ea7fee0 to your computer and use it in GitHub Desktop.
This code can be used to control movement of a bot connected using HC-05 to Arduino.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
int dir; | |
int TxPin=10; | |
int RxPin=11; | |
int LMotor1=6; | |
int LMotor2=7; | |
int RMotor1=3; | |
int RMotor2=4; | |
SoftwareSerial BT(TxPin,RxPin); | |
void setup() | |
{ | |
BT.begin(9600); | |
Serial.begin(9600); | |
pinMode(RMotor1,OUTPUT); | |
pinMode(RMotor2,OUTPUT); | |
pinMode(LMotor1,OUTPUT); | |
pinMode(RMotor2,OUTPUT); | |
} | |
void loop() | |
{ | |
while(BT.available()) | |
{ | |
dir = BT.read(); | |
index=BT.read(); | |
if(dir==1) | |
{ | |
Serial.println("Moves Left"); | |
digitalWrite(LMotor1,LOW); | |
delayMicroseconds(300); | |
digitalWrite(LMotor2,HIGH); | |
} | |
else | |
{ | |
if(dir==2) | |
{ | |
Serial.println("Moves Straight"); | |
digitalWrite(LMotor1,HIGH); | |
digitalWrite(LMotor2,LOW); | |
digitalWrite(RMotor1,HIGH); | |
digitalWrite(RMotor2,LOW); | |
delayMicroseconds(300); | |
} | |
else | |
{ | |
Serial.println("Moves Right"); | |
digitalWrite(RMotor1,HIGH); | |
delayMicroseconds(300); | |
digitalWrite(RMotor2,LOW); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment