This is one of the DIY examples we can do for the internet of things, and the one I implemented in my home. The objective was to make a light turn on or off, and having a radio switch sending the ON or OFF command through the air.

There are many reasons why anybody would want to do something like this. Mine was that I a garage, a corridor, and some stairs in between with lights on them. I have movement sensors both in the garage and the corridor (because both the garage and the corridor have their respective lights), but I needed to have the lights from the stairs to turn on from BOTH the movement sensors. Instead of running 220v cables through the walls from both movement sensors, I've connected both movement sensors with zigbee-enabled radios hooked up to arduinos, and the zigbee coordinator right by the lights to be turned on at the stairs. With this, these lights turn on from both directions (coming down to the garage, or going up from it).

The devices I used was the CC2530 radios from Texas Instruments. In the picture above we can see the arduino Uno used, as well as the radio transceiver coupled onto its development board. This transceiver has a range of 1.5km (if I remember correctly) in straight line, so I pretty much love the range. This ends up being the reason for doing this with Zigbee and not with other enabling communication technologies like Bluetooth or Wifi. We can see better the radio in the following picture:

There are many ways we could approach the problem with this hardware. We do not need to deploy the hardware on sight with the development board, but you can choose to do so (I wanted to save this board for future developments). Another design choice of yours is whether to simply bypass the arduino altogether and develop the entire code for the microcontroller CC2530. I did both options, but I ended up choosing this one. The vendor of this chip provides some code examples for you to deploy with IAR workbench with 8051 addon (the family of the processor of CC2530), and it brings binaries of firmware for you to directly deploy into the devices (containing either the zigbee coordinator or the zigbee router profiles). I developed the code in IAR, deployed it, and even though I could bypass the use of another microcontroller in this (hence less hardware and energy spent), the problem of buying hardware from China is that the development board is not the same as of Texas Instruments. Because of that, all the examples of Z-Stack provided by TI for this Chip do not suffice, and Therefore I prefer deploying another microcontroller and have the transceiver behaving as expected, rather than having things not working and not knowing exactly why.

The receptor, turning on/off the light, with the zigbee coordinator profile:

In the above picture I am using the CC2530 without the development board, a 5v relay to act on the lights (turn them on or off), and a power transformer (step down voltage from 220v to 5v), provided that we are powering the circuit with the main current and not with batteries. These are the commands sent by the sender/switch, which gives the commands:

The sender, the switch giving the commands to the light receptor, with the zigbee router profile:

For you to understand the switch, and why the choice of electronic components I did, I have to clarify some things. First, I want the arduino and CC2530 to be permanently turned on, but I want to have the command being sent with a current coming from a 220v wire provenient from a movement sensor:

So, I have two considerations right here. The first one is that I need to have a power step transformer (step down from 220v AC to 5v DC). The second thing is that because I have to have two power transformers (one for arduino + CC2530, another for 220v signal control), the base line (ground) will likely not be the same, and because of that, the arduino will misbehave when receiving (or not) this electrical 5v+ signal. Arduino needs to have the same 0 or 5 volts coming from the same energy source with the same ground. To solve this second issue, I chose to apply a relay, with a transistor and a resistor (and that is what you see two pictures above, for the sender):

(PIN 2 is the control pin I used in the arduino to read whether the light should be turned on or not). The GND and VCC from the picture are the 220v coming from the main power, which originate from the movement sensor. The transistor used is the BC547 NPN bipolar, coupled with a 10K ohm resistor. Basically what this does is whenever the relay is powered on by the movement sensor, the arduino receives 5v control signal that it understands (regulated by itself). Now soldered, outside the breadboard :) :