Skip to content

Autonomous Systems

AI, Algorithms, Robotics (HelloRob | Berea College)

Menu
  • Home
  • Blog Guidelines
  • Schedule
Menu

Integrating Ultrasonic Sensors into ‘Follow Me’

Posted on December 14, 2023

How does this project build on or extend previous projects:

The final project I did was building on and combining ‘Project 3 Hardware’ and the ‘follow me’ projects. During ‘Project 3 Hardware’ it was pretty simple to set up the code to have the ultrasonic sensors to output the distance from all three sensors.

Issues I had with implementing the code:

The main issue I had when trying to integrate the three ultrasonic sensors into the follow-me project, the code would stall or crash. I did catch that if the distance gets too close, then the sensors would bug out and output a different distance. For instance, the distance could be 10-15cm, but if any slight movement closer to the sensor, then the distance would output ~1500+cm.
// Define GPIO/wiringPi pins
#define TRIG 4
#define ECHO1 5
#define ECHO2 2
#define ECHO3 6

// get distance from ultrasonic sensors getCM() function
int distance1 = getCM(TRIG, ECHO1);
int distance2 = getCM(TRIG, ECHO2);
int distance3 = getCM(TRIG, ECHO3)

// Get closest distance among the three sensors
int ClosestDistance = findMinDist({distance1, distance2, distance3});

My control logic for the ultrasonic sensors:
if (ClosestDistance > setpoint + margin) {robot.drive(-velx, -vely, 0);}
else if (ClosestDistance < setpoint - margin) {robot.drive(velx, vely, 0);}
else {robot.drive(0, 0, 0);}

What this section of the code was supposed to do 'theoretically' was after finding the Closest Distance, it would go onto the control logic and adjust the robot's positions/movement based on the distance from the wall. 

During working on this project, I had a lot of errors beginning with:

  • not having enough space/memory to compile the code.
  • Lidar data being put first or overpowering the ultrasonic sensors.
  • wiringPi library and ultrasonic sensors crashing the code/system.
simeon

Recent Posts

  • Dancing the Hokey Pokey
  • Python Wall-Following Project
  • From Static to Dynamic: Translating Wall Follower Code from C++ to Python
  • Final Project Reflection Blog – Hardware
  • Enhanced Obstacle Avoidance with Ultrasonic Sensors on MBOT
  • Google DeepMind’s AI Agent Dreams Up Algorithms Beyond Human Expertise
  • Google’s Advanced Protection for Vulnerable Users Comes to Android
  • Android 16 Is Getting a Facelift, and Gemini Is Rolling Onto More Google Platforms
  • Google Is Using On-Device AI to Spot Scam Texts and Investment Fraud
  • Singapore’s Vision for AI Safety Bridges the US-China Divide
©2025 Autonomous Systems | Design: Newspaperly WordPress Theme
Menu
  • Home
  • Blog Guidelines
  • Schedule