I want to blink an led on receiver end according to message received. LED must be switch on when message received is "obstacle absent". But led doesn't switch on whatever be the message received. But serial monitor of receiver shows the correct output. What is problem in code?
here is my code
#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;
int pin=11;
void setup()
{
Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
pinMode(LED,OUTPUT);
}
void loop()
{
char message[VW_MAX_MESSAGE_LEN + 1];
if (vw_get_message(message, &messageLength)) // Non-blocking
{ // Existing start of if body
message[messageLength] = '\0';
if(strcmp(message, "obstacle absent") == 0)
{
}
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println("");
delay(200);
}
}
}
sorry but this is my code. The problem is that led is not switch off again when obstacle is present. But led should be switch on when obstacle is absent and switch off when obstacle is present.
What is problem in code. Please help me.
Here is my code
#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;
int pin=11;
void setup()
{
Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
pinMode(LED,OUTPUT);
}
void loop()
{
char message[VW_MAX_MESSAGE_LEN + 1];
if (vw_get_message(message, &messageLength)) // Non-blocking
{ // Existing start of if body
message[messageLength] = '\0';
if(strcmp(message, "obstacle absent") == 0)
{
digitalWrite(LED,HIGH);
}
if(strcmp(message, "obstaclepresent") == 1)
{
digitalWrite(LED,LOW);
}
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println("");
delay(200);
}
}
}