Earlier Plans for the Gate Alarm

Gate movement detector

My initial plan was to fit single magnetic reed switch to the gate post with a magnet on the gate immediately opposite to the switch. Thus the magnet would hold the switch closed, so that the circuit would be broken when the gate opens. This would then light the required light and sound 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 that could either be used as ground or VCC, depending on the requirements of the circuit.

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 sensor circuit is to sound an alarm when the gate is detected to be open. Originally as circuit based on 555 timers was to be used. This circuit produced a sound that was too quiet and a commercial buzzer was used instead.

In the original circuit a 555 timer was to be used to send a square wave to a speaker. In order to make the alarm sound more annoying an additional 555 was added that turned 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 “musical” note somewhere between E5 and F5.

Timer IC1 generates a slow pulse that turns IC3 on and off. The theoretical period of the oscillation is 1.857s, with a duty cycle of 62.687%, so that the alarm should sound for 1.164s 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.