Sei sulla pagina 1di 26

Seminar Report

on

Accelerometer based mouse

BY

Sania Fazal 512


Parth Jhaveri 519
Ruchita Jobanputra 520
Srilalan Iyer 584

Department of

Electronics Engineering

Mukesh Patel School of Technology Management


and Engineering
Vile Parle (West), Mumbai – 400056
NMIMS University
2010-2011
Certificate
This is to certify that the following student/s:

Sania Fazal 512


Parth Jhaveri 519
Ruchita Jobanputra 520
Srilalan Iyer 584

Have submitted their Minor Project:

Accelerometer based mouse

As part of their curriculum for


Trimester IX, course B.Tech,
during the academic year 2010-2011

Examiner:______

H.O.D: ________
Acknowledgement

It is indeed a moment of great pleasure and immense


satisfaction for us to express our profound gratitude to
all the people who contributed in making this project a
rich experience.

I wish to thank Prof. Govinda Ahuja dept. Electronics


Engineering, Mukesh Patel School of Technology
Management and Engineering for her careful
supervision, critical suggestions and encouragement
that has been a source of immense help.
Sincerely,
Sania Fazal
Parth Jhaveri
Ruchita Jobanputra
Srilalan Iyer
Abstract
Many tasks that are performed on the computer require the use of both a keyboard and the
mouse, and many people find it frustrating and awkward to have to switch back and forth
between them. The air mouse can be a great solution for this. As computers have evolved
from 66MHz to the 3+GHz today, the mouse has remained relatively unchanged. There have
been only two major changes to the mouse since its inception: more buttons, and interface
changes (PS/2, USB, Wireless) but the core interaction method has not changed. The touch
pad mouse and the stick mouse have been designed for a laptop, but have not gained
momentum outside of laptops. And most laptop users usually carry a USB mouse with the
laptop as well. The accelerometer based mouse can be treated as the new age input device. It
is more natural in its feel and provides the user with better ease of use. The user interface of
applications can be changed to utilize the free hand movement possible with the device.
Introduction
This project demonstrates the use of an accelerometer as a computer mouse, but first what is
an accelerometer? It is a device that can measure acceleration and the pull of gravity. There
are multiple ways of doing this, the particular one I’m using works with the capacitive
method. Inside the chip is a capacitor with an extra plate in the middle that can move. As you
know the closer the objects are together the bigger the capacitance, the circuit inside the chip
measures the capacitance difference between the two plates and the middle one. Finally, the
circuit coverts this into an analog signal between 0V and 3.3V. All of this is small enough to
fit in to a small SMD chip.
The accelerometer used in this project is MMA7361L manufactured by NEX ROBOTICS
INDIA. It has acceleration range along X, Y, Z axis and also has high sensitivity of 800mV/g
@1.5g.

The MMA7361LT is a low power, low profile capacitive micromachined accelerometer


featuring signal conditioning, a 1-pole low pass filter, temperature compensation, self-test,
0g-detect which detects linear freefall, and g-Select which allows for the selection between 2
sensitivities. Zero-g offset and sensitivity are factory set and require no external devices. The
MMA7361LT includes a sleep mode that makes it ideal for handheld battery powered
electronics.
BLOCK DIAGRAM

The above image shows the block diagram of the ACCELEROMETER BASED MOUSE.
The main components used are:
1. Accelerometer MMA7361.
2. Atmega 16 Microcontroller.
3. MAX232 serial communication to PC.
4. The LCD display.

The basic working of all these components will be explained later in the report.
1. Accelerometer MMA7361

MMA7361L is a Three axis Low-G accelerometer Module which gives selectable


acceleration range from ±1.5g or ±6g. Board has all the necessary components required for
the chip. Board made up of high quality silver plated double sided PCB for giving extra
strength to the connectors.
MMA7361L accelerometer has building signal conditioning, a 1-pole low pass filter,
temperature compensation, self test, 0g-Detect which detects linear freefall, and g Select
which allows for the selection between 2 sensitivities. It also includes a Sleep Mode that
makes it ideal for handheld battery powered electronics.
Possible applications of this board includes 3D-Gaming: Tilt and Motion Sensing, Event
recorder, HDD MP3 Player: Freefall Detection, Laptop PC: Freefall Detection, Anti-Theft,
Cell Phone: Image Stability, Text Scroll, Motion Dialing, E-Compass, Pedometer: Motion
Sensing, PDA: Text Scroll, Navigation and Dead Reckoning: E Compass Tilt Compensation,
Robotics: Motion Sensing etc.
Specifications
• Supply voltage (Vdd): 2.2V to 3.6V @ 400μA
• Sleep mode current: 10 μA
• Sensitivity: 1.5g: 800 mV/g
6g: 206 mV/g
• Static Acceleration: XOUT,YOUT,ZOUT
@ -1g: 0.85V
@ 0g: 1.65V
@ +1g: 2.45V
• Self-Test input: 0V to Vdd
• Bandwidth:
XOUT, YOUT: 400Hz
ZOUT: 300Hz
• Output Impedance: 32KΩ

