Telling tilt orientation with accelerometer

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

Do you ever wonder how your cell phone or tablet knows when you have tilted it? They “have always” known which way is up and act accordingly. Even some cameras will rotate your pictures if you took it with the camera sideways. Well, let’s see what help they got.

In the not so distant past,one can tell orientation with a simple tilt sensor. If you have peeked inside of an old thermostat, you must have seen a springy coil and a glass container with shiny liquid inside it. The liquid is mercury.

Here is an awesome periodic table of elements:

Here is mercury:

Mercury is a metal and is in its liquid state under room temperature. It is a good conductor for electricity. Mercury is sealed inside of a glass tube. Metal contacts are brought inside of the tube. In the above picture, if you tilt the switch clockwise, mercury will flow to the right, making the two metal prongs connect, and a circuit will be closed (turn on the heat). If you tilt it counterclockwise enough, mercury will flow to the left end of the tube, breaking contact between the two metal prongs and opening the circuit (turn off the heat). If you mount this switch on top of a bi-metal metal coil, you will get a temperature control mechanism to control room temperature.

Another type of tilt sensor is a ball sealed inside of a tube. It is essentially the same as the mercury in a glass tube but is much safer now that people know how bad mercury is.

Some early products that had tilt sensing must have used these. The sensitivity is low and you need to debounce to get a reliable reading.

The tilting sensing capability that our current-day devices have come from accelerometers, micro-machined structures that respond to accelerations in general, gravitation in specific. Imagine a mass suspended below a spring. This is how we weight a product with a spring scale. The weight of an object is proportional to its mass and the spring will stretch proportional to force applied to it. We tell weight from how much stretch we see on the spring. Without the earth gravity, the mass will have zero weight, and won’t stretch the spring. If you take the spring scale and suddenly yank it upwards, the spring stretches even more than when it’s staying still with the mass. If you did the opposite, giving the spring a downward acceleration, the spring stretches less than when it’s still.

Using this mechanism and micro-machining, this spring and mass can be shrunk so much that it fits in a small chip less than the size of your finger tip. As many as three of these structures can be made together to give the chip 3-D sensing on its acceleration.

Here is an image of an accelerometer from sparkfun, which I used in a project. It is able to detect acceleration due to gravity.

When the accelerometer is staying statically, it senses the gravitational acceleration and its projection or components along the board’s x-y-z axes. You need basic vector concept to find out the angle of tilt from the components of acceleration measured by the accelerometer. The most basic information that one could get is, which side is up. Say if you read the accelerometer and your x acceleration is exactly one g, then x axis must be facing downwards, making -x direction facing upwards. The cell phones and tablets can then readjust their display to adapt the rotation.

I have started a project of a music box, which contains an accelerometer. You can tap on the box to play a tone that is written on the top of the box. You want another tone, turn the side of the box with that tone upward and tap, the box plays the tone. I have made a prototype last night and will explore ways to make it good looking and more responsive.

When the accelerometer is accelerating with the object that is attached to it, it measures the combined acceleration of the earth and the apparent motion. An application of this is the Nintendo Wii remote controller. One can swing the controller, shake it or else to swing a sword or else in a video game. You can also measure acceleration of an amusement park ride or a car taking a high way exit or racing on a race track. I plan to post a project that uses the accelerometer in explaining physics, in the near future.

Your keyboard drawer greets you!

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

It’s been snowing almost all day today. I made this little fun program to pass some time.

This software will play a tune when you pull out your keyboard tray from your computer desk. It will play another tune when you push the tray back.
It’s perfect for some fun. I used the RTTTL code from Brett Hagman to generate a few tunes included in his original code. Nothing is modified from his code.
You can add a few tunes or sound effects if you prefer.
List of functions:
* Greets you with a tune when you set out to do some work on your computer, by pulling out your keyboard tray.
* Expresses farewell with a tune when you finish work on your computer, by pushing back your keyboard tray.
* TODO – display greeting message on LCD. Should be easy.
* TODO – add some sound effect tunes.
* TODO – add a menu to choose tunes from a list.

You will need to purchase a photo interrupter and breakout board from sparkfun.

You will also need a Phi-1 shield. A protoshield works too but no soldering is needed if you have an assembled Phi-1 shield.
Make sure you purchase all the parts listed here:

Solder everything per documentation.

Insert the photo interrupter in the pins 12, 11, 10, with 12 being the signal pin.

Tape a paper blocker to block the interrupter (notice the white paper blocker taped to the bottom of the table top), enjoy!


Here is a video:

Source code:

Circuit simulations for the beginners

PHET has a number of good circuit simulations that one can use to gain basic understandings on circuits. Here is a DC circuit construction kit. You can use it to explore simple circuits.

I will be adding some tutorials with this simulation when the final exams are over.

New Arduino shield – Phi-1

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

I have developed this shield in my spare time to make prototyping with Arduino much easier. The shield, when assembled, has one LCD monitor, 6 buttons, real time clock and battery backup for keeping time, EEPROM for data storage, GPS connector, buzzer, LED, and two RJ11 connectors for things you absolutely want secured against pull.

