Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arduino Robotic Projects

You're reading from  Arduino Robotic Projects

Product type Book
Published in Aug 2014
Publisher
ISBN-13 9781783989829
Pages 240 pages
Edition 1st Edition
Languages
Author (1):
Richard Grimmett Richard Grimmett
Profile icon Richard Grimmett

Table of Contents (21) Chapters

Arduino Robotic Projects
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Powering on Arduino 2. Getting Started with the Arduino IDE 3. Simple Programming Concepts Using the Arduino IDE 4. Accessing the GPIO Pins 5. Working with Displays 6. Controlling DC Motors 7. Controlling Servos with Arduino 8. Avoiding Obstacles Using Sensors 9. Even More Useful Sensors 10. Going Truly Mobile – the Remote Control of Your Robot 11. Using a GPS Device with Arduino 12. Taking Your Robot to Sea 13. Robots That Can Fly 14. Small Projects with Arduino Index

Accessing the IR sensor from the Arduino IDE


Now, bring up the Arduino IDE. Here is a simple sketch that provides access to the sensor and returns the distance to the object via the serial link:

The sketch is quite simple. The three global variables at the top set the input pin to A3 and provide a storage location for the input value and distance. The setup() function simply sets the serial port baud rate to 9600 and prints out a single line to the serial port.

In the loop() function, you first get the value from the A3 input port. The next step is to convert it to a distance based on the voltage. To do this, you need to use the voltage to distance chart for the device; in this case, it is similar to the following diagram:

There are two parts to the curve. The first is the distance up to about 15 centimeters and then the distance from 15 centimeters to 150 centimeters. This simple example ignores distances closer than 15 centimeters, and models the distance from 15 centimeters and out as...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}