Hi everyone,
Im trying to control a servo using arduino,Bluetooth & Android.
I have the silver sparkfun's moudle, and the android app- "arduino bluetooth controller".
When i press any key at the android this is the result:
numbers close to 255
this is the code:
int data = 0;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup()
{
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission
pinMode(10, OUTPUT);
myservo.attach(13);
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{
data = Serial.read(); //Read the incoming data and store it into variable data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n"); //New line
if(data == 'J') { //Checks whether value of data is equal to 1
digitalWrite(10, HIGH);
myservo.write(80);
delay(500);
myservo.write(155);
delay(300);
myservo.write(100);
}
else { //Checks whether value of data is equal to 0
digitalWrite(10, LOW);
myservo.write(100);
}
}
}
I tried changing int to char, but than i get only empty squares at the serial monitor...
What's wrong with the code?
Thanx
if(data == 'J') { //Checks whether value of data is equal to 1
The comment is just plain stupid.
Put the Android away. Put the bluetooth device away. Open the serial monitor. Send the same data using the Serial Monitor application that you think the Android is sending. If the Arduino does not behave properly, Then show us what you sent and what you got back. If it does, then the problem is that the Android is not sending what you think it is.
yeah don't mind the comments..I copied it with the coed.
Open the serial monitor. Send the same data using the Serial Monitor application that you think the Android is sending
So if i write in the Serial monitor, it will be like the android sent it?
I've changed 1 to J at:
if(data == 'J')
because i found out that if I type on the android "hhhhhh" (6 times h), the serial monitor will somtime shows J, and than the led/servo is on...But i want somthing pricise and not somtimes...
So if i write in the Serial monitor, it will be like the android sent it?
Not necessarily. That is what you need to determine.
Typing "hhhhhh" on the Android, should be no different from typing "h" 6 times. Of course, a picture of an Android is next to useless in terms of solving the problem.
What do u mean "what the Android is doing"? I didnt do anything special with it - just download an APP > paired it with to BT moudle> and now trying to press on buttons/keyboard at the APP, the arduino is getting the data from the android (the TX/RX led on the arduino is blinking when i send somthing from the app) but not what i type, just wierd symbols at the serial monitor
Sorry, but i'm new to arduino communicating with other devices, I do appricate your patiens
So, it seems that the Android app and the Arduino are communicating, using the hardware serial pins, via bluetooth, at some baud rate. The Arduino and the PC are communicating, also using the hardware serial pins, at some baud rate. Somewhere, there is a disconnect concerning what the proper baud rate is.
Typical baud rates for bluetooth devices are 115200 and 38400. What is the rate for your device?
What rate do you have the Serial Monitor app set at?
I tried to use almost all the baud rates at the arduino code, specially 115200 (recommended by sparkfun)' and i changed the serial monitor according to the code.
About the App, how can I know? there is no setting for it - only to pair a device and keyboard/pin on/off options...
Hi every Arduino lover ,
i have i big problem tring to configure on AT mode my HC-05 modem through linux IDE,but none terminal shows normal ascii results.The connections on pins are ok.but serial monitor or any other linux terminal (...minicom..) does not react well.What can i do? Baud is ok 38400.
When i finish with AT configuration(,BIND,NAME,ROLE,CMODE),can i reprogram the arduino with new program?And configuration will stay? Just only i disconnect the 34 pin(key)? HC-05 seems to be slave mode (CMODE=0),is it standard from factory? The HC-06 can not communicate with HC-05.