Bump sensor

So for my intro class I need to make an autonomous robot and when it bumps into something it backs up and turns around. Only problem is once the bump sensor is clicked it will always read high. I was wondering if there is a way to reset it with programming instead of having to hit the reset but every time just to get it to work. The link to the sensor is below, along with the code I had. I can get it to read one switch change but not another one after that

const byte switchPin = 10;
byte oldSwitchState = HIGH;

void setup ()
  {
  Serial.begin (9600);
  pinMode (switchPin, INPUT);
  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);
  
  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    oldSwitchState =  switchState;  // remember for next time 
    if (switchState == LOW)
       {
       Serial.println ("Switch closed.");
       }  // end if switchState is LOW
    else
       {
       Serial.println ("Switch opened.");
       }  // end if switchState is HIGH
    }  // end of state change
   
  }

sketch_nov24b.ino (117 Bytes)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

How have you got the sensor switch wired?

Thanks.. Tom.. :slight_smile: