Go Down

Topic: Development Needed for LED Switch (Read 372 times) previous topic - next topic

setiawanph

Jun 09, 2019, 09:18 am Last Edit: Jun 09, 2019, 09:19 am by setiawanph
Hello, all.

I have some simple project for making LEDs switch and blink based on the LDR and push button.

The principle:
After push button is clicking for second time, the LED is working to blink based on the light intensity in a room or do it outside. If the intensity is darker, the first LED is blinking in 0.5 second. While the room is darker, even totally dark, the second LED would be blinking in 0.1 second. If the push button is clicked for fourth time, the LEDs are "reset" and have to be activated after click the push button twice.

The result:
The principle is working 90% as I expected.

The issues:
-The LEDs are not in off mode after making some transition from the dark room into the lighter one, and also the opposite one. This could let some misinformation for that principle.
-Need a proper reset code after clicking push button fourth time. This day I only use LOW state for getting the LEDs back to the first statement.

If you have some ideas for developing this simple project, it would be a great contribution!

Thank You ^^

Note: For the wiring diagram and coding are in the attachment.

Grumpy_Mike

Quote
The principle is working 90% as I expected.
Why did you expect it to work only 90% of the time?

Your circuit is almost impossible to understand because you have used symbols for components that you probably made up and so only you understand. However, I don't think your push buttons are wired up correctly, if indeed those are push buttons.

setiawanph

#2
Jun 09, 2019, 10:53 am Last Edit: Jun 09, 2019, 10:56 am by setiawanph
Hello,

Thank you for replying me this post.
I've re-designed the wiring diagram. Hope it gives you a better understanding.

Oh, I didn't mention it has to be 90% works. I just mentioned that it has some issues to work properly (or 100%). That's why I mention it the code is just 90% do the job what I want for this simple project.

Grumpy_Mike

#3
Jun 09, 2019, 02:59 pm Last Edit: Jun 09, 2019, 02:59 pm by Grumpy_Mike
Quote
Oh, I didn't mention it has to be 90% works.
True you did not say that. What you did say was that you expected it to work 90% of the time. Maybe you did not mean to say that but that is what you did say.

Thanks for the update, the symbols for the LEDs are still wrong. Please look them up. The one you showed is for an incandescent lamp which has no polarity, LEDs do have a polarity but this is not shown with the symbol you used.

Now only if you could post the code correctly then maybe we could begin to get somewhere. Mobile devices can not cope with a .ino file, which is why when you read the how to use this forum sticky post you will find out how to post code here.

david_2018

A few suggestions:

You need to debounce the switch input.

( counting % 2 == 0 ) will be true for all even numbers, so cannot tell the difference between when the switch has been pressed two or four times.  A better test would be  ( counting % 4 == 2 ) . I would also declare counting as a byte because of how it is being used, a signed integer might lead to complications if it ever became negative.

If you want the LEDs to be off when going from dark to light, you will have to turn them off when the LDR input goes above the darkness level you are testing for, otherwise the LED will stay in whatever state it was in.

Go Up