Author Options:

I need help with my Arduino code Answered

Can you please help me if you can. I have this code for my Arduino that measures the distance of your hand using an ultrasonic sensor (HC-SR04 and then and displays the distance with a 7 segment display. but I am trying to change it so instead detect when a ball has gone through the hoop and starts at 0 and counts up on a 7 segment display every time the ultrasonic sensor it detects something we (me and my dad ) have tried doing this for weeks but both being a beginner at Arduino we don't know what to do. are original code and project came from:



The forums are retiring in 2021 and are now closed for new topics and comments.

11 months ago

thank you this is very useful and will defiantly help us


Best Answer 1 year ago

You want it to work as a simple switch.
Why not use one of the examples from the code library or the Arduino Playgroud for this?
I wouldn't bother trying to make a distance code work as a switch.

In case you do want to bother:
The code gives you a detected distance into some variable.
Take the given distance when installed in the hoop.
Put the ball on a string or similar and check what distance readings you get now.
Assign a new variable that is set if the detected distance differes from what is the baseline with empty hoop.
Use the same or preferably a new variable to increase by 1 very tme the ball triggers the previous variable.
Look for the variable or value used for the distance to be displayed.
I assume a standard code for the numbers is used, so simply replace the distance varibale with your counter.
If in doubt add a reset for the counter to your liking, e.g.: once 10 is reached jum the display nd variable back to zero.