Pages: [1]   Go Down
Author Topic: Motion & Light Activated light  (Read 487 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* Code for Night Light.png (12.16 KB, 768x432 - viewed 12 times.)

* Code for Motion & Darkness.png (17.41 KB, 768x433 - viewed 13 times.)
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8937
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

>  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).
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: