Actually am working with X10 protocol. My idea is send X10 commands with a PSC05 and Arduino Uno and in other room receive those X10 commands with other PSC05 and other Arduino Uno and with this one connect TV, Lamp, etc.
My problem is that I sent commands like: A5 or whatever command and ever sent and receive the same command when I check the debug:
SC-1111 HouseCode-74 UnitCode-13 CMND-31
This is my code and I hope that someone help me please:
Transmissor X10 Source Code:
#include <x10.h>
#include <x10constants.h>
#define zcPin 2
#define dataPin 3
x10 myHouse = x10(zcPin, dataPin);
void setup() {
Serial.begin(9600);
digitalWrite(zcPin,HIGH);
pinMode(13,OUTPUT);
}
void loop() {
Serial.println("House A Code 5 ON:");//Print action
myHouse.write(HOUSE_A,UNIT_5,1);//Sent A5 command once
myHouse.write(HOUSE_A, ON,1);//Sent turn on A5
myHouse.debug();
digitalWrite(13,HIGH);//Turn on the LED in pin 13 for know if a X10 command is written
delay(500);//A little blink for LED in pin 13
digitalWrite(13,LOW);//Turn off the LED in pin 13
delay(4000);
Serial.println("House A Code 5 OFF:");//Print action
myHouse.write(HOUSE_A,UNIT_5,1);//Sent A5 command once
myHouse.write(HOUSE_A,OFF,1);//Sent turn off A5
myHouse.debug();
digitalWrite(13,HIGH);//Turn on the LED in pin 13 for know if a X10 command is written
delay(500); //A little blink for LED in pin 13
digitalWrite(13,LOW);//Turn off the LED in pin 13
delay(2000); //Delay for sent a new X10 command again
}
Receive X10 Source Code:
#include <x10.h>
#include <x10constants.h>
#define ZCROSS_PIN 2 // BLK pin 1 of PSC05
#define RCVE_PIN 4 // GRN pin 3 of PSC05
#define TRANS_PIN 5 // YEL pin 4 of PSC05
#define LED_PIN 13 // for testing
x10 SX10= x10(ZCROSS_PIN,TRANS_PIN,RCVE_PIN,LED_PIN);// set up a x10 library instance:
void setup() {
Serial.begin(9600);
delay(500);
Serial.print("x10 receive/send test");
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
digitalWrite(2,HIGH);
digitalWrite(4,HIGH);
}
void loop(){
if (SX10.received()) { // received a new command
SX10.debug(); // print out the received command
SX10.reset();
if (SX10.houseCode() == 'A' && SX10.unitCode() == 5 ){
byte cmndCode = SX10.cmndCode();
if(cmndCode == ON) {
digitalWrite(13,HIGH);
delay(3000);
digitalWrite(13,LOW);
delay(500);
}
else if(cmndCode == OFF)
{
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
delay(500);
}
}
}
}