Halo semuanya! Berjumpa dengan Miniblog dari Inzaghi's Blog! Kali ini kita akan membuat Program PIR Sensor dengan LED menggunakan Arduino Uno di Tinkercad.
Sumber Tutorial : Arduinogetstarted.com
Lalu, kita akan membuat Program Arduino PIR Sensor dengan LED menggunakan Arduino Uno di Tinkercad.
Kode :
const int PIR_SENSOR_PIN = 10; // Arduino pin connected to the OUTPUT pin of motion sensorconst int LED_PIN = 4; // Arduino pin connected to LED's pinint motionStateCurrent = LOW; // current state of motion sensor's pinint motionStatePrevious = LOW; // previous state of motion sensor's pinvoid setup() {Serial.begin(9600); // initialize serialpinMode(PIR_SENSOR_PIN, INPUT); // set arduino pin to input modepinMode(LED_PIN, OUTPUT); // set arduino pin to output mode}void loop() {motionStatePrevious = motionStateCurrent; // store old statemotionStateCurrent = digitalRead(PIR_SENSOR_PIN); // read new stateif (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // pin state change: LOW -> HIGHSerial.println("Motion detected!");digitalWrite(LED_PIN, HIGH); // turn on}else if (motionStatePrevious == HIGH && motionStateCurrent == LOW) { // pin state change: HIGH -> LOWSerial.println("Motion stopped!");digitalWrite(LED_PIN, LOW); // turn off}}
Gambar (Output) :
Mohon maaf apabila ada kesalahan sedikit pun pada Kode Program ini.
Terima Kasih 😀😊😘👌👍 :)
Tags
Kode Program