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
Acoustics
  • Challenges & Projects
  • Project14
  • Acoustics
  • More
  • Cancel
Acoustics
Blog 1DUltraBot #3 : Finished (and working!)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Acoustics to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dubbie
  • Date Created: 6 Mar 2020 5:03 PM Date Created
  • Views 2067 views
  • Likes 12 likes
  • Comments 8 comments
  • nano
  • 1dultrabot
  • acousticsch
  • ultrasonic proximity sensor
Related
Recommended

1DUltraBot #3 : Finished (and working!)

dubbie
dubbie
6 Mar 2020

The 1DUltraBot is now finished, apart from the final 3D printed flat top piece. The circuit diagram is illustrated below and is very simple. One digital output (D2) from the Nano to control the servo motor and two (D6 and D7) to control the ultrasonic rangefinder module. The servo motor is connected directly to the battery as is the Nano,  whereas the ultrasonic rangefinder is connected to the 5V created by the Nano. I wasn't sure if the ultrasonic module would work properly from the battery voltage so I didn't take the chance.

 

image

 

The programme has been changed so that it takes a measurement using the ultrasonic rangefinder (HC-4) as listed below. First a 12 us trigger pulse is generated to start the ultrasonic module. The ultrasonic module creates a burst of high frequency audio waves for a short period. When the burst of ultrasound has ended the echo signal is activated so that timing can begin. It is not possible to start timing before the ultrasonic burst has completed as it messes up all the receiver signals as it is effectively a very loud noise next to a microphone. This means that a while loop is used to find when the echo signal goes high. This loop is a bit prone to errors because if the echo signal is not detected it will stay in the while loop forever. I could fix this by putting in a counter and exiting on some maximum count value but it works so I didn't bother. Then another while loop counts in increments of 10 us until the echo signal goes low. This while loop also doesn't have a counter to exit in case there is a problem but it would e easy enough to add, but it works, so I didn't. I went for 10 us increments as with anything smaller, the instructions to implement the while loop take up proportionally more time in the loop and the timing is not accurate. I did not perform an accurate calibration of the rangefinder as it isn't necessary for this project but I roughly checked and converted the time count into distance (cm) by dividing by 4.5. This creates a floating point number so I used the int() cast to chop it back into an integer. This value is then returned by this function.

 

 

int range(void)

{

int distance;

distance = 0;
digitalWrite(trigger, HIGH);   // Trigger pulse of 12 us
delayMicroseconds(12);
digitalWrite(trigger, LOW); 
while (digitalRead(echo) == 0)
  {
    //Do nothing - waiting for start of echo pulse
  }
while (digitalRead(echo) == 1)
  {
    distance++;
    delayMicroseconds(10);
  }
distance = (int) (distance / 4.5) ; //Div by 4.5 converts to cm
delay(800); 
return(distance);
} /* range */

 

This range() function is used in a while loop as listed below to take a measurement to the nearest object. Just in case there is a problem I have limited the maximum range to 100. This is about 100 cm, roughly. Then I used my own servo motor driver function called myservo() to make the chassis go forwards for almost the measured distance (it is a bit shorter to avoid crashing into the object). The first value provided to myservo() is the direction (2000 is forward maximum speed, 0 is backwards at the maximum speed), the second value is the specific servo motor (in this case number 2), and the final value is the length of time the servo motor is to be driven. This is set as twice the distance obtained from the rangefinder. This is just a try and see constant but it seems to be OK.

 

while (1)

  {

    dist_value = 0;

    dist_value = range();

    Serial.print("Distance is ");

    Serial.println(dist_value) ;   

//  } /* while */

 

// Just going forwards and backwards

//while (1)

//  {

     if (dist_value > 100)  // Ensure the distance is no more than 100

       dist_value = 100;

     myservo(fl_shoulder, 2000, 2 * dist_value); // Forwards

     delay(1000);

     myservo(fl_shoulder, 0, 2 * dist_value); // Backwards

     delay(2000);

  } /* while */

 

The finished and working 1DUltrabot is illustrated in the following video. I changed the battery holder from 4 x AA to 4 x AAA and the Nano breadboard to a much smaller one, as I realised that if I did this I would be able to squeeze everything back inside the original chassis top. I then 3D printed two side panels and a front panel to hold the ultrasonic rangefinder module, which as clipped in, in order to make a more attractive and complete mobile robot. All it needs is the final top piece 3D printing and all the electronics will be hidden away. I think it looks quite nice and it is a lot more 'finished' than most of my projects.

 

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

 

It works and it does what it is supposed to: nothing useful just an adaptable mobile robot using ultrasonics to determine the distance moved forwards and backwards following a track guide rail.

 

Dubbie

  • Sign in to reply

Top Comments

  • DAB
    DAB over 5 years ago +3
    Very nice build. You can do a lot of project variations with this build, such as play space craft docking. DAB
  • dubbie
    dubbie over 5 years ago in reply to genebren +3
    It does seem to sense pretty well. It only crashed into the object once and I wasn't entirely sure why that was but it may have picked up some rebound sound from somewhere. It was also quite interesting…
  • genebren
    genebren over 5 years ago in reply to dubbie +3
    Given the current project14 challenge (Acoustics) the ultrasonic sensors are a great choice. On my Walky project I opted for an IR distance sensor (GP2Y0A41SK0F with a range of 4-30cm), which I think worked…
Parents
  • three-phase
    three-phase over 5 years ago

    It amazes how you can manage to weave all the different project14 themes into some sort of a robot. Another successful entry to your tally.

     

    Kind regards.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • three-phase
    three-phase over 5 years ago

    It amazes how you can manage to weave all the different project14 themes into some sort of a robot. Another successful entry to your tally.

     

    Kind regards.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • dubbie
    dubbie over 5 years ago in reply to three-phase

    Donald,

     

    I do try to get a robot in somewhere. It's not always possible but you can usually fit one in somehow. To be honest, I only really like doing the robot bits - I have no idea why I like the robots so much, maybe because my PhD was mobile robots, plus, they move and make noises and have flashing lights (sometimes). That just interests me.

     

    Dubbie

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
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