In connection with the planned transition to continious integration and reading a couple of articles on traffic lights in the office, I also wanted to have such a warm lamp device. As a result, it turned out not at all warm and not lamp, but more on that later.
Who was interested in this topic, already knows that the price of a new traffic light hovers around $ 500. Attempts to find a second-hand decommissioned device have not been successful. Both options could not please the budget and the soul of two enthusiasts from the office, so it was decided to make the traffic light myself.
Idea
In principle, there is nothing difficult in the construction of a traffic light, but no layout was made. So it was easier to imagine what you need to cut and how best to do it. ')
Before doing the layout on one of the sites with ads, we were lucky to find glass from the Soviet traffic light. This was a great relief, as the original glass as nothing better than give the design authenticity. Accordingly, the size of the case was dictated by the size of the glass, as well as the size of the internal components such as power supplies, wiring, etc.
The main “brain” was designated raspberry pi for several reasons. The first is its presence after previous experiments with the “raspberry”, the second is the simplicity of implementing the control of the traffic light from the outside, installing various kinds of software, wifi, etc.
Housing
It all began of course with the case. For its manufacture was used PVC plastic which is used for the manufacture of outdoor advertising. It is very easy to handle and, in combination with a super glue on the exit, gives a fairly solid construction. Plastic with cutting of appropriate sizes was ordered at an advertising agency. The cutting accuracy was a little worse than expected, so after gluing the body, we had to work fairly with plastic putty and emery. The result was such a body.
Plastic was so pliable that it was easier to make visors than anyone could have imagined. The cut parts of the visors were thrown into boiling water, and then bent about a two-liter jar before cooling. Yes, yes, the diameter of a two-liter cans was the same as the glass. That was the unification in the USSR!
For the time being, simply by attaching the glass one could already clearly see the future traffic light, although even at the stage of the hull it seemed that nothing good could come of this idea.
After painting in black "traffic light" color, everything began to look even more wonderful. Also masking cords were glued to cover the fasteners of the glasses and make the structure more complete.
Electronics
For the sake of safety, reducing energy consumption and a number of other reasons, LEDs were chosen as the light source. Only 27 pieces, 9 per color. For them, 27 holes were drilled in the housing, respectively.
For the convenience of repair and installation of LEDs, they were placed on plastic matrices with placement coinciding with the holes in the housing.
They are easily installed and removed in case one of the LEDs burns out. To control the logic, GPIO pins on raspberry pi are used, respectively, as a control logic, a board was made with three 3V controlled relays and 12V switching voltages, which are fed to LED arrays.
At the testing stage before the final build, everything looked like this.
Everything is “abandoned” in the case and attached a temporary power cord for 220V since there was not a sufficiently long cord at hand at the time of assembly. Inside there are also two power supplies. One 12V for power LEDs, the second unit with a USB port for raspberry pi.
Software
For ease of control from the outside, a lighttpd server was installed with mod_fcgi for python. Thus, the mode can be controlled simply from the browser. So it was convenient to indulge yourself. Later for Jenkins was written code that polls it and accordingly changes the status of the traffic light. Python, on the other hand, was not chosen by chance, it is quite easy to cope with managing GPIO pins on raspberry using the wiringpi.com library set .
Simple web script code for management, which was later replaced with the one described above.
#!/usr/bin/pythonRoot # Bring in the libraries import RPi.GPIO as G from flup.server.fcgi import WSGIServer import sys, urlparse, time # GPIO lights map light_r = 4 light_y = 17 light_g = 22 # Set up our GPIO pins G.setmode(G.BCM) G.setup(light_r, G.OUT) G.setup(light_y, G.OUT) G.setup(light_g, G.OUT) # Offs all lights def offLights(): G.output(light_r, False) G.output(light_y, False) G.output(light_g, False) # Function which is called for each http request we receive def app(environ, start_response): # start our http response start_response("200 OK", [("Content-Type", "text/html")]) # look for inputs on the URL i = urlparse.parse_qs(environ["QUERY_STRING"]) yield (' ') # flup expects a string to be returned from this function # if there's a url variable named 'q' if "mode" in i: if i["mode"][0] == "red": offLights() G.output(light_r, True) elif i["mode"][0] == "yellow": offLights() G.output(light_y, True) elif i["mode"][0] == "green": offLights() G.output(light_g, True) elif i["mode"][0] == "off": offLights() #Run app WSGIServer(app).run()
Expenses
About a week of work of two people went to everything, an hour a day after work. For the money:
Raspberry Pi model B
$ 50
PVC plastic for housing with cutting
$ 15
Matt black paint
$ 10
Power supplies
$ 10
Relays, LEDs and other trifles
$ 10
Wifi whistle for raspberry
$ 10
Glasses
$ 7
Putty
$ 5
Total: $ 117
Conclusion
Let's start with the video work in demo mode.
As can be seen from the video, the cold glow of the LEDs in combination with our glass gave a bluish tint. Now we are considering options for correction, the benefit of maintainability was incorporated into our design. Agree to the difference in the budget is enormous, the enthusiasm is satisfied and the result is more than satisfactory. As a result, though not a warm lamp, but a cold LED, but still a traffic light, which in the near future I hope will fulfill its purpose. The transition to continious integration is not yet complete.
Good luck to everyone, and fewer red on the build-traffic lights!