Author Topic: Arduino Bluetooth  (Read 3237 times)

0 Members and 1 Guest are viewing this topic.

Offline BrownTopic starter

  • Contributor
  • Posts: 45
Arduino Bluetooth
« on: March 09, 2014, 08:33:26 pm »
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 Inventor
When my Arduino code request a "1" I have to sent a "49" in App Inventor
When my Arduino code request a "2" I have to sent a "50" in App Inventor
When my Arduino code request a "3" I have to sent a "51" in App Inventor
When my Arduino code request a "4" I have to sent a "52" in App Inventor
When my Arduino code request a "5" I have to sent a "53" in App Inventor
and so on

Why can't I send a "1" in App Inv. and request a "1" in Arduino. Is there some sort of conversion?
Thanks

Code:

#include <SoftwareSerial.h>

SoftwareSerial Brown(10, 11); // RX  TX
int 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);
}
 

Offline jancumps

  • Supporter
  • ****
  • Posts: 1272
  • Country: be
  • New Low
Re: Arduino Bluetooth
« Reply #1 on: March 09, 2014, 08:54:25 pm »
Hi,

You are getting the ascii value.

http://www.asciitable.com/

Check if you can use itoa()
« Last Edit: March 09, 2014, 08:56:41 pm by jancumps »
 

Offline BrownTopic starter

  • Contributor
  • Posts: 45
Re: Arduino Bluetooth
« Reply #2 on: March 09, 2014, 08:59:27 pm »
Ohhhh, Thanks! Thank you so much!
 

Offline jancumps

  • Supporter
  • ****
  • Posts: 1272
  • Country: be
  • New Low
Re: Arduino Bluetooth
« Reply #3 on: March 09, 2014, 09:06:27 pm »
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.
« Last Edit: March 09, 2014, 09:22:08 pm by jancumps »
 

Offline BrownTopic starter

  • Contributor
  • Posts: 45
Re: Arduino Bluetooth
« Reply #4 on: March 09, 2014, 09:48:20 pm »
Thanks, do you also know a way to send data from arduino to android using App Inv. ?
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Arduino Bluetooth
« Reply #5 on: March 09, 2014, 10:39:35 pm »
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.
 

Offline kolonelkadat

  • Regular Contributor
  • *
  • Posts: 202
  • Country: us
  • Obviously, windows are central to Windows.
    • Force Project X
Re: Arduino Bluetooth
« Reply #6 on: March 09, 2014, 10:50:51 pm »
lol the first answer was SO close to being right

look at your code
Code: [Select]
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 number

the correct code would be
Code: [Select]
if(BluetoothData == 0){   
 

Offline BrownTopic starter

  • Contributor
  • Posts: 45
Re: Arduino Bluetooth
« Reply #7 on: March 10, 2014, 01:06:47 am »
Thank you Kolonelkadat, Zapta, and Jancumps

Zapta I tried Brown.read but it didn't work then I thought of Brown.write and it WORKED.

Thanks you guys!
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Arduino Bluetooth
« Reply #8 on: March 10, 2014, 05:16:18 am »
Thank you Kolonelkadat, Zapta, and Jancumps

Zapta I tried Brown.read but it didn't work then I thought of Brown.write and it WORKED.

Thanks you guys!

Oops, I meant 'write' since you already use 'read' in the other direction. I am glad that you figured it yourself.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf