Hello , here is what I wrote :
int Status = 12 ;
int sensor = 13;
void setup() {
Serial.begin(9699);
pinMode(sensor,INPUT); // declare sensor as input
pinMode (Status,OUTPUT); // Declares LED As output
}
void loop (){
long state = digitalRead (sensor);
if( state==HIGH){
digitalWrite(Status,HIGH);
Serial.println("Motion detected!");
delay(1000);
}
else {
digitalWrite (Status,LOW);
Serial.println ("Motion absent!");
delay(1000);
}
}
I have loaded and compiled into a nodemcu 8266 , I open the monitor but nothing happens, what I did wrong?
6v6gt
June 1, 2022, 8:32am
2
naimaste:
Serial.begin(9699);
Did you copy this correctly ?
A led, incidentally, needs a series current limiting resistor.
These pins would be OK on a Uno, for example, but not on a NODE.MCU
Oh , how should I put it to make it work on nodemcu?
I thought were the same?
void loop ()
{
long state = digitalRead (sensor);
digitalWrite(Status, state);
Serial.print("Motion ");
Serial.println(state==HIGH ?"detected!" : "absent!");
delay(1000);
}
Too much code
you code of post #1 runs on my NodeMCU v1 ESP-12E OK after I changed the Serial baudrate
sorry english isn't my main language, what is serial baudrate?
I use 115200 baud, e.g.
Serial.begin(115200);
I connected an LED to D6 GPIO12 and then took D7 GPIO13 high and low and the Serial monitor output changed as expected
6v6gt
June 1, 2022, 9:16am
8
Sorry. You are correct. There are two numbering schemes for the node.mcu.
However, you'll still have a problem with the pin driving the LED (D6/GPIO12). That needs a resistor (say 330 ohms).
I tend to buy LEDs with built in resitors - save a lot of messing about attempting to make good connections
Ok I have changed the baud rate Serial.begin(115200);
and now works, I can read info on the monitor, but it seems stuck giving only motion detected and doesnt change state ...
Here is how I changed the setup . I wanted the green pin to light up when motion is detected but doesn't .. I also wanted to add another red pin to show when no motion is detected, what is wrong in my setup ?
I used 220 ohm resistor.
horace
June 1, 2022, 9:23am
11
jcheck the PIR is working
remove it from 13 and connect a jumper from 13 to high then low - does the serial monitor output change as expected
Edit: connected a PIR (similar to your photo in post #1 ) and it works OK detecting motion
as @6v6gt suggested try adjusting the sensitivity - see arduino_pir_sensor
6v6gt
June 1, 2022, 9:26am
12
Post a link to that PIR detector. Some have adjustable delays and jumpers to configure their behaviour.
How you mean ?
If I detach the d7 connection the monitor says no motion .
erm how I see that? ITs the standard PIR Sensor that come out with the elegoo 2560 pack .
Ok here is how looks the setting I guess....
horace
June 1, 2022, 9:32am
16
try removing the delays in loop() you may be missing the pulses from the PIR
This is what happens if I remove the delays
I have setup the sensitivity and temp like this
minimum distance should be 3 m and max time
this is the actual config
I had to disable the resistor to switch off the led to take the pic otherwise the led is always green on and the thing keeps signalling presence ... what can be the issue?
horace
June 1, 2022, 10:46am
18
try printing when a change is detected, e.g.
int Status = 12 ;
int sensor = 13;
void setup() {
Serial.begin(115200);
pinMode(sensor,INPUT); // declare sensor as input
pinMode (Status,OUTPUT); // Declares LED As output
}
void loop (){
static int stateOld=-1;
long state = digitalRead (sensor);
if( state!=stateOld){ // state changed ??
stateOld=state; // yes
if(state) {
digitalWrite(Status,HIGH);
Serial.println("Motion detected!");
}
else {
digitalWrite (Status,LOW);
Serial.println ("Motion absent!");
}
}
}
[/code]
static is used so a value is changed in loop() is maintained for the next call otherwise it is reinitialised
a run gave
Motion absent!
Motion detected!
Motion absent!
Motion detected!
Motion absent!
Motion detected!
whit this nothing is written in the monitor but the led is always on .
I tried switching pins but same results, this is getting me nuts ... the sensor is always shouding motion detected ...
int LED = 14 ;
int sensor = 12;
void setup() {
Serial.begin(115200);
pinMode(sensor,INPUT); // declare sensor as input
pinMode (LED,OUTPUT); // Declares LED As output
}
void loop (){
long state = digitalRead (sensor);
if( state==HIGH){
digitalWrite(LED,HIGH);
Serial.println("Motion detected!");
delay(1000);
}
else {
digitalWrite (LED,LOW);
Serial.println ("Motion absent!");
delay(1000);
}
}
And I do not think the sensor is broken because its new ...