In this post I will provide step by step instructions to turn on a light, switch or any device with an RFID reader and SmartThings.
I will try to make it as simple as I can but please leave a comment if think that anything needs clarification.
On the Arduino side:
- Connect the Arduino and the SmartThings Arduino Shield
- Connect the SL030 RFID:
- A4/SDA to Pin 3 on the RFID board
- A5/SCL to Pin 4 on the RFID board
- GND to Pin 6 on the RFID board
- 3V3 to Pin 1 on the RFID board
- Flash the following code to the Arduino
Note: It requires SmartThings’ Arduino Library and the RFID Reader Library
You can download the SmartThings Arduino Library here
You can download the RFID Reader Library here
For more information about installing Arduino libraries see http://arduino.cc/en/Guide/Libraries
/** * Arduino to SL030 wiring: * A4/SDA 3 * A5/SCL 4 * 5V - * GND 6 * 3V3 1 */ #include <Wire.h> #include <SL018.h> #include <SmartThingsL.h> #define PIN_THING_RX 3 #define PIN_THING_TX 2 SmartThingsCallout_t messageCallout; // call out function forward decalaration SmartThings smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout); // constructor SL018 rfid; void setup() { Wire.begin(); Serial.begin(2400); // setup serial with a baud rate of 9600 while (!Serial); //for the leonardo // prompt for tag Serial.println("Waiting..."); } void loop() { // start seek mode rfid.seekTag(); // wait until tag detected while(!rfid.available()); //Serial.print("ID: "); //Serial.println(rfid.getTagString()); delay(1000); smartthing.send(rfid.getTagString()); } void messageCallout(String message) { }
Now on SmartThings:
- Log in to SmartThings IDE
- Go to “My Device Type” and click on “+New SmartDevice”
- In the following page click on tab “From code” and paste the code below
/** * RFID Reader * * Author: juano23@gmail.com * Date: 2013-09-06 */ // for the UI metadata { // Automatically generated. Make future change here. definition (name: "RFID Reader", author: "juano23@gmail.com") { capability "Refresh" attribute "RFID", "string" attribute "VISUALID", "string" } // Simulator metadata simulator { // status messages status "ping": "catchall: 0104 0000 01 01 0040 00 6A67 00 00 0000 0A 00 0A70696E67" status "hello": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A48656c6c6f20576f726c6421" } // UI tile definitions tiles { valueTile("RFID", "device.RFID", width: 0, height: 0) {} standardTile("OUT", "device.OUT", width: 3, height: 1, canChangeIcon: false, canChangeBackground: false, inactiveLabel: false) { state "Waiting...", label: 'RFID', unit: "ID", icon: "st.contact.contact.closed" } standardTile("VISUALID", "device.VISUALID", width: 3, height: 1, canChangeIcon: false, canChangeBackground: false, inactiveLabel: false, decoration: "flat") { state "Waiting...", label: '${currentValue}', unit: "ID" } main "OUT" details "VISUALID" } } // Parse incoming device messages to generate events def parse(String description) { def value = zigbee.parse(description)?.text log.debug "Parse returned $value" sendEvent(name:"VISUALID", value: value) sendEvent(name:"RFID", value: value) sendEvent(name:"RFID", value: 'waiting...') }
- Go to “My Devices” and click on “+New Device”
- Create the Device type with the following values
- Name: Smart RFID
- Device Network Id: 2323
- Type: Smart RFID
Restart the App and you should be able to see the new device 🙂
To test the integration you use this Smart App
- Go to “MySmartApps” and click on “+New SmartApp”
- In the following page click on tab “From code” and paste the code below
/** * Turn On When RFID * * Author: Juan Pablo Risso */ // Automatically generated. Make future change here. definition( name: "Turn On When RFID", namespace: "", author: "juano23@gmail.com", description: "If the RFID id is listed as authorized it will open the selected door", category: "My Apps", iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png") preferences { section("Read the RFID tag here..."){ input "id", "device.RfidReader", title: "Where?" } section("And if the ID match..."){ input "allow", "text", title: "ID?" } section("Turn on light(s)..."){ input "switches", "capability.switch", multiple: true } } def installed() { subscribe(id, "RFID", RFIDHandler) } def updated() { unsubscribe() subscribe(id, "RFID", RFIDHandler) } def RFIDHandler(evt) { log.debug "$evt.name: $evt.value" if (evt.value == allow) { log.debug "Turning on lights..." switches.on() } else { log.debug "This is not an authorized ID!" } }
If you like to collaborate please contact me at juano23@gmail.com