Need help with this simple project, Photoresistor

Im trying to have the the led stay lit for 30 sec after the photoresistor is triggered.

int lightPin = 0; //define a pin for Photo resistor
int ledPin=8; //define a pin for LED

void setup()
{
Serial.begin(9600); //Begin serial communcation
pinMode( ledPin, OUTPUT );
}

void loop()
{
Serial.println(analogRead(lightPin)); //Write the value of the photoresistor to the serial monitor.
analogWrite(ledPin, analogRead(lightPin)/4); //send the value to the ledPin. Depending on value of resistor
//you have to divide the value. for example,
//with a 10k resistor divide the value by 2, for 100k resistor divide by 4.
delay(400); //short delay for faster response to light.
}

can anyone help?

Stay lit for exactly 30 sec and always turn off? How long before it can turn on again? Stay lit for at least 30 sec each time? You need to be more explicit in describing the behavior you are after.

This link will teach you how to time things on Arduino.

Stay lite for 30 sec after each activation.

Thanks

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

jim_s824:
Stay lite for 30 sec after each activation.

Thanks

You have not clarified a darn thing.

Hi,
Usually when a problem has been solved on the forum, the successful end result is posted so any one using the forum with a similar problem can find a solution.

A copy of your code and if possible a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png will help accomplish this.

This way the forum is not just a learning curve for you but will help others on similar learning curve.

Thanks.. Tom.. :slight_smile:

Your specification is ambigious as pointed out above. Let me be even more specific with the questions you will have to answer before you can even start to implement this project.

Activation lasts some time (can be seconds, can be very short, but it's not zero time). Count from start or end of activation event?

Switch on right away when activation is detected, or wait for activation event to be finished?

Activation can happen again while the LED is lit already. Start counting anew?

When the 30 seconds are over, will a new activation light it right away, or requires it a delay? What to do with activation events during the delay?

Have a look at how millis() is used to manage timing in Several things at a time.

...R

Thanks for all the valuable advice and support for a beginner. I just added a timed relay.