Earlier Plans for the Gate Alarm

Gate movement detector

My initial plan was to fit single reed switch to the gate post and to mount a magnet on the gate immediately opposite to the switch. The magnet would hold the switch closed when the gate was closed and the circuit would be broken when the gate was opened. This would then activate the alarm.

I rejected this plan for two reasons:

  1. The detector circuit would normally be conducting electricity. I would prefer it if the circuit would normally be off.
  2. I would be relying on a single reed switch which would be a single point of failure.

After a rethink I decided to leave the magnet on the gate but to mount three reed switches side by side, offset from the gate post so that the switches remain open when the gate is closed. When the gate was opened the magnet would switch on each of the reed switches in sequence as it passed them. The switches would turn off again after the magnet passed. A microcontroller would detect these switches closing and deduce the direction the gate was travelling. When the gate was closed the switches would open and close in the reverse order and again the microcontroller could deduce the direction of travel. Such a circuit would still work if only two switches activated, so there's some redundancy in the system. The three switches would be mounted inside a plastic case and a magnet strong enough to close the switches through the case would be used.

The following shows various stages in the contruction of the reed switch unit and its mounting bracket:

Montage of photos showing construction of gate sensor unit

Note the four output pins, one for each of the three reed switches and one common connection.

After some thought I decided to reject the detection of gate movement, for two reasons:

  1. Detecting the direction of gate movement would easily be confused if the gate was open and the wind was blowing it around. Such movement could trigger only one of the reed switches, potentially confusing the detection software.
  2. Assume the microcontroller was to be put to sleep to be woken up when the gate moved. To do this would require one or more of the reed switches to signal the microcontroller to wake up. It is probable that in the time taken for the microcontroller to resume it would miss signals from the other reed switches and fail to detect the direction of travel.

Buzzer

The original plan to sound a buzzer when the gate opens was to create a circuit based on a single 555 timer that would send a square wave to a speaker. This was modified to make the alarm sound more annoying by adding a further 555 to switch the alarm on and off every couple of seconds. The following circuit was drawn up:

Alarm circuit diagram

555 timer IC2 generates the square wave that is sent to the speaker via capacitor C5. According calculations, IC2 generates a pulse of approximately 687Hz with a duty cycle ≈52.4%, which is as close as I could get to 50%. This means the speaker should generate a sound pitched somewhere between E5 and F5.

Timer IC1 generates a slow pulse that turns IC3 on and off. The theoretical period of oscillation is about 1.9 seconds, with a duty cycle of 63%, so that the alarm should sound for approximately 1.2 seconds in every cycle. In practise, of course, the actual period and duty cycle differs from the theoretical values.

The following video shows the circuit in action after being mocked up on a breadboard.

The problem was that this circuit produced a sound that was too quiet. In the end it was decided to use a commercial buzzer instead.