Arduino bump switches

I Have my very first robot posted on LMR and he's pretty cool except whet he gets a blind spot on his Parallax PING)) sensors and hits a wall, burning the motors and wheels. I'm really really naive when it comes to programing, i know only how to understand programs people have written before for arduino. I do know tons about non- programmed electronics, though. I want to add something like bump switches to my code. I don't know how! assistance requested. My robot is Makerson and he's new on the front page of robots.

Hi, Young Maker. Welcome to

Hi, Young Maker. Welcome to LMR. I’m sure you can learn a lot by reading through forum posts and robots on this site. I know that I have.For a bump switch, there are a couple of things to consider.

You connect your switch to a digital input of your microcontroller. The switch should be connected to the input that is either pulled high or low via a resistor (say about 10k). If you pull the input low via the resistor, the switch should connected so that it will connect the input to a logical high voltage.

inputswitchpulledlow.jpg

If you pullt he input high via the resistor, the switch should be connected so that it will pull the input to a logical low voltage.

inputswitchpulledhigh.jpg

It is important to know that all mechanical switches "bounce", which means when they make contact there is a momentary make-break-make-break electrical contact that can drive your robot crazy. It happens too fast for you to see if you were just turning on a light switch, but a microcontroller input will see these as logical high-low transitions and will mess up your code. You need to debounce the switch either with a physical circuit or inside your code. Search this site and elsewhere for debounce switch and you will see what I mean.

Another consideration is how you treat the bump switch in code. You can either check the value of a pin during the main loop of your program, or use an interrupt. I recommend an interrupt, as it responds more quickly.

I've just ordered my first Arduino, and it hasn't even arrived yet. So I can't give you specific advice on programming. However, if you look around the site I'm sure you can find an example of an Arduino based robot with a bump switch.

Good Luck!

Very interesting!

Thanks so much for your very helpful advice! I do know how to make a 100ms debouncer from a standard 555 timer, but i really want to try out a string of code. One question that may make me sound stupid, but what is an interrupt, other than the obvious?

I will admit that I’m not

I will admit that I’m not much of a programmer myself, so you should probably research and confirm what I’m about to say. An interrupt is a way to interrupt the normal flow of the software program, carry out a special set of instructions, and then return to the code where you left it.

that makes sense

But i kinda need a piece of starter code just to get my brain running in the right direction. Anyone?

Since your posted bot is

Since your posted bot is written in C++ and on an ATMega328, you should probably be able to use code created for the Arduino. There are lots of code examples on the net for this. Do some searching.

If you install the Arduino environment, there are a bunch of included examples, like this one.

 http://www.arduino.cc/en/Tutorial/Debounce

**Thanks **

I got 2 pieces of code that will set me in the right direction now. Thanksss.