'****************************************
'* Name : lightning detector.BAS *
'* Author : Russ Kincaid *
'* Notice : *
'* Date : 9/8/2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************
REM REM E CONFIGURATION: INTERNAL OSC-CLK OUT,
REM E WDT DISABLED, PWR UP ENABLED, MCLR
REM REM E INPUT PIN,BROWN OUT DISABLED, NO PROTECTION
CMCON = 'SET DIGITAL MODE
ANSEL = 0 'TURN OFF ANALOG MODE
TRISIO = %00011111 'GP. 5 OUTPUT
REM R M 12F6! 5 HAS SIX I/O PINS, GP.0-GP. 4
REM REM R M R M ARE SET AS INPUT,GP5 IS OUTPUT
REM REM REM REM GP2 IS DESIGNATED TMR0 CLOCK INPUT
REM EM GP3 IS DESIGNATED RESET INPUT
DEFINE DEFINE E INE E INE OSCCAL_1K 1 'TO SAVE OSC CAL
LOW O gpio. 5 'initial condition
rain: 'look for rain
IF IF gpio.0 = 0 THEN H N look
GOTO GOTO O O O O rain
look: 'look for lightning
IF IF I gpio.1 = 0 THEN THEN T E T E setup
GOTO OT look
setup:
INTCON = %10100000 'define interrupts
option_reg = 232 'set TMR0 parameters
TMR0 = 0 'initialize TMR0
listen: 'listen for thunder
IF IF gpio. 4 = 1 AND AND AND AND INTCON. 2 = 0 THEN THEN HEN HEN pullplug
REM REM if thunder occurs in less than 5 seconds
IF INTCON. 2 =1 THEN THEN THE THE look
REM REM if TMR0 overflowed (counted more than 5 sec)
GOTO GOTO TO TO listen
pullplug:
HIGH HIGH gpio. 5 'switch power off
STOP STOP STO STO
END END END END ■ FIGURE 6
26
December 2010
■ FIGURE 5
AYou can purchase a moisture detector
or, I made one by
placing two bare
wires in a pill bottle
cap and fixing them
with epoxy (see
Figure 2). The epoxy
did not stick to the
cap, so it would be
better to drill holes
and epoxy the wires
in place. I tested the
detector with distilled
water from my A/C
system; the dry
resistance is open
circuit and under
100K when wet. For
the lightning detector,
I used a cadmium
sulfide cell from
RadioShack, part
number 276-1657.
The detector is
capacitive coupled to
make it insensitive to
sunlight (see Figure 3).
You could purchase
a microphone to detect the
thunder but I used a six inch speaker
salvaged from a radio. The bias on
the speaker is just to insure that the
op-amp output is low normally.
You are only interested in
lightning protection, and lightning
can happen without rain, so I
recommend that you short out the
rain sensor so it is always raining
as far as the circuit is concerned.
I started out with a
microcontroller solution but
became frustrated with it not
working, so I designed the
discrete circuit of Figure 3. In
Figure 3, rain will cause IC2A to
be high which sets the output of
IC1A high. The lightning detector
is arranged such that when
lightning causes a reduction in
the resistance of R5, pin 6 of
IC2B is pulsed high which makes
its output low which triggers the
timer, IC4. The output of IC4 goes
high immediately and stays high for
five seconds. If thunder happens
within the five seconds, IC1B is
clocked which makes its output high.
Both inputs of IC3 being high, Q1 is
turned on which switches the relay, K1.
C3 resets IC1 on power-up; otherwise,
its condition would be random. SW1
lets you reset the circuit after the storm.
If you find the varistors burned or
blackened after the storm, they should
be replaced. The parts list is in Figure 4.
I went back to study the
microprocessor circuit because I
wanted to know why it didn’t work.
Finally re-reading the PIC12F675
documentation, I discovered that I
had put the oscillator input to pin 2
(GP5/CLKIN), but pin 5 (GP2/T0CKI)
is the designated input for the timer
clock. With that change, it started to
work, except IC2A (Figure 5) was
oscillating at 1 MHz. Additional
bypassing of the power supply did not
help and a capacitor from pin1 to pin2
only changed the frequency; so I
substituted an op-amp for the comparator
and that solved the problem. I think
the LM393 should have worked, so I
left it in the schematic. If you have a
problem with oscillation, try an op-amp.
There is no parts list for Figure 5.
The PIC12F675 has two timers