i got something wrong in my code i do want to control a dc motor to both directions and stop it and with the servos keep changing their degreees all of this cotrolling it by an app that i created in mit inventor even tho the code seems ok is not since the servos and motor dont react move etc even tho the i wrote all the commands that the bluettooth has to receive to convert into serial to make my motors work id really know what i have wrong mb the serial signal of both of them are interfering idk
this is my code
/*Project Code*/
#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include<Servo.h>
Servo RightServo;
Servo LeftServo;
int command;
int bluetoothTx =10; // bluetooth tx to 10 pin (TO TX
int bluetoothRx =11; // bluetooth rx to 11 pin TO RX
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
int ForwardMotorPin = 3;
int BackwardMotorPin = 4;
int enablePin = 5;
int flag=0;
void setup () {
/* SERVO MOTORS */
RightServo.attach(8);
LeftServo.attach(9);
/*DC Motor Driver or L293D IC*/
pinMode(ForwardMotorPin, OUTPUT); //This sets the output pins
pinMode(BackwardMotorPin, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);
Serial.begin(9600); //Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop() {
command = Serial.read();
/* Servo motors Code */
if(command>=1 && command <=360) //Rightservo move according to the thumb position on the mob app between 0 -- 360 . (this for the slider)
{
RightServo.write(command);
}
else if (command == 205) //LeftServo Move To Angle 0
{
LeftServo.write(0);
}
else if (command == 206) //LeftServo movw to angle 90
{
LeftServo.write(90);
}
else if (command == 207) //LeftServo move to angle 120
{
LeftServo.write(120);
}
else if (command == 208) //LeftServo movw to angle 60
{
LeftServo.write(60);
}
/* DC Motor Code */
/*if some date is sent, reads it and saves in command*/
if(Serial.available() > 0){
flag=0;
// if the command is 'S' the DC motor will turn off //
if (command == 'S') {
digitalWrite(ForwardMotorPin, LOW); // set pin 2 on L293D low
digitalWrite(BackwardMotorPin, LOW); // set pin 7 on L293D low
if(flag == 0){
Serial.println("Motor: off");
flag=1;
}
}
// if the command is 'F' the motor will turn right
else if (command == 'F') {
digitalWrite(ForwardMotorPin, LOW); // set pin 2 on L293D low
digitalWrite(BackwardMotorPin, HIGH); // set pin 7 on L293D high
if(flag == 0){
Serial.println("Motor: Forward");
flag=1;
}
}
// if the command is 'B' the motor will turn left
else if (command == 'B') {
digitalWrite(ForwardMotorPin, HIGH); // set pin 2 on L293D high
digitalWrite(BackwardMotorPin, LOW); // set pin 7 on L293D low
if(flag == 0){
Serial.println("Motor: Backwards");
flag=1;
}
}
}
}
this is the link of the MIT INVENTOR APP
http://ai2.appinventor.mit.edu/?locale=en#5532662565044224 if u r interested i checked that already but i dont see either where i gto wrong