element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Movers and Shakers
  • Challenges & Projects
  • Project14
  • Movers and Shakers
  • More
  • Cancel
Movers and Shakers
Blog Continuous Servo Bot - using Arduino Nano
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Movers and Shakers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: carmelito
  • Date Created: 14 Aug 2018 5:11 PM Date Created
  • Views 3899 views
  • Likes 10 likes
  • Comments 6 comments
  • ultrasonic sensor
  • arduino nano
  • moversshakersch
  • servo
  • ardexpert
  • arduino_classic
Related
Recommended

Continuous Servo Bot - using Arduino Nano

carmelito
carmelito
14 Aug 2018

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.

image

 

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

 

image

 

 

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 –

Workshopshed image 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.

image

 

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

image

 

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

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply

Top Comments

  • DAB
    DAB over 7 years ago +3
    Nice update. I look forward to see it moving around. DAB
  • genebren
    genebren over 7 years ago +2
    Looking very good. I am excited to see the video. Gene
  • genebren
    genebren over 7 years ago +1
    Very cool! Is the spin motion used to acquire range information to determine the next direction to go? The wheel turned out great, nice smooth movement. Well done! Gene
Parents
  • greenalien
    greenalien over 6 years ago

    If you are thinking about adding WiFi, suggest you look at the NodeMCU board which incorporates an ESP8266 WiFi module and is easy to program from the Arduino IDE.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • carmelito
    carmelito over 6 years ago in reply to greenalien

    Yes that is a great suggestion, I was thinking of adding the Arduino MRK1000 which has on board WiFi..

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • greenalien
    greenalien over 6 years ago in reply to carmelito

    The great advantage that the NodeMCU has over the Arduino MRK1000 is that it is considerably cheaper!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • greenalien
    greenalien over 6 years ago in reply to carmelito

    The great advantage that the NodeMCU has over the Arduino MRK1000 is that it is considerably cheaper!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube