Street Light Parking Aid

by Nebulous in Circuits > Microcontrollers

31 Views, 0 Favorites, 0 Comments

Street Light Parking Aid

Capture.PNG
WhatsApp Image 2024-06-01 at 11.27.21 AM(1).jpeg
WhatsApp Image 2024-06-01 at 11.27.21 AM.jpeg
WhatsApp Image 2024-06-01 at 11.27.21 AM(3).jpeg
WhatsApp Image 2024-06-01 at 11.27.21 AM(5).jpeg
WhatsApp Image 2024-06-01 at 11.27.20 AM(1).jpeg
WhatsApp Image 2024-06-01 at 11.27.20 AM.jpeg
WhatsApp Image 2024-06-01 at 11.27.21 AM(2).jpeg
WhatsApp Image 2024-06-01 at 11.27.21 AM(4).jpeg
WhatsApp Image 2024-06-01 at 11.27.21 AM(6).jpeg
WhatsApp Image 2024-06-01 at 11.27.21 AM(7).jpeg
WhatsApp Image 2024-06-01 at 11.27.22 AM(1).jpeg
WhatsApp Image 2024-06-01 at 11.27.22 AM.jpeg

My brother came to me one day and asked if I could take an old street light he had and turn it into a parking sensor that he can mount in his garage for him and his wife. Without ever messing around with Arduino, or coding for that matter - I said yes, of course! Not knowing what I would be diving into, I made several iterations and many many code changes as I came across bugs in the way I wanted this to operate. Low and behold, we have a fully functional Street Light that will Monitor 2 parking spaces and will go from Green -> Yellow/Orange -> Red based on the distance your car is from the sensor to help you park perfectly every time... Tennis ball on a string is so last century.

Supplies

Tinkcad website is how I learned, and tested code before buying parts, highly recommended!


I ended up using the following:

  • Arduino nano
  • nano terminal adapter IO Shield (breakout board)
  • TF-Luna Lidar sensor x2
  • SainSmart 5v 2-channel SSR G3MB-202P
  • Various Wago connectors and generic lever wire connectors,
  • 120vac to 12vdc converter to power the arduino.
  • 22awg solid core for arduino wiring
  • 14awg for 120v wiring
  • HC-SR04 sensors ( ended up replacing for Lidar sensors)
  • wire strippers.

Downloads

Trial and Error

First I designed this solution around using the HC-SR04 Sonar sensors. This was great for learning, and the biggest hurdle for me was taking a distance measurement sensor and turning it into a Motion detector. (new to coding) The reason for this was that I wanted to the Lights to turn off if there was no movement detected after 10 seconds, which would indicate that the car had stopped. After being introduced to the concept of min-max values - i ended up using them to determine if the readings on the sonar sensor were the same over a period of time to achieve this goal. What I learned along the way however, is that Sound waves reflect differently off different types of materials, and I could not for the life of me get accurate repeatable values off of the HC-SR04 sensors. Due to this reason, I purchased 2 Lidar TF-Luna sensors for roughly $25 a piece to replace the sonar sensors.. This is what really made the project come to life, because of the accuracy of these sensors!


If anyone is using the HC-SR04 sensors, and would like it adapted to this project, let me know and I can provide the project file I used before what I currently linked, however the above is my reason why i chose NOT to use them. They are ultra cheap so why not, i get it.

The Wiring

Please reference the attached pictures. Definitely not an electrician, dont do as I say, dont trust me - I take my own risks, you take yours! Here's a brief write up of what I did though if you're interested.


There are 3 bays in the streetlight, 1 for each light. First I started by wiring up all the neutral wires to a 5 port wago. 3 ports I used for the lights, 1 port for the 120v->12vdc converter i used to power the arduino and the last port was for the negative wire on a 2-wire extension cord. In the pictures that is 2 black, 3 white on the 5-port wago.


I then connected the 120v positive to a wago that connected up to the 120v->12vdc converter, and branched off to power each of the 3 dual-port relays. Each relay is daisy-chained into itself for the important reason that(look at the code) either car in this 2-car parking sensor can activate the lights( more on this later).


Once the relays were wired up, it was now time to hook up the arduino nano. with the 22awg wire, I used 2 greens for the green relay(1 wire per sensor) , 2 yellow for what I called the orange relay, and 2 red wires for the red relay. all blacks lead back to ground.

I used 2x Blue/Yellow pairs + 2x red/black pairs to wire up the 2 Lidar sensors that are terminated with the lever-wire connectors. This allowed me to have them removed, so I could re-wire them once the unit is installed in its final resting place. every other red/black pair was to power the relays.

The Code

After learning about using millis(), I broke each part of my code into independently timed functions in void loop(). I ended up settling on using 250ms for the timing on everything except the sensor reads. The different between using the HC-SR04 and the Lidar sensors is that the lidar sensors require serial ports to communicate, and the HC-SR04 use the normal outputs read as HIGH or LOW. The nano has only 1 serial port, so i found that using the standard SoftwareSerial library along with AltSoftSerial library for a virtual serial port allowed me to use any standard digital output as the second serial port for Lidar sensor #2. awesome! this wasn't the easiest thing to stumble onto.


Each light control has 2 relays, 1 per sensors, and in the code this is represented in void setup() where I've defined them each as an output.


Everything below is duplicated to work the same on both sensors. After final installation, we can adjust the distance settings below per parking spot!


The first part of the arduino program is to take measurements of from the lidar sensor, and this happens extremely fast.

then, after every 250ms, we record these values to a variable $distance. We use this to determine if our object(car in this case) is within range of the pre-defined measurement values( in centimeters) . For my testing, I kept these at a reasonable:

int MinimumDist = 30;

int RedLightDist = 100;

int OrangeLightDist = 206;

int GreenLightDist = 325;


Each quarter second, we store the recorded distance measurement in an array that stores data for 10 seconds.... or in this case, 40 1/4 seconds to equal 10 seconds.

Based on this last 10 seconds of distance data in the array, we then take the minimum distance, and maximum distance and see if they are equal to eachother( with 4cm margin or error) or, are they different?

We can deduce that if they are the same, then there is no movement. But if they are not the same, then our object we are measuring distance on must have moved!

If there is movement, (the motion detection part I talked about in the intro) then lets go ahead and activate our light relays based on those distance measurements.... Once we detect that the last 10 seconds of recorded measurements are the same, then we will turn off the relays, and turn the lights off. Otherwise if we leave the range that we set, in this case, less than 30cm or greater than 325cm - then we disable the lights are reset everything.

All the details are in the functions below the void loop() program for how to control the lights, and the logic there with motion & range.

Seeing It in Action

Downloads