You Are Here: Home » AVR ATmega Projects » Interfacing(USB - RS232 - I2c -ISP) Projects » The Air Mouse Using Atmega1284

The Air Mouse Using Atmega1284


“A wireless mouse unit that requires no flat surface by using ultrasonic positioning.”

For our ECE 4760 final project,we have designed a surface-less mouse interface using ultrasonic transmission as our final project in this class. The idea is to have a ultrasonic transmitter as a mouse, which represents  the mouse’s position in space, with the left, right clicks functionsaccomplished using touch sensors.The separate components to this project include the hardware-generated signal input and the interface to a personal computer. We use a sonar system to position the mouse, and use touch sensors to trigger clicks. There arethree ultrasonic receivers attached to three corners of a board simulating the computer screen(upper-left, upper-right and lower-left corner respectively).Ultrasound travels at roughly 340m/s, and based on the delay of the reception, we can find the distance between the transmitter and receiver, and handle the position calculation with respect to the screen.We used two MCUs, one to generate the data representing the mouse coordinates and clicks activities, the other to import the data to the PC.Two MCUs communicate wirelessly.  There is also a software interface with a personal computer to deal with transmitted data through serial port of the PC. We implement the USB generic HID class using java  to translate serial inputs into mouse commands.

The Air Mouse Using Atmega1284

High Level Design

Rationale and Motivation

Imagine a situation where a public presentation is given and the presenter has to stand in front of the audience to demonstrate his/her idea. All the presenter can do now is going through the powerpoint slides in which case, information must all be incoporated into the slides. What if the presenter wants to show more information? He/she has two options: going back to the computer and do the operation him/herself or ask an assistant to perform the operation. This is where our inspiration comes from and eventually leads to our solution, a 3-D ultrasonic mouse that can give presenters more freedom of presenting.

Despite the convenience it can bring to presenters, it can also benefit ordinary PC users who do not want to be limited to the traditional mouse and compatible surface.

bsp;The motivation of this project is to develop a mouse that correlates the mouse position to the position of user’s hand. We have found that groups of previous years have developed similar projects such as 3D painter or 3D mouse. However they either used relative coordinates or only limit the mouse use to certain applications. Our goal is to develop the most intuitive absolute 3D mouse that could control the cursor directly.


Algorithm and Math

With three ultrasonic sound recievers and one sound transmitter, we want to be able to detect the current location of the transmitter based on the distances between the trasmitter andeach of the receivers. The sound speed is known as 340m/s, which we note as Vs. The timeduration of transmission of the sound wave could be recorded by a synchronized real-timetimer of both MCUs. We note the time as ti (i= a,b,c), then the distance between the ultrasonic transmitter P and each of the recievers A,B, C could be noted as Ra, Rb, Rc, where Ri = Vs / ti (i = a, b, c)

However, the UID device generally reads in a coordinate pair values as (x,y). A simple conversion between Ri values and coordinate values is given as below: Suppose point P is the Ultrasonic sound transmitter;A,B,C represent four ultrosonic receivers at each corner of rectangular laptop ABCD. The projection of P on plan ABCD is O,the projection line of Rc is CO. Ra, Rb, Rc are three measurable distances.Taking C as theorigin, we need to find the value of x and y. We denote the length of AC as a and length of CD as b.

The following equations could be used :

x^2 + (a-y)^2 + I^2 = ra ^2 (1)

x^2 + y^2 + I^2 = rb ^2 (2)

(b-x)^2 +(a-y) ^2 + I^2 = rc ^2 (3)

With equation (1), (2) and (3) we could solve for x, y and I. We note it as ABC, where ABC.x and ABC.y are solved based on receivers A,B,C.

ABC.x = (ra^2 -rc^2) / (2b)

ABC.y =(rb^2-ra^2) / (2a)

In our desgin,we labled our sensors 0,1 ,2 as a,b,c and defined d0 as ra, d1 as rb and d2 as rc.

Desgin Logic

