Acoustic Spirit Level / Tilt Alarm Schematic Circuit Diagram
The original purpose of this device was to assist in leveling large garden tables on uneven ground. Away from buildings, it is difficult to find any reference points to assist in setting up the tables, and conventional spirit levels can be a bit cumbersome. It is however not only useful for leveling tables, it also serves as a security monitor to sense the movement of some object; place it on a table or any other item worth protecting, if anyone tries to move it the alarm sounds and the thief is sent off with a start.
How it works:
The circuit shown in Figure 1 comprises an Atmel ATtiny 45 microcontroller and an MMA7260QT. The MMA7260 is an integrated 3-axis acceleration sensor which has already featured in this magazine back in 2007 and also in the Special Projects (summer) Edition of 2010 where it was used in a large USB tilt sensor with an LCD screen . The small integrated circuit is fixed to a small PCB (Figure 2) and has three analog output signals. The signal produced is proportional to acceleration; at +1 g the output voltage is 2.45 V. The ATtiny45 microcontroller from Atmel  includes a number of built-in A/D converters, three of which we use here to measure acceleration or level of tilt from the three sensors. The A/D converters use an internal voltage reference of 1.1 V so it is necessary to scale the three sensor output voltages using a voltage divider network. Based on the sensor parameters the resistors R1, R3 and R5 have a value of 470 kΩ and resistors R2, R4 and R6 have a value of 330 kΩ. The 2.45V maximum output voltage from each of the sensors is thereby scaled down to around 1 V and optimal measurement resolution is achieved in the A/D conversion process.
The microcontroller firmware uses changes in the X, Y and Z parameters to influence the output frequency of three tone generators. When the sensor is on a flat and level surface the tone generators remains quiet. As soon as one of the sensors detects a movement of more than approximately ±2° on any axis, the tone begins to sound and varies as the tilt increases. The push button S1 is used to calibrate the unit and also to select operational mode. When the button is held down for longer than 5 s the unit is switched into alarm mode. The voltage on the board is regulated by a low drop voltage regulator type LP2950CZ3.3, producing an optimal 3.3 V for both the microcontroller and tilt sensor. A 9-V 6LR22 (PP3) size battery will provide enough energy to keep the circuit running for a long time. During testing, it was found that the circuit would still function with a supply voltage as low as 3.6 V. Maximum current was measured at 4.56 mA and averaged around 3.06 mA with the LED blinking and the tone sounding.
Construction and operation:
Construction of the circuit is relatively simple and can be made using small piece of breadboard such as the prototyping board called ELEX-1. When the finished circuit is first powered up the red LED will light continuously and the loudspeaker should remain silent. If this is not the case then remove power and double check your circuit construction. The first time the circuit is switched on it is necessary to carry out a calibration process which will then act as the reference attitude. Place the circuit board on a flat, level surface and hold down button S1 for approximately 1 s. When the push button is released the LED will extinguish indicating that the calibration is complete and the values have been stored. The unit should not be emitting any sounds now. When the board is waggled you should hear three over lapping beep tones. The LED will also flash and the tone frequencies increase as the angle of tilt increases. With the PCB returned to a level position the tones cease and the LED turns off. Once the unit is fitted into a project case you can quickly begin to develop a feel for when the unit is level.
To use the unit as a movement alarm first place it on the device you want to protect (the surface does not need to be horizontal) and press button S1 now hold down S1 again for a few seconds until the LED starts to flash regularly. Once the push button is released the circuit is primed. Now when the unit is tilted by more than approximately 20 degrees it sets off a loud rising and falling alarm siren. A brief press of S1 silences the siren. The unit still functions in alarm mode until power is turned off. It will always power up in ‘spirit level’ mode. The most recently stored attitude calibration values are again used as the reference plane.
The firmware for this project is written in BASCOM AVR and can be downloaded from the project web page . Port pin PB1 is configured as an output to drive the piezo buzzer. PB0 is used as an input with its internal pull up resister enabled. The A/D converters ADC0, ADC1 and ADC2 use the internal voltage reference of 1.1 V. When push button S1 is pressed (PB0=Low) for approximately 1 s the measured values are stored in EEPROM and used as the calibration values. The next time the circuit is powered up, the same values will be used as reference. The logic used to evaluate the switch status on PB0 is so programmed that calibration of the unit is only possible when the unit is not in alarm mode. In alarm mode a press of S1 resets the alarm. The button S1 therefore performs two functions. A full measurement cycle consists of seven readings from each of the three analog channels taken within 210 ms, the values are given are then averaged. This method has shown to give excellent measurement accuracy and stability. It is relatively easy to alter the sensitivity of the unit operating in either mode by changing the Trigger_value variables declared in the software. If you want to use the firmware as it stands and doesn’t feel the need to make any alterations, it’s a simple job to order a pre-programmed controller from the Elektor shop. Alternatively, go ahead and program your own micro.
Internet Links www.elektor.com/070829  www.atmel.com/devices/ATTINY45.aspx  www.elektor.com/120633  Low-g acceleration sensor: www.freescale.com/webapp/sps/site/taxonomy.jsp?nodeId=01126911184209#2