Wireless Arduino Transmitter & Receiver

The overall idea for creating an Arduino transmitter/reciever combination is this:

  1. Transmitter must transmit at the push of a button.
  2. Transmitter must transmit correct signal depending on what button is pressed and only send ONE code even while button is still being pressed.
  3. The receiver corresponding to the correct code must turn on/turn off a light and keep it at that state until another code has been received.

So to start I knew I needed to wire one Arduino up with a push button which I chose to be placed in pin 3 and an LED which I chose to be on pin 13. The Transmitter then needed to be wired up. As I debugged later on I found out that the antennae is not needed especially in prototyping when the receiver and transmitter are in close proximity. The transmitter hardware can be found on sparkfun here.

Transmitter

For the receiver all I needed was an LED, that would be turned on and off with the wireless signal from the transmitter. I placed the LED on pin 13 as shown in the diagram below. The hardware receiver can also be found on sparkfun here. Like I said, the antennae does not need to be connected while prototyping.

Receiver

Here is the code for the transmitter, which (depending on button pressed) will send a unique code with the help of the VirtualWire.h library. The VirtualWire library can be downloaded here: VirtualWire.h

/*
  Code for controller that transmits signal to
  specified receiver depending on button pressed.
*/

#include <VirtualWire.h>

const int led_pin = 13;
const int switch_pin = 3;
const int transmit_pin = 1;
const int receive_pin = 0;
const int transmit_en_pin = 2;

void setup() {
  // Initialise the IO and ISR
  	vw_set_tx_pin(transmit_pin);
  	vw_set_rx_pin(receive_pin);
  	vw_set_ptt_pin(transmit_en_pin);
  	vw_setup(3000);

  	// Pin Setup
  	pinMode(led_pin,OUTPUT);
  	pinMode(switch_pin,INPUT);
}

byte count = 1;
boolean is_pushed = false;

void loop() {
  	if (digitalRead(switch_pin) == LOW) {
    	is_pushed = false;
  	}

  	if (digitalRead(switch_pin) == HIGH && is_pushed == false) {
    	digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
    	vw_send((uint8_t *)1, 1); // Send Code 1 if switch_pin is hit
    	vw_wait_tx(); // Wait until the whole message is gone
    	delay(200); // Wait for blink
    	digitalWrite(led_pin, LOW);
    	is_pushed = true;
  	}
}

Here is the code for a receiver which takes a unique code of ‘0’ and will turn on/off a light when received. Again, this uses the VirtualWire library to receive the code.

/*
  Code for controller that receives code of
  '1' and turns on and off a light.
*/

#include

const int led_pin = 13;
const int transmit_pin = 1;
const int receive_pin = 0;

void setup()
{
    delay(1000);
    Serial.begin(9600);  // Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_tx_pin(transmit_pin);
    vw_set_rx_pin(receive_pin);
    vw_setup(3000);

    vw_rx_start();       // Start the receiver PLL running

    // Pin Setup
    pinMode(led_pin,OUTPUT);
}

boolean is_switched = false;

void loop() {
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    // Check if message was recieved
    if (vw_get_message(buf, &buflen)) {
      // Check if correct message
      if (buf[0] == 0) {
        // Force led_pin either HIGH or LOW
        if (is_switched == false) {
          digitalWrite(led_pin, HIGH); // Flash a light to show received good message
          is_switched = true;
        } else {
          digitalWrite(led_pin, LOW);
          is_switched = false;
        }
      }
    }
}

There are many extensions to this project that I can think of and will (hopefully) be working on in the near future. You can wirelessly control multiple light switches/lamps/any household appliance with a single transmitter and multiple push buttons. If you were to hook the transmitter up to the internet with an ethernet shield you could have a hub that transmits a signal given to it from an internet site to multiple controllers doing any number of operations. The possibilities are endless.

Thanks for reading! If you have any questions or comments, you can post below and I will be getting back to you.

Mitchel Pigsley