Hi everyone,
I've got a simple setup for testing and have run into a bit of a problem. I have an Uno and a
315 MHz reciever where I'm simply reading the input in from A5 and printing it to the serial. Results are as expected. However, I wanted to add a visual indicator in the form of an LED to blink every time a value greater than zero is received. So I added the following code:
int ledPin = 12;
unsigned long timerA;
boolean ledOn = false;
void setup() {
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}
void loop() {
int sensorValue = analogRead(A5);
Serial.println(sensorValue);
if (sensorValue > 0 && !ledOn) {
timerA = millis();
digitalWrite(ledPin,HIGH);
ledOn = true;
}
if (ledOn && (timerA - millis()) >= 50) {
digitalWrite(ledPin,LOW);
ledOn = false;
}
}
I upload and I can see the LED blinking away, but it appears to be blinking a lot more than I think it should. So I fire up the serial console and see what's being received. With the LED plugged into my breadboard I get the following output (sample):
768
768
0
768
768
0
768
768
0
768
768
0
768
767
If I remove the LED, I get the following (sample):
0
768
0
0
0
768
768
0
0
0
0
0
768
307
768
0
365
92
0
0
0
0
The second set it what I expect to see. With the LED plugged in I get a repeating pattern for sensorValue. I'm very new to this, and I'm not sure how to best troubleshoot this issue. Is it a wiring issue? Grounding? Now quite sure how to best go about this. Any advice or recommendations would be appreciated!