Go Down

Topic: 433 MHZ receiver howe tot get further to activate a digital out (Read 270 times) previous topic - next topic

svarven

I have succed with a code sending and one code receiving a message.
When a digital input is high it sends *on#* and when its low it sends 'off'
But how should i do to transform the message 'on#' to set a digital pin as HIGH output.
Im using Arduino Duemilanove.
Code: [Select]
#include <VirtualWire.h>

const int led_pin = 4;
const int transmit_pin = 12;
const int receive_pin = 11;

void setup()
{
  delay(1000);
  Serial.begin(9600);
  Serial.println("setup");
 
  vw_set_tx_pin(receive_pin);
  vw_setup(2000);
  vw_rx_start();
 
  pinMode(led_pin,OUTPUT);
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if(vw_get_message(buf, &buflen))
  {
    digitalWrite(led_pin,HIGH);
    Serial.print("Got  ");
    for(int i=0; i<buflen; i++)
    {
      Serial.print(char(buf[i]));
      Serial.print(' ');
    }
    Serial.println();
    digitalWrite(led_pin,LOW);
  }
}


Thankful for you proffesional help

Bertil

CrossRoads

Add to your loop:
Code: [Select]

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if(vw_get_message(buf, &buflen))
  {
    digitalWrite(led_pin,HIGH);
    Serial.print("Got  ");
    for(int i=0; i<buflen; i++)
    {
      Serial.print(char(buf[i]));
      Serial.print(' ');
    }
    Serial.println();
    digitalWrite(led_pin,LOW);
  }
if (buf[0] == '2'){
// turn on led connected to 2
digitalWrite (2, HIGH);
}
if (buf[0] == '3'){
// turn off led connected to 3
digitalWrite (3, LOW);
}

// etc
}

Pretty easy for single characters coming on.
Expand test to 2 characters if needed; 1st can be on/off command, 2nd can be the 'pin' to turn on off.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

svarven

Oh skit, so easy.
I'm a fool  as not be able to solve that.

Thank you very very much

Bertil

Go Up