-1

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?

0

VIf you using Virutalwire try exemple in the library. You can't send simple digitata data with Rf. Best Regards Mikael

link Virutalwire

  • 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 Mar 11 '17 at 8:41
  • This will you show you how you use VirutalWire – Carlmikael Mar 12 '17 at 3:11
  • Turned out to be a faulty receiver, it's all working as it should be now :-) – vani11acoke Mar 12 '17 at 4:12
  • Glad you got it working – Carlmikael Mar 12 '17 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.