Friday, 21 October 2016

Control of a servo motor with an ultrasonic sensor

This is a project which aims at development of an interactive interface in which the movement of a hand (or another obstacle) can control a servo motor. The project can be extended to execute projects in robotic control and newer interfaces for musical expressions.

Components:

1.      Arduino Uno
2.      Jumper wires (male to male)
3.      16 X 2 display LCD
4.      Ultrasonic Sensor HC SR-04
5.      Arduino Servo Motor
6.      USB Cable
7.      Compatible laptop with Arduino sketch installed on it.

A brief description of the different components is given as follows:

Arduino Uno

Arduino Uno is a microcontroller board based on the Atmega328P microcontroller. It has 6 analog inputs (A0 to A5), a 16 MHz quartz crystal (acts like a metronome for Arduino), a USB connection (to connect to the laptop), a power jack (to power it using AC to DC adapter), an ICSP header (to edit the In Circuit Serial Programming ports), 14 digital input/output pins (of which 6 can be used as PWM outputs), and a reset button.

Pinout diagram of Arduino Uno (https://arduino-info.wikispaces.com/QuickRef)

16 X 2 LCD Display

LCD or liquid crystal display is an electronic display extensively used to display relevant information. A 16 X 2 LCD means it can display 16 characters per line in the two lines. In this LCD each character is displayed in 5 X 7 pixel matrix. This LCD has two registers, Command and Data. We have displayed the distance of object from ultrasonic sensor on LCD.

Figure shows the LCD with its different pins:

16 X 2 LCD pins

It has 16 pins and function of each pin is defined in the following table:

S.No.
Pin Name
Pin function
1
VSS
Connected to ground
2
VDD
Connected to +5V
3
V0
Used to set contrast of the text appearing
4
RS
Used to select the register in which data is being written
RS = 0 => Command Register
RS = 1 => Data Register
5
RW
Used to select between reading/writing in the registers
0 => Write
1 => Read
6
E
Enable Pin
7 - 14
D0 - D7
Pins where data is written/read interpreted by LCD in ASCII
15
A
Backlight(Connected to +5V)
16
K
Backlight(Connected to ground)

Out of these RS, RW, E and D0 - D7 are connected to the Arduino pins. Because in our project we only need to write data into registers, that's why instead of connecting RW to a pin we directly connect it to ground. We can either use all 8 data pins (D0 - D7) or only 4 data pins (D4 - D7). For our case all the text that is to displayed can be represented by 4 bits. That's why we only use D4 - D7 pins of LCD.

Ultrasonic Sensor HC SR-04

An ultrasonic sensor is a sensor that uses sound waves to detect an object in front of it. It sends out a high frequency sound pulse and then detects the echo generated from an object in path. We can measure the time taken by the wave to travel forth and back. By having this information together with the speed of wave we can determine the distance of object from the sensor. Figure shows the ultrasonic sensor.

HC-SR04 ultrasonic sensor (http://www.ezdenki.com/ultrasonic.php)

The sensor has 4 pins - VCC, GND, TRIG and ECHO. VCC is connected to +5V. GND is connected to ground. TRIG and ECHO are connected to Arduino pins. TRIG is used to send high frequency sound wave and ECHO is used to detect the ECHO that comes back from object in path. A pulse which is HIGH for a minimum of 10us has to be given to TRIG. When done so, it sends out a 40Khz sonic burst of 8 cycles. ECHO pin sets itself HIGH the moment TRIG pin is HIGH. If there is an object in the path of wave it will reflect the wave. When ECHO detects the reflected wave it again sets itself to LOW as shown in the figure. In absence of any object there is no reflected wave and the ECHO remains HIGH until the next cycle.

The process involved (https://alselectro.wordpress.com/2013/03/08/arduinoultrasonic-sensor-for-distance-measurement/)

Servo Motor

Servo motor works on the principle of servomechanism. Basically, servo is given the input signal, corresponding to which the motor moves. It is a closed loop system with a controlled device (motor), an output sensor (inbuilt) and a feedback system (positional control). Servo motor is controlled through a PWM pulse. Servo motor comes with 3 pins:
  1. GND - Connected to ground
  2. Control - PWM pulse is supplied here
  3. VCC - Connected to +5V


Angle of rotation of servo is determined by the duration for which pulse is HIGH. For every servo motor, there is a minimum duration of pulse for which angle is minimum and there is maximum duration of pulse for which angle is maximum. Example is shown in figure below:

Figure shows the pulse duration with respect to rotation

Connections:

The connections have been made using Proteus. The voltmeter has been added so that we can see in simulation the voltage going to the test pin.




No comments:

Post a Comment