Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Having issues with Arduino + Bluetooth

I am working with a combination of Teensy++ 2.0 and Sparkfun Bluetooth Modem.

The Arduino program, inside the loop, continuously reads a sensor value. If the value read is above a threshold, the Arduino transmits a "CHARACTER" over Bluetooth for any receiver.

So, inside the same loop, I check for the availability of data, and print the received character. The problem is, the received character is not what is transmitted. The received character is some garbage value.

Please let me know what is going wrong here.

#include <SoftwareSerial.h>
#define bluetooth Serial1
#define BAUDRATE 9600
// Analog read 0 is pin 38 
int sensorValue = 0;
int SENSOR_ANALOG_READ_PIN = 0;
int LED = 17;
char toPrint = '0円';
bool sent = false;
char state = ' ';
void setup() 
{
// put your setup code here, to run once:
 pinMode(LED, OUTPUT);
 Serial.begin(BAUDRATE);
 bluetooth.begin(BAUDRATE);
}
void loop() {
 // put your main code here, to run repeatedly:
 sensorValue = analogRead(SENSOR_ANALOG_READ_PIN);
 if(value > 500)
 {
 //Serial.println("HIGH");
 digitalWrite(LED, HIGH);
 bluetooth.write(state);
 bluetooth.flush();
 sent = true;
 digitalWrite(LED, LOW);
 }
 else
 {
 delay(100);
 }
 ///////////////////////////////////////////////////////////
 if((bluetooth.available()) && (sent == true))
 {
 Serial.println("printing : ");
 toPrint = (char)bluetooth.read();
 Serial.println((char)toPrint);
 sent = false;
 }
}

Output:

printing : 
1
printing : 
ˆ
printing : 
Ì
printing : 
¦
printing : 
È
printing : 
Ì
printing : 
Ì
printing : 

Answer*

Draft saved
Draft discarded
Cancel

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /