VirtualWire controlling Outputs

I’m using the Virtual Wire library, I’ve sent an ‘A’ from one Arduino and then this Arduino can identify that.
The only problem is, how do I use that received ‘A’ to activate some pins… (I need to switch two digital pins to control a very simple relay circuit).


// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>

int twoPin = 2;
//the two digital pins connected to the relay
int fourPin = 4;

void setup()
{

pinMode(twoPin, OUTPUT);
pinMode(fourPin, OUTPUT);

Serial.begin(9600); // Debugging only
Serial.println(“setup”);

// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec

vw_rx_start(); // Start the receiver PLL running
}

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

if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;

digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");

for (i = 0; i < buflen; i++)
{
Serial.print(buf*, HEX);*

  • Serial.print(" ");*
  • }*
  • Serial.println("");*
  • digitalWrite(13, false);*
  • }*
    }
    ----------------------------------------------------------------------------------------------------------------

I would assume that you dump the received message into a variable, and then compare the variable to what you intended to send (in this case, "A"), and, if they match, digitalWrite your pins HIGH.

FIRST! Before you maybe ruin a pin or two.

What do you mean by “two pins to the relay”? You should only be using 1 pin… and that should be through a 1k resistor to the base on a Transistor that connects the coils on the relay to 5v and ground.

If you hook up the relay with 2 pins… one on each side… you’re not going to do any good… and possibly ruin some pins on your arduino:/

I’ll try put some comments to help:

// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>

int twoPin = 2;
               //the two digital pins connected to the relay
int fourPin = 4;

void setup()
{

  pinMode(twoPin, OUTPUT);
  pinMode(fourPin, OUTPUT);

  Serial.begin(9600); // Debugging only
  Serial.println("setup");

  // Initialise the IO and ISR
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);      // Bits per sec

  vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];  // buf array
  uint8_t buflen = VW_MAX_MESSAGE_LEN; // message lenth

  if (vw_get_message(buf, &buflen)) // if I got a message, then{ 
  {
      int i;

      digitalWrite(13, true); // Flash a light to show received good message
      // Message with a good checksum received, dump it.
      Serial.print("Got: ");

      for (i = 0; i < buflen; i++) // buflen = message length
      {
          Serial.print(buf[i], HEX);// take out the HEX to print ascii chars
          Serial.print(" "); 
      }
      Serial.println("");
      digitalWrite(13, false);

      if(buf[0] == 'A){  // buf[0] is the first byte received, buf[1] is second, etc
        digitalWrite(twoPin, HIGH);  // turn on relay.
        }

  }
}

Thank you so much for the quick help..

I'm using two relays as an H-Bridge, and I'm using transistors.. Which is all fine.

I tried the code you suggested, however I get an error that

"'A' was not declared in this scope" any ideas would help..

Luke

I've figured it out..

Thank you so much. The project is actually required to be submitted to a competition tomorrow morning...... I couldn't really repay you..

Thank's