I want to write a condition on the serial monitor output data. I set a specific range of values that the sensor is giving like from 5cm to 10cm. I want to ask the serial to check if it receives data from that range 10 times let it perform a specific role like put an led on for 4 seconds. Please I need help with this...
What have you tried? What parts do you have (arduino board, rangefinder)? 10 times over what time span?
Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
(deleted)
(deleted)
Yes, the reading has to stay in range continuously for ten times before the task has to perform...
Distance.ino (6.29 KB)
I see you have counters for each range. I am new so there are definitely better ways of doing it but I would just add two extra counters for each range 5-10 & 65-75 with a nested if statement. Like..
if distance 5-10cm
if highCounter =<1
highCounter = 0
lowCounter + 1
if distance 65-75
If lowCounter =<1
lowCounter = 0
highCounter + 1
Then if lowCounter/highCounter = 10 do something.