alarmanlagen
deutsch   english   

9. ALARM SYSTEMS

 

 

YOU LEARN HERE...

 

how to use the micro:bit to monitor systems and trigger an alarm if necessary.

 

 

MONITORING WATER LEVEL

 

 

You rarely have to water your little plant, but you must not forget it completely. With your micro:bit you can check the water level and if it is too low, trigger an alarm.

You use the property of water to conduct electricity, so if you create a circuit from the 3V power supply to P0, which leads through the water, a higher voltage will be measured at P0 than when the circuit is open. You only need two cables with alligator clips and two pieces of wire or other pieces of metal that you put into the flowerpot as probes.

Connect one cable to P0, the other to 3V. During program development you can use any water tank.

 

The command pin0.read_analog() returns the voltage at P0 that you write to the console window. As you notice, the difference in readings is large, depending on whether the probes are in the water or not.

 

 

Program:

from microbit import *

while True:
    v = pin0.read_analog()
    print(v)     
    sleep(500)
► Copy to clipboard

Complete your system with a visual alarm indicator on the LED display.

If you want to trigger an audible alarm, then a buzzer is suitable. However you can not feed it directly from the micro:bit, because it requires too much power. A simple transistor amplifier solves this problem. Moreover you can also use it to drive other devices, for example a relay, to switch on your model railway.

 

 

SIMPLE TRANSISTOR AMPLIFIER

 


You will need a 2N2222 or similar transistor (for example, BC 547), a 1N4148 or similar diode, and a 330 ohm resistor. You also need to have some building material, such as a small circuit board. For the audible alarm you have to use a piezo buzzer who works at a voltage of 3V (not a speaker).

You solder the components together according to the following schematics:

 

 
Construction with a tape board
 

Construction with a breakout board
(Source of supply: Kitronik, Code: 5601B)

 

 

MEMO

 

You can easily set up simple alarm systems with the micro:bit as an embedded system, if you combine your manual skills with some electronics and programming knowledge.

 

 

EXERCISES

 

 

1.

Build an alarm system that monitors if a door is opened. You can use a safety wire, the accelerometer or the magnetic field sensor.

2.
Connect an ordinary small loudspeaker to the transistor amplifier and use it for audible alarming.  
 

 

 

3-1
Professional advice:

Acceleration generally means the rate of change of velocity, that is, one-dimensional

where v is the speed.

3-2
Professional advice:

From the three acceleration components you can calculate pitch and roll angles as shown below. Start the following program and tilt the board sideways or forwards and backwards. In the terminal window, the values of pitch and roll are written out in degrees.

from microbit import *
from math import *

def getPitch():
    a = accelerometer.get_values()
    pitch = atan2(a[1], -a[2])
    return int(degrees(pitch))

def getRoll():
    a = accelerometer.get_values()
    anorm = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2])
    roll = asin(a[0] / anorm)
    return int(degrees(roll))
   
while True:
    pitch = getPitch()
    roll = getRoll()
    print("p: " + str(pitch))
    print("r: " + str(roll))
    print()
    sleep(100)