Advertisement
gabbyshimoni

433m_receiver

May 31st, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. /*
  2.   RF Blink - Receiver sketch
  3.      Written by ScottC 17 Jun 2014
  4.      Arduino IDE version 1.0.5
  5.      Website: http://arduinobasics.blogspot.com
  6.      Receiver: XY-MK-5V
  7.      Description: A simple sketch used to test RF transmission/receiver.          
  8.  ------------------------------------------------------------- */
  9.  
  10.  #define rfReceivePin A0  //RF Receiver pin = Analog pin 0
  11.  #define ledPin 13        //Onboard LED = digital pin 13
  12.  
  13.  unsigned int data = 0;   // variable used to store received data
  14.  const unsigned int upperThreshold = 500;  //upper threshold value
  15.  const unsigned int lowerThreshold = 100;  //lower threshold value
  16.  
  17.  void setup(){
  18.    pinMode(9, OUTPUT);
  19.    Serial.begin(9600);
  20.  }
  21.  
  22.  void loop(){
  23.    data=analogRead(rfReceivePin);    //listen for data on Analog pin 0
  24.    
  25.     if(data>upperThreshold){
  26.      digitalWrite(9, HIGH);   //If a LOW signal is received, turn LED OFF
  27.      Serial.println(data);
  28.    }
  29.    
  30.    if(data<lowerThreshold){
  31.      digitalWrite(9, LOW);   //If a HIGH signal is received, turn LED ON
  32.      Serial.println(data);
  33.    }
  34.   // delay(1000);
  35.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement