Movers and Shakers

Enter Your Electronics & Design Project for Your Chance to Win a $100 Shopping Cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

In my previous blog post, I shared some pictures of the 3D printed parts I designed in Autodesk’s Fusion 360, for more info check out the blog post at –  Continuous Servo Bot- 3D Printing. The idea when designing the 3D printed parts was to make them minimalistic so that they can be printed quickly in less than an hour. Basically the parts below with my printer and infill  setting of 20% takes about 50 mins to print.

For the brain of the bot, I am using a Arduino Nano, and to power it up I am using a 2 cell Lipo battery. Also, let me know in the comments below if you would like to see a WiFi version of  the bot, this would mean I can replace the Arduino nano with a Arduino MKR1000.

 

Now if you plan on replicating this project, and give the bot 'eyes, you will also have to 3D print the Ultrasonic sensor holder STL file as you see in the picture below. Here are the circuit connections to the Arduino Nano

  • left servo connected to pin# 5
  • right servo connected to pin# 6
  • Trigger pin of the Ultrasonic sensor connected pin# 9
  • Echo pin  of the Ultrasonic sensor connected pin# 10
  • 2 cell Lipo connected to the Vin pin on the Nano

 

 

 

And, here is the Arduino code to upload to the Nano using the Arduino IDE

//Sample code for Project14-Continuous Servo bot 
//Please feel free to edit and modify based on your needs
#include <Servo.h>


// create servo object to control a servo
Servo myservoL; 
Servo myservoR;   
//Connections to the ultrasonic sensor
const int trigPin = 9; 
const int echoPin = 10; 
long duration; 
int distance; 
//Change this value to adjust the senstivity of the HC-SR04 
const int maxDistance = 25; 


  


void setup() {  
  //Setting the trigPin as an Output 
  pinMode(trigPin, OUTPUT);  
  //Setting  the echoPin as an Input 
  pinMode(echoPin, INPUT); 
  // Servos attached to pin# 5 and 6
  myservoL.attach(6);
  myservoR.attach(5);


  Serial.begin(9600);  
} 


void loop() { 
  // Clear the trigPin 
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2); 
  //Sets the trigPin to HIGH state for 10 micro seconds 
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(10); 
  digitalWrite(trigPin, LOW); 
  //Reads the echoPin, returns the sound wave travel time in microseconds 
  duration = pulseIn(echoPin, HIGH); 
  //Calculating the distance 
  distance= duration*0.034/2; 
  //Prints the distance on the Serial Monitor- use this to modify the maxDistance above 
  Serial.print("Distance: "); 
  Serial.println(distance); 
  if(distance < maxDistance){ //obstacle detected in front, move back and then turn left 
     move(100,'B'); 
     delay(100); 
     turn(150,'L'); 
     delay(200); 
  }else{ //keep moving foward 
      move(100,'F'); 
  } 
  delay(500); 


  //uncomment this section, and comment the if-else section above to test the direction of the servo 
  /*turn(200,'L');
  delay(300);
  move(220,'B');
  delay(300);
  turn(210,'R');
  delay(300);
  move(220,'F');
  delay(300);
  stop();
  delay(600);
  */ 
} 


//Driving direction functions 
void turn(int speed,char side){ 
  if(side == 'L'){ //left turn 
    myservoL.write(45);
    myservoR.write(90);
  }else{ //Right turn 
    myservoR.write(45);
    myservoL.write(90);
  } 
} 


void move(int speed,char moveDirection){ 
  if(moveDirection =='B'){ 
    myservoR.write(45);
    myservoL.write(45);
  }else{ 
    myservoR.write(135);
    myservoL.write(135); 
    } 
} 


void stop(){ 
myservoR.write(90);
myservoL.write(90);
} 

 

When mounting the battery , use Velcro if possible instead of double sided sticky tape, so it is easy to change the weight distribution if required, this was pointed out by Andy in a comment on my previous blog post –

Andy Clark (Workshopshed) Top Member Jul 31, 2018 4:07 AM

Looking good. The weight distribution is key so try and get the majority of the weight on the wheels rather than the skid as the marble can dig in on some surfaces. If you go too far the other way and the bot will pull a wheelie when accelerating.

 

And here is a picture of the bottom of the bot, which show the marble held at the back of 3D printed part.

 

Here is a quick video demo of the bot trying to climb my door mat  ...