- Регистрация
- 1 Мар 2015
- Сообщения
- 6,375
- Баллы
- 155
With Halloween approaching, I had some fun 3D-printing my own pumpkin to put on display at night (see cover image!).
The pumpkin itself was very nice, so I bought some IR remote controlled led tealights to give it the glow for some additional spooky amusement.
The original idea was to just use a tealight led to light up without messing around with circuitry but I ended up putting it in the Cloud using Azure IoTHub.
Tools
Understanding how to control the candle with IR
In order to control the tealight led, we have to know the command to send and we have to know, in fact, which commands the remote is sending to light and shut off the candle.
For this step an Esp8266 would do the trick: it ensures compatibility with Arduino-IRRemote, a library to interact with IR emitter and receivers.
The following circuit connects an IR receiver to the board and allows to read IR data from pin D5:
The following snippet of code decodes IR commands and prints them on the serial monitor:
When pressing “on” and “off” buttons on the remote control, the library prints all the data received, along with the code to use to send the same command from an IR emitter:
21:32:55.011 -> received
21:32:55.011 -> FE01FF00
21:32:55.011 -> Protocol=NEC Address=0x0 Command=0x1 Raw-Data=0xFE01FF00 32 bits LSB first
21:32:55.142 -> Send with: IrSender.sendNEC(0x0, 0x1, <numberOfRepeats>);
21:32:55.174 -> received
21:32:55.208 -> 0
21:32:55.208 -> Protocol=NEC Address=0x0 Command=0x1 Repeat gap=39700us
21:32:55.274 -> received
21:32:55.274 -> 0
21:32:55.274 -> Protocol=NEC Address=0x0 Command=0x1 Repeat gap=96600us
21:33:01.148 -> received
21:33:01.148 -> FF00FF00
21:33:01.148 -> Protocol=NEC Address=0x0 Command=0x0 Raw-Data=0xFF00FF00 32 bits LSB first
21:33:01.246 -> Send with: IrSender.sendNEC(0x0, 0x0, <numberOfRepeats>);
21:33:01.609 -> received
21:33:01.609 -> 0
21:33:01.609 -> Protocol=UNKNOWN Hash=0x0 1 bits (incl. gap and start) received
In this case, we have to use the statement:
IrSender.sendNEC(0x0, 0x1, <numberOfRepeats>);
to light the candle and the statement:
IrSender.sendNEC(0x0, 0x0, <numberOfRepeats>);
to turn it off.
This part of the circuit can be unwired now (since it’s not going to be useful anymore) and we will integrate those commands in a script to control it through the microcontroller first and the from Cloud.
Controlling the candle, programmatically
It’s now time to setup the circuit to emit an IR signal: as per the following schema, the data will be sent controlling D6 pin.
To test the circuit, we can use serial communication to control the led emitter with a simple command interpreter:
Putting the pumpkin in the Cloud
To put the pumpkin in the Cloud we can use Azure IoTHub.
Azure IoT Hub is a managed cloud service allowing bidirectional communication: cloud to device and device to cloud.
Just to play, we can add a free-tier level service IoTHub service and then add a device:
Here I added a device called “esp8266” and so I obtained a key to establish a bidirectional cloud-device communication.
After configuring our IoTHub resources, we must take note of the following parameters (e.g. from Azure Portal):
Wi-Fi connection parameters are also required.
To send message to the Cloud we can adapt the following example sketch:
We can prepare a command interpreter:
Then we can adapt the callback for received messages:
At this point we can use Azure Portal IoTHub interface to communicate with the device:
The pumpkin itself was very nice, so I bought some IR remote controlled led tealights to give it the glow for some additional spooky amusement.
The original idea was to just use a tealight led to light up without messing around with circuitry but I ended up putting it in the Cloud using Azure IoTHub.
Tools
- IR remote controlled tea light led
- IR receiver
- IR emitter (AZDelivery KY-005)
- Esp8266
- Jumper cables
Understanding how to control the candle with IR
In order to control the tealight led, we have to know the command to send and we have to know, in fact, which commands the remote is sending to light and shut off the candle.
For this step an Esp8266 would do the trick: it ensures compatibility with Arduino-IRRemote, a library to interact with IR emitter and receivers.
The following circuit connects an IR receiver to the board and allows to read IR data from pin D5:
The following snippet of code decodes IR commands and prints them on the serial monitor:
When pressing “on” and “off” buttons on the remote control, the library prints all the data received, along with the code to use to send the same command from an IR emitter:
21:32:55.011 -> received
21:32:55.011 -> FE01FF00
21:32:55.011 -> Protocol=NEC Address=0x0 Command=0x1 Raw-Data=0xFE01FF00 32 bits LSB first
21:32:55.142 -> Send with: IrSender.sendNEC(0x0, 0x1, <numberOfRepeats>);
21:32:55.174 -> received
21:32:55.208 -> 0
21:32:55.208 -> Protocol=NEC Address=0x0 Command=0x1 Repeat gap=39700us
21:32:55.274 -> received
21:32:55.274 -> 0
21:32:55.274 -> Protocol=NEC Address=0x0 Command=0x1 Repeat gap=96600us
21:33:01.148 -> received
21:33:01.148 -> FF00FF00
21:33:01.148 -> Protocol=NEC Address=0x0 Command=0x0 Raw-Data=0xFF00FF00 32 bits LSB first
21:33:01.246 -> Send with: IrSender.sendNEC(0x0, 0x0, <numberOfRepeats>);
21:33:01.609 -> received
21:33:01.609 -> 0
21:33:01.609 -> Protocol=UNKNOWN Hash=0x0 1 bits (incl. gap and start) received
In this case, we have to use the statement:
IrSender.sendNEC(0x0, 0x1, <numberOfRepeats>);
to light the candle and the statement:
IrSender.sendNEC(0x0, 0x0, <numberOfRepeats>);
to turn it off.
This part of the circuit can be unwired now (since it’s not going to be useful anymore) and we will integrate those commands in a script to control it through the microcontroller first and the from Cloud.
Controlling the candle, programmatically
It’s now time to setup the circuit to emit an IR signal: as per the following schema, the data will be sent controlling D6 pin.
To test the circuit, we can use serial communication to control the led emitter with a simple command interpreter:
Putting the pumpkin in the Cloud
To put the pumpkin in the Cloud we can use Azure IoTHub.
Azure IoT Hub is a managed cloud service allowing bidirectional communication: cloud to device and device to cloud.
Just to play, we can add a free-tier level service IoTHub service and then add a device:
Here I added a device called “esp8266” and so I obtained a key to establish a bidirectional cloud-device communication.
After configuring our IoTHub resources, we must take note of the following parameters (e.g. from Azure Portal):
Wi-Fi connection parameters are also required.
To send message to the Cloud we can adapt the following example sketch:
We can prepare a command interpreter:
Then we can adapt the callback for received messages:
At this point we can use Azure Portal IoTHub interface to communicate with the device: