Motion & Light Activated light

Hi guys,

I'm fairly new to using the Arduino and my first big project is getting an led to turn on if an IR distance sensor detects motion AND the photo sensor reads low light.

Now I have all this working but I saw online where someone had an led increase and decrease brightness depending on how bright or dark the ambient light is. I also have this working.

My problem is I want to add these two together. In the "if" statement I want to say (roughly)
if the there motion and light is below X, turn on the led in proportion to how dark.

I hope I've explained this clearly.

I've attached pics of the code to show you what I have at the moment. If you have any tips on how I can get this to work, I would be very grateful.

In the "if" statement I want to say (roughly) "if the there motion and light is below X, turn on the led in proportion to how dark."

Your second example has everything except "in proportion to how dark". You can get that from the first example. Change the "digitalWrite(ledpin, HIGH);" in the seconds example to the "analogWrite(ledPin,howBright);" in the first example.

In the future it would be better to cut and paste the sketch than to attach screen captures. Be sure to enclose the code in code tags (select the code and click on the # icon).

Thank you very much for your tips and I will try this tomorrow. Hopefully its as simple as you make it sound XD