1. light intensity based on room occupancy Simulation



This project is a smart lighting system that automatically adjusts light intensity based on room occupancy using a PIR motion sensor. When someone enters the room, the lights gradually brighten, and when the room is empty, the lights dim down smoothly or turn OFF. The system can also use a relay module to control high-power bulbs.

I used WokWI to simulate this and also provided the code for it as well and a link of the simulation at the bottom.

 

Code:

#define PIR_SENSOR 2  // PIR Sensor connected to Digital Pin 2

#define LED_PIN 9     // PWM LED pin

#define RELAY_PIN 8   // Relay pin for full light ON/OFF

 

int brightness = 0;  // Initial LED brightness

bool motionDetected = false;

 

void setup() {

    pinMode(PIR_SENSOR, INPUT);

    pinMode(LED_PIN, OUTPUT);

    pinMode(RELAY_PIN, OUTPUT);

    Serial.begin(9600);

}

 

void loop() {

    int motion = digitalRead(PIR_SENSOR);

 

    if (motion == HIGH) {

        Serial.println("Motion Detected! Increasing brightness...");

        motionDetected = true;

        digitalWrite(RELAY_PIN, HIGH);  // Turn ON full light (if using relay)

 

        // Gradually increase brightness

        for (brightness = 0; brightness <= 255; brightness += 5) {

            analogWrite(LED_PIN, brightness);

            delay(50);  // Smooth transition effect

        }

 

    } else {

        if (motionDetected) {

            Serial.println("No Motion. Dimming lights...");

            motionDetected = false;

 

            // Gradually decrease brightness

            for (brightness = 255; brightness >= 0; brightness -= 5) {

                analogWrite(LED_PIN, brightness);

                delay(50);

            }

            digitalWrite(RELAY_PIN, LOW);  // Turn OFF full light (if using relay)

        }

    }

 

    delay(500);  // Adjust sensitivity delay

}

 

 



furthermore I have provided the link below of my simulation.
to see if it works 
1.click on the motion sensor
2. and on the left side you'll see simulate motion and you will see the LED light up  


https://wokwi.com/projects/425175939712473089



Comments

Popular posts from this blog

PIR Motion Sensor Working! Now Debugging the BH1750 Light Sensor

Proposal - vision based smart lighting