Recently, I purchased an Arduino Uno from Maplins (a UK electronic store). when I first got in, I simply experimented with LEDs. l then realised that I could make level crossing lights. The idea is that, when you press a button, a yellow light come on for a couple of seconds. Then, I have two red LEDs which come alternately. For example, when the left LED is turned on, the right LED is turned off.
In case you haven’t realised or simply don’t know, I live in the united Kingdom. The normal operating sequence of a level crossing is that a yellow light and siren will come on for a couple of seconds. After that, both the siren and the yellow lights switch off. The two red lights will start flashing alternately whilst barriers lower to block the road. Once they are down, the red lights lights continue to flash. Once the train has one past, the barriers raise and the red lights stop flashing.
The wiring for the lights was fairly straight forward, I simply wired each LED to a 220 ohm resistor (to to protect my Arduino board) I connected each end of the LED (which was not connected to a resistor) to Ground. The end with a resistor was connected to a digital pin on my Arduino. I connected the LEDs to pins 4, 5 and 11. Below is a picture of what the circuit looks like on the breadboard.
As you can see, I have wired all of my ground connections to the ground rail on my breadboard. I then wired the ground rail to my Arduino ground pin. I did this to not only save Arduino pins but also to make the circuit easy to modify in the future.
In terms of writing the code, I basically used a sketch build into the Arduino IDE called ‘blink’. I added extra lines of code and changed the delays.
Here is a youtube video of it in operation. Please note, the lights currently flash continuously until either power is removed from the board or the reset button is pressed.
The next step was to hook up a button. I followed the tutorial on the Arduino.cc website. However, I did not have the correct resistor. The tutorial said that I need a 10K ohm resistor. However, I had to use a 1K ohm resistor as this was the closest to the required resistor that I had. After quite a bit of trial and error, I managed to get the circuit to work. I then implemented the button into my level crossing lights code. Again, I used parts of the button example code, which is built into the Arduino IDE, in my level crossing code. So far I have set it up so that when you hold down the button the red lights start flashing alternately. I have defined a ‘method’ in my Arduino sketch that switches the left LED on for a short amount of time. It then switches off and then the same happens to my right LED.
I am still working on getting the button to work. I will do another blog post so watch this space.