School Project

Recently my teacher told us to do a project by using sensor. My group members chose Light sensor. We decide to make automatic LED for a chicken coop model. Our idea is the led can turn on and off automatically depends of surrounding light intensity. Anyone has any suggestion for the electronic part? meanwhile I found this link can anyone tell me which arduino is it and where can buy the components? http://www.instructables.com/id/Arduino-Night-Light/

Any Arduino will do. The one in the link is an Uno - which is best for people starting out.

The other components can be bought from any electronic components supplier and should not be expensive.

...R

Simplest light sensor is an LDR. It is a resistor that varies with the amount of light.

It is used as part of a potential divider that the Arduino reads the centre of via an analogue input.

You read the value in a loop and when it is dark as you have selected, you turn on the light. When it gets light again, turn the light off. You will need to experiment with the values.

Don't forget to include hysteresis (google it).

Weedpharma

Thanks both of u :slight_smile:

void setup() {
Serial.begin(9600);
pinMode(3, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0);
if (sensorValue < 200) { // To change the point at which the light turns on change this value.
digitalWrite(3, HIGH);
}
else {
digitalWrite(3,LOW);
}

how about the program?
Any other suggestion?

NewbieApple: how about the program? Any other suggestion?

First, and most important, does it do what you want ? The Arduino is a great system for learning-by-doing

You may need to change the ELSE to

if (sensorValue > 250) {

to stop the program from hunting when the value is just a little bit either side of 200

...R

NewbieApple, Robin’s suggestion is for hysteresis.

Your code will turn on at a reading of <200, and off at > 200. What if the light level varies just a little?
The value may move between 199 and 201. This will cause your light to turn on and off rapidly. However if you use the advice given, there has to be a greater change before the light turns off and on.

I assume that your LDR is between 5v and the input and you have a R from the input to gnd.

Why do you have Serial.begin? You have no output to serial.

Weedpharma

Can i have a sample of program for simple arduino project? I'm referring to this example. http://www.instructables.com/id/Arduino-Night-Light/

We try to help when a person has a problem they cannot figure out.

we believe that you learn by doing and that just copying others work is not learning.

the IDE has examples of looking at things and outputting things.

the LDR is a varialbe input or analog. you need to connect it so that as the value changes you see that change.

some change go high, some go low. you need to test what yours does, then add the program that will see that change. or modify the hardware to get the change you want into a signal the arduino can use. the LDR is almost plug and play.

you will often be asked "what happened when you tried to make it work?" what we are saying is that we will not do your homework for you as it robs you of any real learning and your work in based on the knowledge of others, not your own.

that said, this is a beginners project. you learn by doing and you really can do this all by yourself. if it were hard, we would have told you to find a simplier projectt. but that is not the case. this is the simpler project.

load the software, look through the examples and find a way to read the analog input, then find a way to make your led work.

you are building your own fundamentals. skip this part and it only gets harder. figure this out and things get easier.

NewbieApple:
Can i have a sample of program for simple arduino project? I’m referring to this example. http://www.instructables.com/id/Arduino-Night-Light/

You have posted the sample of program for this simple arduino project.

// Arduino Night Light by EGRobotics

void setup() {

  pinMode(3, OUTPUT); 
}
void loop() {

  int sensorValue = analogRead(A0);
  if (sensorValue < 200) { // To change the point at which the light turns on change this value.
    digitalWrite(3, HIGH);
  }

  if (sensorValue > 250) {
    digitalWrite(3,LOW);
  }
}

I have tried the program below but the LDR must be completely in darkness so that the LEDs will light up. Tried to change the value but the sensor still the same means must completely darkness.
void setup() {
// put your setup code here, to run once:
pinMode(3,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead(A0);
if (sensorValue < 120) { // To change the point at which the light turns on change this value.
digitalWrite(3, HIGH);
}

if (sensorValue > 200) {
digitalWrite(3,LOW);
}
}

Really need guidance please help me.

Please confirm you are using the LDR in a voltage divider as suggested previously. What value R?

Weedpharma

void setup() {
  // put your setup code here, to run once:
  pinMode(3,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorValue = analogRead(A0);
  if (sensorValue < 120) { // To change the point at which the light turns on change this value.
    digitalWrite(3, HIGH);
  }

  if (sensorValue > 200) {
    digitalWrite(3,LOW);
  }
}

You are looking for an input of a low value to turn the LED on. This suggests you have the LDR between gnd and the input.

Put a 10k R from input to 5v

What do you mean by “Tried to change the value but the sensor still the same means must completely darkness.”?

Weedpharma