I have simple snippet of code that reads data from an RF433 module via A0.
The crux of the code looks like this:
const int dataSize = 500; //Arduino memory is limited (max=1700)
#define ledPin 13 //Onboard LED = digital pin 13
#define rfReceivePin A0 //RF Receiver data pin = Analog pin 0
const unsigned int upperThreshold = 100; //upper threshold value
const unsigned int lowerThreshold = 80; //lower threshold value
int maxSignalLength = 512; //Set the maximum length of the signal
int dataCounter = 0; //Variable to measure the length of the signal
void setup(){
Serial.begin(9600);
}
void loop(){
byte storedData[dataSize]; //Create an array to store the data
pinMode(ledPin, OUTPUT);
while(analogRead(rfReceivePin)<1){
//Wait here until a LOW signal is received
}
//Read and store the rest of the signal into the storedData array
for(int i=0; i<dataSize; i=i+1){
//Identify the length of the LOW signal---------------LOW
dataCounter=0; //reset the counter
while(analogRead(rfReceivePin)>upperThreshold && dataCounter<maxSignalLength){
dataCounter++;
}
//Identify the length of the HIGH signal---------------HIGH
dataCounter=0;//reset the counter
while(analogRead(rfReceivePin)<lowerThreshold && dataCounter<maxSignalLength){
dataCounter++;
}
storedData[i]=dataCounter;
Serial.print(dataCounter);
}
}
When I run this on an old Arduino Uno, I get exactly what I am expecting, but when I use the exact same code on a nano, the readings are all too high (by multiples) - i.e. Uno returns values between 9 and 100 for HIGH, nano returns values well over 100, for pretty much every return?
Why would the Nano return different results?
The code, when run on an Uno, can successfully decode the RF temperatures published by a digital cooking probe.