Go Down

Topic: Problem on bluetooth and dc motor (Read 41 times) previous topic - next topic



Here is my program where i can control a servo and a dc motor, but only the servo is ok,
when i send 2 on my bluetooth nothing happen..

#include <SoftwareSerial.h> // TX RX software library for bluetooth

#include <Servo.h> // servo library
Servo myservo; // servo name

int cmd;
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
int E1 = 5;
int M1 = 4;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
  myservo.attach(9); // attach servo signal wire to pin 9
  //Setup usb serial connection to computer
 pinMode(M1, OUTPUT);
  //Setup Bluetooth serial connection to android

void loop()
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()> 0 ) // receive number from bluetooth
    cmd = bluetooth.read(); // save the received number to servopos
    Serial.println(cmd); // serial print servopos current number received from bluetooth
    myservo.write(cmd); // roate the servo the angle received from the android app
     if(cmd == '2')            //Checks whether value of Incoming_value is equal to 1
      analogWrite(E1, 255);
    if(cmd == '0')       //Checks whether value of Incoming_value is equal to 0
       analogWrite(E1, 0); 

Go Up