Four wheeled Arduino robot

I’m just starting out building a four wheeled robot powered by Arduino. Initially, I’m hooking up four servos for driving, a distance sensor for obstacle avoidance, and an LCD display for debugging the distance sensor.

I’ll keep building on the project over time (maybe hook up GPS or IMU for navigation), and increasing the code complexity - right now the robot simply drives until it reaches an obstacle and then stops. I’ll also post a link to parts once I make some more progress.

Circuit:

Arduino UNO Code:

#include <Servo.h>
#include <LiquidCrystal.h>

// Servo variables
Servo servo_br; // back right servo
Servo servo_bl; // back left servo
Servo servo_fl; // front left servo
Servo servo_fr; // front right servo

int speedForward = 100;
int neutralSpeed = 1500;
int centeringOffset = -10;

// LCD Variables
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Ultrasonic sensor variables
const int trigPin = A0; 
const int echoPin = A1;

void driveForward() {
  servo_bl.writeMicroseconds(neutralSpeed + speedForward + centeringOffset);
  servo_fl.writeMicroseconds(neutralSpeed + speedForward + centeringOffset);
  servo_br.writeMicroseconds(neutralSpeed - speedForward + centeringOffset);
  servo_fr.writeMicroseconds(neutralSpeed - speedForward + centeringOffset);
}

void driveStop() {
  servo_bl.writeMicroseconds(neutralSpeed);
  servo_fl.writeMicroseconds(neutralSpeed);
  servo_br.writeMicroseconds(neutralSpeed);
  servo_fr.writeMicroseconds(neutralSpeed);
}

void setup()
{
  servo_br.attach(7);
  servo_bl.attach(8);
  servo_fl.attach(9);
  servo_fr.attach(10);

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
}

void loop()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  float duration = pulseIn(echoPin, HIGH);
  float distance = (duration*.0343)/2;

  // Print out the distance
  // set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  lcd.print("Distance: ");
  lcd.print(distance);
  delay(100);

  if (distance < 20) {
    driveStop();
  } else {
    driveForward();
  }
}

Some things that I noticed building this circuit:

  • It would be nice to be able to rotate components. It was difficult to place components how they actually sit on my breadboard without rotating.
  • It would be nice to be able to add more breadboards. I’m going to be extending my project at some point, so only 3 three breadboards is somewhat limiting.
  • I used the screen shot feature to capture the image I uploaded, but this feature took a screen shot of the whole screen, and I had to zoom out so it would capture my whole circuit.
  • I noticed there isn’t a built-in zoom-in/zoom-out feature. This will be nice to have once my project gets larger.

Hi Jeslee1002,

Thanks for posting your project! We’re very excited to see where it goes.

We also really appreciate the feedback. Those are some excellent points, which we will definitely work on incorporating into Cirkit Studio as part of an update. We’ll keep you updated on our progress.

Thanks for being a part of this community!

-Austin on behalf of the Cirkit Design Team

Hi Jeslee1002,

I hope your project is progressing well!

I just wanted to follow up to let you know that we added a couple of your feature requests to our latest release!

  • We added better schematic / circuit capturing
  • We also added panning/zooming

We’re working on your other requests (component rotation and changing the number of breadboards) as part of a future release, which we’ll keep you updated on.

Best,

-Austin on behalf of the Cirkit Design Team