Eliminating vibration noise from a mercury tilt switch

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!

Look into bounce suppression.

Mr. Gammon has a nice library called SwitchManager

http://gammon.com.au/Arduino/SwitchManager.zip
.

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.

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 :slight_smile: 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 :slight_smile:

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