programming Rf 433mhz module with 4 push button switches

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._

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don’t do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The “Code: [Select]” feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

You have two sketches there - please post each one in separate pairs of code tags.

It would appear you are using an Uno. Yes? Your traffic light controller needs another pin for the Rf receiver. Your example uses pin 8 but you are using that for one of your traffic lights. You can use the analog pins as digital pins so I would suggest changing your lights to use A0 or A1 or something and freeing up pin 8 for the receiver.

receiver code

#include <VirtualWire.h>
const int receive_pin = 8;

const byte Lane1[] = {13, 12, 11}; // Lane 1 Red, Yellow and Green
const byte Lane2[] = {A2, A1, A0}; // Lane 2 Red, Yellow and Green
const byte Lane3[] = {7, 6, 5}; // Lane 3 Red, Yellow and Green
const byte Lane4[] = {4, 3, 2}; // Lane 4 Red, Yellow and Green

void setup()
{
  for (int i = 0; i < 3; i++)
  {
    pinMode(Lane1[i], OUTPUT);
    pinMode(Lane2[i], OUTPUT);
    pinMode(Lane3[i], OUTPUT);
    pinMode(Lane4[i], OUTPUT);

    digitalWrite(Lane1[i], LOW);
    digitalWrite(Lane2[i], LOW);
    digitalWrite(Lane3[i], LOW);
    digitalWrite(Lane4[i], LOW);
  }
  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 allOff() {
  for (int i = 0; i < 3; i++)
  {
    digitalWrite(Lane1[i], LOW);
    digitalWrite(Lane2[i], LOW);
    digitalWrite(Lane3[i], LOW);
    digitalWrite(Lane4[i], LOW);
  }
}

void loop()
{
  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') {
      // lane 1 green, others off
      allOff();
      digitalWrite(Lane1[2], HIGH);
    }

    if (buf[0] == '2') {
      // lane 2 green, others off
      allOff();
      digitalWrite(Lane2[2], HIGH);
    }

    if (buf[0] == '3') {
      // lane 3 green, others off
      allOff();
      digitalWrite(Lane3[2], HIGH);
    }

    if (buf[0] == '4') {
      // lane 4 green, others off
      allOff();
      digitalWrite(Lane4[2], HIGH);
    }
  }
}

transmitter code

//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);

}