I am building security system and I have the RF signal working (the transmitter in the sensors sends a message through a HT12E and the control box receives it through HT12D) and I have LED wired to VT (valid transmission) pin. However, I have been trying to get my esp32 to read this value to trigger an alert. This is my code that doesn't seem to be working:
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
int red = 5;
int buzzer = 23;
int rf_in = 36;
int rf_state = LOW;
bool armed = false;
bool alarm_ = false;
unsigned long previousMillisRed = 0;
const long interval = 1000;
void setup() {
SerialBT.begin("Security Control Box");
Serial.begin(9600);
pinMode(red, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(rf_in, INPUT_PULLUP);
digitalWrite(red, LOW);
digitalWrite(buzzer, LOW);
}
void loop() {
rf_state = digitalRead(rf_in);
if (rf_state == HIGH && armed) {
alarm_ = true;
} else {
digitalWrite(buzzer, LOW);
if (armed) {
digitalWrite(red, HIGH);
} else {
digitalWrite(red, LOW);
}
}
if (alarm_) {
unsigned long currentMillisRed = millis();
if (currentMillisRed - previousMillisRed >= interval) {
previousMillisRed = currentMillisRed;
digitalWrite(red, !digitalRead(red));
digitalWrite(buzzer, HIGH);
}
}
if (SerialBT.available()) {
if (SerialBT.read() == 'a') {
armed = !armed;
}
if (SerialBT.read() == 'r') {
alarm_ = false;
}
}
}