Automatic Room Light Intensity Control System

Help, Room Light Intensity Control System
We are on a project right now.

We will be using the ambient light sensor on an arduino to control the light for power consumption.
The light source will automatically adjust whenever the environment is dark or bright.
We will use PIR sensor as the switch for the LED, The PIR sensor will go to high condition when it detects infrared or motion from the environment.
But we have a problem on the right codes to be use on the arduino.
We will use LED as the light source.
We will also be using relays on the project.
The title of our project is Automatic Room Light Intensity Control System.
Can you help us?

We dont know the right codes for the arduino uno.
Thank you!

Your project combines 3 items

  1. how to work with a PIR sensor
  2. how to work with a light sensor
  3. how to switch a light on and off.

All these three projects are discussed several times on this forum so a search in the upper right would help you.
Better go to the tutorial section and you will find approx 90% of the code you need. You only have to invent the 10% glue.

Question 1: How would you do it when you were the device? write the steps in plain English (or whatever) and you have a big part of the algorithm.

Question 2: Have you thought about the fact that the light sensor is affected by the light switched on/off?

Hope this helps a bit,

cross post?

I built something similar for under and over cabinet lighting for my kitchen. It uses a PIR for movement detection to turn on the lights when movement is detected in the kitchen but the light sensor is only used for detecting ambient light to determine whether or not the lights need to be turned on. It won't turn them on during the day or if the kitchen lights are on. And if they are on then the kitchen lights are turned on, it will fade them out. The code is very simple.

#define ledPin 5        // Top LED strip
#define ledPin1 6       // Middle LED strip
#define ledPin2 9       // Bottom LED strip
#define analogPin A0    // potentiometer connected to input 0
#define motionSensor A1 // motion sensor connected to input 1
#define lightPin A2     // Light sensor connected to input 2
#define lightThresh 15 // Light threshold
#define maxbright 255
int motion = 0;         // variable to store the read value
int curLight = 0;       //current light level
void setup()
{
  pinMode(ledPin, OUTPUT);   // sets the pin as output
  pinMode(ledPin1, OUTPUT);   // sets the pin as output
  pinMode(ledPin2, OUTPUT);   // sets the pin as output
  Serial.begin(9600);
}

void loop()
{
//  analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
  if (analogRead(motionSensor)>0 && analogRead(lightPin) < lightThresh) {
    turnon();
    delay(1000);
    while(analogRead(motionSensor)>0 && analogRead(lightPin)<(lightThresh+15)){
      delay(200);
      Serial.println(analogRead(lightPin));
    }
    turnoff();
  }
      Serial.println(analogRead(lightPin));
}

void turnon(){
  for (int i =0; i<maxbright; i++){
    analogWrite(ledPin, i);
    analogWrite(ledPin1, i);
    analogWrite(ledPin2, i);
      Serial.println(analogRead(lightPin));
    delay(25);
  }
}

void turnoff(){
  for (int i =maxbright; i>=0; i--){
    analogWrite(ledPin, i);
    analogWrite(ledPin1, i);
    if (i<25) analogWrite(ledPin2, i);
    delay(35);
  }
}