Motion Following Robot
Intro: Motion Following Robot
Hello instructables community!
After messing around with an Arduino for a couple months and avidly reading instructables, I decided that I would finally publish my own. I wanted to create something that moves by itself. I also wanted to create a system that reacts to the outside environment. After some thought I decided on a simple motion follower.
Potential Applications:
• Motion following camera
• Robots that will acknowledge their environments
• Motion following turret
• Educational projects
• Obstacle avoiding robots
Required Materials:
• Breadboard
• Ultrasonic Range Sensor x2 (I used the four pin version so if you are using the ping version you'll have to change the code a bit)
• Servo (I used a micro size)
• Arduino UNO or similar microcontroller
• Jumper Cables (female to male and male to male)
• Particle Board
• 9v Battery and connector
• Something to mount the servo on (I used some poster mounting putty)
Required Tools:
• Hot glue gun
• Xacto knife
• Computer with Arduino IDE
• Electrical tape or similar
STEP 1: Build the Sensor Mount
First, we will need to build the sensor mount. For this I built a prototype out of cardboard and then built my final project in particle board. In the future I plan to 3d print a perfect mount for the sensor.
Cut a rectangle that is about the same height as one of the sensors and an 1/8th inch (about 3mm) longer than two of them together. Set the rectangle aside and cut out two identical isosceles triangles with the odd angle out being 120 degrees. I cut it at 120 degrees because the range sensors have a 15 degree cone that they measure, this allows for no blind spots while optimizing the area that is sensed.
Finally, place the sensors on the mount to determine where to cut the rectangular holes for them to fit in. Make the hole as small as possible because this snug fit makes up for not using any other adhesives or connectors. Now cut another small rectangular hole on the bottom triangle of the mount to allow for jumper cables to be passed through. Once the jumper cables are plugged in, the sensors should stay in place. If they don't, you will need to fasten them with some hot glue or pins.
When you are done with the mount, attach it to the servo.
STEP 2: Wire Everything!
Now all you need to do is connect everything! I used Fritzing to create a circuit diagram. I have also provided some pictures of the final product.
The code provided uses digital pins 9 through 13. Pin 9 is the data pin for the servo. Pins 10 and 11 are the echo and trig pins, respectively, of the left sensor. Pins 12 and 13 are the echo and trig pins, respectively, of the right sensor. I connected the 5v and gnd pins from the Arduino to the breadboard and then used jumpers to connect the servo and sensors.
STEP 3: Code
The code that I provided allows for the changing of the distance threshold. So in other words, how far the sensors can see. I will be uploading a new instructable soon to show how you can make the sensors even more accurate using a temperature sensor. Finally, my friend showed me a cool way of debugging really quick. All you do is use a boolean and some if statements. If the boolean is true, then serial communication will be on and communicating. If the boolean is false, then the program will run much faster but not communicate.
The code has been embedded on this page. If for some reason that doesn't work, you can also download the .ino file.
STEP 4: Conclusion
Once the code has been loaded, plug in the 9v battery and watch it start following anything that comes within the threshold range!
Troubleshooting:
- If the sensors keep turning the wrong way, try switching the cables in pins 10 and 11 with the cables in pins 12 and 13.
- If the sensors don't move at all, or just a little bit, check the wiring. It is really easy to accidentally move the jumper cables over one spot on the breadboard.
- If the sensors are moving really slowly, go back to the code and make sure that the debug is false. The serial communications can really slow down the reaction time of the robot.
- If you are still having issues, first make sure that the Arduino is on and that all jumper cables are in the correct spots. Switch the debug to true and check to see if the range sensors are working. You might also want to test the servo to make sure that it is also in working condition.
Some improvements I am planning on for the future:
- Improving the accuracy of the sensors with the use of a temperature sensor
- 3d printing the sensor mount and servo mount
- Adding another servo and sensor to allow for vertical movement
- Switching out the servos with stepper motors to allow for 360 degree following
I had a great time writing this instructable and hope to create many more! Please let me know how I did and how I can improve my future instructables.
91 Comments
Jacks how2s 4 years ago
MagicByCalvin 4 years ago
DamirŠ17 6 years ago
Hello, I have an issue with this project. I connected everything as it should be according to the scheme, but the application just doesn't seem to work. I tested out each sensor separately and they did work. To make it sure, I even bought another 2 sensors and changed the old ones but still nothing. Also I tested servo separately and it also works perfectly fine. But for some reason when I connect it all together nothing happens - sensors don't move and they don't even measure the distance when I turn on the serial communication (it shows distance every once in a while, most often immediatelly when I turn it on only for once and every next reading goes back to 0). I changed each wire with a new one to make sure that none of them are malfunctioning and again nothing. 9V batter works fine too since there is a sufficient voltage on every pin (I checked it with a voltmeter). I consulted some experienced guys and they told me that the problem most be in the program itself. Do you have any suggestions where the problem might be coming from? Thank You in advance
rayman6 6 years ago
I just hook all this up like the Fritzing diagram and then uploaded the sketch as is. Everything works as expected. I think you may have some wires mixed up on your circuits kids.
If your using a tower 9gram servo, the servo wire connections are, black goes to the brown, red to red and orange to pin 9. Fyi, servo wire colors may vary by manufacture.
Try a different breadboard or a different Arduino. Don't assume that this stuff is working properly. I fried an Arduino nano once and didn't realize it for 6 hours....
Don't copy and paste the code from this webpage. Webpages can do weird things to micro controller code. Download his sketch and upload to your Arduino.
Download his code here https://cdn.instructables.com/ORIG/FZY/9RIA/HVXC2C...
MagicByCalvin 6 years ago
Since the code is old, there may be some problems with it. I haven't looked at it in a while. However, depending on the servo and other parts you are using, it is possible that you are pulling too much power. A 9V battery can't produce very much current and a motor can easily take high amounts of current, even if it is small. Try using a different power supply. If that still doesn't work, it may be the code. I'll look through it at some point and revise it a little bit.
thesquidguy78 7 years ago
first off thanks for the help
but quick question
i have the design fully assembled, and i'm using the serial monitor, the device keeps printing linches 0 rinches 0. from my knowing this means that the sensors are functioning, but the micro servo wont even budge. i have tried slowly moving objects across it, im using the same sensors as you and the orange wire of the micro servo is connected to the arduino, so do you have any tips for a quick fix of a stationary micro servo?
MagicByCalvin 7 years ago
I would first test out whether the servo is truly not working. Use the Arduino servo sweep example (I think that's what it's called) to see whether the servo is in fact able to correctly function. Next, the fact that the sensors are printing 0 means to me that they aren't working correctly. Very seldom do I ever see them measure zero.
thesquidguy78 7 years ago
additionally all the wires are in the correct postition
thesquidguy78 7 years ago
does it matter which way the sensors are placed
MagicByCalvin 7 years ago
It does. You'll have to look at the specs of your sensors and do some testing on your own to determine the best placement of the sensors. If you look through the comments here, you'll see why I picked the angle I did for the sensors I was using. It was a simple approximation though and I did not perform any thorough engineering analysis so be sure to take that with a grain of salt.
thesquidguy78 7 years ago
@MagicByCalvin do you have any methods to print the real time data into the arduino serial monitor?
thesquidguy78 7 years ago
with still having a decent time reaction (not delayed by more than 4 seconds
MagicByCalvin 7 years ago
thesquidguy78 7 years ago
thanks
thesquidguy78 7 years ago
but will it track smoothly or stiffly
MagicByCalvin 7 years ago
It should still track smoothly. However, due to the nature of the system, even without serial communication, the follower doesn't move very smoothly. In order to move smoothly, a lot more work would have to go into the design. For one, more sensors would need to be used to increase the resolution of detection. Two, an output smoothing controller should be designed. Three, a better motor should be used. Those are some of the design tweaks I can come up with off the top of my head if you want to keep the system from jerking as it tries to follow you.
aditya.15jics007 7 years ago
MagicByCalvin 7 years ago
I am not sure what you are asking.
aditya.15jics007 7 years ago
nigel.trewartha 7 years ago
19.2.2017
May I suggest puting the source + construction info in GIT?
BD