Connections:

Pin Configurations
Pin# Pin name Description
1 XOUT X direction output Voltage
2 YOUT Y direction output Voltage
3 ZOUT Z direction output Voltage
4 Vss Supply Ground
5 Vdd 3.3V supply voltage
6 Sleep (Active Low) Logic input pin for sleep mode
7 0g-Detect Freefall digital logic output signal
8 g-select Logic input pin to select G level
9 ST Self-test (logic 0: normal mode; logic 1: self-
test)
10 NC Leave Unconnected

Pin Descriptions:
XOUT: This provides the change in acceleration in X direction in terms of analog voltage
YOUT: This provides the change in acceleration in Y direction in terms of analog voltage
ZOUT: This provides the change in acceleration in Z direction in terms of analog voltage
Vss: Supply Ground: This is the supply ground pin for system.
Vdd: Supply voltage: apply the 3.3 v supply to this pin.
Sleep(Active Low): This is control input pin, logic High for normal mode where system
consume only 400μA current and logic low for Sleep mode where system consume only
10μA current.
0g-Detect: The sensor offers a 0g-Detect feature that provides a logic high signal when all
three axes are at 0g. This feature enables the application of Linear Freefall protection if the
signal is connected to an interrupt pin or a poled I/O pin on a microcontroller.
G-select: The G-Select feature allows for the selection between two sensitivities.
Depending on the logic input placed on this pin, the device internal gain will be changed
allowing it to function with a 1.5g or 6g sensitivity.
G-Select (logic level) G-Range Sensitivity
0 1.5G 800mV/G
1 6G 206mV/G
ST(Self-test): Self Test allows the verification of the mechanical and electrical integrity of
the accelerometer at any time before or after installation.
Circuit Diagram:

Accelerometer with recommended connections


0.1μF power supply decoupling capacitors placed near the supply pins. Use a 3.3nF capacitor
on the outputs of the accelerometer to minimize clock noise (from the switched capacitor
filter circuit). A/D sampling rate and any external power supply switching frequency should
be selected such that they do not interfere with the internal accelerometer sampling frequency
(11 kHz for the sampling frequency). This will prevent aliasing errors.
The compact board with few mounted components gives you the analog output voltage on the
connector pins.
2. ATmega 16 Microcontroller

The ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced
RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega16
achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize
power consumption versus processing speed.

Pin Configurations
Pin Descriptions

VCC: Digital supply voltage.


GND: Ground.
Port A (PA7..PA0): Port A serves as the analog inputs to the A/D Converter. Port A also
serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can
provide internal pull-up resistors (selected for each bit). The Port A output buffers have
symmetrical drive characteristics with both high sink and source capability. When pins PA0
to PA are used as inputs and are externally pulled low, they will source current if the internal
pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes
active, even if the clock is not running.
Port B (PB7..PB0): Port B is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port B output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port B pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset
condition becomes active, even if the clock is not running.
Port C (PC7..PC0): Port C is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port C output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port C pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset
condition becomes active, even if the clock is not running. If the JTAG interface is enabled,
the pull-up resistors on pin PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a
reset occurs.
Port D (PD7..PD0): Port D is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port D output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port D pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset
condition becomes active, even if the clock is not running.
RESET: Reset Input. A low level on this pin for longer than the minimum pulse length will
generate a reset, even if the clock is not running.
XTAL1: Input to the inverting Oscillator amplifier and input to the internal clock operating
circuit.
XTAL2: Output from the inverting Oscillator amplifier.
AVCC: AVCC is the supply voltage pin for Port A and the A/D Converter. It should be
externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be
connected to VCC through a low-pass filter.
AREF: AREF is the analog reference pin for the A/D Converter.
BLOCK DIAGRAM

The ATmega16 provides the following features: 16 Kbytes of In-System Programmable


Flash Program memory with Read-While-Write capabilities, 512 bytes EEPROM, 1 Kbyte
SRAM, 32 general purpose I/O lines, 32 general purpose working registers, a JTAG interface
for Boundary scan, On-chip Debugging support and programming, three flexible
Timer/Counters with compare modes, Internal and External Interrupts, a serial programmable
USART, a byte oriented Two-wire Serial Interface, an 8-channel, 10-bit ADC with optional
differential input stage with programmable gain (TQFP package only), a programmable
Watchdog Timer with Internal Oscillator, an SPI serial port, and six software selectable
power saving modes. The Idle mode stops the CPU while allowing the USART, Two-wire
interface, A/D Converter, SRAM, Timer/Counters, SPI port, and interrupt system to continue
functioning. The Power-down mode saves the register contents but freezes the Oscillator,
disabling all other chip functions until the next External Interrupt or Hardware Reset. In
Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a
timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the
CPU and all I/O modules except Asynchronous Timer and ADC, to minimize switching noise
during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while
the rest of the device is sleeping. This allows very fast start-up combined with low-power
consumption. In Extended Standby mode, both the main Oscillator and the Asynchronous
Timer continue to run.
The device is manufactured using Atmel’s high density non-volatile memory technology. The
Onchip ISP Flash allows the program memory to be reprogrammed in-system through an SPI
serial interface, by a conventional nonvolatile memory programmer, or by an On-chip Boot
program running on the AVR core. The boot program can use any interface to download the
application program in the Application Flash memory. Software in the Boot Flash section
will continue to run while the Application Flash section is updated, providing true Read-
While-Write operation. By combining an 8-bit RISC CPU with In-System Self-
Programmable Flash on a monolithic chip, the Atmel ATmega16 is a powerful
microcontroller that provides a highly-flexible and cost-effective solution to many embedded
control applications.
The ATmega16 AVR is supported with a full suite of program and system development tools
including: C compilers, macro assemblers, program debugger/simulators, in-circuit
emulators, and evaluation kits.
3. MAX232 serial communication to PC

The MAX 232 is to connect a serial port device to a serial port which uses the RS232 standard. The serial port
device is usually a UART, but that is often incorporated into a microprocessor chip.
The RS232 standard specifies the voltage levels that represent the signalling and data lines in the interface. The
standard is that the lines have a source impedance around 300 ohms, the minimum voltage is +/- 6V, the
maximum voltage is +/-22V, the minimum load is 3000 ohms and so on. The logic states are therefore plus or
minus 6V, and it is common to use plus/minus 12V.
The logic level devices that create the RS232 signal work at 0 and +5V (in this case anyway). TheMAX232
provides the interface, which involves a logic voltage inversion. It is two line drivers(outputs) that convert logic
level to +/- RS232 and two line receivers (inputs) that receive +/- RS232and convert then to logic level.
The MAX232 is popular because it also generates the extra voltages for the +/- 12V, using the +5V as a
supply. There is no need for separate supplies just for this purpose. The voltage is generated by electronic
switches which charge capacitors in parallel then discharge them in series.
Low cost systems sometimes dispense with these, as RS232 usually works with 0V and +5V logic levels too,
although this is not specified. I have to say that it doesn't always work, or it may only work at slower speeds on
longer lines etc. It is still necessary to provide a logic level inversion with most devices, as they are designed to
work with an inverting line driver. This could be a transistor or an unused gate device from a package.
4. The LCD display

In this application note liquid crystal display JHD 162A is used to interfacing with
microcontroller.

LCD interfaced with a microcontroller

Function of JHD162A:
Pin no. Name Function Use
1 Vss Ground
2 Vdd +ve supply 5V regulated DC
3 Vee Contrast This is used to set the contrast
4 RS Register set Register select signal:Instruction
register (when writing) Busy flag &
address counter (Whenreading):Data
register(when writing & reading)
5 R/W Read / Write Read/Write select signal for reading
and for writing.
6 E Enable Operation ( data read/ write) enable

CIRCUIT DIAGRAM
The above image shows the complete circuit diagram of the ACCELEROMETER
CONTROLLED MOUSE.
It shows all the connections between the microcontroller ATMEGA16, accelerometer
MMA7361L, MAX232 serial connection to computer as well as the LCD JHD162A.
SOFTWARE

This is the code to program the microcontroller:


#include<avr/io.h>
#include<compat/deprecated.h
#include<util/delay.h>
#include <avr/interrupt.h>
#include"LCD.h"

#define BIT(x) (1 << (x))


#define CHECKBIT(x,b) (x&b) //Checks bit status
#define SETBIT(x,b) x|=b; //Sets the particular bit
#define CLEARBIT(x,b) x&=~b; //Sets the particular bit
#define TOGGLEBIT(x,b) x^=b; //Toggles the particular bit
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

volatile static unsigned char byte, x, y, z,x1,y1,z1;


volatile static unsigned int count=1, i;

void usart_init()
{
UCSRA=0;
UCSRB=0;
UCSRC=0;

UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the
low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value
into the high byte of the UBRR register

UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception
circuitry
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character
sizes

UCSRB |= (0xC0); // Enable the USART Recieve Complete interrupt


(USART_RXC)
}

int main(void)
{
MCUCSR=0x80;
MCUCSR=0x80;

DDRA=0x00;
DDRB=0xFF;
PORTA=0x00;
PORTB=0xFF;
DDRC=0xFF;
PORTC=0x00;
ADCSRA=0x00;
ADMUX=0x00;
lcd_init();
usart_init();

ADCSRA = 0x00; //disable adc

ADMUX |= (1 << REFS0) ; // Set ADC reference to AVCC


ADMUX |= (1 << ADLAR); // Left adjust ADC result to allow easy 8 bit reading

ADCSRA |= (1 << ADPS2);

ADCSRA |= (1 << ADEN); // Enable ADC


ADCSRA |= (1 << ADIE); // Enable ADC Interrupt
SREG|=0x80;

while(1)
{
ADMUX&=0xF0;
ADCSRA |= (1 << ADSC); // Start A2D Conversions
count=0;
while((ADCSRA & ( 1 << ADSC))!=0);
while(count==0);
x=byte;

ADMUX|=0x01;
ADCSRA |= (1 << ADSC); // Start A2D Conversions
count=0;
while((ADCSRA & ( 1 << ADSC))!=0);
while(count==0);
y=byte;

ADMUX&=0xF0;
ADMUX|=0x02;
ADCSRA |= (1 << ADSC); // Start A2D Conversions
count=0;
while((ADCSRA & ( 1 << ADSC))!=0);
while(count==0);
z=byte;

lcd_cmd(1);
_delay_ms(20);
x1=x; y1=y; z1=z;
//lcd_string(" ");
//_delay_ms(250);
lcd_string(" x:");
lcd_char(x/100+48);
x=x%100;
lcd_char(x/10+48);
lcd_char(x%10+48);

lcd_string(" y:");
lcd_char(y/100+48);
y=y%100;
lcd_char(y/10+48);
lcd_char(y%10+48);

lcd_cmd(LINE2);
lcd_string(" z:");
lcd_char(z/100+48);
z=z%100;
lcd_char(z/10+48);
lcd_char(z%10+48);

if ((x1<50)&(y1<80)&(y1>68)) \\up
UDR=0x02;
else if ((x1>80)&(y1<80)&(y1>68)) \\down
UDR=0x0F;
else if((y1<62)&(x1<70)&(x1>55)) \\right
UDR=0xC0;
else if ((y1>80)&(x1<70)&(x1>55)) \\left
UDR=0xFF;

// for(i=0; i<2; i++)


//_delay_ms(250);
}

return 0;
}

ISR(ADC_vect)
{
count++;
byte=ADCH;
}
The following program is written for the mouse for matlab software:
clc
clear all

import java.awt.Robot;
mouse = Robot;
s1 = serial('COM1');
set(s1,'BaudRate',9600);
fopen(s1);
mouse.mouseMove(512, 384);
i=512; j=384;

load m;
t=0;

while s1.BytesAvailable>100
temp=fread(s1, s1.BytesAvailable-1);
end

tic;
while t<40
if s1.BytesAvailable>1
temp = fread(s1, s1.BytesAvailable-1,'uint8');

=mean(temp);

if (temp>100)&(temp<180)
i=i-10;
if j<0 j=768; end
if j>765 j=0; end
mouse.mouseMove(i,j);
end

if temp>200
i=i+10;
if j<0 j=768; end
if j>765 j=0; end
mouse.mouseMove(i,j);
end

if (temp<7)
j=j-10;
if i<0 j=1024; end
if i>765 j=0; end
mouse.mouseMove(i,j);
end

if (temp>7)&(temp<temp20)
j=j+10;
if i<0 j=1024; end
if i>765 j=0; end
mouse.mouseMove(i,j);
end

end

t=toc;
end
fclose(s1);

Potrebbero piacerti anche