So far I'm putting together a robot that I can control with my android phone. Thus far I've been able to somehow manage to write a code and I can control the robot wirelessly.
I am coming to you all to work out some kinks in the programming to make the operation very fluid.
In the code below I am only controlling the arduino's ability to control 2 led's by either as numeric or alphabetic signal sent from my phone.
int val = 0; // variable
#include <SoftwareSerial.h>
#define RxD 6
#define TxD 7
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(13, OUTPUT);
setupBlueToothConnection();
}
void loop()
{
char recvChar;
while(1){
if(blueToothSerial.available() > 0){
{int val = blueToothSerial.read(); }//check if there's any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar);
{recvChar = Serial.read();}
{val = blueToothSerial.read();}
// read value coming in from phone
if(isDigit(val));{ //
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);}
}
}}
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=Bluebot\r\n"); //set the bluetooth name as "Bluebot"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("Bluebot is ready for your command!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
Hardware
Arduino Duemilanove AtMega 328
Bluetooth shield from trossen robotics http://www.seeedstudio.com/wiki/index.php?title=Bluetooth_Shield
1 LEDs
Android Phone (T-mobile g2)
Application on phone: Bluetooth SPP <- Great app by the way!
Here is what I WANT it to do.
- When LED command is received as a numeric digit...turn on LED attached to 13
- Do not turn on upon receiving any kind of signal that is not numeric
Here is what it is doing right now
- Turns LED on no matter what signal is sent from phone.