
APPENDIX C 413
RFID–to-X10 translator
Language: Arduino
Reads RFID tags and sends X10 messages in response to
the tags.
// include the X10 library files:
#include <x10.h>
#include <x10constants.h>
#define zcPin 9 // the zero crossing detect pin
#define dataPin 8 // the X10 data out pin
#define repeatTimes 1 // how many times to repeat each X10 message
// in an electrically noisy environment, you
// can set this higher.
#define tagLength 10 // each tag ID contains 10 bytes
#define startByte 0x0A // for the ID Innovations reader, use 0x02
#define endByte 0x0D // for the ID Innovations reader, use 0x03
#define dataRate 2400 // for the ID Innovations reader, use 9600
// set up a new x10 library instance:
x10 myHouse = x10(zcPin, dataPin);
char tagID[tagLength]; // array to hold the tag you read
int tagIndex = 0; // counter for number of bytes read
int tagComplete = false; // whether the whole tag's been read
char tagOne[] = "0415AB6FB7"; // put the values for your tags here
char tagTwo[] = "0415AB5DAF";
char lastTag = 0; // value of the last tag read
void setup() {
Serial.begin(dataRate); // begin serial.
// Turn off all lights:
myHouse.write(A, ALL_LIGHTS_OFF,repeatTimes);
}
void loop() {
// read in and parse serial data:
if (Serial.available() > 0) {
readByte(