Go Down

Topic: Motion & Light Activated light (Read 525 times) previous topic - next topic

uno_r3

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.

johnwasser

>  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).
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

uno_r3

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

Go Up