Go Down

Topic: Eliminating vibration noise from a mercury tilt switch (Read 163 times) previous topic - next topic


Mar 27, 2016, 06:33 pm Last Edit: Mar 27, 2016, 06:38 pm by IMEEnginer
Hi there,

I am using a mercury tilt switch on a line following robot and am currently have it set up so that when the robot is inclined it triggers a digital pin to go high which changes the speeds of the robot when going up the hill. (Slows it down so it doesn't fly off the table) although as the robot vibrates when going round the track it constantly triggers the tilt switch slowing it down. Is there a way to get rid of the tilt switch noise within the circuitry or maybe in the code? Would putting a capacitor and resistor across the tilt switch output get rid of quick spikes of noise? Is there a way of only changing the speeds of of the robot if the tilt switch has been HIGH for a whole second without delaying the loop as the PID can't be delayed?

Thanks for your help!


Mar 27, 2016, 06:35 pm Last Edit: Mar 27, 2016, 06:39 pm by LarryD
Look into bounce suppression.

Mr. Gammon has a nice library called SwitchManager

No technical PMs.
The last thing you did is where you should start looking.


Thanks LarryD, I will have a look at using the library and the Debouncing without delay method.


You will probably have to modify the "debounce" for your need - typical switch bounce is in the milisecond range where as with a mercury switch, you are probably looking at a much longer time constant in the "bounce" (or slosh as it were) times.  Typically, with something like that, sample it 3 or 4 times for example over a 1 or 2 second time frame.  If the results are the same for all samples, then it is valid.
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3


Thanks Mikey, I will have to experiment, as the ramp is only short probably about 30cm long at 30 degrees. It probably takes less than a second to go up and over the ramp. Do you know of any other (cheap/simple) methods to detecting an upward ramp? There is also a downwards ramp at the same angle and length although I don't want my robot to react to it.
Many thanks.


A gyro comes to mind  :)   The problem you are going to run into typically is that those ramps do not start gradually, so it is almost like you hit something when you run into it (in fact if the CG of your robot is too high, the transition may tip it over).  The tilt switch is probably OK, you just need to find that sweet spot between the slosh when it hits the ramp and before it gets to the top (or bottom) of the ramp.  Welcome to the world of "real time" - the response time for flight controls at mach 2 is not the same as the rudder control on a super tanker  :)
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3


I was tempted to use a gyro but it's tad too expensive for the budget, tipping isn't an issue as it has a fairly low centre of gravity, it's mainly designed for speed but as there is a corner directly after the ramp it flys off the track. Yeah the tilt switch should do the job once I have filtered the noise, it works fine on the bench it just vibrates a bit much round the track. Thanks again for your help

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131