I am doing my first project on an arduino uno board, it is a motion sensor that uses the PIR sensor, I did the simulation and everything went well, but when I assemble the components the sensor seems to always be sensing movement, so the power never turns off indication led, when trying to find the problem, I decided to disconnect the sensor from the board and accidentally realized that the pin 2 cable, which is where the PIR sensor signal enters, is very sensitive, so much so that if I pass my hand near to it (4 or 5 cm away) the circuit is activated, I don't even need to touch that cable to activate the led and the buzzer... this problem seems very strange to me because I have seen several videos with this same assembly and they never have that problem, I changed the Arduino board (I have two) and the same thing happens on both boards, obviously I also changed the cable and the pins where I can connect it, I have the same problem on all of them, what can I do? I leave my code so you can see it and I will be very attentive to your answers!
int pinsensor = 2; // Definimos como variable el pin donde se conecta el sensor PIR
int pinLed = 3; // Definimos como variable el pin donde se conecta el Led
int pinBuzzer = 4; // Definimos como variable el pin donde se conecta el sensor PIR
int move = 0;
void setup() // configuración inicial del Arduino
{
Serial.begin(9600);
pinMode(pinsensor, INPUT); // Configuramos el pin del sensor PIR como entrada
pinMode(pinLed, OUTPUT); // Configuramos el pin del Led como salida
pinMode(pinBuzzer, OUTPUT); // Configuramos el pin del Buzzer como salida
}
void loop() // Instrucciones que se repetirán mientras el Arduino este en funcionamiento
{
move = digitalRead(pinsensor);
delay(50);
if(move == HIGH) // Condicional para cuando el sensor PIR detecte movimiento
{
Serial.print(move);
Serial.print(" : ");
Serial.print("Movimiento Detectado");
digitalWrite(pinLed, HIGH); // Encendido del Led
tone(pinBuzzer, 80000, 1000); // Se emite una señal tipo tomo al Buzzer, con una frecuencia de 80Khz y una duración de 10 segundos
move = 0;
delay(300);
}
else // Instrucciones para cuando no se cumpla la condición
{
Serial.print(move);
Serial.print(" : ");
Serial.print("Movimiento Detectado");
delay(100);
digitalWrite(pinLed, LOW); // apagado del Led
digitalWrite(pinBuzzer, LOW); // apagado del Buzzer
}
}
I wired a PIR sensor like yours to my Uno and with your code the PIR sensor works OK. The LED lights when there is movement detected.
You print "Movimiento Detectado" whether there is movement or not.
Did you adjust the pots on the sensor for sensitivity and delay?
Could you actually hear an 80KHz tone if it were possible to generate that frequency?
An input that is disconnected is said to be "floating". A floating input is, as you have seen, very sensitive to noise. Your body acts as an antenna for noise.
That's right, I tried several settings and it didn't work
As for the frequency, I need it to be 80 Khz, the idea is to scare away bats, I'm still looking for a buzzer that can generate that frequency.
Here you are right, my body works as an antenna, I already configured pin 2 as pull down with the help of a 1K ohm resistor, and the active signal disappears, but I can't activate it again, without the 1K resistor when i connect the cable to the PIR sensor the problem gets worse and it is as if the sensor is always detecting movement, i start to believe that the problem is that the sensor is damaged
That PIR sensor has a "stay on timer" potentiometer, with a range between 3 seconds and 7 minutes. Turn the pot fully anticlockwise for the shortest time, otherwise you have to sit still for several minutes for the PIR to turn off. Use this sketch with only the LED and PIR sensor for testing.
Leo..
Thank you very much everyone for the comments, I'm going to investigate the issue of the speakers more to achieve the expected frequency.
Thanks for this information, I already made the required adjustments, but it didn't work either, I think the problem is in the sensor, I'm going to buy another one.