Introduction: UCL-lloT-Outdoor-light Triggered by Sunrise/sundown.

Hello everyone!

With a bit work, some parts and code I've put together this instructable that will show you from start to end exactly how to produce this outdoor light. The idea originated from my father, whom during the summer had to manually go out and change when the light was on from. With the rapidly changing sundown and sunrise times all year around, he asked if I could find an automated way to do it.

And so we are here. A relatively small project.

Step 1: IO List and What You'll Need.

Arduino MEGA 2560. It is what I've used at least, I know that you could easily use another.

DS3231 and it's library. ( http://rinkydinkelectronics.com/library.php?id=73... It's important to know that the pins set for SDA and SCL are different depending on which Arduino you are using.

I052116 IR Infrared Motion Detector Sensor Module. This particular module can be exchanged for your sensor of choice, it's honestly optional to the whole thing.

Step 2: Flowchart.

As seen in the simple flowchart, much of the heavy lifting resides in Node-Red. With relatively simple nodes, the idea is that from Node-Red you'll reach out to a website that knows what time the sun sets and rises. Once it has it, it'll send the information on to the Arduino telling it. From the Arduino we will get a signal that indicates precisely when the Lights are actually on, so that you may check from your home just when the lights burn away.
It's also from the Arduino we'll get information that the proximity sensor has been activated, which has the light turn on for x amount of time.

Step 3: Fritzing.

Compared to other projects the cabling is rather simple here. What you need to be aware of is that you'll need a WIFI module to keep contact with the Node-Red server, or get a throw-away computer to host the Node-Red server on that is connected to the Arduino. Not shown on the picture is the connection between Arduino and Laptop, and I apologize on beforehand for the poor Fritzing picture!

Step 4: Coding.

If there's one thing I found is that with Firmata (for Arduino communication with Node-Red), the DS3231 library and more, there was a lot of loaded libraries. As of being published, the coding is not quite done, so pseudo-code is included.

Included in the library from the DS3231 is preset pins for each of the Arduino boards, and in the case of the Mega it's pin 20 and 21 as they are the SDA and SCL pins on the mega. Once hooked up, the clock can be told exactly what day it is, and what it should be keeping track of. What I found to be easier to work with when it comes to keep track of numbers, is using int instead of string. So what I've done is that I convert the numbers of a string into int, but as int can't use : to separate a clock, I decided to do something else instead.
Instead of working with hours, we'll be working with minutes. Lots of minutes.

If the clock is 13:21 for example, I'll have the first two digits separated and timed with sixty. We are now at 801 minutes, as 13 times 60 equals 780 and you add the last 21 minutes. If our Node-Red says the sun goes down at 16:58 (in case of winter), we get the outdoor lights to turn on between 1018 minutes and a pre-defined shut-off time, which will be 1380 (23:00). If our timer is between those, the lights turn on.

The above math is basicly the entire program, without the steps of getting Node-Red to connect to the Arduino and communicate. Also having a sensor that makes sure the lights turn on (Past sun-down, anyway) will be used, but otherwise that is the entire program above.

Step 5: Node-Red.

Not a particularly big flow, not that it needs to be in this case.
The first 2 rows of nodes are the big part of the program. Using a GET function, we retrieve todays forecast on how the sun will rise and set. From there we use a CSS selector to retrieve our specific information, usually accessed on a websites "Inspect Elements" on a firefox as indicated on the pictures. Do note, that not all websites work this way and the one I use happen to work perfectly this way. From there it'll write information to pin 13 because that is what I've designated it to be, though testing is yet to dictate if one pin getting to different times is workable.

As described in the coding part, information will come from the Arduino to Node-Red, where it will then indicate on an accessable website where one can easily check it.

You'll be needing Firmata for this if you desire to use the Arduino functions acquired through the node-red-node-arduino library on Node-Red. Though not entirely set up yet, and it will be updated as I finish the project, I've attached the code for the Node-Red Flow in a text document for easy access.

Step 6: Deployment and Use.

And to finish off our instructable, is the practical part of it. With few houses having this level of automatic light, an all-year around solution is welcome with many houseowners. To actually connect this with lamps using electricity that isen't an Arduino, I do not recommend doing it yourself unless you know exactly what you're doing. With the project over, I'll be taking on this task with the aid of an electrician just to be sure.

Lighting up your driveway by sensor or strictly time-wise, I recommend that you build upon what I've done already if you mean to actually put it to use beyond this test-phase it is currently in. Most of my trouble with the project was strictly in the Node-Red to Arduino part, and I hope I've managed to explain as plainly as possible how that is done.