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 :