Pir-sensor -Infrarödsensor
och koden :
int set_sensorState_to_read_digital_pin_2 = 0;
int sensorState = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
// read the state of the sensor/digital uinput
sensorState = digitalRead(2);
// Check if sensor pin
if (sensorState == HIGH) {
digitalWrite(13, HIGH);
Serial.println(“sensor activated”);
} else {
digitalWrite(13, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
Den funkar bra.
Bild: https://www.electrokit.com/produkt/pir-rorelsedetektor/