0% found this document useful (0 votes)
6 views

programme arduino voiture

Uploaded by

F0R3X
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

programme arduino voiture

Uploaded by

F0R3X
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <SoftwareSerial.

h>
#include <AFMotor.h>

AF_DCMotor motor1(3);
AF_DCMotor motor2(4);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
SoftwareSerial hc06(2,3);
String cmd="";

void setup(){
motor1.setSpeed(150);
motor2.setSpeed(150);
motor3.setspeed(150);
motor4.setspeed(150);

//Initialize Serial Monitor


Serial.begin(9600);
//Initialize Bluetooth Serial Port
hc06.begin(9600);
}

void loop(){

//Read data from HC06


while(hc06.available()>0){
cmd+=(char)hc06.read();
}

//Select function with cmd


if(cmd!=""){
Serial.print("Command recieved : ");
Serial.println(cmd);
// We expect ON or OFF from bluetooth
if(cmd=="avant"){
motor1.run(FORWARD); // faire avancer la voiture
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);

}
if(cmd=="arriere"){
motor1.run(BACKWARD);// faire reculer la voiture
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
}
if(cmd=="gauche"){
motor1.run(FORWARD); // faire tourner la voiture à gauche
motor3.run(F0RWARD);
}
if(cmd=="droite"){
motor2.run(FORWARD); // faire tourner la voiture à droite
motor4.run(F0RWARD);
}
if(cmd=="stop"){
motor1.run(RELEASE); // arrêter la voiture
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);

cmd=""; //reset cmd


}

delay(100);
}

You might also like