Hello,
Beginner warning!
Just got a few Nano boards (not official) and I can’t get a simple PIR + LED setup to work.
It works just fine with my Uno board.
At first I thought I soldered something wrong on the Nano board but same thing with a second one. Tried changing pins, and 2 other PIR sensors.
Setup (pic below):
- PIR power supplied with 5v breadboard supply hooked to 9V battery. Output pin on D2 on Nano
- LED on D5 and GND on nano
The PIR and LED just go crazy switching on and off like alternating a detection/stop cycle.
You can see this on the pic of the serial monitor.
EDIT1: added pictures as images, no need to click on attached files.
EDIT2: tried with a third Nano board without pins just by sticking the wires in, same problem. I wondered if my soldering skills could be the problem but it seems they are not that bad :-X
/*
* PIR sensor tester
*/
int ledPin = 5; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}