Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

const int pir_motion = 2; // the pin that the pir motion sensor is attached

to pin number 2
const int led = 13; // the pin that the led is attached to
pin number 13

int sensorState = 0; // variable to store the sensor status (sensorState)


void setup()
{
pinMode(2, INPUT); // initialize pir motion sensor as an output
pinMode(13, OUTPUT); // initialize LED as an output
Serial.begin(9600); // initialize the speed of the serial monitor

void loop()
{
sensorState = digitalRead(2); // read sensor value and save it in
the sensor state

if (sensorState == HIGH) { // check if the sensor is


HIGH
digitalWrite(13, HIGH); // turn LED ON
Serial.println("Sensor activated!"); // print Sensor activated in the
serial monitor
} else { // if any another thing happened

digitalWrite(13, LOW); // turn LED OFF


Serial.println("Sensor not activated!"); // print the Sensor not
activated! in the serial monitor
}

You might also like