Ultrasonic Distance Sensors Turning Servo Motors

From ESE205 Wiki
Revision as of 20:47, 1 May 2019 by Michael.horwitz (talk | contribs) (Moved stuff to the more accurately named page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Tutorial: How to use ultrasonic distance sensors to turn servo motors

Overview: When creating any vehicle, it is essential that it has the ability to avoid bumping into walls and other objects. One effective way of doing this is via the usage of ultrasonic distance sensors. By using ultrasonic distance sensors, obstacles can be evaded because they can be detected from several meters away, at which point the servo motor can be told to turn. This is done through coding things in a specific way and assembling the pieces of whatever you're turning in a way that works.

Materials: - ultrasonic distance sensors - servo motor - wires (male-female and male-male) - fan

Process: The ultrasonic distance sensor has 4 pins, which are power, trig, echo and ground. The trig pin is the pin that tells the ultrasonic distance sensor to emit ultrasonic waves, while the echo is utilized to receive the signal and send the information to the arduino. Both of these are digital pins. The obstacle detection code is placed below, however, the way it works can be simplified to the following procedure. First, the distance sensor is used to calculate the distance from the object in front of the hoverboard. If the object is within a distance of our choosing, then this information is relayed to the arduino which in turn calls the servo motor to turn in direction. Before the completed, however, the direction it is turning must be checked to guarantee the hoverboard is not just turning into another object. This is the process generalized.

 HoverCode.jpg HoverCode2.jpg

Now that the coding has been established, the wiring and connection to the servo motor must be explained. The servo motor is wired to ground, 5v and a digital pin. The servo motor is utilized, in coding, by inputting the angle change that we want to occur after an object is sensed. However, because the angle is not saved, it was necessary to create a method that rotates the motor and then records the current status that is at. The coding for the servo motor is seen below with the servo motor code.

Authors: James Shaheen, Michael Horwitz, Lucas Alcantara

Group Link: Link to our Log

Project Page

External References: https://www.youtube.com/watch?v=2XIG_DD4tt4&t=45s