loading
Vision is one of the most exciting senses you can endow on your robot. The ability to perceive obstacles allows a robot to make an educated decision regarding further movements.

However, it is also not the easiest senses to implement for a few reasons. Firstly, vision can be abstracted to a two-dimensional vector when it comes to computing, as opposed to a single dimensional scalar such as, say, temperature. Secondly, it is an analog value like many other senses, so it requires a certain degree of digitization and processing for it to make sense to a computer. Finally, though this is not strictly a problem, is visualization. Vision data cannot be represented as mere numbers to humans. Although that is how computers process data, it makes no sense for a human to decode digits. However, with the help of modern technology, and basic knowledge of physics and math, we will be able to endow our robot with the gift of sight!

Step 1: Theory

In this project, we are using an ultrasonic Distance sensor. It generates sound waves beyond the scope of human hearing and measures distance by calculating the time required by these waves to hit an obstacle and travel back. This is similar to the principle used by bats.

Another component that we are going to use is a servo motor. It differs from the usual DC motor in that it can turn very precisely to a given angular position and hold its state there. When a servo motor is given pulses of a specific duration, it moves to the corresponding angular position.

We will be using both these components to get a 180 degree field of view for our robot.

Step 2: Collecting Materials

This project uses the following hardware

  1. Arduino Uno/Yun (Please note that any Arduino footprint board can be used in place of the Uno or Yun)
  2. Arduino Prototyping Shield
  3. An HC-04 Ultrasonic Sensor
  4. A servo motor (I've used the Tower Pro SG90 because its very compact)

On the software side we are using the following programs

  1. The Arduino IDE to upload control code to the Arduino to rotate the servo and get distance data from the ultrasonic sensor and also push it to the serial port.
  2. Mathworks MatLab to receive data from the serial line, process it and visualize it to a graph.

Step 3: Mechanical Assembly

Using a small piece of general purpose PCB, make a small header for the HC-04, and attach it to a servo horn using a piece of double sided tape.

This step is optional, but to make the system more compact, I've attached the servo to the jutting part of the protoboard shield using double sided tape as well.

The final result should look like Wall-E's abdomen.

Step 4: The Arduino Code

The Arduino code controls the motion of the servo motor, and when the readings from the ultrasonic sensor are captured and how frequently. It also pushes the sensor data to the serial port.

  1. Import libraries
  2. Initialize variables and pins.
  3. Initialize servo object
  4. Initialize serial communication
  5. Wait for 3 seconds
  6. Initialize counters to 0
  7. Rotate servo by 1 degree
  8. Get ultrasonic sensor data 10 times (set by default)
  9. Average the data
  10. Send the average to serial port
  11. Return to step 7

Step 5: The MatLab Code

The MatLab code deals more with data than the actual control of the board, so all the sensor data is pushed over serial to the PC, where it is read by MatLab.

Now, the data that we receive from the Arduino tells us two things. The degree of rotation of the servo and the distance of an obstacle in that direction. Hence, the data that we have at this point is in the Polar coordinate system. For it to make sense to human eyes when visualized, it must be converted to the Cartesian or X-Y coordinate system.

So the MatLab code does just this. It gets data serially from the COM port, saves it into a matrix with the angle of rotation, and then converts it into Cartesian coordinates with the formula given above.
Once it's done, it gives an output by plotting the points on a graph. I placed the board in the box, and I got the following result.

Step 6: Conclusion

Although the system isn't perfect, it gets the job done. It can get a rough estimate of the box width and length and sends the data accurately

The only errors that I can see at the moment are due to the shaking of the sensor while the servo is moving and faulty readings from the sensor itself. Apart from this, the system works fine and can be used for depth perception experiments as well as basic computer vision projects.

<p>WOW! It took a little bit of figuring out, but in the end it was well worth it. Thanks!</p>
<p>Can We use Stepper motor instead</p><p>??</p>
nice project ! satya
<p>Thanks man!</p>
<p>Hi, i did the same project for my bachelor degree. So if you need any help you can conact me.</p><p>Just a suggestion: from the specs the angle of the US is about 15 degrees so you can speed up the scanning by increasing the the rotation angle from 1 degree to 5 or maybe 10 degree per scan. If you really want to map the environment on a robot you should add a compass module. </p><p>and remember have fun ;)</p>
<p>Thanks a lot for your suggestions! I'll be sure to implement them!</p>
<p>hi, how can i contact you. Email?</p>
<p>Private message</p>
<p>WOW, way over my head but I do enjoy seeing smart people figuring things out like this. Maybe more pictures would help though, still pretty cool, thanks. Semper Fi</p>
<p>Thanks a lot! I will certainly keep that in mind from my next Instructable :)</p>
<p>The only thing I don't understand is the wiring. Could you put a scheme of the circuit in the ible, maybe the 2nd step?</p>
<p>I'm sorry I didn't include it in the first place! I've uploaded the schamatic of the circuit I created in Fritzing</p>
<p>Congratulations for the intresting project!</p><p>As a challenge I sugest you to do the same with Python in the PC side.</p><p>Matlab is cool, but is very expensive, and you don't need it for this job ;)</p>
<p>Thank you so much! </p><p>That thought has been running through my mind ever since I actually made the project, and since then I've found a few alternatives.</p><p>- As you said, Python with an appropriate data visualization library. (Running that on an RPi and interfacing both could be fun!)</p><p>- Theres a software called SciLab which also does the same job as MatlLab for free, though I'm not sure about Serial communcication failities</p><p>- The Arduino equivalent of MatLab, called Processing. This is actually something I'm planning to use in the near future!</p>
<p>yes true, a free alternative should be used since the hardware itself is cheap too. I would suggest that i like to see more graphic pictrures. maybe You could make a multicolor height map. greetings</p>
<p>Nice project! Congrats!</p><p>A further step would be to use 2 ultrassonic sensors to make a more precise map (maybe kalman filter?)</p>
<p>Thanks so much for your insight! I'll look into the Kalmann filter, I'm looking into DSP practices or even statistical techniques to make the maps more accurate, the Kalmann filter would be a good contender.</p>
<p>Thanks so much for your insight! I'll look into the Kalmann filter, I'm looking into DSP practices or even statistical techniques to make the maps more accurate, the Kalmann filter would be a good contender.</p>
<p>How much is Matlab? What programming language does it use? </p>
<p>I really don't know, because I used my college PC to test and fine tune the code. As far as I know, the MatLab language doesn't really have a name, but it's a very high level language, pretty close to Arduino or R. </p>
<p>Interesting! .....I think I'll re-do this project on a Raspberry Pi 2 (or 3). The Rpi 2/3 are powerful enough for advanced processing that the Arduino cannot match.</p><p>Perhaps using an Arduino an IO board... </p>
<p>I'm really interested in what can be done using an RPi 3! I'm planning on ordering one soon and see what can be done using a Camera and OpenCV. I'm looking forward to your project!</p>
so does this thing make maps?<br>I'm kinda confused?
<p>Agreed. Would be an interim ting project. I will try it at RPi-3</p>
16.4.2016<br><br>That would be super. Since this is your excellent project, I'll wait until your RPi project is finished. Please let me know when, if possible.<br><br><br>NT<br>
Love the project. Keep up the good work. I'd love to see what more this application can do in the future
<p>Thank you for making this ible, It will help a lot with my Electric Water Gun sentry!</p>
<p>GREAT!..</p>
Thanks for your subscribe,it'll help me a lot.

About This Instructable

32,207views

406favorites

License:

More by Satyavrat:Hybrid Rover - Cloud Controlled Robot Future Sight Greenhouse System - Predictive Plants on the Cloud! CyberSafe : Your Personal Cloud IoT Platform 
Add instructable to: