Saturday 21 November 2020

IOT: Traffic Lights with Arduino - Timer

In the previous blog post, I created a pair of traffic lights. I also added a push button for emergency vehicles that activated a RGB LED that blinked (blue/red).

Now, I'll add a LCD display that will show how long the cars/bicycles need to wait for green light.

The LCD Display

The display that I'll use is a monocromatic display that can show two rows with 16 characters each. It has 16 pins and I'll use 12 of them:

  1. GND - Ground/Cathode. 
  2. VCC -  Anode. Connected to the 5V DC pin on the Arduino Uno board
  3. V0 - Controls the contrast of the display. The user controls the display by turning the knob of the potentiometer that is connected to V0.
  4. RS - Register Set. This pin decides whether to write data to the data register or to the instruction register. 
    1. The contents of the data register goes to the screen. 
    2. The instruction register contains instructions about what to write in the near future.
  5. RW - Select reading or writing mode. I connect it to ground, setting the LCD in permanent writing mode.
  6. E - Enable pin. This pin informs the LCD that it will receive data.
  7. D0 - not used in this case. The LCD can receive the data using either 8 data pins (quicker) or using 4 pins (simpler design). In my case, I'll go for simplicity instead of speed.
  8. D1 - not used.
  9. D2 - not used.
  10. D3 - not used.
  11. D4 - Data pin.
  12. D5 - Data pin.
  13. D6 - Data pin.
  14. D7 - Data pin.
  15. LED+ -  Connected to anode using a 220 ohm resistor.
  16. LED- - Connected to ground.

The Physical Connections

The traffic lights to the left will turn green in 14 seconds.

I had to re-wire the existing LEDs a bit to make the LCD fit to the breadboard. I also ran out of digital pins so I have used three analog pins to power the right set and one analog pin as an input from the push button. 

The Code

I added code for estimating the remaining time until the left and red set of traffic lights turns green. It takes the time in the current state into account and sums up the remaining states until the light turns green.

In case of emergency, the times will temporarily be set to 99 s.

The code is available here.

Next steps:

I'll bring up the Raspberry PI and connect it to the Arduino board. After that,  I want to send some small messages to the LCD on the arduino board.




No comments:

Post a Comment