Hello again guys, I'm stuck on creating an app for my Arduino project, basically I'm creating an app in which if a person is in bed (sick) and needs help, just click on the button that is connected to the Arduino and it will call the person via bluetooth communication which will notify the app and the person. I have a problem that I can connect the hm-10 with my application, everything is ok, but when I click on the button on the arduino it does not change color and it does not even want to change its state, but in the arduino terminal it sends it to the application , but still I am not successful . And even if I click on the app button to turn on the led via the app, the led does not light up. In theory it's simple, but I'm having trouble building the app and code. I'm using a BLE HM-10 on an Arduino shield. I already asked my teacher but he doesn't know anything about bluetooth communication lol. You are my last hope for me to finish my course.
I'm using an application and code from this site here: Arduino, HM-10 e App Inventor 2 | Martyn Currey
application blocks:
Arduino code:
#include <AltSoftSerial.h>
AltSoftSerial ASSserial;
// Constants for hardware
const byte LEDPin = 8;
const byte SwitchPin = 7;
// general variables
boolean LED_State = false;
boolean switch_State = false;
boolean oldswitch_State = false;
char c=' ';
void setup()
{
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(FILE);
Serial.print("Uploaded: "); Serial.println(DATE);
Serial.println(" ");
ASSserial.begin(9600);
Serial.println("AltSoftSerial started at 9600");
Serial.println(" ");
pinMode(LEDPin, OUTPUT);
digitalWrite(LEDPin,LOW);
pinMode(SwitchPin, INPUT);
} // void setup()
void loop()
{
checkSwitch();
checkRecievedData();
}
void checkSwitch()
{
// Simple toggle switch function with even simpler debounce.
boolean state1 = digitalRead(SwitchPin); delay(1);
boolean state2 = digitalRead(SwitchPin); delay(1);
boolean state3 = digitalRead(SwitchPin);
if ((state1 == state2) && (state1==state3))
{
switch_State = state1;
if ( (switch_State == HIGH) && (oldswitch_State == LOW) )
{
// toggle LED_State.
LED_State = ! LED_State;
// If LED_State is HIGH then LED needs to be turned on.
if ( LED_State == HIGH)
{
digitalWrite(LEDPin,HIGH); // turn on the LED
ASSserial.print("1" ); // tell the app the LED is now on
Serial.println("Sent - 1");
}
else
{
digitalWrite(LEDPin,LOW); // turn off the LED
ASSserial.print("0"); // tell the app the LED is now off
Serial.println("Sent - 0");
}
}
oldswitch_State = switch_State;
}
}
void checkRecievedData()
{
// Read from the Bluetooth module and turn the LED on and off
if (ASSserial.available())
{
c = ASSserial.read();
Serial.println(c);
// The ascii code for 0 is dec 48
// The ascii code for 1 is dec 49
if ( c== 48) { digitalWrite(LEDPin, LOW); LED_State = LOW; }
if ( c== 49) { digitalWrite(LEDPin, HIGH); LED_State = HIGH; }
}
}
But it's not working, I think the problem is in the arduino code and not in the App