Loading...
Loading...
// Current-based occupancy detection
const int SENSOR_PIN = A0;
const int THRESHOLD = 50;
const int LED_PIN = 13;
int baseline = 0;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
// Calibrate with no load
baseline = analogRead(SENSOR_PIN);
}
void loop() {
int reading = analogRead(SENSOR_PIN);
int current = abs(reading - baseline);
if (current > THRESHOLD) {
digitalWrite(LED_PIN, HIGH);
Serial.println("OCCUPIED");
} else {
digitalWrite(LED_PIN, LOW);
Serial.println("CLEAR");
}
delay(100);
}This is starter code - modify and expand for your specific needs.
Before building this project, make sure you have the Arduino IDE installed and are comfortable uploading basic sketches to your board.
Most projects use standard Arduino libraries. Some may require additional libraries like AccelStepper, Servo, or NmraDcc - install these through the Arduino Library Manager.