I want to create an automatic lamp using Zigbee and two Arduino Uno development boards. The idea is that one of the Arduinos will be placed at the door, with a HC-SR04 ultrasonic sensor attached to it. Another Arduino will be positioned at the lamp. When I walk into the room, the ultrasonic sensor measures this, and the Arduino uses the XBee module to send a message to the other module. When this module receives the message, it will turn on the light.For this, I will need:

Item Amount
Arduino Uno 2
Zigbee S2C module 2
Phillips Hue bulb 1
HC-SR04 ultrasonic sensor 1

After doing some research, I wrote down some notes on configuring the S2C modules. I also found an article describing how Philips Hue lights work, and found out it's quite a hassle trying to control a single Hue light with just Zigbee, so I chose to replace the Hue light with a normal light bulb connected to a relay.

I first configured the modules through XCTU using this link, and verified that they could see eachother. I configured the S2C module at the door to be an end point, and the module at the lamp will be the coordinator. This is because the coordinator will always be on, so it makes sense to put it next to a device that will also always be connected to power, which is the lamp.

After that, I configured the modules and connected each of them to an Arduino Uno, using an Arudino XBee shield. After that, I used the Arduino XBee library to set up a simple communication between the modules, to verify that they could talk to eachother through the Arduinos. You can see a video of it here. When I connect the coordinator, the end point connects to it and you can see that the messages are being sent and received by the orange LED of the end point blinking, and the red LED of the coordinator blinking.

After that, I connected the HC-SR04 to the end point (left) and the relay to the coordinator (right):

arduinos

The pin connection is as follows:

End point HC-SR04
3V3 VCC
7 Echo
6 Trig
GND GND
Coordinator Relay
5V VCC
5 IN
GND GND

After verifying the code for the ultrasonic sensor works (video (You can see that the zigbee nodule sends a message when the ultrasonic sensor senses a small distance.)), I put the two sensors in their locations: the end point at the door:

and the coordinator at the lamp:

You can see the lamp working in this video. I also added a button with a pull-down resistor to pin 2 to turn the lamp off. All the code is available in the library, for the coordinator and the end point.