You are viewing an older revision! See the latest version
iX
”general intro"\

Range detector¶
The range detector sends a flag to the hub if it detects anyone crossing the road.

We are using the MB1000 LV‑MaxSonar‑EZ0 ultrasonic rangefinder.
data sheet: http://www.maxbotix.com/documents/MB1000_Datasheet.pdf
| pin numbers | MB1000 pins | mbed pins |
|---|---|---|
| 1 | BW | not connected |
| 2 | PW | not connected |
| 3 | AN | p15 |
| 4 | RX | not connected |
| 5 | TX | not connected |
| 6 | VCC | 3.3V |
| 7 | GND | 0V |
- Ranging
Outputs analog voltage with a scaling factor of (Vcc/512) per inch. 3.3V yields 6.4mV/in. The output is buffered and corresponds to the most recent range data.
- Operating Range
The sensor minimum reported distance is 6-inches (15.2 cm). However, the LV-MaxSonar-EZ will range and report targets to the front sensor face. Large targets closer than 6-inches will typically range as 6-inches.
The sensor saturation distance is 254-inches (6.45 m).
Because of acoustic phase effects in the near field, objects between 6-inches and 20-inches may experience acoustic phase cancellation of the returning waveform resulting in inaccuracies of up to 2-inches. These effects become less prevalent as the target distance increases, and has not been observed past 20-inches (50.8 cm).
- Response
Our designed road width is 20cm. Whenever the range detector detects a target nearer than 20cm, it will send a flag back to the hub telling there is someone crossing the road.
obstruction.cpp
#include "mbed.h"
AnalogIn ranger(p15);
int obstruction_finder()
{
AnalogIn ranger(p15);
float r;
float d;
int obstruction;
r = ranger;
d = r / 0.00084;
if (d < 20) {
obstruction = 1;
} else {
obstruction = 0;
}
return obstruction;
}
Cross counter¶
The Cross counter counts the no. of crosses happen when the red light is on, and display the counting on the TextLCD.
We are using a HD44780 TextLCD.
data sheet: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
| Pin number | TextLCD pins mbed pins | |
| 1 | GND | 0V |
| 2 | VCC | 3.3V |
| 3 | VO | 0V, via 1k resistor |
| 4 | RS | p15 |
| 5 | RW | 0V |
| 6 | E | p16 |
| 7 | D0 | not connected |
| 8 | D1 | not connected |
| 9 | D2 | not connected |
| 10 | D3 | not connected |
| 11 | D4 | p17 |
| 12 | D5 | p18 |
| 13 | D6 | p19 |
| 14 | D7 | p20 |
The counter will receive a flag from the hub whenever there is someone crossing the road during a red light. We do a for loop, so the counter will keep checking the input flag and increment by one when the flag is high.
Buzzer and traffic light¶
traffic light introduction?

- include "mbed.h" PwmOut buzzer(p23);
<<code buzzer.cpp>>
red light float frequency[]= {500,0,500,0,500,0,500,0,500,0} ;alarm frequency array
float beat[]= {1,1,1,1,1,1,1,1,1,1}; beat array int main() { while (1) { for ( int i=0; i<=9 ; i++) {buzzer.period(1/(frequency[i])); PMW period 1/frequency buzzer=0.5; 50% duty cycle wait(0.5*beat[i]); hold for beat period } } }
yellow light
while (flag = 2);
{ float frequency[]= {659,554,659,554,550,494,554,587,494,659,554,440}; music frequency array
float beat[]= {1,1,1,1,1,0.5,0.5,1,1,1,1,2}; beat array int main() { while (1) { for ( int i=0; i<=11; i++) {buzzer.period(1/(frequency[i])); PMW period 1/frequency buzzer=0.5; 50% duty cycle wait(0.5*beat[i]); hold for beat period } } } }
green light
while (flag = 3);
{
int main() {
buzzer.period_ms(1); 1ms period 1k Hz
buzzer = 0; 0% duty cycle
}
<</code>>
"photo here"
The reactions of Buzzer is according to 4 statements of traffic light.
"introduction of PWM and duty cycle"


VOICE 3
“voice 3 code"
VOICE 1
“voice 1 code here”
This voice is for the red light and quick yellow light (from green to red).
VOICE 2
“