Hi!
I have a problem in coding section.
AIM:- In this project i want to get the output from the Receiver when the Switch is press from the Transmitter circuit.The output is in the form of blnking LED.
I am using RadioHead Library File for this project.
Here is my code for the Transmitter Section:-
Arduino Pin----433MHz Transmitter
12 – DATA
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
RH_ASK driver;
int switchPin1=8;
int switchPin2=9;
void setup()
{
Serial.begin(9600);
if (!driver.init())
Serial.println("init failed");
pinMode(switchPin1,INPUT);
pinMode(switchPin2,INPUT);
pinMode(7,OUTPUT);
}
void loop()
{
if(digitalRead(switchPin1) == HIGH)
{
const char *msg = "REDRED";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(1000);
digitalWrite(7 ,HIGH);
delay(500);
digitalWrite(7 ,LOW);
}
if(digitalRead(switchPin2) == HIGH)
{
const char *msg = "YELLOW";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(1000);
digitalWrite(7 ,HIGH);
delay(500);
digitalWrite(7 ,LOW);
}
}
Here is my code for the Receiver Section:-
Arduino Pin----433MHz Receiver
11 – DATA
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
int ledPin1=8;
int ledPin2=9;
void setup()
{
pinMode(ledPin1,OUTPUT);
pinMode(ledPin2,OUTPUT);
Serial.begin(9600);
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
uint8_t buf[6];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);
if( (char*)buf == "REDRED")
{
digitalWrite(8 , HIGH);
delay(500);
digitalWrite(8 , LOW);
}
if( (char*)buf == "YELLOW")
{
digitalWrite(9 , HIGH);
delay(500);
digitalWrite(9 , LOW);
}
}
}
I am facing the problem in Reciever section of :-
if( (char*)buf == "REDRED")
{
digitalWrite(8 , HIGH);
delay(500);
digitalWrite(8 , LOW);
}
if( (char*)buf == "YELLOW")
{
digitalWrite(9 , HIGH);
delay(500);
digitalWrite(9 , LOW);
}
In above code , when the program is running ,the above step is ignored by the device.
The statement written in the bracket of if statement is not working…
please help me.