I have use 433Mhz transmitter and receiver to send values of two sensors from transmitter to receiver. I am able to print the values received by receiver over serial monitor. But I want to blink an LED according to message received. I want to blink an LED when messages are "Pres" and "More". And else don't blink. What's wrong with my code??
Here is my code
Transmitter
#include <VirtualWire.h>
int ObstaclePin = 7; // This is our input pin
int Obstacle = HIGH; // HIGH MEANS NO OBSTACLE
const int AOUTpin=0;//the AOUT pin of the alcohol sensor goes into analog pin A0 of the arduino
const int DOUTpin=8;//the DOUT pin of the alcohol sensor goes into digital pin D8 of the arduino
int limit;
int value;
void setup()
{
pinMode(ObstaclePin, INPUT);
pinMode(DOUTpin, INPUT);
Serial.begin(9600);
vw_set_tx_pin(12); // Pin data
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
}
void loop()
{
irsensor();
delay(100);
alcoholsensor();
}
void irsensor()
{
Obstacle = digitalRead(ObstaclePin);
if (Obstacle == LOW)
{
Serial.println("obstacle absent");
send("message =Abse");
}
else
{
Serial.println("obstacle present");
send("message =Pres");
}
}
void alcoholsensor()
{
value= analogRead(AOUTpin);//reads the analaog value from the alcohol sensor's AOUT pin
limit= digitalRead(DOUTpin);//reads the digital value from the alcohol sensor's DOUT pin
Serial.print("Alcohol value: ");
Serial.println(value);//prints the alcohol value
Serial.print("Limit: ");
Serial.print(limit);//prints the limit reached as either LOW or HIGH (above or underneath)
delay(100);
if (limit == HIGH){
Serial.println("value is less");//if limit has been reached, LED turns on as status indicator
send("message =Less");
}
else{
Serial.println("value is more");//if threshold not reached, LED remains off
send("message =More");
}
}
void send (char *message)
{
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx(); // Wait until the whole message has gone
}
Receiver code
/*
2 SimpleReceive
3 This sketch displays text strings received using VirtualWire
4 Connect the Receiver data pin to Arduino pin 11
5 */
#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("Device is ready");
// Initialize the IO and ISR
vw_set_rx_pin(11);
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
pinMode(Led,OUTPUT);
}
void loop()
{
receive1();
decision1();
decision2();
}
void receive1()
{
if (vw_get_message(message, &messageLength)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println();
}
}
void decision1()
{
if(strcmp(message, "Pres"))
{
digitalWrite(Led,HIGH);
}
else
{
digitalWrite(Led,LOW);
}
}
void decision2()
{
if(strcmp(message, 'More'))
{
digitalWrite(Led,HIGH);
}
else
{
digitalWrite(Led,LOW);
}
}