This is a really basic problem, but I haven't been able to resolve it myself and would really appreciate the help. So I've been struggling for a few weeks now to set up RF communication between two arduino uno chips. I have the transmitter and receiver hooked up to 5V supply, with the data pins connected to digital pin 4. My code looks like this:
Transmitter code:
#define rfTransmitPin 4 //RF Transmitter pin = digital pin 4
#define ledPin 13 //Onboard LED = digital pin 13
unsigned int data = 0; // variable used to store transmission data
void setup(){
pinMode(rfTransmitPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
digitalWrite (rfTransmitPin, HIGH);
data = digitalRead (rfTransmitPin); // Read the digital transmitter pin
Serial.println(data);
digitalWrite (ledPin, HIGH);
delay(2000);
digitalWrite (rfTransmitPin, LOW);
data = digitalRead (rfTransmitPin); // Read the digital transmitter pin
Serial.println(data);
digitalWrite (ledPin, LOW);
delay(2000);
}
Receiver code:
#define rfReceivePin 4 //RF Receiver pin = digital pin 4
#define ledPin 13 //Onboard LED = digital pin 13
unsigned int data = 0; // variable used to store received data
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(rfReceivePin, INPUT);
Serial.begin(9600);
}
void loop(){
data=digitalRead(rfReceivePin); //listen for data on Digital Pin 4
if(data = HIGH){
digitalWrite(ledPin, HIGH); //If a HIGH signal is received, turn LED ON
Serial.println(data);
}
if(data = LOW){
digitalWrite(ledPin, LOW); //If a LOW signal is received, turn LED OFF
Serial.println(data);
}
}
This should be really simple, but for some reason I'm reading a continual HIGH signal from the receiver module. I'm trying to sort out the basic functionality of the RF tx-rx pair before developing code to send a char using the Virtual Wire library, but I can't even get it to function at this level. Since my code is so basic I'm convinced it must be a hardware issue and I'm not sure what I'm doing wrong. Any suggestions?
1 Answer 1
VIf you using Virutalwire try exemple in the library. You can't send simple digitata data with Rf. Best Regards Mikael
-
Hi Mikael, thanks for the reply. I've tried running the example transmitter/receiver code, and all I get is the setup printout on the serial monitor, the message doesn't come through.vani11acoke– vani11acoke03/11/2017 08:41:36Commented Mar 11, 2017 at 8:41
-
hackshed.co.uk/rf-communication-between-2-arduinosCarlmikael– Carlmikael03/12/2017 03:08:11Commented Mar 12, 2017 at 3:08
-
This will you show you how you use VirutalWireCarlmikael– Carlmikael03/12/2017 03:11:31Commented Mar 12, 2017 at 3:11
-
Turned out to be a faulty receiver, it's all working as it should be now :-)vani11acoke– vani11acoke03/12/2017 04:12:35Commented Mar 12, 2017 at 4:12
-
1