Arduino Bluetooth - Page 1
Forum section: electronics / beginners

author: Brown
author_rank: Contributor
timestamp: March 09, 2014, 08:33:26 pm
content: So I was playing around with the HC-05 BT module and MIT App Inventer 2. I'm trying to make Arduino Pins toggle HIGH/LOW.When my Arduino code request a "0" I have to sent a "48" in App InventorWhen my Arduino code request a "1" I have to sent a "49" in App InventorWhen my Arduino code request a "2" I have to sent a "50" in App InventorWhen my Arduino code request a "3" I have to sent a "51" in App InventorWhen my Arduino code request a "4" I have to sent a "52" in App InventorWhen my Arduino code request a "5" I have to sent a "53" in App Inventorand so onWhy can't I send a "1" in App Inv. and request a "1" in Arduino. Is there some sort of conversion?ThanksCode:#include <SoftwareSerial.h>SoftwareSerial Brown(10, 11); // RX TXint ledpin=13;int BluetoothData;void setup() {Brown.begin(9600);Brown.println("Bluetooth On please press 1 or 0 blink LED ..");pinMode(ledpin,OUTPUT);}void loop() {if (Brown.available()){BluetoothData=Brown.read();if(BluetoothData=='0'){digitalWrite(ledpin,1);Brown.println("LED On D13 ON ! ");}if (BluetoothData=='1'){digitalWrite(ledpin,0);Brown.println("LED On D13 Off ! ");}}delay(100);}

author: jancumps
author_rank: Unknown
timestamp: March 09, 2014, 08:54:25 pm
content: Hi,You are getting the ascii value.http://www.asciitable.com/Check if you can use itoa()

author: Brown
author_rank: Contributor
timestamp: March 09, 2014, 08:59:27 pm
content: Ohhhh, Thanks! Thank you so much!

author: jancumps
author_rank: Unknown
timestamp: March 09, 2014, 09:06:27 pm
content: The example sketch Strings - CharacterAnalysis shows how to interprete different types of input.And don't use the itoa() suggestion from me above. It is num to string.

author: Brown
author_rank: Contributor
timestamp: March 09, 2014, 09:48:20 pm
content: Thanks, do you also know a way to send data from arduino to android using App Inv. ?

author: zapta
author_rank: Super Contributor
timestamp: March 09, 2014, 10:39:35 pm
content: I am not familiar with app inventor but probably you send data in the opposite direction just the same.Try something like Brown.read("1") and see if you can read the serial data on the android side.BTW, you can also try to debug it from a computer with bluetooth adapter. Pair with the arduino bt and see if you can access the bt/spp port on the computer with a terminal program. This way you will see what the arduino sends and you can type back commands.

author: kolonelkadat
author_rank: Regular Contributor
timestamp: March 09, 2014, 10:50:51 pm
content: lol the first answer was SO close to being rightlook at your codeCode:if(BluetoothData=='0'){'0'means the char value of 0 which is 48(0x30)if you want the integer value for 0 (0x0) then do NOT use the single quotes around the numberthe correct code would beCode:if(BluetoothData == 0){

author: Brown
author_rank: Contributor
timestamp: March 10, 2014, 01:06:47 am
content: Thank you Kolonelkadat, Zapta, and JancumpsZapta I tried Brown.read but it didn't work then I thought of Brown.write and it WORKED.Thanks you guys!

author: zapta
author_rank: Super Contributor
timestamp: March 10, 2014, 05:16:18 am
content: Quote from: Brown on March 10, 2014, 01:06:47 amOops, I meant 'write' since you already use 'read' in the other direction. I am glad that you figured it yourself.