ESP32 read VT pin on HT12D

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;
    }
  }
}

So you have connected both an LED and pin 36 to the VT pin? How did you wire this exactly?

Also, the pullup is probably not needed, but I did not read the datasheet of the HT12D.

When an r is available when this snippet is executed, it will not be detected. Likewise an a may not be detected when the buffer contains ra. You would be better off putting the result of SerialBT.read() in a variable first and then do the tests.

Try...

  if (SerialBT.available()) {
    char received = SerialBT.read();
    
    if (received == 'a') {
      armed = !armed;
    }

    if (received == 'r') {
      alarm_ = false;
    }
  }

sorry for late reply. thanks guys this is very helpful!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.