Chat freely about anything...

User avatar
By Rajendra Khope
#79265 I have this 433 Mhz remote with 12 key using PT2264 and having universal receiver module to decode signal from this remote. Receiver module output in TX pin with 9600 baud rate. It send data after receiving from remote as REMOTE_ID:KEY_NUMBER. for example after pressing key 1 from remote I get #AAAA:01 this as data.

Problem is that it does not send any data if pressed once. Instead we have to keep remote key pressed to transmit key code. This creates a burst of continuous data for that key in format #AAAA:01.

Now my problem is I want to interface this remote to ESP8266 and toggle a http resource. I understand this very typical setup, but i need it this way. My problem is how to detect multiple same key as one event on serial so that if it happens again I can achieve the toggle action.

So in short i want to toggle a resource upon pressing switch on remote.

Hardware setup is simple: Ive attached 433Mhx receiver modules TX pin to ESP8266's D13 and using SoftwareSerial to read data. Currently I get :

Code: Select all#AAAA:01#AAAA:01#AAAA:01#AAAA:01#AAAA:01#AAAA:01#AAAA:01#AAAA:01#AAAA:01#AAAA:01

I want it only to detect as one #AAAA:01 but if pressed again after few seconds its second #AAAA:01 with which we can toggle some variable.

code is simple.
Code: Select all#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 14, false, 256);//RX, TX
String readString; //main captured String

int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed
int ledState = 0; //this variable tracks the state of the LED, negative if off, positive if on

long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 10;    // the debounce time; increase if the output flickers
const byte interruptPin = 13;
void setup() {
  pinMode(interruptPin, INPUT_PULLUP);
  Serial.begin(9600);
  mySerial.begin(9600);

}

void loop() {
  if (mySerial.available())  {
    char c = mySerial.read();  //gets one byte from serial buffer
    if (c == '#') {
      //do stuff

      int ind1 = readString.indexOf(':');
      String id = readString.substring(0, ind1);
      String key = readString.substring(ind1 + 1);


      Serial.println(id);

      if (id == "AAAA") {
        Serial.println(millis());
        if ((millis() - lastDebounceTime) > 50 ) {
          //lastDebounceTime = millis();
          Serial.println("key Pressed: ");
          Serial.println(key);
        }
      }
      readString = ""; //clears variable for new input
      id = "";
      key = "";

    }
    else {
      readString += c; //makes the string readString
    }
  }
}

I tried debauching like code with millis() but it did not work.