Red or Green?

I call this project “red or green?”. The idea is that you guess a color and touch the light sensor to pick the right colour while the LEDs blink. You can use the potentiometer to change the speed of the blinking to make it easier or harder. Here is the demo:

I started this project with just the blinking LEDs. Then I added the potentiometer to the circuit to make the speed controllable. Things were going smoothly until I added the push button. I wanted to use this component to make the LEDs stop blinking and just let the one that was last on continue to glow while the push button is pressed down. However, the push button did not work every time I pressed it because the delay function at the end of every loop didn’t just stop the LEDs but the entire system. So, I looked into the example in the Arduino IDE “Blinking without Delay” which introduced the milis() function to me. After referring to this example, I managed to get the push  button to behave a bit more consistently. 

However, it was still behaving strangely. Ideally, a push button should print 1 on the serial monitor while it is pressed down and 0 when it is not. However, there seemed to be a lag because it would print 1 after I released the button.  My code depended on these values and so I could not get my LEDs to behave like I wanted them to.  I consulted with Jack and a lab monitor as well but to no avail. So, I decided to use a light sensor instead of a push button. 

It worked well with a light sensor although I had to test several times to get the optimal threshold sensor value . I imagine I will have to repeat this step under the different light conditions in class to produce the same results. 

 

The following is the schematics of the project

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *