Hardware Reference
In-Depth Information
This sketch reads
incoming tags and
checks them against a list of tags in
memory. When it sees a tag it knows,
it checks the status of an X10 lamp or
appliance module that corresponds to
that tag, and then changes the status.
Refine It
/*
RFID Tag checker
Context: Arduino
*/
// include the X10 and softwareSerial library files:
#include <x10.h>
#include <SoftwareSerial.h>
The global variables are the X10 pin
and SoftwareSerial pin numbers, the
number of tags being used, and a
bunch of arrays for the tag IDs, unit
names, and unit states.
const int x10ZeroCrossing = 2; // x10 zero crossing pin
const int x10Tx = 3; // x10 transmit pin
const int x10Rx = 4; // x10 receive pin (not used)
const int rfidRx = 7; // rfid receive pin
const int rfidTx = 8; // rfid transmit pin (not used)
int numTags = 2; // how many tags in your list
The setup() method initializes serial,
software serial, and X10, then sends an
ALL LIGHTS OFF code to reset all the
remote X10 units.
String currentTag; // String to hold the tag you're reading
// lists of tags, unit names, and unit states:
String tag[] = {
"10000CDFF7","0F00AD72B5"};
int unit[] = {
UNIT_1, UNIT_2};
int unitState[] = {
OFF, OFF};
SoftwareSerial rfid(rfidRx,rfidTx);
void setup() {
// begin serial:
Serial.begin(9600);
rfid.begin(9600);
// begin x10:
x10.begin(x10Tx, x10Rx,x10ZeroCrossing);
// Turn off all lights:
x10.beginTransmission(A);
x10.write(ALL_LIGHTS_OFF);
x10.endTransmission();
}
The loop() method just checks
for new serial bytes from the RFID
reader. The real work is left to a pair of
other methods.
8
void loop() {
// read in and parse serial data:
if (rfid.available()) {
readByte();
}
}
 
Search WWH ::




Custom Search