Introduction:
Since this project is an add-on of current traffic light system and this project consists of two parts that will be installed in different locations in an intersection, we are adding a wireless communication part between two parts. We only need one-way data transmission, which is from the crosswalk to the traffic light area. In this project, we are using RF 433MHz Transmitter/Receiver Module to transmit the data.
Description and specifications:
The 433MHz transceiver/receiver modules are used on a wide variety of applications that require wireless control. These modules are very cheap and you can use them with any microcontroller (MCU), whether it’s an Arduino, ESP8266, or ESP32.
433MHz Transmitter Receiver Module Kit
Receiver:
Product Model: MX-05V
Frequency Range: 433.92MHz
Input Voltage: DC5V
Receiver sensitivity: -105DB
External antenna: 32cm single core wire, wound into a spriral
Transmitter:
Product Model: MX-FS-03V
Launch Distance: 20 – 200 meters ( different voltage, different results)
Operating Voltage: 3.5-12V
Transfer Rate: 4 kb/s
Transmitting Power: 10mW
Transmitting Frequency: 433.92MHz
External Antenna: 25cm ordinary multi-core or single-core line
Parts List:
Arduino Uno * 2
433MHz Transmitter * 1
433MHz Receiver * 1
Breadboard * 2
LED *2
Resistor 330Ω *2
Jumper Wire * n
Installing the RadioHead Library:
The RadioHead library provides an easy way to work with the 433 MHz receiver/transmitter. Follow the next steps to install that library in the Arduino IDE:
1.Click here to download the RadioHead library. You should have a .zip folder in your Downloads folder.
2.Unzip the RadioHead library.
3.Move the RadioHead library folder to the Arduino IDE installation libraries folder.
4.Restart your Arduino IDE
Wire:
Connection of Receiver(Source)
Connection of Transmitter(Source)
Wiring of two boards:
Code:
Running this code separately can be hard without other parts, since I am only concentrating on the data transmitting. Also, the scripts require two boards working together but currently I only have one(my teammates are still using their boards). I wrote two separate scripts for the board.
The transmitter part:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
/* * Tutorial * 433 MHz RF Module Transmitter Demonstration * Connect DATA pin to pin 12 in Arduino Uno * Connect GND pin to pin GND in Arduino Uno * Connect VCC pin to pin 5V in Arduino Uno * We can also use antenna to enhance the strengh of the signal */ // Include RadioHead Amplitude Shift Keying Library #include <RH_ASK.h> // Include Serial Peripheral Interface Library #include <SPI.h> // Create ASK object RH_AKS sl_driver; const int SmartCrossPin = 13; void setup() { // Create a pin that responds to illegal crossing pinMode(SmartCrossPin, OUTPUT); Serial.begin(9600); // Debugging if the transmitter could work if(!sl_driver.init()) { Serial.println("Init Failed! Please Check Your Transmitter."); } } void loop() { // Define the states of the smartlight in crosswalk and crosswalk light int smartcrosshigh = 1; int crosslight = 1; // Create a list of strings and combine into a message that could be // sent to the receiver char a1 = "SmartCrossLight,"; char a2 = String(smartcrosshigh) + ','; char a3 = "CrosswalkLight," char a4 = String(crosslight); // We will be sending a sentence like "SmartCrossLight,1,CrosswalkLight,1" // After the receiver receive the data, it could parse the data and extract useful // information from the data char msg = a1 + a2 + a3 + a4; // Send the msg using transmitter per 0.1 second al_driver.send((uint8_t *)msg, strlen(msg)); sl_driver.waitPacketSent(); delay(100); } |
The Receiver Part:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
/* * Tutorial * 433 MHz RF Module Receiver Demonstration * Connect DATA pin to pin 11 in Arduino Uno * Connect GND pin to pin GND in Arduino Uno * Connect VCC pin to pin 5v in Arduino Uno * We can also use antenna to enhance the strengh of the signal */ // Include RadioHead Amplitude Shift Keying Library #include <RH_ASK.h> // Include Serial Peripheral Interface Library #include <SPI.h> const int SmartTraffiPin = 2; // Suppose we receive traffic light from pin 7. // Create ASK object RH_ASK sl_driver; unsigned long startMillis; unsigned long currentMillis; unsigned long trafficMillis; const unsigned long period = 20000; const unsigned long period2 = 5000; const int TrafficPin = 7; int count=0; void setup() { // Create a pin that respond to traffic smart light pinMode(SmartTrafficPin, OUTPUT); // Here we use an output to simulate the state of traffic light, HIGH means RED // In reality, it should be INPUT pinMode(TrafficPin, OUTPUT); // Initial start time startMillis = millis(); Serial.begin(9600); // Debugging if the receiver could work if (!sl_driver.init()) { Serial.println("Init Failed! Please Check Your Receiver."); } } void loop() { // get the current time since the program starts currentMillis = millis(); if (currentMillis - startMillis >= period) { digitalWrite(TrafficPin,!digitalRead(TrafficPin)); // See if we need to notice driver about the illegal crossing behavior if (digitalRead(TrafficPin) == LOW) { uint_8_t msg[35]; uint_8_t msglen = sizeof(msg); if (sl_driver.recv(msg, &msglen)) { int i = 0; if (msg[16] == '1') { i ++; // This is the situation where we need to turn on the traffi smart light and record illegal crossing Serial.print("Someone has crossed the intersection illegally!"); if ((currentMillis - startMillis) < (period - 5000)) { // Haven't figure out how to set a light period of 5 seconds during the green light digitalWrite(SmartTrafficPin, HIGH); } else { digitalWrite(SmartTrafficPin, HIGH); } } } if (i >= 1) { // Record one illegal crossing behavior for one red-light interval. count ++; } } else { int i = 0; // During this situation, the traffic smart light won't work digitalWrite(SmartTrafficPin,LOW); uint_8_t msg[35]; uint_8_t msglen = sizeof(msg); if (sl_driver.recv(msg, &msglen)) { if (msg[16] == '1') { i++; // We don't need to turn on the light, but the illegal crossing should be // recorded. Serial.print("Someone has crossed the intersection illegally!"); } } if (i >= 1) { // Record one illegal crossing behavior count ++; } } startMillis = currentMillis; } // Create two variables that store the data received from transmitte } |