Hi,
I've got an Arduino Genuino R3, HC-05 bluetooth system, Motor shield Arduino official, and two RC Motor.
I want to control my cars (all of the motor), with my phone with the bluetooth but i try some project but always fails :
//#include <SoftwareSerial.h>
//char data = 0;
int data;
//SoftwareSerial Serial(0, 1);
void setup() {
Serial.begin(9600);
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A piné
//Setup Channel B
pinMode(13, OUTPUT); //Initiates Motor Channel A pin
pinMode(8, OUTPUT); //Initiates Brake Channel A pin
}
void loop(){
if (Serial.available()> 0){ // Send data only when you receive data:
data = Serial.read(); //Read the incoming data & store into data
//Serial.print(data); //Print Value inside data in Serial monitor
//Serial.print("\n");
if(data == "1") // Checks whether value of data is equal to 1
//Motor A forward @ full speed
{
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
digitalWrite(13, HIGH); //Establishes backward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
}
else if(data == "2")
{
//Motor B backward @ half speed
digitalWrite(13, LOW); //Establishes backward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
digitalWrite(12, LOW); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
}
else if(data == "3")
{
//tourner d'un coté
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
digitalWrite(13, LOW); //Establishes backward direction of Channel B
digitalWrite(8, HIGH); //Disengage the Brake for Channel B
}
else if(data == "4")
{
//tourner de l'autre coté
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, HIGH); //Disengage the Brake for Channel A
digitalWrite(13, LOW); //Establishes backward direction of Channel B
digitalWrite(8, LOW); //Disengage the Brake for Channel B
}
}
}
Someone can help me to do my bluetooth cars ?
Cheers,
LoadzFire