Hi, everyone
I want programming Rf 433mhz module with 4 push button switches to serve as an emergency control remote control for 4-junction traffic light in such away when sw1 is on green of junction 1 is on and all other junctions are off. when sw2 is on green of junction 2 is on and all other junctions are off.
when sw3 is on green of junction 3 is on and all other junctions are off. when sw4 is on green of junction 4 is on and all other junctions are off.
my codes for 4-junctions traffic work successfully (with out Rf ) be the codes of traffic light:
int Lane1[] = {13,12,11}; // Lane 1 Red, Yellow and Green
int Lane2[] = {10,9,8};// Lane 2 Red, Yellow and Green
int Lane3[] = {7,6,5};// Lane 3 Red, Yellow and Green
int Lane4[] = {4,3,2};// Lane 4 Red, Yellow and Green
void setup()
{
for (int i = 0; i < 3; i++)
{
pinMode(Lane1*, OUTPUT);*
_ pinMode(Lane2*, OUTPUT);_
_ pinMode(Lane3, OUTPUT);
pinMode(Lane4, OUTPUT);
}
for (int i = 0; i < 3; i++)
{
digitalWrite(Lane1, LOW);
digitalWrite(Lane2, LOW);
digitalWrite(Lane3, LOW);
digitalWrite(Lane4, LOW);
}*_
}
void loop()
{
* digitalWrite(Lane1[2], HIGH);*
* digitalWrite(Lane3[0], HIGH);*
* digitalWrite(Lane4[0], HIGH);*
* digitalWrite(Lane2[0], HIGH);*
* delay(10000);*
* digitalWrite(Lane1[2], LOW);*
* digitalWrite(Lane3[0], LOW);*
* digitalWrite(Lane1[1], HIGH);*
* digitalWrite(Lane3[1], HIGH);*
* delay(6000);*
* digitalWrite(Lane1[1], LOW);*
* digitalWrite(Lane3[1], LOW);*
* digitalWrite(Lane1[0], HIGH);*
* digitalWrite(Lane3[2], HIGH);*
* delay(10000);*
* digitalWrite(Lane3[2], LOW);*
* digitalWrite(Lane4[0], LOW);*
* digitalWrite(Lane3[1], HIGH);*
* digitalWrite(Lane4[1], HIGH);*
* delay(6000);*
* digitalWrite(Lane3[1], LOW);*
* digitalWrite(Lane4[1], LOW);*
* digitalWrite(Lane3[0], HIGH);*
* digitalWrite(Lane4[2], HIGH);*
* delay(10000);*
* digitalWrite(Lane4[2], LOW);*
* digitalWrite(Lane2[0], LOW);*
* digitalWrite(Lane4[1], HIGH);*
* digitalWrite(Lane2[1], HIGH);*
* delay(6000);*
* digitalWrite(Lane4[1], LOW);*
* digitalWrite(Lane2[1], LOW);*
* digitalWrite(Lane4[0], HIGH);*
* digitalWrite(Lane2[2], HIGH);*
* delay(10000);*
* digitalWrite(Lane1[0], LOW);*
* digitalWrite(Lane2[2], LOW);*
* digitalWrite(Lane1[1], HIGH);*
* digitalWrite(Lane2[1], HIGH);*
* delay(6000);*
* digitalWrite(Lane2[1], LOW);*
* digitalWrite(Lane1[1], LOW);*
I have the following codes for Rf 433mhz module:
1. for transimitter:
#include <VirtualWire.h>
void setup()
{
* pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
_ Serial.begin(9600);_
vw_set_tx_pin(8);
vw_setup(3000);
_}
void loop()
{
int bt1 = digitalRead(2);
int bt2 = digitalRead(3);
int bt3 = digitalRead(4);
int bt4 = digitalRead(5);
Serial.print(bt1);
Serial.print(" ");
Serial.print(bt2);
Serial.print(" ");
Serial.print(bt3);
Serial.print(" ");
Serial.print(bt4);
Serial.println(" ");
if (bt1 == 0)
{
char msg[1] = {'1'};_
vw_send((uint8_t )msg, 1);
vw_wait_tx();
* delay (5);*
* }*
* if (bt2 == 0)*
* {*
* char msg[1] = {'2'};*
vw_send((uint8_t )msg, 1);
vw_wait_tx();
_ delay (5);
}
if (bt3 == 0)
{
char msg[1] = {'3'};_
vw_send((uint8_t )msg, 1);
vw_wait_tx();
* delay (5);*
* }*
* if (bt4 == 0)*
* {*
* char msg[1] = {'4'};*
vw_send((uint8_t )msg, 1);
vw_wait_tx();
_ delay (5);
}*_
* char msg[1] = {'0'};*
vw_send((uint8_t )msg, 1);
vw_wait_tx();
_ delay (5);
}
2. for reciever
#include <VirtualWire.h>
const int receive_pin = 8;
void setup(void) {
Serial.begin(9600);_
vw_set_rx_pin(receive_pin);
vw_set_ptt_inverted(true);
vw_setup(3000);
vw_rx_start();
_ // Register the pop event callback function of the components*
}
void loop(void) {
* uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))*
* {
Serial.println(buf[0]);
if (buf[0] == '1') {
// make what do you wont !!
}
if (buf[0] == '2') {
// make what do you wont !!
}
if (buf[0] == '3') {
// make what do you wont !!
}
if (buf[0] == '4') {
// make what do you wont !!
}
}
}*
please what are the modifications for the codes so that i can connect the traffic light codes with the RF codes??
thanks in advance._