How many times you have you accidentally left your home lights turned on? That's why we figured out how to design an automatic system that can shut off (and turn on) your lights depending on the daylight.
The system works with a light sensor will be responsible for detecting the amount and clarity of daylight. If the sensor detects daylight, will turn off your house light and raises the blinds; If the sensor detects that there is no light, will turns on the light and lowers the blinds. Also, using Ubidots you can turn on or off an extra light whenever you want.
It's very simple to make, and more importantly, helps you save energy.
This post explains how to use the NodeMcu with Ubidots. NodeMcu is an Internet of Things (IoT) device with GPIO, PWM, IIC, 1-Wire, and ADC all in one board, and it has Wi-Fi connection. It's easy to use and you just need the Arduino IDE to learn to program it.
1. First, couple the NodeMcu to its base shield and then connect the components.
Base Shield Pins
Relay D3 LED D5 Light Sensor A0 Servomotor
- Yellow Wire - D8
- Red Wire - 3.3 V
- Black Wire - GND
It should look like this:
2. Go to the Arduino IDE, click on Files --> Preferences and enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into the "Additional Board Manager URLs" field. You can add multiple URLs, separating them with commas.
3. Open "Boards Manager" from Tools --> Board menu and install the esp8266 platform. Don’t forget to select your NodeMCU 1.0 board from the menu after installation.
4. Download the UbidotsESPMQTT library if you haven't already. Now, click on Sketch --> Include Library --> Add .ZIP Library
5. Select the .ZIP file of Ubidots ESPMQTT and then “Accept” or “Choose” for all libraries. If you can't add the library, try manually: unzip the downloaded rar / zip and copy the folder from the library to the path C:\Users\ubidots\Documents\Arduino\libraries.
6. Close the Arduino IDE and open it again.
1. Add a new Data Source called "manual" and a new Variable called "extra_light" (as seen below).
2. Verify that the name of the Data Source and Variable is the same as their API Lables. This is important because our variable will be subscribed through the API Label and it allows the communication between Ubidots and the NodeMcu. After you verified the Data Source and Variable labels, you can edit their name with just one click.
3. Create the switch that allows you turn the light on or off. To do this, go to Dashboard and in the upper right of the page, click Add widget. Select Control --> Switch --> manual (data source) --> light(variable) --> finish.
Once everything is connected correctly, we will go to the IDE and write the following code:
After flashing your code, go to Ubidots and refresh the page. You will see the new Data Source "control" created.
If you want to check the state of the blinds or light you can build your dashboard as you desire. If you don't know how, check this tutorial.
We've just shown you how to design a light control based on the Internet of Things, which proves how seemingly complex things can be done very easily with the right tools.