Hello Arduino community!
This is my first time posting on the forum so I hope I’m follow the correct protocol with everything! (unsure if this should go in 'Project Guidance’ or ‘Sensors’.. but I thought I’d post it here to start)
I recently built a light installation for a festival (Img.1), using the HC-SR04 ultrasonic range sensors to control a relay module switching LED baton lights. The installation was supposed to comprise of 3 triangular prism towers arranged facing each other (Img.2: ariel view sketch).
The original plan was that once people enter the triangular arrangement of towers, all the inner lights (coloured) would turn on (RELAY 1 in code - if between 80-300cm). As you move closer towards each tower (RELAY 1 if average<60cm), the light facing you would stobe faster.
The outside lights (RELAY 2 and RELAY3), would strobe based on the proximity value only when it’s <260cm, otherwise they will perform a fast ‘blink’ at random intervals between 10000-20000ms.. the idea was that the outside lights would subtly ‘beckon’ festival goers into the otherwise dark installation which would all activate once people were nearby/inside.
Anyway I ran into a few issues on the day. One Arduino broke (hence why there are only 2 towers in the first picture) but more importantly the program wasn’t running anywhere near as well as it did when I tested it in my studio.
I think directly using the distance value calculated from the HC-SR04 for the relay switch interval value wasn’t a good idea. If the sensors weren’t getting an ‘echo’ response, it seemed as though it delayed the program. When all 3 sensors for each tower were getting a response, the program would run well and the strobe-rate would be correct. Otherwise the behaviour was a bit strange/unpredictable. I think this is why in a studio with walls for the 'ping' to bounce off, it seems to work well.
I experimented with averaging for RELAY1 to deal with some of unstable sensor reading values, but it seemed to delay the immediacy of the interaction with the installation. I think I got rid of it on the final version I used, but it's still in this version of the code.
I’ll post the code in the next reply - it makes the post too long unfortunately.. I’m really sorry it’s probably a huge mess - I’m still quite new to Arduino and it’s an amalgamation of lots of things from other places.. definitely a bit of cowboy coding going on!
I’m mainly looking to just get a reliable interval value, so the lights are responsive when in an outside environment where they may get no ‘echo’ response (if nobody is in-front of the towers). I thought that the strobe would just initiate when the distance value is < (x), although clearly I’m missing something that’s delaying the program. Now I’m thinking about it, there’s definitely something wrong with how much is going on in the loop().. so I’m assuming I need to take some functions out of there somehow?
If anybody could give me any pointers on how to get a good, stable strobe rate (relay switch interval) with the HC-S04 distance readings that would be amazing!
Please feel free to correct me on any other errors in my programming as well.
Thanks so much for taking the time to help out!!!
Img.1
Img.2