Go Down

Topic: HT12E for a pushbutton (Read 408 times) previous topic - next topic

Zjokkeh

Hi,

First off all I say hello because I am new to this community. I live in Belgium, so if I make a mistake in my english, please forgive me.

The question:

I recently bought a house with an existing home automation system. I would like to replace that system with arduino because it is more versatile. All the lights in my house are controled by pushbuttons. The pushbuttons are wired in a loop with an "id block from 1-20" per button. The wireing is done in UTP cat 5e cable. The system uses only 1 pair. I was thinking that I could replace the id's with an HT12E ic per button and read the date with arduino. Would this be possible? Or is there anyone else with a better idea?

Tnx,

Zjokkeh (Joris)

Zjokkeh

Hi, me again.

I bought some HT12E's and tested the wireing. It works fine. So my test setup is now 3 HT12E's connected to an arduino uno with 125m of utp cable.

Ik read in the binary code and use dec to compair. I allready made a toggle switch to put a light on or off. That works fine alltough it could be better. I just have problems with the momentary switch code. It stays on. Normally it should go on when button pushed and held, and go off when u stop pushing the button. But it won't go off.

Code: [Select]
#include <HT12E.h>
 
HT12E remoteControl(7, B00000000); /* the incoming stream is tied to pin 7, and the address mask is the binary 01111111 */
 
const int ledPin1 = 8;
const int ledPin2 = 9;
const int ledPin3 = 10;
int state1 = LOW;
int state3 = LOW;
int data;
 
void setup()
{
 Serial.begin(9600);
 pinMode (ledPin1,OUTPUT);
 pinMode (ledPin2,OUTPUT);
 pinMode (ledPin3,OUTPUT);
}
 
void loop()
{
 
    if (remoteControl.available() > 0)
      {
        data = 0;
        Serial.println("Test");
        Serial.println(data);
        data = remoteControl.read();
        Serial.println("I have just received the following data stream: ");
        Serial.println(data);
      }
 
    else
      {
        switch (remoteControl.error())
          {
              case 0:
                  break;
              case 1:
                  Serial.println("Failure when waiting for a pilot stream");
                  break;
              case 2:
                  Serial.println("Failure when waiting for sync bit to go away");
                  break;
              case 4:
                  Serial.println("Failure when waiting for a data stream");
                  break;
              case 8:
                  Serial.println("Data mask does not match predefined address mask");
                  break;
              default:
                  Serial.println("Unknown error occurred");
              break;
          }
      }
 
 
 
     if (data == 4078)
        {
          if (state1 == LOW)
            {
            state1 = HIGH;
            digitalWrite(ledPin1,state1);
            delay(500);         
            }
          else
            {
            state1 = LOW;
            digitalWrite(ledPin1,state1);
            delay(500);
            }
        }
 
      if (data == 2043)
        {
          if (state3 == LOW)
            {
            state3 = HIGH;
            digitalWrite(ledPin3,state3);
            delay(500);         
            }
          else
            {
            state3 = LOW;
            digitalWrite(ledPin3,state3);
            delay(500);
            }
        }
 
 
 
 
 
      if (data == 4077)
        {
         digitalWrite(ledPin2,HIGH);
 
        }
      else
        {
         digitalWrite(ledPin2,LOW); 
 
        }
 
 
 
  Serial.println("Test2");
  Serial.println(data);
 
}

Go Up