Tilt switch problems

4 views
Skip to first unread message

Marshall Wilson

unread,
Mar 22, 2011, 11:29:17 AM3/22/11
to nycresistormi...@googlegroups.com
Am having problems finding a good tilt switch for an arduino project.

I've already tried the "ball" type tilt switches from Sparkfun - but the closure isn't clean at all. Even with a decent debounce routine in my code the switch still sends lots of "phantom" signals. Have tried it with 2 different ones.

Wondering if anyone (a) has dealt with the ball tilt switches and knows what I am doing wrong, or (b) knows where I can get my hands on a mercury switch to try out....

or (c) if anyone has used the solid-state Omron or similar Tilt sensor devices. I really don' t need anything that fancy so I'd rather not steer into solid state.

thanks!

marshall


derek enos

unread,
Mar 23, 2011, 11:56:01 AM3/23/11
to nycresistormi...@googlegroups.com
These switches are unfortunately just really noisy.

Assuming that you're trying to detect when the switch closes....

One approach is to unequally debounce the open and closed switch states.  You could impose a greater debounce period on the open state and set each period to as great a duration as your performance requirements allow.

You could also just debounce the open state, consider the very next switch closure as valid and ignore additional switch closures until the open state has once again been fully debounced.  This would make the logic very sensitive to switch closures.

Depending on your performance requirements, there's the chance that no amount of logic wrangling is going to make this type of switch work for you.

Derek






--
You received this message because you are subscribed to the Google Groups "NYCResistor:Microcontrollers" group.
To post to this group, send email to nycresistormi...@googlegroups.com.
To unsubscribe from this group, send email to nycresistormicrocon...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nycresistormicrocontrollers?hl=en.


Dave Clausen

unread,
Mar 23, 2011, 2:16:20 PM3/23/11
to nycresistormi...@googlegroups.com
Sparkfun sells a number of MEMS accelerometers which can be used for
tilt sensing. They are generally much less noisy than the traditional
mass-on-a-spring or mercury switches.

http://www.sparkfun.com/tutorials/167

Or you could try the OSRAM optical switch but it's a leadless surface
mount part that would be a pain to solder, and I suspect it might have
similar noise/oscillation problems like the spring switch you've
already tried.

William Macfarlane

unread,
Mar 23, 2011, 2:21:12 PM3/23/11
to nycresistormi...@googlegroups.com
You can also potentially smooth out some of the noise by using a bunch
of switches and adding some statistics to your debouncing logic.

--
-Will
www.partsandcrafts.org

Marshall Wilson

unread,
Mar 23, 2011, 4:04:57 PM3/23/11
to nycresistormi...@googlegroups.com
Thanks guys...

Since I've noticed that the "off" zone is much cleaner than the "on", so perhaps I could combine a few of these ideas - use 2 switches, but turn one around so I'm triggering from a combination of both an "off" signal AND an "on". Don't know how it will work yet, but it just might be the ticket.

m

Andy Leviss

unread,
Mar 23, 2011, 5:21:20 PM3/23/11
to nycresistormi...@googlegroups.com
On Wed, Mar 23, 2011 at 4:04 PM, Marshall Wilson <li...@wilsonbuilt.com> wrote:
> Thanks guys...
>
> Since I've noticed that the "off" zone is much cleaner than the "on", so perhaps I could combine a few of these ideas - use 2 switches, but turn one around so I'm triggering from a combination of both an "off" signal AND an "on".  Don't know how it will work yet, but it just might be the ticket.

That could definitely help, but if you want to play a bit with the
single switch and scaling the closed timing vs the open, as a previous
poster suggested, I can give you some example code I've used.
Basically it sets a short debounce time and a longer "safety window".
After the first "closed" passes the short debounce, it uses millis()
to keep track of the time, it will only register a second "closed"
after that safety window has passed. Pretty straightforward in its
most basic form, just adding a variable and an extra if... to the mix.

--Andy

Marshall Wilson

unread,
Mar 24, 2011, 1:46:25 AM3/24/11
to nycresistormi...@googlegroups.com

I think i have it working now. Just one tilt switch (once i tried it - two really didn't make much sense). My code was a bit messy, but another problem was one of the switches was really quite bad. Once I started using another switch with a cleaner signal, things started working better, even with just a single stage debounce.

Anyway thanks again!
m

Reply all
Reply to author
Forward
0 new messages