Bumper Switch or Ultrasonic Sensor?

We are currently trying to improve our programming skills score by realigning the robot with the wall to increase accuracy. We thought a bumper switch may be a valid option to align with the wall without running up the wall. We are planning on having a bumper switch on the left and right side of the robot side that aligns with the wall. We aren’t sure how to program a bumper switch, let alone two, but we have some what of an idea. For example, if the left bumper switch is pressed by the wall, that side would stop running until the right bumper switch hits the wall. If both bumper switches are pressed, the robot then moves on to the next action in the programming. How would we program the bumper switches to do this? And is this the best way to do this? We are using C++ on Robot Mesh Studio.

If you put the bumpers on in such a way that the wheels do not touch the wall, you will likely have solved the problem without any programming. Your bot is only climbing because the wheels come into contact.

That said, your plain language description will translate to code pretty much exactly as you wrote it. I will give it a bit more structure:

while (leftBumper == 0 || rightBumper == 0){ // if either one is equal to 0
   if (leftBumper == 0){
   // run left motors in the direction the bumpers face
   else {
   // stop left motors
   if (rightBumper == 0){
   // run rightmotors in the direction the bumpers face
   else {
   // stop right motors

Once both bumpers are pressed, the next line in the code is run.

1 Like

Yeah, you are right, I was planning on putting it ahead of my wheels so that it doesn’t run up the wall. Where do I put this within my programming for autonomous? Do I just input it where I need it when it aligns with the wall? And does it matter if I am programming with degrees, rotations, or time? I am currently using degrees.

-code to back to the wall (in whatever form you choose)
-bumper code
-code to drive away from the wall

you have to program them from the brain and the brain will send them commands.In other words you have to put a command in the brain and the brain will notify the bumper switches.