There are two main components of our design: the base station unit and the mouse unit. The mouse unit contains the mouse controller, a mega1284P microcontroller, an ultrasonic sound transmitter, three ultrasonic sound receivers and an XBEE wireless transceiver. The base station contains a mega32 microcontroller and an XBEE wireless transceiver.It is connected to PC using a USB cable. Users input their commands using the mouse controller, the raw distance data will be generated in the mouse unit within the mega1284P microcontroller for it to output the x and y coordinate data. The microcontroller also handles the ISR generated by button click actions. The mouse unit finally encodes the data into packets and the data is then transmitted to the base station unit using XBEE radio transceiver. When the base station receives the data, it encodes and transmit the data to PC through serial connection. The serial data is read and decoded by java application and utilized for the java HID class. A diagram demonstrating the logical structure is shown as above.

Hardware and Software Tradeoffs

Teensy2.0 ++

Inspired by the Glove Mouse project designed by Adam Shih and Hyodong Lee of Fall2012, our first design idea was based on the usage of an extra board teensy 2.0++. It has AT90USB1286 microcontroller and can work as an HID device. We implemented a USART receive complete interrupt service routine so that upon arrival of each data packet , we can read in each data byte and decode their information. We achieved success in transmitting data using USART channel. However, two problems became the reasons that we discarded this design approach. First, teensy simulates a relative mouse. Our three sensors decide an absolute mouse position so that extra calculation needed to be done to get a relative mouse position change. That way, extra errors would be introduced through the calculation and the poor performance of the mouse proved that teensy is a bad choice for our mouse implementation. Second, we encountered a problem of unstable data transmission. Bad data can be read every now and then which required us to use several synchronization bits as headers of our transmitted packet. This led to a certain amount of data loss which caused a significant delay and lack of accuracy of the mouse.


Instead we decided to use java to read in the serial data and move the mouse using the java.awt.robot class which provides neat functions that could implement an absolute mouse and perform mouse click actions. More details about this will be introducted in the software section. In a word, to better serve the purpose of devloping a mouse using absolute coordinate bases, we chose java instead of an additional board to finish the task.

The Air Mouse Using Atmega1284 Schemetic


Relevant Patents and Copyrights



The bulk of the hardware of this project revolves around turning the ultrasonic receivers’ raw voltage swings into digital data that our microcontroller can comprehend. Because the receivers output relatively weak and noisy signals when they receive a 40 kHz signal from the transmitter, we needed to amplify, filter, and then convert the signal into a digital input. We found that putting a constraint in a distance of no larger than two meters would allow us to directly drive the transmitter with a output from the MCU and still get very good response from the receivers, greatly simplifying our hardware for the transmitter circuit. A number of button switches were needed to perform clicking events and state changes. The XBee units and the serial-to-USB breakout boards are capable of communicating serial data directly, requiring no intermediate hardware manipulation.

Parts List:

PartVendorCost/UnitQuantityTotal Cost
40 kHz Tx/Rx Pair (Part #139492)Jameco Electronics$7.953$23.85
9v BatteryTarget$1.571$1.57
Prototype Board (Atmega 1284)Lab Stock$15.001$15.00
Custom PC BoardLab Stock$4.001$4.00
LF353N Op-ampAdafruit Industries$0.002$0.00
LM311P ComparatorLab Stock$0.002$0.00
Schottky P401 DiodeLab Stock$0.001$0.00
Header PinLab Stock$0.058$0.40
White BoardLab Stock$63$18
XBee (Series 1)Lab Stock$0.002$0.00
XBee Breakout BoardLab Stock$0.002$0.00
CP2103 Breakout BoardLab Stock$0.001$0.00
Atmega 32Lab Stock$1.001$1.00
SwitchLab Stock$0.001$0
Diode 1N4001Lab Stock$0.001$0.00
5V RegulatorLab Stock$0.001$0.00
ButtonLab Stock$0.004$0.00
Poster BoardLab Stock$0.001$0.00
Wires ResistorsLab Stock$0.00Many$0.00
CapacitorsLab Stock$0.00Many$0.00
LEDSLab Stock$0.00Many$0.00
16MHz Crystal OscillatorLab Stock$01$0.00

For more detail: The Air Mouse Using Atmega1284

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Increasingly severe disturbances weaken world’s temperate forests

Longer, more severe, and hotter droughts and a myriad of other threats, including diseases and more extensive and severe wildfires,...

Scroll to top