I have followed a tutorial controlling an Arduino uno via the hm-10 Bluetooth module from an android phone, I then changed the uuid to the one for my module. However, when I run the app on evothings, the connect button does not seem to do anything. can anyone guide me towards what I may be doing wrong ?
#include <SoftwareSerial.h>
#define LED_PIN 2
SoftwareSerial mySerial(7, 8); // RX, TX
// Connect HM10 Arduino Uno
// Pin 1/TXD Pin 7
// Pin 2/RXD Pin 8
void setup() {
Serial.begin(9600);
// If the baudrate of the HM-10 module has been updated,
// you may need to change 9600 by another value
// Once you have found the correct baudrate,
// you can update it using AT+BAUDx command
// e.g. AT+BAUD0 for 9600 bauds
mySerial.begin(9600);
}
void loop() {
int c;
if (mySerial.available()) {
c = mySerial.read();
Serial.println("Got input:");
if (c != 0)
{
// Non-zero input means "turn on LED".
Serial.println(" on");
digitalWrite(LED_PIN, HIGH);
}
else
{
// Input value zero means "turn off LED".
Serial.println(" off");
digitalWrite(LED_PIN, LOW);
}
}
}
A few words of commentary, or just friendly chat would be nice.
This does not look right
if (c != 0)
{
// Non-zero input means "turn on LED".
Serial.println(" on");
digitalWrite(LED_PIN, HIGH);
}
else
{
// Input value zero means "turn off LED".
Serial.println(" off");
digitalWrite(LED_PIN, LOW);
}
}
I wonder if you mean
if (c != '0')
in other words the character '0' rather than a byte value of 0. I guess it's possible you are sending the byte value of 0 but it seems unlikely. Debugging is much easier if you send data as human readable characters.