Here is a video of a 360 degree view of an assembled Phi-1 shield:

Just running a clock with DS1307 Real Time Clock (RTC) module

Running a testing routine to make sure everything works

Running a fully-functional alarm clock (it woke me up this morning) Details of making the alarm clock is on a separate post. The code is listed near the end of this post.

Morse encoder: type in a sentence and translate it into Morse code.

Function list:

  • 16X2 LCD character display
  • 6 push buttons –  four arranged in arrow keys and two more on the side
  • 2 RJ11 ports for long and robust connections with sensors or control devices
  • Optional buzzer and LED in place of the RJ11 ports
  • Real time clock with battery backup keeps the time when Arduino is turned off
  • EEPROM for easy data logging keeps data when Arduino is turned off. Use 24LC256 or compatible I2C EEPROM
  • GPS connector and breakout for this popular GPS module (
  • Reset button for Arduino
  • All Arduino pins are brought out for maximal flexibility.
  • Hackable for more functionalities (see the end of the assembling)

 Possible projects with this shield:

  • Alarm clock
  • Standalone or PC data logger
  • Lab data acquisition system (Physics, Chemistry etc)
  • Weather station
  • Input or operating panel, like security panels or garage door opener
  • Handheld GPS
  • Morse code generator
  • The list goes on… 


Phi-1 shield documentation revision 11/19/2010

PCB design:


Fully assembled shield running clock:


PCB and parts:

Connector board design pictures:

Standard board breaks out connections from the RJ11 jack and 5V/GND. The prototype space has 5V/GND running down middle for convenience. You can make a TTL-RS232 circuit on it, or maybe power an opamp, add I2C A/D converter to it or else. The screw terminals are pretty convenient and their connections are brought out for prototyping. You can also simply plug it into a breadboard. It also has two LED indicators and has connections for X, Y, 5V and GND.

The relay board has a standard AC or DC relay with control signal coming through the RJ11 jack from the main board. Several screw terminals are included for wiring. A power jack is also included so that it can easily power a single piece of equipment with the relay. You can turn on and off an electromagnetor else light with it. 

This board passes the RJ11 connection to a 3.5mm stereo plug. It also has an LED indicator.

Assembling pictures:

Sample codes:

Clock display This is a basic program that displays the Clock. You can modify it to suit your needs.

Testing all functions This program tests everything, LCD, buttons, the clock, and EEPROM if you have one on board. Learn the basics of everything with this program.

Alarm clock (buzzer and LED) This program is a fully-functional alarm clock. You will find it more complex than the basic clock. If you can’t understand, try the Click display first.

Morse encoder This program allows you to type in a sentence in letters, numbers, and symbols. Then it plays it in Morse code. Use the arrow up and down to type letters (think old-school arcade game record) use left and right to move cursor. Use B to enter.

More to come!

I am coordinating an effort to have it made in a small quantity so it will be affordable. If I have one made, it will cost me around $30, but if I have more made, I could cut the cost down and possibly have it for $12. Leave me a message if you’re interested in getting one. I might be able to get my favorate electronics online store to sell these so you could buy the board along with all needed components in one purchase.

Arduino photogate shield

So I set out to make my own photogate with Arduino and got some success. I then tried to make my design more robust for students. The breadboard version is not safe enough or convenient for labs. I decided to make a printed circuit board so there won’t be any loose wires that would be pulled out or even short the board. Also I want to stack the board on top of the Arduino, as a shield. I made this design back during the summer of 2010. This is a basic design with connections to photogates via stereo audio cables, a few buttons and an LCD connector for future development.

This is the assembled picture:

Here I powered it on with an LCD to display some information:

This is the schematic diagram:

This is the PCB design:


I will add more detail of the design and testing results in a later post. Time to grade papers.

Arduino and photogates

Photogates are optical sensors that are are routinely used in physics labs to measure speed of objects passing through them. Arduino can sense photogates fairly easily. The following is an example of how to use arduino to sense photogates.

What is a photogate made off?

It has an infrared LED that emits IR light. It also has an IR phototransistor to sense the IR light. There are two ways to make a photogate: one way is to build an interruptive gate. One will have an IR LED emit light and an IR transistor on the opposite side of the gate to receive the light. If no object obstruct the light, the transistor reports low. When an object passes through the gate, it blocks the IR light and the transistor reports high. This way reduces false triggers since the transistor only looks at the IR LED and is not easily disturbed by nearby IR sources, like a lamp. Another way is to construct a reflective photogate. This gate has IR LED and transistor on the same side but a reflective surface needs to be brought near the assembly so enough IR light is reflected by the surface back and hits the transistor to product a signal. This way larger objects can be detected but the sensor is more subject to external noise.

There are pre-manufactured photogates for a few bucks so I will use one made by Sharp.

Here I have connected two photogates to arduino.

Here is a detailed hookup picture:

Here is some video:

Arduino and physics

Arduino is a physical computing platform with onboard inputs and outputs. With sensors and relays, arduino can perform jobs as simple as turning on a light-emitting diode or as complicated as flying a model plane. Use arduino to make yourself gadgets or audio and visual arts.

%d bloggers like this: