Example Code for Arduino-Bumper Sensor

Last revision 2025/12/31

Use this code to read the bumper sensor status.

The codes of the bumpers should be used in Mega ADK.

Hardware Preparation

  • Main controller: Arduino Mega ADK/2560
  • Three bumper sensors
  • GMR board
  • Switch system

Software Preparation

  • Development tool: Arduino IDE 1.0.x or higher

Wiring Diagram

connection

Other Preparation Work

  • Insert the Mega and Nano on the GMR board, connect the output of the switch system to the power supply of the motor controller and the GMR board.
    switch system

  • Turn off the switch.

  • Connect the circuits as the connection diagram, connect the bumpers.

  • You may test it use another microcontroller (Arduino Uno), then move the codes to the Mega ADK.

  • The codes of the bumpers should be used in Mega ADK. The communication between Nano and Mega ADK is I2C.

Sample Code

#include "Arduino.h"

int BumperR_pin;
int BumperL_pin;
int BumperC_pin;
byte BumperValue;
boolean blocked = false;
void OpenBumper(int,int,int);
void bumperRead();
/*************************** Details *****************************/


void OpenBumper(int LIO,int CIO,int RIO)
{
  BumperL_pin = LIO;
  BumperC_pin = CIO;
  BumperR_pin = RIO;

  pinMode(BumperL_pin,INPUT);
  pinMode(BumperC_pin,INPUT);
  pinMode(BumperR_pin,INPUT);
}
/*************************************************Bumper Sensor Status***********************************/
void bumperRead()
{
  BumperValue = 0x07;
  BumperValue=digitalRead(BumperL_pin)<<2;
  BumperValue|=digitalRead(BumperC_pin)<<1;
  BumperValue|=digitalRead(BumperR_pin);
//  Serial.println(BumperValue,BIN);
}

Result

Test the bumper sensors using the example code.

Was this article helpful?

TOP