Created
August 29, 2017 04:19
-
-
Save ArduinoBasics/7a9f30e85bf980d59d777eb7483898e1 to your computer and use it in GitHub Desktop.
A simple sketch used to test RF transmission/receiver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
RF Blink - Receiver sketch | |
Written by ScottC 17 Jun 2014 | |
Arduino IDE version 1.0.5 | |
Website: http://arduinobasics.blogspot.com | |
Receiver: XY-MK-5V | |
Description: A simple sketch used to test RF transmission/receiver. | |
------------------------------------------------------------- */ | |
#define rfReceivePin A0 //RF Receiver pin = Analog pin 0 | |
#define ledPin 13 //Onboard LED = digital pin 13 | |
unsigned int data = 0; // variable used to store received data | |
const unsigned int upperThreshold = 70; //upper threshold value | |
const unsigned int lowerThreshold = 50; //lower threshold value | |
void setup(){ | |
pinMode(ledPin, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop(){ | |
data=analogRead(rfReceivePin); //listen for data on Analog pin 0 | |
if(data>upperThreshold){ | |
digitalWrite(ledPin, LOW); //If a LOW signal is received, turn LED OFF | |
Serial.println(data); | |
} | |
if(data<lowerThreshold){ | |
digitalWrite(ledPin, HIGH); //If a HIGH signal is received, turn LED ON | |
Serial.println(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment