#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
int LED= 13;
void setup()
{
Serial.begin(9600);
Serial.println("Receiver is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
pinMode(LED,OUTPUT);
}
void loop()
{
if (vw_get_message(message, &messageLength)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
if(Serial.println(obstacle absent));
{
digitalWrite(LED,HIGH);
}
else()
{
digitalWrite(LED,LOW);
}
}
delay(200);
}
Here is my error
virtualwire_reciever:32: error: 'obstacle' was not declared in this scope
}
^
exit status 1
'obstacle' was not declared in this scope
I have connected transmitter and receiver. The transmitter is connected with ir sensors and detect whether there is obstacle or not.
I want to light up led in the receiver when it receive 'obstacle absent' as a message
Regarding vw_get_message(message, &messageLength), read the documentation closely
uint8_t vw_get_message (uint8_t * buf,uint8_t * len)
If a message is available (good checksum or not), copies up to *len octets to buf.
Parameters
[in] buf Pointer to location to save the read data (must be at least *len bytes.
[[color=blue]in[/color], [color=red] out[/color]] len [color=blue]Available space in buf[/color]. [color=red]Will be set to the actual number of octets read[/color]
You need to ensure that messageLength is reset to the full length of the buffer before calling that again otherwise you will send whatever was there before and may be it will be super short...
#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
int LED= 13;
void setup()
{
Serial.begin(9600);
Serial.println("Receiver is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
pinMode(LED,OUTPUT);
}
void loop()
{
if (uint8_t vw_get_message (uint8_t * buf,uint8_t * len)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
if(Serial.println("obstacle absent"))
{
digitalWrite(LED,HIGH);
}
if((Serial.println("obstaclepresent"))
{ digitalWrite(LED,LOW);
}
};
delay(200);
}
exit status 1
expected '=' before ')' token
sorry for double post. It was done by mistake . I am newbie to Arduino. I want to light up led in the receiver when it receive 'obstacle absent' as a message . If there is any more error please make them correct. Thanks in advance.