0

I just watched this excellent video tutorial that shows a simple Arduino program that toggles an LED via a pushbutton. Very cool!

Being brand new to electronics/robotics, I was shocked that something as simple as a pushbutton required his debounce behavior. That's something I would have never thought about in a million years. What is the 'rule of thumb' for when this type of debounce behavior (regardless of what sensor we're talking about, pushbutton or otherwise) must be accounted for? Is it simply that any type of analog sensor can generate this kind of unexpected 'noise'?

Can someone provide other examples for when special code must be put in place to accommodate unexpected sensor noise?

  • 1
    Switch bounce and sensor noise are two distinct issues. – Ignacio Vazquez-Abrams May 5 '15 at 19:25
  • Thanks @IgnacioVazquez-Abrams (+1) - ok then my apologies for getting my terminology mixed up. What I'm asking for is: what types of sensors, besides pushbuttons and their 'bounce', also exhibit this unexpected behavior. For instance, if I try integrating my Arduino with some new "Fizz Buzz Sensor" (that detects Fizz Buzz), how do I know that I can't just accept the readings it gives me, and that I won't have to do something similar to debounce? – smeeb May 5 '15 at 19:29
  • 1
    I'm not sure if this is called noise, per see, as the problem with buttons is mechanical, not electrical. I can't think of any other sensors with similar (unexpected) gotchas. Most electrical noise is caused by varying power use, that will result the supply voltage not being stable. This instability can cause malfunctions or give inaccurate readings (like e.g. measuring a voltage while the supply voltage isn't stable, will lead to inaccuracies). Most of this can be negated by adding (decoupling-) capacitors. – Gerben May 5 '15 at 19:32
  • Thanks @Gerben (+1) - so to confirm - this "switch bounce" is more of the exception than the rule, and these types of problems are not really encountered with other types of sensor readings, yes? Thanks again! – smeeb May 5 '15 at 19:37
  • 1
    Rotary encoders have the same problem (as they work just like buttons on the inside), but other that I don't think so. All sensors probably have some things to look out for. E.g. light sensors will detect IR (that we humans can't see); Range sensors won't work on certain material; magnetometers might not give correct information when near speakers or microwaves. etc. etc. But nothing as "illogical" as switch bounce (to my knowledge). – Gerben May 5 '15 at 19:46
1

Switch bounce is a physical issue that can be cleaned up with filtering. Since the sense states are very simple, only very crude (time-based) filtering is required to clean up its signal.

Other mechanical sensors that can exhibit similar characteristics are bump sensors, tilt sensors, and accelerometers. Bump and tilt sensors are also very simple, and similar filtering will clean up their signals.

Accelerometers on the other hand react to very minute perturbations, so they may require more advanced filtering based on the application they will be used in; orientation sensing can use time-based filtering, whereas things such as motion tracking including dead reckoning will require one or more layers of calculus in order to clean up the signal.

  • Awesome, thank you @Ignacio Vazquex-Abrams (+1) - when you say "filter/filtering", how does such a filter manifest itself in an Arduino program? For instance, in that video tutorial, the author simply implements a delay(...) inside his debounce function. Is that an example of an actual time-based filter, or does Arduino have some "filter API" that can be coded against to implement various types of filters. Thanks again! – smeeb May 5 '15 at 19:46
  • 1
    @smeeb you can either filter in software, or with additional components (resistor+capacitor) – Gerben May 5 '15 at 19:51
  • @smeeb: There are entire series of university courses that cover digital filtering. – Ignacio Vazquez-Abrams May 5 '15 at 20:03
  • @smeeb: Summing (averaging) several readings is one way of filtering. It depends on the assumption that the signal is consistent and the noise is random with a mean of 0. Thus summing statistically emphasizes the signal and deemphasizes the noise. The average can be as simple as the mean of the last n readings; or: f * (previous average) + (1-f)*(present reading), called an exponential average; and on up to much more complicated ways of treating the signal to reject specific kinds of noise. For most projects, a mean or an exponential average will do and are easy to code. – JRobert May 5 '15 at 20:15
0

Anyone who believes sensors do not have noise has never used one. True you may not encounter noise while reading the digital information, but I promise you the information will have noise in it. Noise from a switch can be dealt with by hardware or software, such as his debounce behavior. Other sensor noise is 4 years of study at college. Look into Kalman Filters, probabilistic robotics. Even the self driving cars you hear about currently require large compute capacity, mostly in order to deal with sensor noise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.