A programming challenge involving piezo sensors, LEDs, and relays

Oh dear, that’s no good at all. I hate to ask, but could you check they’re still connected to A3 and A1 pins on the Arduino? (The video movement is too fast for me to see.)

By the way, what is the chart on the screen showing?

1 Like

okay so the screen is displaying a value whenever the button or sensors are triggered and it just wasn’t showing having sensed the sensors. And yes they are plugged into A1 and A3.


also i want to again thank you for the help you have provided!

1 Like

I couldn’t have gotten so far on my own. Here’s a look at what is currently done overall of the project.


This is the light enclosure and the arduino enclosures I designed.

1 Like

So where do we go from here?

It might be a good idea to either change the program to provide a diagnostic/test mode. In my fish feeder project, it behaves differently for testing if the button is held down when the system is powered up.

I’ve got work in 45 minutes. I’ll “design” the test mode now and hope to implement it at lunch time.

1 Like

Good news, it didn’t take that long to do. Please get the latest version and try that. The change you should see is as follows:

On startup, the word “Startup…” should appear on the LCD for almost a second (800ms). If at the end of that the button is “down” (being pressed) then it’ll enter test mode. The simplest is just to hold it down when powering up until you see the message “TEST MODE” on line one and “Release button” on line 2. Releasing the button will start the tests:

During test mode, line one will show “TEST MODE”. Line 2 will show the test in progress in this order:

  1. Relay 1 ON (for 2 seconds)
  2. Relay 2 ON (for 2 seconds)
  3. Relay 1 OFF (for 2 seconds)
  4. Relay 2 OFF (for 2 seconds)
  5. Show the value for piezo vibration sensor 1 as “PV1: 0000” (for 5 seconds)
  6. Show the value for piezo vibration sensor 2 as “PV2: 0000” (for 5 seconds)

After this test process, the system will start normally and you’ll see “Ready” on line one and “Press the button” on the second line.

If you could share a video of your test we’ll know if it’s a problem with the sensors or the code. (Probably the code, but I think this test mode will be valuable regardless.)

1 Like


seems to work great!

1 Like

I can see from the video that the test mode works which is great news. Looked like the target sensors were working as well but I could not see the values on the LCD clearly. I think the room is either too dark, or the LCD is too bright and the camera can’t adjust for both.

Does that mean that the whole thing is working now? Looked to me like it was showing player 1 and player 2 times at the end, but that might just be because you didn’t press the button to reset them after the test mode?

Please let me know what’s still not working and I’ll have a look at the code again. I’m over at friends tonight and might not be back until tomorrow. Sorry, I’ll get on it as soon as I’m free again.

1 Like

Once this is working, or maybe just as my next update, I’d like to refactor the code. That means changing how it’s written without changing how it behaves. The two functions are far too long and that makes them difficult to read and understand. My hope all along has been that sharing the code will be clear enough that you’re interested to learn more, or the next person to visit this thread will look at the history of the code file and see how things can be written.

1 Like

Okay so the thing appears to work really well! it still on rare occasion wont reset but other than that the test mode works well and it appears to all be sensing well. also as far as it working after the test mode it also adds the time it took to cycle through the test mode to the reaction time but this only happens after you enter test mode. If you don’t enter test mode then it works just fine.

Still, a bug I can easily fix so I’ll do that after work this evening.

1 Like

Let me take those opportunity to say how rewarding it’s been for me to help you on this project. Your feedback has been encouraging and detailed. :+1:

1 Like

hey i totally couldn’t have done it without you and I’m thrilled that you are as excited as i to do it! without a doubt I will continue increasing my understanding of python and the arduino language!

1 Like

so what changes have you made?

I’m sorry, I’ve been snowed under at work. Had to work 6 days last week and will be doing the same this week again. :slightly_frowning_face:

I might have some time tonight to review and update the code.

1 Like

Right… I can’t see why the target times would include the test time from the diagnostics run. Might be just me being dead on my feet.

I’ve refactored the code into methods to make it easier to comprehend. In theory nothing should have changed with regards functionality/operation. You’ll notice that the Setup and Loop methods are now a lot shorter and easier to understand:

1 Like

Where do we go from here @Drewkus? Do you want me to make further code changes, or are you happy with it as it is now?

I’m hoping you’ll post a video of the final build in use! :smiley:

1 Like

Yes! finally got back from a long unexpected family trip. Ill give it a go as soon as i return home today and will progress to getting the final product ready for everybody to see!

1 Like

I hope all is going well with your project. It could make an interesting video of all the trial and error leading up to the final product. :wink: :smiley:

1 Like

What happened too this project @Drewkus? I’m hoping you and your body have had so much fun playing with it you’ve forgotten to post a follow up? :smile: