Hey guy, I am currently having trouble with my project. I am sending messages between HC-05 and HC-06 bluetooth modules. My code is supposed to control a door strike by sending a one and a zero one being being off and 0 being on, as this is a fail-safe door strike. I have the Door strike in this configuration. Note this is a diagram I followed and the LED is my door strike. My problems is that the door stike is not responding when I press the button on the transmitting end (HC-05) the HC-06 modue is recieving it but the doorstike is not turning off. I supposed it might be might code:
HC-05:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
char c = ‘ ‘;
byte switchPin = 8;
boolean switch_State = HIGH;
boolean oldswitch_State = HIGH;
void setup()
{
Serial.begin(9600);
Serial.println(“Arduino is ready”);
Serial.println(“Remember to select Both NL & CR in the serial monitor”);
BTserial.begin(9600);
}
void loop()
{
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
}
if (Serial.available())
{
c = Serial.read();
BTserial.write(c);
}
boolean state1 = digitalRead(switchPin); delay(1);
boolean state2 = digitalRead(switchPin); delay(1);
boolean state3 = digitalRead(switchPin); delay(1);
if ((state1 == state2) && (state1==state3))
{
switch_State = state1;
if (switch_State != oldswitch_State)
{
if ( switch_State == LOW) { BTserial.print(“1” ); Serial.println(“1”); }
else { BTserial.print(“0” ); Serial.println(“0”); }
oldswitch_State = switch_State;
}
}
}
HC-06: The is where the door strike is connected
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX | TX
char c=’ ‘;
byte LEDpin = 4;
void setup()
{
Serial.begin(9600);
Serial.println(“Enter AT commands:”);
// HC-06 default baud rate is 9600
BTSerial.begin(9600);
pinMode(LEDpin, OUTPUT);
digitalWrite(LEDpin,LOW);
}
void loop()
{
if (BTSerial.available())
{
c = BTSerial.read();
// 49 is the ascii code for “1”
// 48 is the ascii code for “0”
if (c==49) { digitalWrite(LEDpin,LOW); }
if (c==48) { digitalWrite(LEDpin,HIGH); }
Serial.println(c);
}
{
if (BTSerial.available())
Serial.write(BTSerial.read());
if (Serial.available())
BTSerial.write(Serial.read());
}
}
