1. Motorized Gesture Controlled Pan-Tilt
Mechanism
A Project report
Student: Kanishka V. Namdeo (BE 3rd
Year)
Guidance:A C Tiwari, Head of Department of Mechanical
Engineering
Roll no. : 0101ME111022
A C TIWARI
HOD, Department of Mechanical Engineering
2. Objective: Controllingthe two servo
motors with an accelerometer
Servo motor
Servomotors (or servos) areself-contained electric devices that rotate or push
parts of a machine with great precision.
Itis a rotary actuator that allows for precisecontrol of angular position,
velocity and acceleration. Itconsists of a suitable motor coupled to a sensor for
position feedback
As the name suggests, a servomotor is a servomechanism. Morespecifically, it
is a closed-loop servomechanismthatuses position feedback to control its
motion and final position. The input to its controlis some signal, either
analogue or digital, representing the position commanded for the output shaft.
3. Accelerometer
An accelerometer is an electromechanical device that will measure
acceleration forces. These forces may be static, like the constantforceof
gravity pulling at your feet, or they could be dynamic - caused by moving or
vibrating the accelerometer.
What are accelerometers useful for?
By measuring the amount of static acceleration due to gravity, you can find out
the angle the device is tilted at with respect to the earth. By sensing the
amount of dynamic acceleration, you can analyze the way the device is
moving. At first, measuring tilt and acceleration doesn'tseem all that exciting.
However, engineers have come up with many ways to make really useful
products with them.
Accelerometers havemultiple applications in industry and science. Highly
sensitiveaccelerometers are components of inertial navigation systems for
aircraftand missiles. Accelerometers are used to detect and monitor vibration
in rotating machinery. Accelerometers are used in tablet computers and digital
cameras so that images on screens arealways displayed upright.
Accelerometers are used in drones for flight stabilisation.
4. Arduino Uno (ATmega328)
The Arduino Uno is a microcontroller board based on
the ATmega328 (datasheet). Ithas 14 digital input/output pins (of which 6 can
be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB
connection, a power jack, an ICSP header, and a reset button. Itcontains
everything needed to supportthe microcontroller; simply connect it to a
computer with a USB cable or power it with an AC-to-DC adapter or battery to
get started.
5. Summary
Microcontroller ATmega328
Operating Voltage 5V
InputVoltage
(recommended)
7-12V
InputVoltage (limits) 6-20V
Digital I/O Pins 14 (of which 6 providePWMoutput)
Analog InputPins 6
DC Currentper I/O Pin 40 mA
DC Currentfor 3.3V Pin 50 mA
Flash Memory
32 KB (ATmega328) of which 0.5 KB used by
bootloader
SRAM 2 KB (ATmega328)
EEPROM 1 KB (ATmega328)
Clock Speed 16 MHz
6. ADXL345( the Accelerometer I used)
The ADXL345 is a small, thin, low power, three-axis MEMS accelerometer with
high resolution (13-bit) measurement up to ±16g. Digital output data is
formatted as 16-bittwos complement and is accessiblethrough either a SPI (3-
or 4-wire) or I2Cdigital interface.
The ADXL345 is well suited for mobile device applications. Itmeasures the
static acceleration of gravity in tilt-sensing applications, as well as dynamic
acceleration resulting frommotion or shock. Its high resolution (4mg/LSB)
enables resolution of inclination changes of as little as 0.25°.
Several special sensing functions areprovided. Activity and inactivity sensing
detect the presenceor lack of motion and if the acceleration on any axis
exceeds a user-setlevel. Tap sensing detects single and double taps. Free-Fall
sensing detects if the device is falling. These functions can be mapped to
interrupt output pins. An integrated 32 level FIFO can be used to storedata to
minimize host processor intervention.
Low power modes enable intelligent motion-based power management with
threshold sensing and active acceleration measurementat extremely low
power dissipation.
Features:
1.8V to 3.6V supply
7. Low Power: 25 to 130uA @ 2.5V
SPI and I2Cinterfaces
Up to 13bit resolution at +/-16g
Tap/Double Tap detection
Activity/Inactivity monitoring
Free-Fall detection
11. Servo Motor to UNO Connection
Source Code
#include <Wire.h>
#include <Servo.h>
#define DEVICE (0x53) //ADXL345 device address
#define TO_READ (6) //num of bytes we are going to read each
time (two bytes for each axis)
byte buff[TO_READ] ; //6 bytes buffer for saving data read from the
device
char str[512]; //string buffer to transform data
before sending it to the serial port
Servo myservox;
Servo myservoy;
int pos = 0;
int anglex;
int angley;
void setup()
{
Wire.begin(); // join i2c bus
Serial.begin(115200); // start serial for output
myservox.attach(11);
myservoy.attach(12);
//Turning on the ADXL345
writeTo(DEVICE, 0x2D, 0);
writeTo(DEVICE, 0x2D, 16);
writeTo(DEVICE, 0x2D, 8);
12. }
void loop()
{
int regAddress = 0x32; //first axis-acceleration-data register on
the ADXL345
int x, y, z;
readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration
data from the ADXL345
//each axis reading comes in 10 bit resolution, ie 2 bytes. Least
Significat Byte first!!
//thus we are converting both bytes in to one int
x = (((int)buff[1]) << 8) | buff[0];
y = (((int)buff[3])<< 8) | buff[2];
z = (((int)buff[5]) << 8) | buff[4];
anglex = x;
anglex = constrain(anglex, -279, 279);
angley = y;
angley = constrain(angley, -279, 279);
anglex = map(anglex, -279, 279, 5, 175);
angley = map(angley, -279, 279, 5, 175);
myservox.write(anglex);
myservoy.write(angley);
//we send the x y z values as a string to the serial port
sprintf(str, "%d %d %d", x, y, z);
Serial.print(str);
Serial.write(10);
//It appears that delay is needed in order not to clog the port
delay(15);
}
//---------------- Functions
//Writes val to address register on device
void writeTo(int device, byte address, byte val) {
Wire.beginTransmission(device); //start transmission to device
Wire.write(address); // send register address
Wire.write(val); // send value to write
Wire.endTransmission(); //end transmission
}
//reads num bytes starting from address register on device in to buff
array
void readFrom(int device, byte address, int num, byte buff[]) {
Wire.beginTransmission(device); //start transmission to device
Wire.write(address); //sends address to read from
Wire.endTransmission(); //end transmission
Wire.beginTransmission(device); //start transmission to device
Wire.requestFrom(device, num); // request 6 bytes from device
int i = 0;
13. while(Wire.available()) //device may send less than requested
(abnormal)
{
buff[i] = Wire.read(); // receive a byte
i++;
}
Wire.endTransmission(); //end transmission
}
Actual photos of the project
Figure 1: Arduino UNO board setup with sensor
14. Figure 2: sensor wiring
Figure 3: what the actual wiring looks like