The aim of this project is to create an automatic night light IoT LED Strip using the Wia Platform and a Dot One. The Dot One retrieves sunrise and sunset information from your location from the cloud and activates the LED's between those two times at night.
List of items required to create this project:
Wia Dot One (Buy Yours Here)
Dot One TFT LCD Screen Module (Buy Yours Here)
Micro USB Cable (Buy yours here)
Phone- Computer- IRL2203N Mosfet- 10k Ohm Resistor
Jumper Wires
Breadboard
LED Strip
Step 1: Create a Wia account with the Dot One connected. If you haven’t done so yet, you can follow this tutorial over here.
Step 2: Go to this URL, and enter the location where the Sunset Light will be placed. Save the Longitude and Latitude information as we will be needing it later.
Step 3: Open dashboard.wia.io and select your space. Click on the flows Icon. Create a new flow using the blue "Create a Flow" button. Give your flow a name and press the blue button "Create flow".
Step 4: Drag the nodes from the left side of the screen so that they look like this. Link them together according to the image shown.
From the "Trigger" tab select the "Timer" Node.From the "Service" tab select the "HTTP Service" NodeFrom the "Logic" tab select the "Run Function" NodeFrom the "Logic" tab select the "Update State" Node
Step 5:In the Timer Node, select the tickbox beside "Every X Minutes" and from the drop down menu select "Every 15 Minutes".
Step 6:In the "HTTP" Service Node Select "Method" as "GET" and in the URL Paste this URL.
https://api.sunrise-sunset.org/json?lat=XXXXXXXXXX&lng=YYYYYYYYYY&formatted=0
Replace the "XXXXXXXXXX" with your latitude coordinates from Step 2 and the "YYYYYYYYYY" with the Longitude Coordinates. Update the node using the blue boxx.
Step 7:In the "Run Function" Node paste this Code into the code editor:
var startTime_temp = JSON.parse(input.body).results.sunrise;
var endTime_temp = JSON.parse(input.body).results.sunset;
var startTime = startTime_temp.substring(11,19);
var endTime = endTime_temp.substring(11,19);
var currentDate = new Date();
var startDate = new Date(currentDate.getTime());
startDate.setHours(startTime.split(":")[0]);
startDate.setMinutes(startTime.split(":")[1]);
startDate.setSeconds(startTime.split(":")[2]);
var endDate = new Date(currentDate.getTime());
endDate.setHours(endTime.split(":")[0]);
endDate.setMinutes(endTime.split(":")[1]);
endDate.setSeconds(endTime.split(":")[2]);
if (startDate < currentDate && endDate > currentDate)
{
output.body = "Off";
}
else
{
output.body = "On";
}
Step 8:In the "Update State" Node click on the "Update devices from list" and select your device from the list that pops down. In the "Key", type in "LED_Light" and in the value type in "${input.body}". Update the Node by pressing the blue Button.
Step 9:Click on the Code Icon on the left side of the Wia dashboard and Create a Blocks project. Give your project a name and click on "Blocks Project". Copy the blocks so that the code looks like this:
Alternative Method: Click on the Code Icon on the left side of the Wia dashboard and Create a Code project. Give your project a name and click on "Code Project". Copy the code from underneath
#include <WiFi.h>
#include <Wia.h>
Wia wiaClient = Wia();
void setup()
{
WiFi.begin();
delay(2500);
pinMode(15, OUTPUT);
}
void loop()
{
if ((wiaClient.getDeviceState("LED_Light")) == "On")
{
digitalWrite(15, HIGH);
}
if ((wiaClient.getDeviceState("LED_Light")) == "Off")
{
digitalWrite(15, LOW);
}
delay(2500);
}
Step 10:Click on the rocket icon on the top right side of the screen and select your device from the list below. Click on the blue "Deploy" Button. Upload the code by pressing the left button whilst it is turned on to download new code onto it.
Step 11:Connect the Dot One to the LED Strip, Mosfet and resistor as shown
Step 12:Congratuilations!, If wired correctly, you should have a working IoT Enabled Sunset/Sunrise Light
Here's other fun projects you can try out -
Comments