Skip to main content

Timeline for Arduino Coding Issue

Current License: CC BY-SA 4.0

7 events
when toggle format what by license comment
Oct 11, 2020 at 14:53 vote accept motion channel
Oct 6, 2020 at 7:52 comment added Edgar Bonet @motionchannel: For reference, the behavior described by your prose and implemented in Majenko's code is called hysteretic control. Within the hysteresis band (5 – 10 cm) the pump is supposed to stay in whatever state is was previously set. Hysteresis is a very sensible way of avoiding the motor rapidly switching on and off. See for example Wikipedia: Hysteresis in engineering.
Oct 5, 2020 at 19:41 comment added Duncan C You might want to add a maximum time value as well, so that if your ultrasonic sensor fails with the pump on, it has an upper limit on how long the pump will run. That would require recording the millis() value at the moment you turn the pump on, and turning it off if the motor is on and the current value of millis() is far enough in the past.
Oct 5, 2020 at 19:39 comment added Duncan C With Majenko's code, the motor won't turn on until the distance is > 10. Then it will stay on until the distance drops to < 5. That's what you wanted.
Oct 5, 2020 at 18:41 comment added Majenko If distance < 10 then the motor shouldn't work. You haven't specified that it should. You want it on for distance > 10 not < 10. If it's cycling on and off then distance is changing from greater than 10 to less than 5 repeatedly.
Oct 5, 2020 at 18:35 comment added motion channel Thanks. Two points, using the code above, if distance < 10, motor won't work. I tried adding digitalWrite(motor, HIGH); before if statement but I didn't test it yet. Second, The motor keeps running on repetitive cycles I believe every time code loops. is that healthy?
Oct 5, 2020 at 17:57 history answered Majenko CC BY-SA 4.0