LCD-LED DisplaySensors - Tranducers Circuits

Acoustic Spirit Level / Tilt Alarm Schematic Circuit Diagram

Initially designed to level large garden tables on uneven terrain where finding reference points is challenging, this device eliminates the need for cumbersome conventional spirit levels in outdoor settings. However, its utility extends beyond table leveling; it doubles as a security monitor. Placed on an object of value, such as a table, it detects any movement attempts. If someone tries to move the item, the alarm activates, startling the intruder away.

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.

Polling the Switch: Managing States 3 and 4

In states 3 and 4, where the I/O pin acts as an output, polling the switch might seem complex. However, the solution is surprisingly simple. The pin is momentarily switched to an input mode several times per second. This brief transition creates states 1 or 2 for a fraction of a second, which, due to the persistence of vision (a phenomenon where the human eye perceives a visual stimulus for a brief duration even after the stimulus is removed), goes unnoticed. If the pushbutton is depressed during this period, the pin stays in state 2 until it’s released, as state 4 (where the LED remains unlit) doesn’t affect the outcome and only leads to unnecessary current consumption.

Following this, the controller promptly reverts to state 3, re-illuminating the LED. In the microcontroller’s firmware, advanced debouncing and additional functions like variable LED brightness can be implemented effortlessly. The LED’s brightness can be modulated by toggling rapidly between states 1 and 3, allowing for creative possibilities. The author’s solution was based on the PIC16F883, which utilizes internal pull-up resistors similar to those in well-known AVR controllers. While these internal pull-ups could replace R2, their values range from 10 to 50 kΩ, potentially causing the LED to emit a faint glow in state 1. To counter this, the firmware activates the pull-up only during pushbutton polling to avoid this issue.

Diode Considerations and Resistor Dimensioning

Careful selection of R2 is essential to ensure the input’s switching threshold is surpassed, especially since the forward voltage (Uf) drops with small currents. This effect can be problematic, particularly with a red LED and a 5 V operating voltage. In such cases, an ordinary silicon diode placed in series with the LED resolves the issue. To determine resistor values relative to the supply voltage and LED color, reference a provided table. For various currents, additional calculations may be necessary for precise dimensioning.

Acoustic Spirit Level or Tilt Alarm Schematic Circuit Diagram 1

Acoustic Spirit Level or Tilt Alarm Schematic Circuit Diagram.2jpg

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.

Calibration and Operational Status

Upon releasing the push button, the LED will go out, indicating the completion of calibration and successful storage of values. At this point, the unit should be silent, emitting no sounds. If you gently shake the board, you will hear three overlapping beep tones. Simultaneously, the LED will flash, and the tone frequencies will increase with the tilt angle. When the PCB is leveled again, the tones will stop, and the LED will turn off. When the unit is enclosed within a project case, you can easily discern its level status.

Movement Alarm Functionality

To utilize the unit as a movement alarm, place it on the desired device surface (which doesn’t need to be horizontal) and press button S1. Hold down S1 for a few seconds until the LED begins to flash regularly, indicating that the circuit is primed. Upon releasing the push button, the unit is armed. If the unit is tilted beyond approximately 20 degrees, it triggers a loud, oscillating alarm siren. A brief press of S1 will silence the siren. The unit remains in alarm mode until the power is switched off, always booting up in ‘spirit level’ mode. The most recent stored calibration values serve as the reference plane in this mode.

The program:

The firmware for this project is written in BASCOM AVR and can be downloaded from the project web page [3]. 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




[4] Low-g acceleration sensor:


Related Articles

Leave a Reply

Your email address will not be published.

Back to top button