Skip to main content

PIR sensor part 1

The PIR sensor is used in home automation, but also to can be used for many applications, here I'm going to explain only the basics about this sensor, and I'm going to use Arduino Uno, some Jumpers, one PCB, one red LED, cable type D, a computer and Arduino software.
the Sketch:

const int sensorPir = 2;
const int ledPin = 13;

int buttonState = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(sensorPir, INPUT);
Serial.begin(9600);
}

void loop(){
buttonState = digitalRead(sensorPir);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
Serial.println(buttonState);
delay(500);
}

This works only in a simple way to detect movement.
Let's see how it works.
const int sensorPir = 2;    it's about where is going to be put in the digital input on the Arduino Board.
const int ledPin = 13;   I put it there because we can put the LED into the input on the Arduino Board.
int buttonSate =0;   here we tell the sensor to star on off mode.
pinMode(ledPin, OUYPUT);  here we are telling Arduino than the ledPin is only an output issue.
Serial.begun(9600);    Is the data rate in bits per second (baud) for serial data transmission. For communicating with the computer, and you can use: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. you can, however specify other rates, here we are going to use only 9600.
buttonState = digitalRead(sensorPir);   here we specify than is only a digital read from the sensor.
digitalWrite(ledPin, HIGH);   here we put the state ON for the LED.
delay(500); delay is the speed of the sensor to read or show all the data and collected, it's on milliseconds and you can put any time you need.