MATERIALS NEEDED
1.ARDUINO UNO
2.300 RPM MOTORS *2
3.CHASIS
4.ADAFRUIT MOTOR SHILED
5.HC-05
6.CASTOR WHEEL
7.WHEELS FOR MOTOR
CODE
#include <AFMotor.h>
#include <SoftwareSerial.h>
SoftwareSerial bt(14,15);
String message;
AF_DCMotor motor2(3);
AF_DCMotor motor1(2);
void setup() {
// put your setup code here, to run once:
bt.begin(9600);
Serial.begin(9600);
motor1.setSpeed(200);
motor1.run(RELEASE);
motor2.setSpeed(200);
motor2.run(RELEASE);
}
void loop() {
// put your main code here, to run repeatedly:
while(bt.available()){
delay(10);
char m=bt.read();
message +=m;
if (message.length()>0){
Serial.println(message);
if (message=="forward"){
motor1.run(FORWARD);
motor2.run(FORWARD);
delay(100);
}
else if(message=="backward"){
motor1.run(BACKWARD);
motor2.run(BACKWARD);
delay(100);
}
else if(message=="right"){
motor1.run(FORWARD);
motor2.run(BACKWARD);
delay(100);
}
else if(message=="left"){
motor1.run(BACKWARD);
motor2.run(FORWARD);
delay(100);
}
else if(message=="stop"){
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(100);
}
}
}
message="";
}
Comments
Post a Comment