Hello everyone,
I'm doing a remote control car project for college.
The project consists of:
Remote Control:
1 Bluetooth module to send the information to the car.
2 Joysticks to send signals to the Arduino
Car:
1 Bluetooth module to receive control information;
1 servo motor - move the direction of the car
1 H-Bridge - To receive the Bluetooth signals and send to the motors.
2 Motors - Receives the signals from the H-bridge and starts driving the car.
My problem is in programming.
I can get the servo to move as I wish, but when I try to set the engine motion, I do not succeed.
When I try to send signals to my engine, it simply blends in with the signals from my servo, and ends the servo and the motor being controlled by the 2 Joysticks, instead of each Joystick controlling its due component.
Below is my program.
I went back to square one.
At this point I can control the Servo motor normally.
I just need some help in developing programming to control the engines.
Note: The connections are correct and the communication is perfect, with no delay.
My only problem is to generate the codes to move the motors, without affecting the movement of the servo
I really need help, this project is for Monday 05/13 and I'm panic .....
Master:
int state = 0;
int potValue = 0;
int pot2Value = 0;
void setup() {
Serial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
// Reading the potentiometer
potValue = analogRead(A0);
int potValueMapped = map(potValue, 0, 1023, 0, 255);
Serial.write(potValueMapped); // Sends potValue to servo motor
delay(10);
// Reading the potentiometer 2
pot2Value = analogRead(A1);
Serial.write("{");
Serial.write(pot2Value);
Serial.write("}");
delay(10);
}
Slave:
#include <Servo.h>
Servo myServo;
int motorA = 5; // velocidade motor A - de 0 a 255
int motorB = 6; // velocidade motor B - de 0 a 255
int dirA = 7; // direcao do motor A - HIGH ou LOW
int dirB = 8; // direcao do motor B - HIGH ou LOW
int state = 20;
int pot2Value = 0;
boolean flag_pot2 = false;
void setup() {
pinMode(motorA, OUTPUT);
pinMode(motorB, OUTPUT);
pinMode(dirA, OUTPUT);
pinMode(dirB, OUTPUT);
myServo.attach(9);
Serial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
if(state == "{")
{
flag_pot2 = true;
}
if(flag_pot2 && state != "{")
{
analog2Value = state;
}
else
{
flag_pot2 = false;
}
//Limpa Buffer
state = " ";
}
// Controlling the servo motor
myServo.write(state);
delay(10);
if(pot2Value < 512) {
//Reverso
int velocidade = map(pot2Value, 511, 0, 0, 255);
digitalWrite(dirA, LOW); // SENTIDO DE ROTACAO
digitalWrite(dirB, LOW);
analogWrite(motorA, velocidade); // VELOCIDADE
analogWrite(motorB, velocidade);
} else {
//Frente
int velocidade = map(pot2Value, 512, 1023, 0, 255);
digitalWrite(dirA, HIGH); // SENTIDO DE ROTACAO
digitalWrite(dirB, HIGH);
analogWrite(motorA, velocidade); // VELOCIDADE
analogWrite(motorB, velocidade);
}
}
Please, I really need some help solving this ...
Mestre.ino (655 Bytes)
Escravo.ino (1.46 KB)