Robotics Notes
Robotics Notes
Robotics Notes
An Arduino servo motor refers to a type of motor commonly used with Arduino microcontrollers for
precise control of position and movement. Servo motors are designed to provide accurate angular or
linear displacement based on the electrical signals they receive.
Arduino libraries and example codes are available to simplify the programming and control of
servo motors. These libraries abstract the low-level details of generating PWM signals, allowing
users to easily set the desired position or angle of the servo motor.
Circuit
Servo motors have three wires: power, ground, and signal. The power wire is typically red and should be
connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be
connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and
should be connected to a digital pin on the Arduino board. Note that servos draw considerable power, so if
you need to drive more than one or two, you'll probably need to power them from a separate supply (i.e.
not the 5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power
supply together.
Knob Circuit
For the Knob example, wire the potentiometer so that its two outer pins are connected to power (+5V) and
ground, and its middle pin is connected to A0 on the board. Then, connect the servo motor to +5V, GND
and pin 9.
Controlling a servo position using a potentiometer (variable resistor).
Sweep Circuit
For the Sweep example, connect the servo motor to +5V, GND and pin 9.
Sweeps the shaft of a RC servo motor back and forth across 180 degrees.
Ultrasonic Sensors
How Does an Ultrasonic Module Work?
• This module consists of two drums, one of which is an emitter that emits ultrasound and other is
receiver which receives the reflected ultrasound from the object.
• The emitter drum emits ultrasound when we trigger the module using the trigPin by sending a 10
microseconds high pulse.
•As soon as the ultrasound is emitted through the emitter the module makes the echoPin high.
•Emitted ultrasound travels forward till it gets reflected by object and then travels backward.
• The reflected ultrasound is detected by the receiver.
•When the reflected ultrasound is received by the receiver, echoPin is made low.
•Now we have the time take by the ultrasound to reach the object and again reach the source which is also
equal to the duration for which the echoPin was high.
•This time is stored in the microcontroller. Therefore travel time of ultrasound between just source to
object is half the time take to travel source-object-source we know that:
Code
First we define the pins that Trig and Echo are connected to.
const int trigPin = 9;
const int echoPin = 10;
Then we declare 2 floats, duration and distance, which will hold the length of the sound wave and how far
away the object is.
float duration, distance;
The float is one of the most important Arduino data type as it can store decimal numbers. This data type is
for floating-point numbers which are numbers with a decimal point. Floating-point numbers are often
used to approximate the analog and continuous values because they have greater resolution than integers
Sidt
pulseIn()
Returns the length of the pulse in microseconds or gives up and returns 0 if no complete pulse was
received within the timeout.