Parts Page
Peripherals
Input:
Ultrasonic Sensor: detect vehicle's speed
Output:
Motor: control the trap door
LED Traffic Light: periodic signal controlled by RTC
8 * 8 LED Matrix: traffic light signal countdown (I2C)
Buzzer: set off an alarm
Termite: print the detailed speeding / running red light information
Software Structure
Plan
Again, this is for a simple one-way, one-lane scenario, the software structure might change if we moved on to a more complex traffic system, but the general idea should be the same.
The LEDs on board should be periodically lit up in the sequence of green-yellow-red, and the distance sensor should monitor the position of incoming vehicles constantly.
Runnin Red Light Detection
Let's say that the distance interval of the crossroad is from X1 to X2, when LED is on red, no vehicle should be in that distance interval, meaning that the readings from the distance sensor should not fall in that interval. If it does, then it means that the vehicle is running a red light. The buzzer and camera then should be triggered to ring an alarm and take a photo.
Speeding Detection
The speed is calculated from the distance sensor reading, by the equation distance/time. And if a certain threshold speed limit is exceeded, the buzzer and camera then should be triggered to ring an alarm and take a photo. (depending on the position/angle of the placement of the distance sensor, the distance value might not be the original reading, some experiment trials are required to figure out the exact procedure.)
Peripherals Configuration
8 * 8 LED Matrix (I2C Config & Library functions implementation)
Ultrasonic Sensor
Traffic Light (periodic signal)
RTC (set off an alarm every second)
UART
Motor
Traffic Light & RTC & 8 * 8 LED Matrix
The periodic LED traffic light signal is configured using RTC, which sets off an alarm every second. A counter is incremented every second and controls the traffic light timing (6 seconds green -- 2 seconds yellow -- 6 seconds red). We use this to display a countdown for each light on our 8 * 8 LED matrix using I2C.
Implementation
If the red light is on:
If the distance detected is less than a threshold:
ring buzzer
open the trap door
send timing information to Termite
Else:
If the speed is greater than a threshold
ring buzzer
open the trap door
send timing and speeding information to Termite
External Pin Connections
PA 3: Ultrasonic Sensor Echo
PB 2: Buzzer
PB 3: L298N (Motor)
PB 6: LED Matrix (I2C Clock)
PB 7: LED Matrix (I2C Data)
PD 5: Termite (UART)
PD 6: Termite (UART)
PE 11: Ultrasonic Sensor Trigger
PE 13: LED Traffic Light (Red)
PE 14: LED Traffic Light (Yellow)
PE 15: LED Traffic Light (Green)
Serial Interface Protocols
UART -- Termite
I2C -- 8*8 LED Matrix