Beruflich Dokumente
Kultur Dokumente
CIRCUIT
IDEAS
92 MAY 2007 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
D. MOHAN KUMAR
MAT SWITCH
S.C. DWIVEDI
T
his simple circuit produces a
warning beep when somebody
crosses a protected area in your
home or office. The switch, hidden be-
low the floor mat, triggers the alarm
when the person walks over it.
The circuit uses a conductive foam
as the switch. It can be two small
pieces of conductive pads usually used
to pack sensitive ICs as antistatic cover.
Alternatively, you can make the switch
by coating conducting carbon ink on
two small pieces of a copper-clad
board.
When the circuit is in standby
mode, transistor T1 does not conduct,
since its base is
floating. When
the person
walks, the switch
is pressed and
current flows
through R1 and
the switch to
provide positive
bias to transistor
T1. Transistor T1
conducts and its
collector voltage
drops, which
acts as a negative
trigger input for
the monostable
wired around IC NE555 (IC1).
IC1 outputs a pulse of fifty-seconds
duration with preset values of R4 and
C3. This pulse is applied to the buzzer
through transistor T2. The buzzer
sounds a warning beep on
unauthorised entry. The pulse dura-
tion can be changed to the desired
value by changing the values of R4 and
C 3 .
Resistor R2 in the circuit makes the
trigger pin of IC1 high to prevent false
triggering.
Assemble the circuit on a general-
purpose PCB and enclose in a plastic
case. Use a 9V battery to power the
circuit. Connect the touchpad switch
with the PCB and hide under the mat
at the entrance. The PCB can be
mounted on the nearby wall.
Make the switch carefully using
conducting foam or copper clad coated
with conducting ink. Place the two
pieces with their conducting surface
facing each other. Solder carefully a
thin copper electric wire and ensure
that it makes contact when the two
plates touch together on pressing. Pro-
vide two 1cm rubber tabs between the
plates to avoid touch in the standby
mode.
ConstruCtion
58 August 2006 electroni cs for you www. e f y mA g . c o m
CMYK
K. S. SANKAR
MicRocoNtRolleR-bASed
code locK
SUNI L KUMAR
C
ode locks can be constructed
using digital and timer ICs em-
ploying pushbuttons or keypads
for entering the code for authentication
and operation of the code lock. How-
ever, such circuits would require a
large number of ICs.
On the other hand, a microcon-
troller-based code lock will require
very few peripheral components.
With the cost of microcontrollers now
dropping to the equivalent cost of ap-
proximately four digital ICs, it makes
sense to design simple logic circuits
using microcontrollers and free version
of programming languages. Although
free-version-language code length is
normally limited to around 2 kB, but
that is adequate for small projects like
this one.
This simple code lock project is
based on a 20-pin ATMEL microcon-
troller AT89C2051. It employs a 4-digit
sequential code with time-out security
feature. In addition to the microcon-
troller, the circuit uses a single ad-
ditional IC (CD4050) and a transistor
to drive a relay. Although the project
uses a liquid-crystal display (LCD), it
is useful for design and developmental
purpose only and is not really an es-
sential part of the circuit. The same can
be removed from the circuit without
any change in the software.
As regards LCD modules, these are
available in 14- or 16-pin packages. The
16-pin variety has an additional back-
light option. Popular brands available
in India are Lampex, Hantronix and
Hitachi. Most other models also have
the same pin confguration. The model
used in this project is Lampex LM16200
16-character2-line alphanumeric
dot-matrix display with backlight op-
tion. However, you may also use any
other branded/unbranded LCD for
the purpose.
circuit description
As already mentioned, the project
makes use of ATMEL AT89C2051 mi-
crocontroller, in 20-pin DIP package,
which supports 2 kB of fash-based
program memory. A 6MHz crystal is
used for providing the clock. Port-1 of
the microcontroller is used to drive the
LCD in 4-bit mode with 10-kilo-ohm
pull-up resistors. The 10-kilo-ohm
potentiometer controls the contrast of
the LCD panel. It works better when its
wiper is nearer to ground potential.
Timer 0 of 89C2051 is used as an
internal counter that increments a vari-
able every second. This variable is used
in the project to time out the delay for
entering the code.
After initialisation, the software
Fig. 1: Circuit of microcontroller-based code lock
ConstruCtion
60 August 2006 electroni cs for you www. e f y mA g . c o m
CMYK
switches on Ready LED and waits
for a 4-digit code to be entered. The
valid code for this project is 1324. The
code is entered using the seven input
switches that are connected to port-
Parts List
Semiconductors:
IC1 - AT89C2051
microcontroller
IC2 - CD4050 non-inverting
buffer
IC3 - 7805 +5V regulator
T1 - 2N2222 npn transistor
D1-D5 - 1N4007 rectifer diode
LED1-LED3 - 5mm LED
Resistors (all -watt, 5% carbon):
R1, R2, R4 - 220-ohm
R3 - 150-ohm
R5 - 10-kilo-ohm
RNW1, RNW2 - 10-kilo-ohm resistor
network
VR1 - 10-kilo-ohm preset
Capacitors:
C1 - 10F, 16V electrolytic
C2, C3 - 22pF ceramic disk
C4, C6 - 0.1F ceramic disk
C5 - 1000 F, 25V electrolytic
Miscellaneous:
X
TAL
- 6MHz crystal
RL1 - 5V, 100-ohm, 1C/O re-
lay
S1- S8 - Push-to-on switch
S9 - On/off switch
X1 - 230V AC primary to 9V,
250mA secondary
transformer
- 16-character2-line LCD
(male-53 pins used)
- Bergstick connector
(female- 36 pins used)
- 1m long, 4-core ribbon
3. Port-3 does not have the bit P3.6
and hence the same is ignored by the
software. Two LEDs at port-1 are inter-
faced to P1.0 and P1.1 pins to provide
Ready and Relay On indication via
respective LEDs.
The P1.1 line is also interfaced to
relay driver transistor T1 through a buf-
fer to switch on a 12V relay, which can
activate an electrically operated lock.
Timer 0 is started on the first
keystroke to validate the remaining
three digits, provided these digits
are entered within fve seconds. If
not, the software loops back to the
initial state. After three unsuccess-
ful attempts, the circuit will wait for
about 10 seconds (before accepting
the next keystroke) to avoid unwanted
tampering attempts. All these timings
can be changed through the software
program to suit your specifc require-
ments.
Power supply (Fig. 2). A con-
ventional regulated power supply
ci rcui t empl oyi ng a step-down
transformer followed by bridge rec-
tifier, smoothing capacitor and 5V
regulator is used to meet the supply
requirement for the code lock circuit
shown in Fig. 1.
Fig. 2: Power supply
Fig. 3: Actual-size, single-side PCB of microcontroller-based code lock
Fig. 4: Component layout for the PCB
ConstruCtion
62 August 2006 electroni cs for you www. e f y mA g . c o m
CMYK
An actual-size PCB layout for the
code-lock including the power supply
is shown in Fig. 3 and its component
layout in Fig. 4.
the software
The software is written using BAS-
COM-51. (You may fnd details about
it in my article Real-Time Clock
Using Microcontroller published
in Jan. 2005 issue of EFY magazine.)
The source code fle EFYCLOCK.BAS
EFYCLOCK.BAS
pass = 1 4 2 8 bin ( 1324) decimal
$crystal = 6000000
$regfle = 89c2051.dat
Dim I As Byte
Dim K(4) As Byte
Dim Pass(4) As Byte
Dim Key As Byte
Dim Invalid_pass As Bit
Dim Sec_count As Byte
Dim Clock_word As Word
Dim Passtime As Byte
Dim Attempts As Byte
Dim Maxattempts As Byte
Ready_led Alias P1.0
Relay_out Alias P1.1
For I = 1 To 4
K(i) = 0
Next I
Pass(1) = 1
Pass(2) = 3
Pass(3) = 2
Pass(4) = 4
Sec_count = 0
Passtime = 5
Attempts = 0
Maxattempts = 3
Confg Lcd = 16 * 2
Confg Lcdpin = Pin , Db4 = P1.4 , Db5 = P1.5 , Db6 =
P1.6 , Db7 = P1.7 , E = P1.3 , Rs = P1.2
port 1
P1 = 0
P3 = 255
Confg Timer0 = Timer , Gate = Internal , Mode = 2
Timer0 use timer 0
Gate = Internal no external interrupt
Mode = 2 8 bit auto reload
set t0 internal interrupt 2000 times a sec
On Timer0 Timer_0_overfow_int
Load Timer0 , 250
Priority Set Timer0
Enable Interrupts
Enable Timer0
Begin:
If Attempts >= Maxattempts Then
Locate 0 , 0 : Lcd Maxattempts ; attempts over
Locate 2 , 0 : Lcd try after 10 seconds
Attempts = 0
Gosub Trylater
End If
Sec_count = 0
For I = 1 To 4
K(i) = 0
Next I
Cls
Cursor On Blink
clear the LCD display
Lcd Enter Pass:
display this at the top line
Ready_led = 1
For I = 1 To 4
While 1 = 1
If Sec_count > Passtime Then
Exit For
End If
If P3 <> 255 Then
some key pressed - check it
If I = 1 Then
start timer0 on frst keystroke
Sec_count = 0
Start Timer0
End If
Key = P3
wait for key release
While Key = P3
Wend
K(i) = 255 - Key
If K(i) = 1 Then
Goto Lcd_out
End If
If K(i) = 2 Then
Goto Lcd_out
End If
If K(i) = 4 Then
K(i) = 3
Goto Lcd_out
End If
If K(i) = 8 Then
K(i) = 4
Goto Lcd_out
End If
If K(i) = 16 Then
K(i) = 5
Goto Lcd_out
End If
If K(i) = 32 Then
K(i) = 6
Goto Lcd_out
End If
If K(i) = 128 Then
K(i) = 7
Goto Lcd_out
End If
invalid key combination
Key(i) = 0
Lcd_out:
Lcd K(i)
Waitms 30
Exit While
End If
Wend
Next I
Ready_led = 0
Stop Timer0
check if time over
If Sec_count > Passtime Then
Locate 2 , 0 : Lcd time over
Incr Attempts
Gosub Error_fash
Wait 1
Goto Begin
End If
check valdity
Invalid_pass = 0
For I = 1 To 4
If K(i) <> Pass(i) Then
Invalid_pass = 1
End If
Next I
If Invalid_pass = 1 Then
Goto Invalid
End If
Valid:
Locate 2 , 0 : Lcd valid password
Relay_out = 1
Wait 3
Relay_out = 0
Goto Begin
Invalid:
Locate 2 , 0 : Lcd invalid
Gosub Error_fash
Incr Attempts
Wait 1
Goto Begin
Trylater:
wait for 10 seconds
For I = 1 To 10
Wait 1
Key = P3
Key = 255 - Key
If Key = 3 Then
Exit For
End If
Next I
Wait 2
Return
Error_fash:
For I = 1 To 10
Ready_led = Ready_led Xor 1
Waitms 100
Next I
Ready_led = 0
Return
interrupt subroutine
Timer_0_overfow_int:
program comes here 2000 times a sec with a 6mhz
xtal
Incr Clock_word
If Clock_word > 2000 Then
Clock_word = 0
Incr Sec_count
End If
Return
End
for the project in BASCOM-51 is given
at the end of the article. Although the
program is self-explanatory, you need
to be aware of BASCOM51 compiler
directives and syntax of statements,
which are available within the help
menu of BASCOM compiler. BAS-
COM contains a lot of statements to
control various peripherals including
the LCD.
The BOSCOM compiler/IDE can
be used to generate a hex fle, which
should be burnt into the chip using
any universal programmer. The hex
code of the program is only 1.5k long,
while AT89C2051 microcontroller can
take up to 2k of code. This program
may be modifed to suit your specifc
requirement.
EFY note. All fles pertaining to
this project have been carried in this
months EFY-CD, while BASCOM-8051
package has already been included in
the EFY-CD for May 2005.
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
R
U
P
A
N
J
A
N
A
MICROCONTROLLER-BASED
SCHOOL TIMER
U.B. MUJ UMDAR
T
he basic r equir ement s of a r eal-
t ime pr ogr ammable t imer gener -
ally used in schools and colleges
for sounding t he bell on t ime ar e:
Pr ecise t ime base for t ime keep-
ing.
Read/wr it e memor y for st or ing t he
bell t imings.
LCD or LED display for display-
ing r eal t ime as well as ot her dat a t o
make t he inst r ument user -fr iendly.
Keys for dat a ent r y.
Elect r omechanical r elay t o oper -
at e t he bell.
We ar e descr ibing her e a sophist i-
ca t ed, yet econ omi ca l , s ch ool t i mer
ba s ed on Mot or ol a s 20-pi n
MC68HC705J 1A micr ocont r oller .
Description
The pin assignment s and main feat ur es
of t he micr ocont r oller a r e shown in
Fig.1 a nd t he Box, r espect ively. The
complet e syst em is divided int o four
sect ions, namely, t he t ime keeping sec-
t ion, t he input sect ion (keyboar d), t he
out put (display, indicat or s, and r elay
dr iving) sect ion, and power supply and
bat t er y backup.
The t i me-k eep i ng sect i on. Accu-
r a t e t i me-k eepi n g depen ds on t h e
accur acy of t ime base used for dr iving
t he micr ocont r oller . In t his pr oject , t he
micr ocont r oller is dr iven by AT-cut par -
allel r esonant cr yst al oscillat or t hat is
expect ed t o pr ovide a ver y st able clock.
A 3.2768MHz cr yst al pr ovides a t ime
base t o t he cont r oller . The fr equency
(f
osc
) of t he oscillat or is int er nally di-
vided by 2 t o get t he oper a t ing fr e-
quency (f
op
). This high-fr equency clock
sour ce is used t o cont r ol t he sequenc-
ing of CPU inst r uct ions.
Timer. The basic funct ion of a t imer
i s t h e mea s u r emen t or gen er a t i on
of t ime-dependant event s. Timer s usu-
ally measur e t ime r elat ive t o t he int er -
na l clock of t he micr ocont r oller . The
MC68HC705J 1A has a 15-st age r ipple
count er pr eceeded by a pr e-scaler t hat
divides t he int er nal clock signal by 4.
This pr ovides t he t iming r efer ence for
t imer funct ions.
The pr ogr ammable t imer st at us and
cont r ol r egist er (TSCR) is used for de-
ciding t he int er r upt r at e. It can be pr o-
gr ammed t o give int er r upt s aft er ever y
16,384, 3,2768, 65,536, or 131,072 clock
cycles. In Table I, t he cont r ol wor d is
set t o pr ovide t he int er r upt s aft er ev-
er y 16,384 cycles. For a 32,768MHz
cr ys t a l , t h e i n t er r u pt per i od wi l l
be 10 ms. Thus, t imer int er r upt s will
be gener at ed aft er ever y 10 ms (100
Hz). That is, 100 int er r upt s will make
1 second.
Now t i me-keepi n g becomes ver y
simple. As we a r e ha ving a pr ecise
1-second t ime count , a r eal-t ime clock
can be easily built .
The MC68HC705J 1A has a 64 byt e
RAM t hat is used for dat a st or age. Real
t ime (in t er ms of seconds, minut es,
PARTS LIST
S emiconductors:
IC1 - 68HC705J IACP
micr ocont r oller
IC2 - CD4532 8-bit pr ior it y
encoder
IC3 - 74LS138 3-line t o 8-line
decoder
IC4 - 74LS47 BCD-t o-7-segment
decoder /dr iver
T1-T3 - BC547/BC147 npn
t r ansist or
T4-T7 - 2N2907 pnp t ransist or
D1- D7 - 1N4007 diode
ZD1 - 5.6V, 0.5wat t zener
Resistors (-watt, 5% carbon, unless stated
otherwise)
R1 - 210-ohm, 0.5 wat t
R2 - 27-ohm
R3, R12-R14,
R24-R27 - 1-kilo-ohm
R4-R8 - 100-kilo-ohm
R9 -R11,
R23,R29 - 10-kilo-ohm
R15-R22 - 47-ohm
R28 - 10-mega-ohm
Capacitors:
C1 - 350F, 25V elect r olyt ic
C2, C3 - 1F, 16V elect r olyt ic
C4, C5 - 27pF ceramic disk
C6 - 0.1F ceramic disk
Miscellaneous:
S1-S5 - Push-t o-on swit ch (key)
S6 - On/off swit ch
PZ1 - Piezo buzzer
RL1 - Relay 12V, 300-ohm, 1C/O
XTAL - 3.2768MHz AT-cut cryst al
X1 - 230V AC primary t o 12V-
0-12V, 500mA seconda r y
t r ansfor mer
DIS.1-DIS.4 - LTS542 common-anode
display
- 4 x 1.2V Ni-Cd cells
Fig. 1: MC68HC705J1A pin assignment
Mai n features of MC68H705JIA
14 bidir ect ional input /out put (I/O) lines.
(All t he bidir ect ional por t pins ar e pr ogr ammable as input s or out put s.)
10mA sink capabilit y on four I/O pins (PA0-PA3).
1,240 byt es of OTPROM, including eight byt es for user vect or s.
64 byt es of user RAM.
Memor y-mapped I/O r egist er s.
Fully st at ic oper at ion wit h no minimum clock speed.
Power -saving st op, halt , wait , and dat a-r et ent ion modes.
Illegal addr ess r eset .
A wide supply volt age r ange fr om 0.3 t o 7 volt s.
Up t o 4.0MHz int er nal oper at ing fr equency at 5 volt s.
15-st age mult ifunct ion t imer , consist ing of an 8-bit t imer wit h 7-bit pr e-scaler .
On-chip oscillat or connect ions for cr yst al, cer amic r esonat or , and ext er nal clock.
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
hour s, days of a mont h, and mont hs)
is st or ed in t his RAM. Thus an accu-
r at e r eal-t ime clock is gener at ed.
The i nput sect i on. For set t ing t he
r eal-t ime clock and st or ing oper at ing
t imes, t he t imer r equir es t o be pr o-
gr ammed ext er nally. Dat a is fed us-
ing t he keyboar d.
Pr ess-t o-on t ype keys a r e int er -
faced t o t he micr ocont r oller using an
8-bit pr ior it y encoder CD4532. This en-
coder det ect s t he key-pr ess oper at ion
and gener at es t he equivalent 3-bit bi-
nar y dat a. It s t r ut h t able is shown in
Table II. The pr ior it y encoder is in-
t er fa ced t o por t A of t h e
micr ocont r oller .
Va r ious keys used in t he t imer ,
a long wit h t heir funct ions, a r e de-
scr ibed below:
Time (4): For set t ing r eal t ime in
minut es and hour s.
Bell (5): For set t ing t he bells op-
er at ing t imings.
Digit Advance (6): Dat a set t ing is
done digit wise (hour s digit followed
by minut es digit ). The Digit Advance
key shift s t he decima l point t o t he
r ight .
St or e (7): For st or ing t he dat a (r eal
t ime or bell t ime).
Delet e (3): For delet ing a par t icu-
lar bell t iming.
Her e, t he figur es wit hin par ent he-
ses indicat e t he decimal equivalent s
of 3-bit binar y dat a fr om t he keyboar d.
S et and run modes. Dat a set t ing
is possible only in set mode. Set mode
or r un mode can be select ed by t oggle
swit ch S6. By using a lock swit ch for
S6, t he t imer can be pr ot ect ed fr om
unaut hor ised dat a ent r y/st or age.
In r un mode if you pr ess Bell key
once, t he display shows t he bells var i-
ous oper at ing t imings one aft er t he
ot her , in t he sa me or der in which
t hese had been pr eviously st or ed. In
case you want t o discont inue seeing
all t he bell t imings, you may pr ess
Time key at any st age t o r ever t back
t o t he display of r eal t ime.
The out p ut s ect i on. Seven-seg- F
i
g
.
2
:
S
c
h
e
m
a
t
i
c
d
i
a
g
r
a
m
o
f
t
h
e
m
i
c
r
o
c
o
n
t
r
o
l
l
e
r
-
b
a
s
e
d
s
c
h
o
o
l
t
i
m
e
r
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
ment displays ar e used for dat a dis-
play. As LEDs ar e br ight er , t hese have
been used in t he syst em. Ther e ar e t wo
t echniques for dr iving t he displays: (i)
dr iving each display using a separ at e
dr iver (like 74LS47 or CD4511) and (ii)
using mult iplexed displays.
The fir st t echnique wor ks well, but
pr act ically it has t wo pr oblems: it uses
a lar ge number of IC packages and con-
sumes a fair ly lar ge amount of cur r ent .
By using mult iplexed display bot h t he
pr oblems can be solved. In mult iplex-
ing, only one input is displayed at any
given inst ant . But if you chop or alt er
input s fast enough, your eyes see t he
r esult a s a cont inuous displa y. Wit h
LEDs, only one digit is light ed up at a
t ime. This sa ves a lot of power a nd
a lso component s, ma king t he syst em
economica l.
Gener ally, displays ar e r efr eshed at
a fr equency of 50 t o 150 Hz. Her e, dis-
plays ar e r efr eshed at a fr equency of
100 Hz (aft er ever y 10 ms). The dis-
play-r efr eshing pr ogr am is an int er r upt
ser vice r out ine pr ogr am. BCD-t o-7-seg-
ment decoder /dr iver 74LS47, along wit h
t r ansist or 2N2907, and 3-line-t o-8-line
decoder 74LS138 ar e used for dr iving
common-anode displays.
In mult iplexed display, t he cur r ent
t hr ough t he segment s is doubled t o
i n cr ea s e t h e di s pl a ys br i gh t n es s .
74LS47 is r at ed for sinking a cur r ent
of up t o 24 mA. As t he cur r ent per sist s
for a ver y small t ime in mult iplexed
display, it is peaky and can be as high
as 40 mA per segment .
Th e deci ma l poi n t i s con t r ol l ed
i n di vi du a l l y by t r a n s i s t or BC547,
as 74LS47 does not suppor t t he deci-
mal point . PA0 and PA1 bit s of por t
A ar e used for cont r olling t he elect r o-
mechanical r elay and buzzer , r espec-
t ively.
P ow e r s u p p l y
a nd ba t t er y ba ckup.
Th e mi cr ocon t r ol l er
and t he associat ed IC
pa ck a ges r equ i r e a
5V DC supply, while
t h e r el a y a n d t h e
bu zzer r equ i r e 12V
DC supply. A simple
r ect i fi er a l on g wi t h
zener diode-r egulat ed
power supply is used.
The micr ocont r oller is
fed t h r ou gh a ba t -
t er y-backed power supply, so t hat in
t he case of power failur e t he funct ion-
ing of t he cont r oller s t imer sect ion is
not affect ed. Dur ing power failur e t he
t imer is t a ken t o low power mode
(called wait mode). In t his mode t he
cont r oller dr aws a ver y small cur r ent .
So small Ni-Cd bat t er ies can pr ovide a
good backup.
A simple diode-r esist ance (27-ohm,
1/4-wat t ) char ger maint ains t he char ge
of t he bat t er y at pr oper char ging r at e.
Software
Mot or ola offer s Int egr at ed Development
Envir onment (I DE) soft wa r e for pr o-
gr amming it s micr ocont r oller and com-
pl et e devel opmen t of t h e s ys t em.
Th e devel opmen t boa r d comes wi t h
Edit or , Assembler , a n d Pr ogr a mmer
soft war e t o suppor t Mot or olas device
pr ogr a mmer a nd soft wa r e simula t or .
Th e I CS05J W i n -ci r cu i t s i mu l a t or
a long wit h development boa r d (pod)
for ms a compl et e s i mu l a t or a n d
non-r ea l-t ime I/O emula t or for simu-
la t ing, pr ogr a mming, a nd debugging
code for a MC68HC705J 1A/KJ 1 family
device.
When you connect t he pod t o your
host comput er a nd t a r get ha r dwa r e,
you ca n u s e t h e a ct u a l i n pu t s a n d
out put s of t he t a r get syst em dur ing
s i mu l a t i on of t h e code. You ca n
also use t he ISC05J W soft war e t o edit
and assemble t he code in st andalone
mode, wit hout input /out put t o/fr om pod.
The pod (MC68HC705J 1CS) can be in-
t er faced t o any Windows 3.x- or Win-
dows 95-based IBM comput er using se-
r ial por t .
The soft war e for t he t imer has been
so developed t hat t he syst em becomes
as user -fr iendly as possible. The main
const r aint is r ead/wr it e memor y (RAM)
Fig. 3: Power supply circuit for the school timer
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
s pa ce. As men t i on ed ea r l i er , t h e
micr ocont r oller has only 64 byt e RAM.
About t went y bell oper at ing t imings ar e
r equir ed t o be st or ed. So t he efficient
use of RAM becomes essent ial.
The soft war e r ou-
t i n es for t h e t i mer ,
a long wit h t heir As-
s embl y l a n gu a ge
codes, ar e list ed in a
fol der . (Not e: Th i s
fol der , con t a i n i n g
sour ce code (.asm) and
list ing file (.lst ) will
for m par t of t he EFY-
CD pr ovided wit h t he
August issue. As files
ar e quit e lar ge, it is
not feasible t o include
t hem her e.) Basically,
t h e fol l owi n g fu n c-
t i on s a r e per for med
by t he soft wa r e pr o-
gr a m:
1. Init ialisat ion of
por t s and t he t imer .
2. Reading of key-
pr essed dat a.
3. St or ing of r eal
t ime and bell t imings.
4. Compa r ison of
r ea l t i me a n d bel l
t i me. I f t h e t wo
mat ch, t he bell r ings.
5. Display of dat a.
6. Time-keeping.
For a user -fr iendly
syst em, t he associat ed
soft war e is r equir ed t o per for m many
dat a manipulat ion t r icks and int er nal
br anching. The oper at ion and logic can
be under st ood fr om t he Assembly lan-
guage list ings. The soft war e is mainly
TABLE I
Ti mer Status and Control Regi ster (TSCR)
Bit 7 6 5 4 3 2 1 0
Signal TOF RTIF TOIE RTIE TOFR RTIFR RTI RTO
Reset 0 0 0 0 0 0 1 1
TOF: Timer over flow flag RTIF: Real-t ime int er r upt flag
RTIE: Real-t ime int er r upt enable RTI and RTO: Real-t ime int er r upt select bit .
RTI RTO Int er r upt per iod
0 0 fop 2
14
For 3.2768MHz cryst al
0 1 fop 2
15
Fr equency of oper at ion (fop)
1 0 fop 2
16
= 3.2768x10
6
/2 = 1.638x10
6
MHz
1 1 fop 2
17
For RTI=RTO=0
Int er r upt per iod = 10ms (100Hz)
divided int o t he following modules:
Keyboa r d . When a key is pr essed,
CD4532 sends t he cor r esponding dat a.
Aft er r eading t he dat a, t he cont r oller
decides on t he act ion. Set / Run key
(S6) is connect ed t o por t PA4.
Bel l . This par t of t he pr ogr am is
used for displaying t he bell oper at ing
t imings st or ed in t he RAM. The oper -
at ing t imings ar e displayed one by one
wit h a delay of 5 seconds bet ween t wo
consecut ive t imings.
Set . The r eal t ime and bell t imings
ar e st or ed using t his par t of t he soft -
war e. Dat a is ent er ed digit wise; for ex-
ample, 08:30 a.m. will be st or ed as 0,
followed by 8, followed by 3, and finally
0. Dat a is st or ed in 24-hour for mat .
Dat a fed fr om t he keyboar d is con-
ver t ed int o equivalent hex and st or ed
in RAM. Any par t icular oper at ing t im-
ing can be delet ed fr om t he memor y
using Delet e key, pr ovided t he t iming
is alr eady st or ed in t he memor y.
Run. Her e t he r ea l t ime is com-
par ed wit h bell oper at ing t ime. If t he
t wo mat ch, t he r elay is oper at ed.
Da t a Con. This par t of t he soft war e
is u sed for fin din g ou t t h e decima l
equ i va l en t of h ex da t a . Th e
micr ocont r oller ma nipula t es t he hex
dat a and conver t s it int o BCD for mat
for display.
Ti me r . Th e t i mer of t h e
micr ocont r oller is init ialised t o give an
int er r upt a ft er ever y 10 ms. A r ea l-
t ime clock is gener at ed using t he int er -
r upt . Also t he display is r efr eshed dur -
ing t he int er r upt ser vice r out ine.
F or r ea l -t i me s ys t ems ba t t er y
backup is ver y essent ial, because power
failur e affect s t he t ime keeping. In in-
t er r upt ser vice r out ine, t he availabilit y
of power supply is checked. If t he power
is available, displays ar e r efr eshed and
t he t imer oper at es nor mally. However ,
dur ing t he power -fa ilur e per iod, dis-
plays ar e off and syst em is t aken t o
low power mode. In t his mode only
t he t imer par t of t he micr ocont r oller
r emains act ivat ed while oper at ions of
a ll ot her per ipher a ls a r e suspended.
Fig. 4: Actual-size single-sided PCB for the circuits in Figs 1 and 2
ELECTRONICS FOR YOU JULY 2001
C O N S T R U C T I O N
This consider a bly r educes t he power
consumpt ion. When t he supply get s r e-
st or ed, t he cont r oller st ar t s oper at ing
in nor mal fashion.
Operating procedure
When t he power is swit ched on, t he
display shows 12.00. Two set t ings ar e
r equir ed in t he t imer : (a) set t ing of r eal
t ime and (b) set t ing of bell oper at ing
t imin gs . For s et t in g r ea l-t ime clock
Time key is used, while for set t ing
bell t imings Bell key is used.
St or i ng of r ea l t i me. To st or e r eal
t ime, sa y, 05:35 p.m., flip Run/Set
key (S6) t o set mode. The display will
show 0.000. Pr ess Time key. Fur t her
pr essing of Time key will incr ement
t he dat a, like 0.000, 1.000, 2.000, and
t h er ea ft er it will r epea t 0.000, et c.
To select t he digit , pr ess Digit Ad-
va nce. This st or es t he pr esent digit
and t he next digit is select ed as indi-
cat ed by t he decimal point er . Dat a is
st or ed in 24-hour for mat . The t ime t o
be st or ed is 17.35, of
which t he fir st digit
wi l l be 1. 000. Th e
s econ d, t h i r d, a n d
four t h digit s can be
s t or ed i n s i mi l a r
fa s h i on . Aft er t h e
fou r t h di gi t , pr es s
Digit Adva n ce key
once mor e. The dis-
play will show 1735
(wi t h n o deci ma l ).
Now pr ess St or e t o
st or e t he dat a.
S t or i n g of b el l
t i mi ngs. The pr oce-
dur e t o st or e bell op-
er a t i n g t i mi n gs i s
similar t o t hat of set -
t ing r ea l t ime. The
only differ ence is t hat
her e dat a is changed
by Bell key in place
of Ti me k ey. An y
number of bell t im-
i n gs (<20) ca n be
s t or ed in t h e s a me
fashion. If t he num-
ber of bell oper at ing
t imings exceeds 20,
t he t imer will not ac-
cept a n y n ew bel l
t imin g u n t il on e of
t he pr eviously st or ed t imings is delet ed.
Del et i on of bel l op er a t i ng t i m-
i ngs. For delet ing a par t icular t iming,
fir st st or e t his t iming using t he st eps
given above. Then pr ess Delet e key t o
delet e t he specific dat a fr om t he memor y.
Di spl a y of r ea l t i me. If Run/Set
key is t aken t o r un mode, r eal t ime
will be displayed.
Checki ng of bel l oper a t i ng t i mes.
For checking t he bell oper at ing t imes,
pr ess bell key in Run mode only. The
st or ed bell oper at ing t imings will be dis-
pla yed one by one wit h a dela y of 5
seconds bet ween t wo consecut ive t im-
ings.
Programming
Ther e a r e t wo wa ys t o pr ogr a m t he
EPROM/OTPROM (one-t ime pr ogr am-
mable ROM):
1. Manipulat e t he cont r ol bit s in t he
EPROM pr ogr amming r egist er t o pr o-
gr am t he EPROM/OTPROM on a byt e-
by-byt e basis.
2. Pr ogr am t he EPROM/OTPROM
wit h Mot or olas MC68HC705J in-cir cuit
simula t or .
The a ut hor ha s used t he second
met hod for pr ogr amming t he OTPROM.
(EFY n ot e . Rea der s wh o wi s h t o
a cqu i r e a P od for 705KJ 1/J 1A
micr ocon t r oller s , a lon g wit h t h e r e-
qu ir ed soft wa r e, ma y con t a ct Vin a y
Chaddha at gvc@vsnl.com.)
An a ct u a l-s ize, s in gle-s ided PCB
for t he cir cuit s in Figs 2 and 3 is shown
in Fig. 4, wit h it s component layout
shown in Fig. 5.
Fig. 5: Component layout for the PCB
TABLE II
Truth Table for Pri ori ty Encoder CD4532
Keys E1 D7 D6 D5 D4 D3 D2 D1 D0 Q2 Q1 Q0
St or e 1 1 X X X X X X X 1 1 1
Digit Adv. 1 0 1 X X X X X X 1 1 0
Bell 1 0 0 1 X X X X X 1 0 1
Time 1 0 0 0 1 X X X X 1 0 0
Delet e 1 0 0 0 0 1 X X X 0 1 1
c i r c u i t i d e a s
electronics for you january 2002
Mobile Phone
battery charger
t.k. hareendran
M
obile phone chargers available in
the market are quite expensive.
The circuit presented here comes
as a low-cost alternative to charge mobile
telephones/battery packs with a rating of
7.2 volts, such as Nokia 6110/6150.
The 220-240V AC mains supply is
downconverted to 9V AC by transformer
X1. The transformer output is rectifed
by diodes D1 through D4 wired in bridge
confguration and the positive DC supply is
directly connected to the chargers output
contact, while the negative terminal is
connected through current limiting resis-
tor R2.
LED2 works as a power indicator with
resistor R1 serving as the current limiter
and LED3 indicates the charging status.
During the charging period, about 3 volts
drop occurs across resistor R2, which
turns on LED3 through resistor R3.
An external DC supply source (for
instance, from a vehicle battery) can also
be used to energise the charger, where
resistor R4, after polarity protection diode
D5, limits the input current to a safe value.
The 3-terminal positive voltage regulator
LM7806 (IC1) provides a constant voltage
output of 7.8V DC since LED1 connected
between the common terminal (pin 2) and
ground rail of IC1 raises the output voltage
to 7.8V DC. LED1 also serves as a power
indicator for the external DC supply.
After constructing the circuit on a
veroboard, enclose it in a suitable cabi-
net. A small heat sink is recommended
for IC1.
circuit
idea
Periodically ON-OFF
MOSQUITO REPELLENT
Some of the mosquito repellents available in the market use a toxic liquid to generate poisonous
vapours in order to repel mosquitoes out of the room. Due to the continuous release of poisonous
vapours into the room, after midnight the natural balance of the air composition for good health
reaches or exceeds the critical level. Mostly, these vapours attack the brain through lungs and exert
an anesthetic effect on mosquitoes as well as other living beings by small or greater percentage. Long
exposure to these toxic vapours may cause neurological or related problems.
Here is a circuit that automatically switches on and off the mosquito repellent after preset time interval,
thus controlling the release of toxic vapours into the room. The circuit turns the mosquito repellent on
for approximately 20 minutes then process of 'on' and 'off' occurs repeatedly.So if you leave the
mosquito repellent switched on from 10 pm to 6 am (eight hours), it will be on for four hours and off
for four hours of the total duration. During off time, the room air tries to balance its natural
composition. Another important feature is that the circuit switches to on/off operation without
producing any noise or a sound click as in a relay and hence doesnt disturb your sleep. The circuit
consists of a timer section built around IC 555 (IC1) and an automatic switching section using triac
BT136 (triac1). Power supply to the circuit is derived from the AC mains by stepping it down to a
required level and rectifying it. The elimination of the transformer saves on space as well as money.
Zener diode ZD1 and capacitor C2 provide regulated 9V DC power supply to timer IC1.The timer
section comprises resistors R1 and R2 and capacitor C1. The output of timer IC 555 is fed to the gate
terminal of BT136 through series LED1 and resistor R4. When the timer output goes high, it triggers
the gate of triac 1 and LED1 shows the on period. During off time, the output of IC1 goes low and
hence triac 1 is not fired and LED1 doesnt glow. The circuit is very compact and can be assembled on
a general-purpose PCB. Use an 8-pin IC base for timer IC LM555. After assembly, fit the unit inside
the housing electric board where you plug in the mosquito repellent.
ELECTRONICS FOR YOU MARCH 2001
C I R C U I T I D E A S
S
.C
. D
W
IV
E
D
I
H
er e is a musical call bell t hat
can be oper at ed by just br idg-
ing t he gap bet ween t he t ouch-
plat es wit h ones finger t ips. Thus t her e
is no need for a mecha nica l on/off
swit ch because t he t ouch-plat es act as
a swit ch. Ot her feat ur es include low cost
and low power consumpt ion. The bell
can wor k on 1.5V or 3V, using one or
t wo pencil cells, a nd ca n be used in
homes and offices.
Two t r ansist or s ar e used for sens-
i n g t h e fi n ger t ou ch a n d s wi t ch i n g
on a melody IC. Tr ansist or BC148 is
npn t ype while t r ansist or BC558 is pnp
t ype.
The emit t er of t r ansist or BC148 is
shor t ed t o t he gr ound, while t ha t of
t r a nsist or BC558 is connect ed t o t he
posit ive t er minal. The collect or of t r an-
sist or BC148 is connect ed t o t he base of
BC558. The base of BC148 is connect ed
t o t he washer (as shown in t he figur e).
The collect or of BC558 is connect ed t o
pin 2 of musical IC UM66, and pin 3 of
IC UM66 is shor t ed t o t he gr ound. The
out put fr om pin 1 is connect ed t o a t r an-
s i s t or a mpl i fi er compr i s i n g BEL187
t r ansist or for feeding t he loudspeaker .
One end of 2.2-mega-ohm r esist or R1
is connect ed t o t he posit ive r ail and t he
ot her t o a scr ew (as shown in t he fig-
ur e). The complet e cir cuit is connect ed
t o a single pencil cell of 1.5V.
When t he t ouch-plat e gap is br idged
wit h a finger , t he emit t er -collect or junc-
t ion of t r ansist or BC148 st ar t s conduct -
SUKANT KUMAR BEHARA
ing. Simult aneously, t he emit t er -baser
junct ion of t r ansist or BC558 also st ar t s
conduct ing. As a r esult , t he collect or of
t r ansist or BC558 is pulled t owar ds t he
posit ive r ail, which t hus act ivat es melody
gener at or IC1 (UM66). The out put of
IC1 is amplified by t r ansist or BEL187
and fed t o t he speaker . So we hear a
musical not e just by t ouching t he t ouch
point s.
The washer s inner diamet er should
be 1 t o 2 mm gr eat er t han t hat of t he
scr ewhead. The washer could be fixed in
t he posit ion by using an adhesive, while
t he scr ew ca n be ea sily dr iven in a
wooden piece used for mount ing t he
t ouch-plat e. The use of br ass washer and
scr ew is r ecommended for easy solder -
abilit y.
MUSICAL TOUCH BELL
circuit
ideas
104 February 2010 electroni cs for you www. e F y ma g . c o m
M
ost water-level indicators
for water tanks are based
upon the number of LEDs
that glow to indicate the correspond-
ing level of water in the container.
Here we present a digital version of the
water-level indicator. It uses a 7-seg-
ment display to show the water level
in numeric form from 0 to 9.
The circuit works off 5V regulated
power supply. It is built around prior-
ity encoder IC 74HC147 (IC1), BCD-to-
7-segment decoder IC CD4511 (IC2),
7-segment display LTS543 (DIS1) and a
few discrete components. Due to high
input impedance, IC1 senses water in
the container from its nine input termi-
nals. The inputs are connected to +5V
via 560-kilo-ohm resistors. The ground
Daniyal SyeD
nUMeRiC WaTeR-leVel inDiCaTOR
S.C. DW
IVEDI
terminal of the sensor must be kept at
the bottom of the container (tank). IC
74HC147 has nine active-low inputs
and converts the active input into ac-
tive-low BCD output. The input L-9
has the highest priority.
The outputs of IC1 (A, B, C and
D) are fed to IC2 via transistors T1
through T4. This logic inverter is used
to convert the active-low output of IC1
into active-high for IC2. The BCD code
received by IC2 is shown on 7-seg-
ment display LTS543. Resistors R18
through R24 limit the current through
the display.
When the tank is empty, all the
inputs of IC1 remain high. As a result,
its output also remains high, making
all the inputs of IC2 low. Display
LTS543 at this stage shows 0, which
means the tank is empty. Similarly,
when the water level reaches L-1 posi-
tion, the display shows 1, and when
the water level reaches L-8 position,
the display shows 8. Finally, when
the tank is full, all the inputs of IC1
become low and its output goes low
to make all the inputs of IC2 high.
Display LTS543 now shows 9, which
means the tank is full.
Assemble the circuit on a gen-
eral-purpose PCB and enclose in a
box. Mount 7-segment LTS543 on the
front panel of the box. For sensors L-1
though L-9 and ground, use corrosion-
free conductive-metal (stainless-steel)
strips.
do-it-yourself
KitsnSpares
OVERVIEW
The Parrot Sounding AC Doorbell is a mains-operated
doorbell that produces parrot-like sweet sound without
requiring a melody generator IC. The circuit is cheap and
easy to construct. The AC mains are fed to the circuit with-
out using any step-down transformer and hence the circuit
is not bulky either.
COMPONENT DESCRIPTION
Audio Transformer:
Audio transformers are specifcally designed for use in
audio circuits. They can be used to block radio frequency in-
terference or the DC component of an audio
signal, to split or combine audio signals, or to
provide impedance matching between high
and low impedance circuits, such as between
a high impedance tube (valve) amplifer
output and a low impedance loudspeaker,
or between a high impedance instrument
output and the low impedance input of a
mixing console.
Being magnetic devices, audio transform-
ers are susceptible to external magnetic felds such as those
generated by AC current-carrying conductors. Hum is a
term commonly used to describe unwanted signals originat-
ing from the mains power supply (typically 50 or 60 Hz).
Audio transformers used for low-level signals, such as those
from microphones, often include shielding to protect against
extraneous magnetically coupled signals.
Transistors (NPN Type BC337):
The BC337 is a general purpose tran-
sistors used for switching and amplif-
cation purposes. The common-emitter
amplifer is designed so that a small
change in voltage in (V
in
) changes the
small current through the base of the
transistor and the transistors current am-
plifcation combined with the properties
Parrot Sounding
AC Doorbell
of the circuit mean that small swings in V
in
produce large
changes in V
out
.
From mobile phones to televisions, vast numbers of
products include amplifers for sound reproduction, radio
transmission, and signal processing. Modern transistor
audio amplifers of up to a few hundred watts are common
and relatively inexpensive.
In the Parrot Sounding AC Doorbell circuitry; this tran-
sistors is being basically used for amplifcation of the audio
signal. The amplifed signal is available at the collector pin
of the BC337 which is input to the loudspeaker for genera-
tion of the parrot sound.
Resistors:
The most basic role of resistors is current limiting i.e.
precisely controlling the quantity of electrical current that
is going to fow through a device or a conductor. Resistors
can also be used as voltage divider, in other words they can
be used to generate any voltage from an initial bigger volt-
age by dividing it.
Capacitors:
Capacitors store
el ect r i c char ge.
They are used with
resistors in tim-
ing circuits because
it takes time for a
capacitor to fll with
charge. Capaci -
tors are also used
to smooth varying
DC supplies by act-
ing as a reservoir
of charge. They are
also used in filter
circuits because ca-
pacitors easily pass
AC (changing) sig-
nals but they block
DC (constant) sig-
nals.
Note: Electro-
lytic capacitors are
polarized and they
Fig. 3: Pin
Confguration of
transistor BC337
Fig. 1: Block diagram of the Parrot Sounding AC Doorbell
Fig. 2:
Construction
of an Audio
Transformer
Parts List
Semiconductors:
T1 - Transistor BC337
D1 - Diode 1N4007
Resistors (all -watt, 5% carbon):
R1 - 1.5 Kilo-ohm, 5W
R2 - 1Kilo-ohm, 1W
R3 - 47 Kilo-ohm
R4 - 2.2 Kilo-ohm
R5 - 3.9 Kilo-ohm
Capacitors:
C1 - 0.22F, Ceramic Disk
C2 - 1000F, 25V Electrolyte
C3 - 330F, 25V Electrolyte
C4, C5 - 0.047F, Ceramic Disk
Miscellaneous:
LS1 - 8 ohm, 0.5 Watt
Loudspeaker
X1 - Audio Transformer
S1 - Push-to-On Switch (only
meant for prototyping)
Printed Circuit Board (PCB)
Note: Kits N Spares does not provide
Doorbell Switch alongwith the compo-
nents, it is however highly recommended
for use in place of the push-to-on switch
(S1)
do-it-yourself
KitsnSpares
must be connected the correct way round, at least one of
their leads will be marked + or -. They are not damaged by
heat when soldering.
WORKING PRINCIPLE:
The main components of the Parrot Sounding AC
Doorbell circuit are a resistor-capacitor network, transistor
BC337 and an audio output transformer X1. The oscillation
frequency of the audio signal depends on the combina-
tion of resistors R4 and R5 and capacitors C3, C4 and C5.
When switch S1 is closed, the audio signal generated due
to oscillations is amplifed by transistor BC337 and parrot-
like sound is reproduced from loudspeaker LS1 connected
across the secondary of transformer X1. The audio output
transformer (X1) is normally used in transistor radio. The
function of the audio output transformer is to transform
the high impedance of the output amplifer to match the
much lower impedance of the speaker. This is necessary to
get an effcient transfer of the audio signal to the speaker.
If a wrong audio transformer is used, the result can be low
output and loss of tone quality.
The audio frequency tone across the speaker terminal is
about 3 kHz. The circuit is powered directly from 220V AC
mains. The operating DC voltage obtained at the cathode
of diode D1 is about 6V. However, if switch S1 is pressed
continuously for a few seconds, the maximum voltage
developed at this point may go up to 20 volts, which must
be avoided to prolong the life of the circuit. R1 limits surge
current in the circuit. The parallel combination of resistor R1
and capacitor C1 limits the circuit current to a safe level for
circuit operation. R2 across C1 provides DC path for the cur-
rent as well as a discharge path when the circuit is switched
off. This is to prevent a possible shock to the operator by
charged capacitor C1.
ASSEMBLING THE KIT
Preparing the soldering iron:
Place the soldering iron in its stand and plug in. The
iron will take a few minutes to reach its operating
temperature of about 400C.
Dampen the sponge in the stand.
Wait a few minutes for the soldering iron to warm
up. You can check if it is ready by trying to melt a
little solder on the tip.
Wipe the tip of the iron on the damp sponge. This
will clean the tip. Melt a little solder on the tip of
the iron.
Soldering the components:
Use the component overlay on the PCB to insert
the components and solder them, in the following
order:
1. Resistors
2. Diodes
3. Capacitors
4. Transistor
5. Doorbell Switch (or Push-to-on switch strictly for
testing)
6. Audio Transformer
7. Loudspeaker
Hold the soldering iron like a pen, near the base of
the handle. Touch the soldering iron onto the joint
to be made. Make sure it touches both the compo-
nent lead and the track.
Hold the tip there for a few seconds and Feed a
little solder onto the joint. It should fow smoothly
onto the lead and track to form a volcano shape.
Apply the solder to the joint, not the iron.
Remove the solder, then the iron, while keeping
the joint still.
After all the components have been soldered, check
the soldering closely for any breaks. Inspect your
work carefully under a bright light. The solder
Component Identifcation
Printed Circuit Board
Resistor (R1)
Ceramic Capacitors
Electrolytic
Capacitors
Audio
Transformer
(X1)
Resistors (R2-R5)
Diode (D1)
Transistor
(T1)
Push-to-on
Switch
(S1)
Loudspeaker
Completed prototype after assembling the components and soldering
(via transformer)
Connection to
AC Supply Mains
Loudspeaker
Printed Circuit Board
do-it-yourself
KitsnSpares
joints should have a shiny look about them. Check
that there are no solder bridges between adjacent
pads. Connectivity in circuit can be tested by the
help of a multi-meter.
Precautions to be taken:
Please note that the connections to the loudspeaker
need to be made externally using wires. Please
refer to the pictorial illustration to fgure out these
connections.
It is preferable to use multi-thread wires for con-
nection with the loudspeaker, rather than single
thread copper wires since they tend to break upon
soldering.
The three-legged transistor should also be carefully
placed into the correct drill holes on the PCB.
Attention must be paid to the polarity of compo-
nents of such as the electrolytic capacitors and
diodes, before soldering them onto the PCB.
The leads of the audio transformer should be
scratched mildly before soldering
them into the circuitry, for proper
functioning.
Note: For testing/prototyping purposes,
a push-to-on switch may be used. However,
it is highly recommended to use a doorbell
switch (which is used for most commercial
doorbells). This is because the Parrot Bell cir-
cuit operates on AC supply, which typically
cannot be tolerated by a push-to-on switch
for too long, without heating up.
TESTING
To perform a test on the working of the Parrot
Sounding AC Doorbell, plug in the AC supply and
switch it ON. Once the circuit is powered, press
the push-to-on switch or the doorbell switch. This
should cause a sweet parrot-like sound to be gener-
ated from the loudspeaker.
The parrot-like sound should be generated for a
preset interval of time which typically lasts about
30 to 40 seconds.
TRY THIS OUT NEXT!
The Parrot Sounding Doorbell discussed here can be
modifed to generate other sounds/tunes. This can be done
by replacing the audio transformer with a different audio
transformer. This will alter the sound generated by the
loudspeaker. Else, a melody generator IC (like the BT66 or
the UM66) can be included in the circuit to generate ones
favorite musical tune!
CONTACT DETAILS:
For full range of available kits, take a look at our web-
site: www.kitnspares.com
Documented by Aditi Goswami
Fig. 4: Circuit Diagram of the Parrot Sounding AC Door Bell
A Doorbell Switch
ConstruCtion
60 December 2006 electroni cs for you www. e f y ma g . c o m
M
ore and more experiments
are now PC-assisted. Also
conventional acquisition sys-
tems are very expensive. Since portable
PCs are today common and a USB link
is a better solution than an old ISA bus,
here we present an oscilloscope using
USB port of the PC that operates at up
to 10 kHz with 16V input voltage. It
has much more improved features than
the PC-based oscilloscope and LED
scope for audio servicing published in
EFY Dec. 2002 and Electronics Projects
Vol. 8, respectively. The oscilloscope
uses IC PIC18F2550 from Microchip
as the main controller, which makes
the oscilloscope compact as there is no
need of additional power supply for
the entire circuit board. The prototype
of the circuit along with the enclosure
is shown above.
Circuit description
At the heart of this oscilloscope is
USB2.0-compliant microcontroller
PIC18F2550 from Microchip. You
can also use PIC18F2445 in place of
PIC18F2550. Specifcations of this mi-
its pins 5, 6 and 7.
The MCP6S91 amplifer is designed
with CMOS input devices. It is de-
signed to not exhibit phase inversion
when the input pins exceed the supply
voltages. The maximum voltage that
can be applied to the input pin is 0.3V
(V
SS
) to +0.3V (V
DD
). Input voltages that
exceed this absolute maximum rating
can cause excessive current into or out
of the input pins. Current beyond 2
mA can cause reliability problems. Ap-
plications that exceed this rating must
be externally limited with a resistor to
the input pin.
Vref (pin 3), which is an analogue
input, should be at a voltage between
V
SS
and V
DD
. The voltage at this pin
shifts the output voltage. The SPI
interface inputs are chip-select (CS),
serial input (SI) and serial clock (SCK).
These are Schmitt-triggered, CMOS
logic inputs.
The only disadvantage is that these
amplifers accept only positive signals.
Thats why voltage-shifting ampli-
fiers LF353 (IC4A
and IC5A) are used,
one each for each
channel input (see
Fig. 1). The LF353
is a JFET input op-
erational amplifier
with an internally
compensated input
offset voltage. The
JFET input device
provides wide band-
width, low input
bias currents and
offset currents. This
voltage-shifting am-
plifier results in a
high input imped-
ance and an attenu-
ation factor of 1:4.5.
A 16V input signal
is then shifted to the
crocontroller are given here in the box.
This microcontroller has a USB2.0-com-
pliant transceiver and a CPU running
up to 12 MIPS.
Fig. 1 shows the circuit of the
two-channel PC-based oscilloscope.
MCP6S91 from Microchip Technology
is an analogue programmable gain am-
plifer that is well suited
to driving analogue-to-
digital converters (ADCs)
and an analogue input to
a PIC microcontroller.
Two MCP6S91 pro-
grammable gain ampli-
fers (IC2 and IC3) make
it possible to choose the
input ranges for each of
the two channels, by se-
lecting a gain from 1:1 to
32:1. The amplifers are
small, cheap and easy to
use. A simple three-wire
serial peripheral inter-
face (SPI) allows the PIC
to control them through
Gerard SamblanCat
two-Channel PC-
baSed oSCilloSCoPe
Authors prototype
Features of PIC18F2550
Programming
1. Up to 32 kB of flash memory, 2kB RAM and 256-byte EEPROM
2. Extended instruction set (optimised for C compiler)
3. 8x8 single-cycle multiplier
4. Single-supply serial programming and easy debugging
USB transceiver
1. USB1.1 and 2.0 from 1.5 MB/s to 12 MB/s
2. Isochronous, bulk and interrupt transfer modes
3. 1 kB of access RAM usable with 32 endpoints (64 bytes each)
Multiple oscillator and power modes
1. From internal 31 kHz to external 48 MHz with PLL
2. Possible software switching between run, idle and sleep
modes. In sleep mode, current is down to 0.1 A.
3. Wide operating voltage range (2.0V to 5.5V). Useful for battery
operations.
Complete set of classical peripherals
1. Several input/output (I/O) ports, four timers with capture/
compares
2. Synchronous and asynchronous enhanced modules
3. Streaming parallel port
4. 10-bit ADC module with up to 13-channel multiplexer.
ConstruCtion
electroni cs for you December 2006 61 www. e f y ma g . c o m
0-5V range when the pro-
grammed gain is 1:1.
Two halves of the
LF353 (IC4B and IC5B) are
used as voltage follow-
ers to provide a low-im-
pedance shifting voltage
(Vref) to the program-
mable amplifiers. This
voltage must be precisely
adjusted with two 4.7-kilo-
ohm presets to measure
precisely 2.5V level on
the inputs of IC2 and IC3
when the input signals are
grounded.
Because LF353 op-
amps need a symmetrical
supply voltage, a small
DC-DC voltage converter
ICL7660 (IC6) is used
to feed 5V to LF353.
With its small 8-pin DIP
package, it needs only
two polarised capacitors.
ICL7660 can be replaced
with a MAX1044. The
MAX1044 and ICL7660
are monolithic, CMOS
switched-capacitor volt-
age converters that invert,
double, divide or multiply
a positive input voltage.
These are pin compatible
with the industry-stan-
dard LTC1044.
overview of the
universal serial
bus
The specifcations of the
USB can be found on web-
site www.usb.org. One
of its major advantages
is the ability to drive 5V,
100mA devices.
All the data is trans-
mitted on the D+/D- sym-
metrical pins using a vari-
able bit rate. The position
of a resistor (R13) on D+
or D- allows you to choose between
the full-speed (12 Mbps) and low-
speed modes (1.5 Mbps). Note that the
PIC18F2550/2455 devices have built-in
pull-up resistors designed to meet the
requirements of low-speed and full-
speed USB. The UPUEN bit (UCFG=4)
enables the internal pull-ups. In this
project, R13 is not used. External pull-
up may also be used. The VUSB pin
may be used to pull up D+ or D-. The
pull-up resistor must be 1.5 kilo-ohms
(5%) as required by the USB specifca-
tions.
You can also hot-plug a new de-
vice. When this is done, the host PC
starts an enumeration process to iden-
tify the device. The device sends the in-
formation to the PC by way of different
descriptors. Each descriptor contains
F
i
g
.
1
:
T
w
o
-
c
h
a
n
n
e
l
P
C
-
b
a
s
e
d
o
s
c
i
l
l
o
s
c
o
p
e
c
i
r
c
u
i
t
ConstruCtion
62 December 2006 electroni cs for you www. e f y ma g . c o m
a specifc kind of information about
the device (vendor ID, serial number,
format and type of data transmitted).
You can see in Fig. 2 that each
device is structured in a layered frame-
work of descriptors. The frst layer con-
taining the confguration descriptors
describes the power mode.
Each confguration may have dif-
ferent interfaces and each interface
may have different endpoints. An
interface can use several endpoints
and an endpoint can be IN (data from
device to the host) or OUT (from host
to the device). With such an opened
structure, its important to carefully
design the descriptors.
A 64-byte buffer is allocated to
each of the 32 possible endpoints. Here
only one is used and the more possible
amount of RAM buffer is then reallo-
cated to store the measured values.
the PiC software
The program for the microcontroller
is written in C language. MPLAB
7.31 along with MPLAB_C18 is used
as the software tool for develop-
ment. The software tools can be
downloaded for free from website
www.microchip.com.
Based on Microchips application
notes, the program for the chip is cen-
tered on a main loop continually poll-
ing the USB transceiver state. This loop
never stops and each USB operation is
done in one pass. All operations are
initiated by the host (the PC), which
sends a 16-byte command.
The frst command byte determines
the chip actions. The four possible ac-
tions are:
1. Command 80h: Clears the EE-
PROM calibration memory
2. Command 81h: Receives param-
eters, and stores the gain-error com-
pensation for the two channels.
3. Command 83h: Initiates a zero
calibration sequence of the two chan-
Fig. 2: Layered framework of a USB device
nels. The two inputs have to be
grounded.
4. Command 85h: Initiates mea-
surement of the input signals.
The PIC software consists of
eight C program source fles, 14
header fles and a linker fle all un-
der aquis.mcp project. The main
C program source fles (main.c
and user.c) are given at the end of
this article. The rest of the program
fles are included in the EFY-CD.
Programming the chip. Program-
ming the PIC18F2455/2550 is easy
with an ICD2 module or PICSTART
Plus development board along with
MPLAB software. But many serial
programmers for PIC16F84 are not
compatible here. While using the
PICSTART Plus development board,
you can copy the hex file into the
MPLAB IDE using import command
from fle menu bar. Select the device
as PIC18F2550 and confgure the bits
as per this device from confg menu.
Installation of the USB driver. 1. If
everything is fne, plug the oscilloscope
with a USB cable to your PC (running
Windows 98SE or higher version). A
new hardware detectedUSB2-Min-
iOscilloscope dialogue box must im-
mediately appear on the screen.
2. Now you can start the driver in-
stallation process. The driver has been
included in the EFY-CD. The goal is
to select a good driver (mchpusb.inf)
by choosing the specifc location op-
tion. Dont let Windows take a generic
driver by default.
3. When you are done with
installation, go to device manager
and check whether USB2-MiniOscillo-
scope is under other device in view
devices by type option. Otherwise,
repeat Steps 1 and 2.
User interface program and op-
erations. A user-interface software
written in Visual Basic 6, called Os-
cilloPIC, is included in the EFY-CD.
Run the set up program from the
Setup_files folder included in the
EFY-CD. This will automatically install
the OscilloPIC user-interface pro-
gram. Alternatively, you can open the
Source_VB6 folder, compile and run
the Synchropic program using Visual
Basic 6. Now run the OscilloPIC. The
Parts List
Semiconductors:
IC1 - PIC18F2550 microcon-
troller
IC2, IC3 - MCP6S91 program-
mable gain amplifer
IC4(A, B),
IC5(A, B) - LF353 dual operational
amplifer
IC6 - ICL7660 switched-ca-
pacitor voltage convert-
ers
Resistors (all -watt, 5% carbon):
R1, R7 - 1-mega-ohm
R2, R8 - 82-kilo-ohm
R3, R9 - 33-kilo-ohm
R4, R10 - 220-kilo-ohm
R5, R11 - 150-kilo-ohm
R6, R12 - 1-kilo-ohm
Capacitors:
C1, C2 - 2.7pF ceramic
C3, C4,
C5, C6 - 68nF ceramic
C7 - 0.022F polyester
C8 - 150nF ceramic
C9 - 10F, 16V electrolytic
C10 - 47F, 16V electrolytic
Miscellaneous:
X1 - 4MHz crystal oscillator
CON1 - USB socket (type-B) for
PCB
ConstruCtion
electroni cs for you December 2006 63 www. e f y ma g . c o m
application program looks like a
small digital oscilloscope as shown
in the screenshot below.
Various settings for operations
are given in the following menu
bars:
1. Inputs: Selects the active
channels
2. Sampling: Sets time-base and
number of samples
3. Trigger: Sets the triggering
condition
4. Cursors: Selects horizontal or
vertical cursor positions
5. Num: Shows numerical
sampled values, with an export
command (text fle format)
6. Confg: Confgures gain and
offset errors
Calibration is to be done as
described below before reading
the output signals on the monitor
screen by clicking channels cali-
bration under confg menu bar.
Feed the input waveforms (say,
sine, rectangular, sawtooth, etc)
from the source. Click go but-
ton. The output waveform will be
displayed on the monitor screen.
Channel-1 and channel-2 output
waveforms can be differentiated by
green and red lines, respectively.
By default, the time base is 200 s
per division and amplitude is 4V
per division. You can set these param-
eters as per your requirements.
Test and calibration. The first
step is to adjust the zero offset error.
Connect the two analogue inputs to
the ground level and tune the two 4.7-
kilo-ohm presets until pin 2 of both
MCP6S21 is at 2.5V. A more precise
tuning can be achieved through Oscil-
loPIC software. Choose the smallest
calibration value at 0.5V for both the
inputs.
The zero calibration
command tells the PIC
to start its own internal
compensation for all cali-
brations. Dont forget to
connect the inputs to the
ground while calibrat-
ing.
The second parameter
to check is the gain error.
By clicking the gain cali-
bration command, its
possible to specify a small
correction factor. This
can be done after several
measurements. You have
to know the actual levels
Screenshot: Oscilloscopic program output screen along with typical
sine and triangular waveforms
Fig. 3: An actual-size, single-side PCB layout of the two-channel PC-based USB oscilloscope
Fig. 4: Component layout for the PCB
and the measured levels (with the cur-
sors) for the two channels. The gain er-
ror is less than 0.1 per cent. The number
of samples can be set between 10 and
500. The minimum sampling rate is
5 s for one channel and 10 s for two
channels.
Construction
An actual-size, single-side PCB layout
for the two-channel PC-based USB os-
cilloscope circuit is shown in Fig. 3 and
its component layout in Fig. 4. Since
the circuit is compact, the construction
is easy. It is advised to use IC bases for
mounting IC2 through IC6 on the PCB
for easy troubleshooting. The USB con-
nector (CON1) must be frmly soldered
and fxed on the board. It is located on
the extreme right of the board (refer
Fig. 4).
Two BNC connectors can be used
for the input signals for channels 1
ConstruCtion
64 December 2006 electroni cs for you www. e f y ma g . c o m
/**********************************************************
* FileName: main.c
* Dependencies: See INCLUDES section below
/** I N C L U D E S ************************************/
#include p18f2550.h
#include typedefs.h // Required
#include usb.h // Required
#include io_cfg.h // Required
#include user.h // Modifable
/** V A R I A B L E S ***********************************/
#pragma udata
extern unsigned char voie1[256];
extern unsigned char voie2[256];
extern unsigned char voiesH1[64],voiesH2[64];
extern char ordre, timeout;
/** P R I V A T E P R O T O T Y P E S ****************/
static void InitializeSystem(void);
void USBTasks(void);
void timer_isr(void);
/** V E C T O R M A P P I N G *********************/
extern void _startup (void); // See c018i.c in
//your C18 compiler dir
#pragma code _RESET_INTERRUPT_VECTOR =
0x000800
void _reset (void) {
_asm goto _startup
_endasm
}
#pragma code
#pragma code low_vector = 0x18
void low_interrupt (void) {
_asm goto timer_isr _endasm
}
#pragma code
#pragma interruptlow timer_isr
//Fixe une periode de 1 seconde pour le time-out
//aquisition
maIn.C
void timer_isr(void) {
//Reset lit du timer 1
INTCONbits.TMR0IF=0;
TMR0H= 256-183;
TMR0L= 0;
timeout++; // incremente le compteur time-out !!
}
/*#pragma code _LOW_INTERRUPT_VECTOR =
0x000818
void low_ISR (void) {
;
}*/
/** D E C L A R A T I O N S **************************/
#pragma code
/******************************************************
****
* Function: void main(void)
* PreCondition: None
* Input: None
* Output: None
* Side Effects: None
* Overview: Main program entry point.
* Note: None
**********************************************************
*******************/
void main(void) {
InitializeSystem();
ordre=0;
while(1) {
USBTasks(); // USB Tasks
ProcessIO(); // See user\user.c & .h
}//end while
}//end main
/*********************************************************
*********************
* Function: static void InitializeSystem(void)
* PreCondition: None
* Input: None
* Output: None
* Side Effects: None
* Overview: InitializeSystem is a centralize ini-
/**********************************************************
* FileName: user.c
* Processor: PIC18
********************************************************
************/
/** I N C L U D E S ************************************/
#include p18f2550.h
#include typedefs.h
#include usb.h
#include io_cfg.h // I/O pin mapping
#include user.h
/** V A R I A B L E S **********************************/
#pragma udata
DATA_PACKET databuff;
//Caracteristiques de lacquisition
unsigned char t_basethh, t_baseth, t_basetl;
unsigned char t_seuilh, t_seuill;
unsigned int t_nbpts;
//Boucle de dechargement vers le bus Usb
int send1_pts, send2_pts, s_shift;
int send1H_pts, send2H_pts, sendoffs;
user.C
//Compteur et pointeur des buffers de voies
unsigned char acqcyc, timeout;
unsigned char ordre;
unsigned char vH1, vH2, nptsH, nptsL;
unsigned char testH, testL;
unsigned char tt1, tt2, tt3;
unsigned char savFSR1L, savFSR1H,savFSR2L,
savFSR2H;
//--- Reservation de 640 octets pour la voie 1 -----
// de 0x100 a 0x37F
#pragma udata voieA = 0x100
unsigned char voie1A[256];
#pragma udata voieB = 0x200
unsigned char voie1B[256];
#pragma udata voiesMSB = 0x300
unsigned char voiesH1[128];
//--- La voie 2 est UsbRam de 0x500 a 0x77f -----
/** P R I V A T E P R O T O T Y P E S ***************/
void CopyData(unsigned int addr);
unsigned char RdEEPROM(unsigned char ad);
void WrEEPROM(unsigned char ad, unsigned char
dat);
/** D E C L A R A T I O N S **************************/
#pragma code
/***********************************************************
* Initialisation des ports, timer1, Adcon
*
********************************************************
**********/
void UserInit(void) {
//!!! NE PAS RALENTIR AVANT LENUM USB !!!
//Reglage ADC voie AN0 ok
ADCON0 = 0x01; //
adc on
ADCON1 = 0b00001101; // no ref , AN0-1
ADCON2 = 0b10001100; // 2.Tad Fosc/4
PORTA = 0b11110011;
TRISA = 0b11100011; //cde MCP6S ch0
TRISB = 0xff;
PORTC = 0b11111100;
TRISC = 0b11111000; //cde MCP6S ch1
send1_pts = send2_pts = 0;
send1H_pts = send2H_pts = 0;
sendoffs=0;
}
and 2, respectively. The connectors
can be fxed on the front panel of the
enclosure.
The performance of the oscilloscope
can be improved by changing the PIC
and its ADC with a faster model.
AD9238 (20 MS/s) is a good choice.
This fast, parallel ADC converter could
be used with a powerful DSP PIC. A
PIC18Fx455 could be used for its USB
link. An auto-zero-level calibration
system could be a good idea. This can
be done with an analogue switch on all
input signals.
EFY Note. All the relevant software
of this article have been included in
this months EFY CD.
tialization routine.
* All required USB initialization routines
are called from
* here.
* User application initialization routine
should also be
* called from here.
**********************************************************
*******************/
static void InitializeSystem(void) {
ADCON1 |= 0x0F; // Default all pins to digital
#if defned(USE_USB_BUS_SENSE_IO)
tris_usb_bus_sense = INPUT_PIN; // See io_cfg.
h
#endif
#if defned(USE_SELF_POWER_SENSE_IO)
tris_self_power = INPUT_PIN;
#endif
UserInit(); // See user.c & .h
mInitializeUSBDriver(); // See usbdrv.h
}//end InitializeSystem
/*********************************************************
*********************
* Function: void USBTasks(void)
* PreCondition: InitializeSystem has been called.
* Input: None
* Output: None
* Side Effects: None
* Overview: Service loop for USB tasks.
**********************************************************
*******************/
void USBTasks(void) {
/* Servicing Hardware */
USBCheckBusStatus(); // Must use
polling method
if(UCFGbits.UTEYE!=1)
USBDriverService(); // Interrupt or
polling method
}// end USBTasks
/** EOF main.c ****************************************/
ConstruCtion
electroni cs for you December 2006 65 www. e f y ma g . c o m
/***********************************************************
* Function: Lecture data eeprom
**************************************************************/
unsigned char RdEEPROM(unsigned char ad) {
EEADR=ad;
_asm
bcf EECON1,7,0
// clear EEPGD
bcf EECON1,6,0
// clear CFGS
bsf EECON1,0,0
// set RD
_endasm
return(EEDATA);
}
/***********************************************************
* Proc: Ecriture data eeprom
********************************************************
***********/
void WrEEPROM(unsigned char ad, unsigned char
dat) {
EEADR=ad;
EEDATA=dat;
_asm
bcf EECON1,7,0
// clear EEPGD
bcf EECON1,6,0
// clear CFGS
bsf EECON1,2,0
// set WREN
movlw 0x55
movwf EECON2,0
movlw 0xAA
movwf EECON2,0
bsf EECON1,1,0
// set WR
_endasm
while (EECON1bits.WR!=0) { ; }
_asm
bcf EECON1,2,0
// raz WREN
_endasm
}
/***********************************************************
* Function: void SetGain0(char)
* Overview: Change le gain program-
mable ampli voie0.
***********************************************************/
void SetGain0(unsigned char gain) {
unsigned char nn, q;
CS_CH0=0;
//Envoie cde ecriture registre gain (SPI 0.0)
nn=0b01000000;
for (q=0;q<8;q++) {
if (nn&128) SI_CH0=1; else SI_CH0=0;
SCK_CH0=1;
nn<<=1;
SCK_CH0=0;
}
//Envoie le gain (SPI 0.0)
nn=gain;
for (q=0;q<8;q++) {
if (nn&128) SI_CH0=1; else SI_CH0=0;
SCK_CH0=1;
nn<<=1;
SCK_CH0=0;
}
CS_CH0=1;
}
/***********************************************************
* Function: void SetGain1(char)
* Overview: Change le gain program-
mable ampli voie1.
*****************************************************************/
void SetGain1(unsigned char gain) {
unsigned char nn, q;
CS_CH1=0;
//Envoie cde ecriture registre gain (SPI 0.0)
nn=0b01000000;
for (q=0;q<8;q++) {
if (nn&128) SI_CH1=1; else SI_CH1=0;
SCK_CH1=1;
nn<<=1;
SCK_CH1=0;
}
//Envoie le gain (SPI 0.0)
nn=gain;
for (q=0;q<8;q++) {
if (nn&128) SI_CH1=1; else SI_CH1=0;
SCK_CH1=1;
nn<<=1;
SCK_CH1=0;
}
CS_CH1=1;
}
/************************************************************
* Function: CopyData (int)
* Overview: Recopie un bloc de 64 octets vers
databuff.
* avant envoie sur le bus USB.
***************************************************************/
void CopyData(unsigned int addr) {
_asm
decf FSR1L,1,0 //!!! adr sur 8
bits
decf FSR1L,1,0
movf INDF1,0,0 // recup l e
Msb
movwf FSR0H,0
decf FSR1L,1,0
movf INDF1,0,0 // recup le Lsb
movwf FSR0L,0
//Sauve FSR2
movf FSR2H,0,0
movwf vH2,1
movf FSR2L,0,0
movwf tt2,1
movlw databuff // adr sur 16
bits
movwf FSR2L,0
movlw 0
// !!!!
movwf FSR2H,0
movlw 64
movwf vH1,1
//Boucle de copie
copydo: movf POSTINC0,0,0
movwf POSTINC2,0
decfsz vH1,1,1
bra copydo
incf FSR1L,1,0
incf FSR1L,1,0
incf FSR1L,1,0
//Restitue FSR2
movf vH2,0,1
movwf FSR2H,0
movf tt2,0,1
movwf FSR2L,0
_endasm
}
/***********************************************************
* Function: Mesure sur voies sur les ADC
**************************************************************/
unsigned int doADC(unsigned char voie) {
if (voie==0) ADCON0=5; else ADCON0=1;
_asm
//lance mesure voie
bsf ADCON0,1,0
// lance aquis
waitvn: btfsc ADCON0,1,0
bra waitvn
_endasm
return(ADRES);
}
void doADC0(void) {
ADCON0=5;
_asm
//lance mesure voie 0
bsf ADCON0,1,0
// lance aquis
waitv0: btfsc ADCON0,1,0
bra waitv0
_endasm
}
void doADC1(void) {
ADCON0=1;
_asm
//lance la mesure voie 1
bsf ADCON0,1,0
// lance aquis
waitv1: btfsc ADCON0,1,0
bra waitv1
_endasm
}
/***********************************************************
* Function: void ProcessIO(void)
* Overview: This function is a place holder for
other user routines.
* It is a mixture of both USB and non-USB
tasks.
***********************************************************/
void ProcessIO(void) {
unsigned char ordrelen, pt;
unsigned int level;
unsigned long int sum32;
// User Application USB tasks
i f ( ( usb_devi ce_st at e < CONFI GURED_
STATE)||(UCONbits.SUSPND==1)) return;
ordrelen=(USBGenRead((byte*)&databuff,16));
//Verife que le prefxe est recu
if (ordrelen!=0) ordre=databuff._byte[0];
//====================================
// RECEPTION COMMANDE RAZ
//ETALONNAGE
//====================================
if (ordre==0x80) {
//Raz premier eeprom location
pt=0xff;
WrEEPROM(2,pt); // msb zero shift = ff
WrEEPROM(4,pt); //
//Lance lemission des offs en accus de recep-
tion
sendoffs=64;
ordre=0;
} //fn si ordre=80
//====================================
// RECEPTION COEFFICIENTS DE GAIN
//====================================
if (ordre==0x81) {
//Sauve les coeff de gain Voie 1
pt=databuff._byte[1];
WrEEPROM(9,pt);
//Voie 2
pt=databuff._byte[2];
WrEEPROM(10,pt);
//Lance lemission des offs en accus de recep-
tion
sendoffs=64;
ordre=0;
} //fn si ordre=81
//====================================
// RECEPTION COMMANDE REGLAGE DU
//ZERO
//====================================
if (ordre==0x83) {
//Met les calibres +/-16v
SetGain0(0);
SetGain1(0);
sum32=0;
//Moyenne de 256 acquisitions
for (level=0;level<0x100;level++) {
sum32+=doADC(0);
for (tt1=0;tt1<64;tt1++) { ; }
}
//Sauve moyenne Voie0+/-16v en eeprom 1-2
pt=sum32>>8;
WrEEPROM(1,pt);
pt=sum32>>16;
WrEEPROM(2,pt);
//Moyenne de 256 acquisitions
sum32=0;
for (level=0;level<0x100;level++) {
sum32+=doADC(1);
for (tt1=0;tt1<64;tt1++) { ; }
}
//Sauve moyenne Voie1+/-16v en eeprom 3-4
ConstruCtion
66 December 2006 electroni cs for you www. e f y ma g . c o m
pt=sum32>>8;
WrEEPROM(3,pt);
pt=sum32>>16;
WrEEPROM(4,pt);
//===================================
//Met les calibres +/-1v
SetGain0(6);
SetGain1(6);
sum32=0;
//Moyenne de 256 acquisitions - voie 0
for (level=0;level<0x100;level++) {
sum32+=doADC(0);
for (tt1=0;tt1<64;tt1++) { ; } }
//Sauve moyenne Voie0+/-1v en eeprom
pt=sum32>>8;
WrEEPROM(5,pt);
pt=sum32>>16;
WrEEPROM(6,pt);
//Moyenne de 256 acquisitions - voie 1
sum32=0;
for (level=0;level<0x100;level++) {
sum32+=doADC(1);
for (tt1=0;tt1<64;tt1++) { ; } }
//Stocke ecarts en eeprom
pt=sum32>>8;
WrEEPROM(7,pt);
pt=sum32>>16;
WrEEPROM(8,pt);
//Lance lemission des offs en accus de recep-
tion
sendoffs=64;
ordre=0;
} //fn si ordre=83
//====================================
// RECEPTION COMMANDE ACQUISITION
//====================================
if (ordre==0x85) {
//Met les calibres demands
SetGain0(databuff._byte[8]);
SetGain1(databuff._byte[9]);
//Prend le mode et seuil de declenchement
t_seuilh=databuff._byte[1];
t_seuill=databuff._byte[2];
//Prend la base de temps sur 24 bits
t_basethh=databuff._byte[3];
t_baseth=databuff._byte[4];
t_basetl=databuff._byte[5];
//Prend le nombre de points
nptsH = databuff._byte[6];
nptsL = databuff._byte[7];
t_nbpts= nptsL + 256*nptsH;
//--------- Vidage de la memoire courbes ---------
_asm
movlw 1
// Voie 1 - 100h/37fh
movwf FSR0H,0
clrf FSR0L,0
raz1: clrf INDF0,0
decfsz FSR0L,1,0
bra raz1
incf FSR0H,1,0
clrf FSR0L,0
raz2: clrf INDF0,0
decfsz FSR0L,1,0
bra raz2
incf FSR0H,1,0
movlw 127
// met les msb 512
movwf FSR0L,0
raz3: movlw 0xAA
movwf INDF0,0
decfsz FSR0L,1,0
bra raz3
movwf INDF0,0
movlw 5
// Voie 2 - 500h/77fh
movwf FSR0H,0
clrf FSR0L,0
raz4: clrf INDF0,0
decfsz FSR0L,1,0
bra raz4
incf FSR0H,1,0
clrf FSR0L,0
raz5: clrf INDF0,0
decfsz FSR0L,1,0
bra raz5
incf FSR0H,1,0
movlw 127
// met les msb a 512
movwf FSR0L,0
raz6: movlw 0xAA
movwf INDF0,0
decfsz FSR0L,1,0
bra raz6
movwf INDF0,0
//------------ Prepare Acquisition ----------------
incf nptsH,1,1 // compense les decfsz...
movf FSR1H,0,0 // sauve FSR1
movwf savFSR1H,1 // pour apres
aquis
movf FSR1L,0,0 //
movwf savFSR1L,1 //
movf FSR2H,0,0 // sauve FSR2
movwf savFSR2H,1 // pour apres
aquis
movf FSR2L,0,0 //
movwf savFSR2L,1 //
movlw 0x1
movwf FSR0H,0
movlw 0x5
movwf FSR2H,0
clrf FSR0L,0 // fsr0 ptr de lsb
voie 0
clrf FSR2L,0 // fsr2 ptr de lsb
voie 1
movlw 0x3
movwf FSR1H,0
clrf FSR1L,0 // fsr1 ptr de
msb v0&v1
movlw 4
// raz paquet de poids forts
movwf acqcyc,1
clrf vH1,1
clrf vH2,1
_endasm
//-------- Conditions declenchement ---------
// t_seuilh - b7 =1 : synchro
// b6 =0 : voie0, =1:voie1
// b5 =1 : montant, =0:descen-
dant
// b4 =1 : voie1 active
// b3 =1 : voie0 active
// t_seuilh 1:0 +seuill = niveau vu par ADC direct.
if (t_seuilh & 0x80) {
//Si synchro sur un seuil alors
level = t_seuill+0x100*(t_seuilh&0x3);
T0CON=0b10010110;
TMR0H= 256-183;
TMR0L= 0;
INTCON=0b10100000;
timeout=0;
//Si synchro sur VOIE 1
if (t_seuilh & 0x40) {
//Sync sur front montant
if (t_seuilh & 0x20) {
doADC0();
while (ADRES>=level)
{ doADC0(); if (timeout==15) break; }
while (ADRES<level)
{ doADC0(); if (timeout==15) break; } }
else {
//Sync sur front descendant
doADC0();
while (ADRES<level)
{ doADC0(); if (timeout==15) break; }
while (ADRES>=level)
{ doADC0(); if (timeout==15) break; } }
} // fn si voie1
//Si synchro sur VOIE 2
else {
if (t_seuilh & 0x20) {
doADC1();
while (ADRES>=level)
{ doADC1(); if (timeout==15) break; }
while (ADRES<level)
{ doADC1(); if (timeout==15) break; } }
else {
//Sync sur front descendant
doADC1();
while (ADRES<level)
{ doADC1(); if (timeout==15) break; }
while (ADRES>=level)
{ doADC1(); if (timeout==15) break; } }
} // fn si voie2
INTCON=0;
}
//====================================
// AQUISITION DE LA VOIE 0 SEULE - MINI
//MUM 5 uS
//====================================
if ((t_seuilh & 0x18)==0x08) {
_asm
movlw 0x01
movwf ADCON0,0
bsf ADCON0,1,0
// lance aquis
nop
nop
loopv0: movff ADRESL,POSTINC0
// stocke lsb voie 0
bcf STATUS,0,0 // prend les deux bits
rlcf vH1,1,1
rlcf vH1,0,1 // decale de 2 et OR
iorwf ADRESH,0,0
movwf vH1,1
//Test si cycle de Msb
decfsz acqcyc,1,1 // decr ctr
bra stoh0
//Stocke les 4*2 bits fnis
movf vH1,0,1
movwf POSTINC1,0 // FSR1 pointeur MSB
clrf vH1,1
// raz next msb
movlw 4
movwf acqcyc,1 // raz acqcyc
bra dosui0
stoh0: movlw 1 // tempo compens
pti1: decfsz WREG,1,0 //
bra pti1
//
nop
//
//Relance next aquisition
dosui0: bsf ADCON0,1,0
// lance aquis
//Tempo dune periode dech basehh->33mS
movff t_basethh, tt3
movff t_baseth, tt2
movff t_basetl, tt1
tpo1: decfsz tt1,1,1
bra tpo1
decfsz tt2,1,1
bra tpo1
decfsz tt3,1,1
bra tpo1
//Compte le nombre de points sur 16 bits
decfsz nptsL,1,1
bra loopv0
decfsz nptsH,1,1
bra loopv0
_endasm
}
//====================================
// AQUISITION DE LA VOIE 1 SEULE - MINI
//MUM 5 uS
//====================================
if ((t_seuilh & 0x18)==0x10) {
_asm
ConstruCtion
electroni cs for you December 2006 67 www. e f y ma g . c o m
movlw 0x7
movwf FSR1H,0 // msb voie2 en
0x7xx
movlw 0x05
movwf ADCON0,0
bsf ADCON0,1,0 // lance aquis
nop
loopv1: movff ADRESL,POSTINC2
// sto lsb voie1 (fsr2)
bcf STATUS,0,0 // prend les
deux bits
rlcf vH1,1,1
rlcf vH1,0,1 // decale de 2 et OR
iorwf ADRESH,0,0
movwf vH1,1
//Test si cycle de Msb
decfsz acqcyc,1,1 // decr ctr
bra stoh1
//Stocke les 4*2 bits fnis
movf vH1,0,1
movwf POSTINC1,0
// FSR1 pointeur MSB
clrf vH1,1 // raz next msb
movlw 4
movwf acqcyc,1 // raz acqcyc
bra dosui1
stoh1: movlw 1 // tempo compens
pti2: decfsz WREG,1,0 //
bra pti2
//
nop
//
//Relance next aquisition
dosui1: bsf ADCON0,1,0 // lance aquis
//Tempo dune periode dech basehh->33mS
movff t_basethh, tt3
movff t_baseth, tt2
movff t_basetl, tt1
tpo2: decfsz tt1,1,1
bra tpo2
decfsz tt2,1,1
bra tpo2
decfsz tt3,1,1
bra tpo2
//Compte le nombre de points sur 16 bits
decfsz nptsL,1,1
bra loopv1
decfsz nptsH,1,1
bra loopv1
_endasm
}
//====================================
// AQUISITION DES DEUX VOIES - MINIMUM
//10 uS
//====================================
if ((t_seuilh & 0x18)==0x18) {
_asm
// Acquisition de la Voie 0
loopaq: movlw 0x05
movwf ADCON0,0
bsf ADCON0,1,0 // lance aquis
nop
nop
movff ADRESL,POSTINC0 // stocke lsb voie 1
bcf STATUS,0,0 // prend les
deux bits
rlcf vH1,1,1
rlcf vH1,0,1 // decale de 2 et OR
iorwf ADRESH,0,0
movwf vH1,1
//Test si cycle de Msb
decfsz acqcyc,0,1 // (decr sans modifer)
bra stoh2
//Stocke les 4*2 bits fnis
movf vH1,0,1
movwf INDF1,0
clrf vH1,1 // raz new msb
bra do_v2
stoh2: movlw 1 // tempo compens
ptit1: decfsz WREG,1,0 //
bra ptit1 //
nop
//
//-------- Acquisition sur Voie 1 (AN1) ---------
do_v2: movlw 0x01
movwf ADCON0,0
bsf ADCON0,1,0
nop
nop
nop
movff ADRESL,POSTINC2 // stocke lsb voie 2
bcf STATUS,0,0 // prend 2 Msbs
rlcf vH2,1,1
rlcf vH2,0,1
iorwf ADRESH,0,0
movwf vH2,1
//Test si cycle de Msb
decfsz acqcyc,1,1
bra stoh3
//Stocke les 4*2 bits fnis
movlw 0x4
addwf FSR1H,1,0 // passe en 0x7..
movf vH2,0,1
movwf POSTINC1,0
movlw 0x4
subwf FSR1H,1,0 // repasse en 0x3..
clrf vH2,1 // raz next Msb
movlw 4
movwf acqcyc,1 // raz acqcyc
bra do_sui
stoh3: movlw 3 // tempo compens
ptit2: decfsz WREG,1,0 //
bra ptit2 //
nop
//
//Tempo dune periode dech basehh->33mS
do_sui: movff t_basethh, tt3
movff t_baseth, tt2
movff t_basetl, tt1
tp1: decfsz tt1,1,1
bra tp1
decfsz tt2,1,1
bra tp1
decfsz tt3,1,1
bra tp1
//Compte le nombre de points sur 16 bits
decfsz nptsL,1,1
bra loopaq
decfsz nptsH,1,1
bra loopaq
_endasm
}
//====================================
//Remet contexte fsr apres aquisitions
_asm
movf savFSR1H,0,1 // remet FSR1
movwf FSR1H,0
movf savFSR1L,0,1
movwf FSR1L,0
movf savFSR2H,0,1 // remet FSR2
movwf FSR2H,0
movf savFSR2L,0,1
movwf FSR2L,0
_endasm
ordre=0;
//Lance la retransmission
send1_pts = t_nbpts;
s_shift = 0x100;
send1H_pts = send2_pts =send2H_pts = send-
offs=0;
} //fn if ordre=85
/******** ENVOI DE LA VOIE 1 *****************/
if (send1_pts>0) {
//Envoi le premier groupe de 64oc de la Voie 1
CopyData(s_shift);
s_shift+=64;
send1_pts-=64;
//Voit si envoie les 128 Msb max
if (send1_pts<=0) {
send1H_pts=128; // lance les 128 msb
s_shift=0x300; }
while(mUSBGenTxIsBusy()) { }
USBGenWrite((byte*)&databuff,USBGEN_EP_
SIZE);
}
else {
/****** ENVOI DE LA VOIE 1 - POIDS FORTS ******/
if (send1H_pts>0) {
//Envoi le premier groupe des 128 msb de la
Voie 1
CopyData(s_shift);
s_shift+=64;
send1H_pts-=64;
//Voit si envoie les 128 Msb max
if (send1H_pts<=0) {
send2_pts= t_nbpts; // lance envoi voie 2
s_shift=0x500; }
while(mUSBGenTxIsBusy()) { }
USBGenWrite((byte*)&databuff,USBGEN_EP_
SIZE); }
else {
/************ ENVOI DE LA VOIE 2 *****************/
if (send2_pts>0) {
//Envoi le premier groupe de 64oc de la Voie 1
CopyData(s_shift);
s_shift+=64;
send2_pts-=64;
//Voit si envoie les 128 Msb max
if (send2_pts<=0) {
send2H_pts=128; // lance les 128 msb
s_shift=0x700; }
while(mUSBGenTxIsBusy()) { }
USBGenWrite((byte*)&databuff,USBGEN_EP_
SIZE); }
else {
/******* ENVOI DE LA VOIE 2 - POIDS FORTS *****/
if (send2H_pts>0) {
//Envoi le premier groupe des 128 msb de la
Voie 1
CopyData(s_shift);
s_shift+=64;
send2H_pts-=64;
sendoffs=64;
//Voit si envoi des Offsets
while(mUSBGenTxIsBusy()) { }
USBGenWrite((byte*)&databuff,USBGEN_
EP_SIZE); }
else
/********* ENVOI DES OFFSETS VOIE 0 & 1 *********/
if (sendoffs>0) {
//Envoi le premier groupe offsets +/-16v
databuff._byte[0]=RdEEPROM(1); //
Lsb voie 0
databuff._byte[1]=RdEEPROM(2); //
Msb
databuff._byte[2]=RdEEPROM(3); //
Lsb voie 1
databuff._byte[3]=RdEEPROM(4); //
msb
//Envoi le second groupe offsets +/-1v
databuff._byte[4]=RdEEPROM(5); //
Lsb voie 0
databuff._byte[5]=RdEEPROM(6); //
Msb
databuff._byte[6]=RdEEPROM(7); //
Lsb voie 1
databuff._byte[7]=RdEEPROM(8); //
msb
//Calibration des gains sauvs en eeprom
databuff._byte[8]=RdEEPROM(9); //
voie 0
databuff._byte[9]=RdEEPROM(0x0a); //
voie 1
//envoie les octets offset + cal gains
while(mUSBGenTxIsBusy()) { }
USBGenWrite((byte*)&databuff,USBGEN_
EP_SIZE);
sendoffs=0;
}
}
}
}
}//end ProcessIO
/****************************************************/
98 February 2005 electroni cs for you www. e F y ma g . c o m
circuit
ideas
CMYK
CMYK
T
imers are very useful both for
industrial applications and
household appliances. Here is
a PC-based timer that can be used for
controlling the appliances for up to
18 hours. For control, the timer uses a
simple program and interface circuit.
It is very cost-effective and effcient for
those who have a PC at workplace or
home. The tolerance is 1 second.
The circuit for interfacing the PCs
parallel port with the load is very sim-
ple. It uses only one IC MCT2E, which
isolates the PC and the relay driver
circuits. The IC prevents the PC from
any short circuit that may occur in the
relay driver circuit or appliance. The
glowing of LED1 indicates that the ap-
pliance is turned on. Transistor BC548
is used as the relay driver.
The program code is written in C
language and compiled using Turbo
C compiler. When the program is run,
it prompts the user to input the time
duration in seconds or minutes to con-
trol the appliance. After entering the
required timing, press any key from
AkshAy MAthur
the keyboard.
Suppose you input the total dura-
tion as x minutes, of which on and
off durations are y and z minutes,
respectively. The program will repeat
the on-off cycle for x/(y+z) number
of times. After completion of the total
time, to repeat the cycle, you will have to
reset the time in the program to activate
the circuit.
The program uses two bytes for stor-
ing integer type data. So when input is
PC-bAsed tiMer
given in terms of seconds or minutes,
it can hold 2
16
1=65,535 seconds or 18
hours at the maximum. The sleep() func-
tion in the program is used to hold the
appliance in on or off condition for
the on and off periods as entered by
the user against prompts. The sound()
function is used to give a beep during
on condition of the appliance.
EFY note. The source code and ex-
ecutable fle of this program have been
included in this months EFY-CD.
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
void main()
{
int PORT=0x0378,a,b,c,d=0;
clrscr();
_setcursortype(_NOCURSOR);
gotoxy(1,15);
textcolor(2);
printf(This is the Program to use PC Parallel
port as Timer for external circuits);
gotoxy(1,17);
printf(\nWith this program you can time the
circuits for precision upto a second\n);
printf(\nPress any key to continue....\n);
getch();
clrscr();
gotoxy(1,5);
printf(How do you want to enter the time dura-
tion ?);
printf(\n\n\n1.Enter time duration in minutes
(press m));
printf(\n\n2.Enter time duration in seconds
(press s)\n);
gotoxy(1,15);
switch(getch())
{
case m:
{
printf(Enter the total time duration (in min-
utes): );
scanf(%d,&a);
printf(Enter the time to keep the circuit on (in
minutes): );
scanf(%d,&b);
printf(Enter the time to switch off the circuit (in
minutes): );
scanf(%d,&c);
a=a*60;
b=b*60;
c=c*60;
printf(Press any key to start the program);
getch();
do
{
outportb(PORT,1);
printf(\nYour circuit is on);
sound(330);
sleep(b);
nosound();
outportb(PORT,0);
printf(\nYour circuit is off);
sleep(c);
d=d+b+c;
}
while(d<a);
printf(\n Your program completed succes-
fully);
outport(PORT,0);
sleep(5);
exit(0);
}
case s:
{
printf(Enter the total time duration (in sec): );
scanf(%d,&a);
printf(Enter the time to keep the circuit on (in
sec): );
scanf(%d,&b);
printf(Enter the time to switch off the circuit
(in sec): );
scanf(%d,&c);
printf(Press any key to start the program);
getch();
do
{
outportb(PORT,1);
printf(\nYour circuit is on);
sound(330);
sleep(b);
nosound();
outportb(PORT,0);
printf(\nYour circuit is off);
sleep(c);
d=d+b+c;
}
while(d<a);
printf(\nYour program completed succes-
fully);
outportb(PORT,0);
sleep(5);
exit(0);
}
}
}
Timer.c
ConstruCtion
electroni cs for you June 2010 69 www. e f y ma g . c o m
s.v.n. harish k.
AnshumAn BezBorAh
PIC mICroController-BAsed
eleCtronIC loCk
electronic door lock by interfacing the
output of the circuit with an electrically
actuated door lock. The system turns
on the appliance on entering a four-
digit password set by the user.
Circuit description
Fig. 1 shows the circuit of the PIC mi-
crocontroller-based electronic lock. It
can be divided into fve sections: input
(44 matrix keypad), processing unit
(PIC16F877A MCU), appliance control-
ler (relay driver), display (162 LCD),
and power supply.
PIC16F877A MCU. The PIC-
16F877A is an 8-bit microcontroller
based on reduced instruction set com-
puter (RISC) architecture. It has 8k14-
A
n electronic lock allows
activation of an electric appli-
ance only on entering the cor-
rect password. Here we present such
an electronic locking system in which a
PIC16F877A microcontroller plays the
role of the processing unit. The MCU
is interfaced with a 44 matrix keypad
and a 162 LCD to form the user inter-
face. Using this circuit, you can make
any electrical appliance password-
protected. It can also be used as an
Fig. 1: Circuit of PIC microcontroller-based electronic lock
Fig. 2: Power supply circuit
ConstruCtion
70 June 2010 electroni cs for you www. e f y ma g . c o m
bit fash program memory, 368 bytes of
RAM and many other internal periph-
erals like analogue-to-digital converter,
USART, timers, synchronous serial
port, compare captures and pulse-
width modulation modules, EEPROM
and analogue comparators.
The job of the MCU in this project is
to receive signals from the input device
(keypad) and take corresponding ac-
tions. Whenever any key is pressed on
the keypad, the software program in
the MCU identifes the pressed key and
accordingly turns on or turns off the ap-
pliance. Simultaneously, it also displays
a message on the LCD screen.
44 matrix keypad. A 44 matrix
keypad is used to give commands and
the password to the MCU. It consists of
16 keys (S2-S17) arranged in the form
of a square matrix of four rows and
four columns. Each key in the matrix
is labeled according to the operation
assigned to it. The connections from
the pin-outs of the keypad to the
MCU pins are shown in Fig. 1. Rows
1 through 4 are connected to pins RB3,
RB2, RB1 and RB0 of Port B of the
MCU, respectively. Columns 1 through
4 are connected to pins RB4 through
RB7 of Port B, respectively.
162 LCD. A Hitachi HD44780
162 LCD is used to display various
messages. It also displays an asterisk
mark (*) for each digit of the password
entered. Control lines EN, RW and RS
of the LCD module are connected to
pins RA1, RA2 and RA3 of Port A of
the MCU, respectively. Commands
and the data to be displayed are sent
to the LCD module in nibble mode
from Port D of the MCU. The higher
four data bits of the LCD (D4 through
D7) are connected to the lower nibble
of Port D (RD0 through RD3) of the
MCU.
Relay driver. RC2 pin
of Port C of the MCU is
interfaced with the relay
driver circuit (shown in
Fig. 3) to switch on or
switch off the AC load
(appliance). A relay driver
circuit is nothing but a sim-
ple electronic circuit that
drives an electromechani-
cal relay. In this project,
a 6V, single-changeover
relay is used for switching
the appliance on or off.
Transistor SL100 plays the
role of the relay driver.
Whenever the user
enters the correct pass-
word, RC2 pin goes high
(RC2=1). Consequently,
transistor SL100 is trig-
gered to energise the relay
and the appliance turns
on. When RC2 is low
(RC2=0), the appliance turns off.
Free-wheeling diode 1N4007 pro-
tects the relay driver circuit from
the reverse voltage developed in
the relay coil.
You can also use optocoupler
MCT2E to isolate the relay driver
circuit from the microcontroller
circuit. Whenever the user enters
the correct password, RC2 pin
goes high (RC2=1) and the inter-
nal LED of the MCT2E IC glows,
which, in turn, triggers the inter-
nal transistor of MCT2E.
Power supply. Fig. 2 shows the
power supply circuit. The 230V AC
mains supply is stepped down to 9V
AC using step-down transformer
X1. The output from the secondary
of the transformer is rectifed by a
bridge rectifer comprising diodes D3
through D6 and fltered by capacitor
C1. The fltered output is regulated by
ICs 7805 and 7806 connected in paral-
lel to obtain the required 5V and 6V,
respectively.
software
The software code is written in C
language and compiled using Hitech C
PArts List
Semiconductors:
IC1 - PIC16F877A microcontroller
IC2 - 7805 voltage regulator
IC3 - 7806 voltage regulator
LED1 - 5mm Light-emitting diode
D1 - 1N4148 diode
D2-D6 - 1N4007 diode
T1 - SL100 transistor
Resistors (all -watt, 5% carbon unless stated
otherwise):
R1-R8, R10 - 4.7-kilo-ohm
R9 - 150-ohm
R11 - 10-kilo-ohm
R12 - 470-ohm
VR1 - 10-kilo-ohm preset
Capacitors:
C1 - 1000F, 25V electrolytic
C2, C3 - 0.1F ceramic
C4, C5 - 22pF ceramic
Miscellaneous:
X
TAL
- 4MHz crystal oscillator
X1 - 230V AC primary to 0-9V,
500mA secondary
transformer
- HD44780-based 162 LCD
RL1 - 6V, 1C/O relay
S1-S17 - Push-to-on tactile switch
Functions of Various Keys of the
Keypad and Their Labeling
S.No. Row Column Label Operation/digit entry
1 1 1 1 Digit1
2 1 2 2 Digit2
3 1 3 3 Digit3
4 1 4 Nil Nooperationallotted
5 2 1 4 Digit4
6 2 2 5 Digit5
7 2 3 6 Digit6
8 2 4 Lock Lockorturnoff
theappliance
9 3 1 7 Digit7
10 3 2 8 Digit8
11 3 3 9 Digit9
12 3 4 New Changethepassword
13 4 1 C Clearorbackspace
14 4 2 0 Digit0
15 4 3 Go Shouldbepressedafter
enteringthepassword
16 4 4 Open Openthelock(asksfor
passwordwhenpressed)
Fig. 3: Relay driver circuit
ConstruCtion
electroni cs for you June 2010 71 www. e f y ma g . c o m
compiler in MPLAB IDE. MPLAB IDE
is a very powerful software develop-
ment tool for Microchips MCUs. It can
be downloaded from www.microchip.
com free of cost. It consists of tools like
text editor, assembler, cross compliers
and simulator. Hitech C compiler is
meant for Microchips PIC10/12/16
series of MCUs. Its Lite edition comes
for free with newer versions of MPLAB
IDE like MPLAB v8.2 or v8.3, and it
can also be downloaded for free from
www.htsoft.com.
The tasks performed by the soft-
ware are:
1. Identify the key
Fig. 4: Actual-size, single-side PCB for the PIC microcontroller-based electronic lock
Fig. 5: Component layout for the PCB
ConstruCtion
72 June 2010 electroni cs for you www. e f y ma g . c o m
2. Take the action allotted to the
identifed key
The key identifcation is done by
identifying the row and the column to
which the key belongs. Fig. 1 shows
how the keypad is connected to Port B
of the MCU. The lower nibble of Port B
is declared as output pins (scan lines)
and the upper nibble is declared as
input pins (return lines). The number
0Fh is written to Port B so that the
lower four bits become high and the
upper four bits become low.
Whenever a key is pressed, the up-
per nibble pin (return line) of Port B, to
which the column containing the key is
connected, goes high. Thus the column
is identified. Column identification
is done using a switch-case block in
the main program. On identifying
the column, the rowfnd(int) function
is called, which does the job of row
identification. To identify the row,
scan lines are made low one by one in
sequence and status of the return line
corresponding to the key is checked. If
it becomes low, the key belongs to that
scan line or row. The row and column
numbers are stored in two global vari-
ables row and col. A key debounc-
ing delay of 20 ms is provided in the
program by calling the DelayMs(20)
function.
After identifying the key, the ac-
tion( ) function is called in the main
program, to perform the action corre-
sponding to the identifed key.
The detailed procedure for devel-
oping the project using MPLAB IDE,
compiling the same using Hitech C
compiler and burning the executable
hex fle to the microcontroller was
explained in Construction section of
EFYs May issue.
The above description is available
in a fle named lock.c. Functions lcd_
init( ), lcd_goto(int), lcd_clear( ) and
lcd_putch(char) are defned in a fle
named lcd.c and the DelayMs(int)
function is defned in the delay.c fle.
Add all the three C fleslock.c, lcd.
c and delay.cas source fles to the
MPLAB IDE project. Save the project
fle as Elock.mcp. Set confguration
bits properly before building the
project. Select the oscillator as XT
and disable all other features like
watchdog timer, power-up timer and
brownout detection. After successfully
building the project, the Elock.hex
fle is generated. Burn it into the chip
using a suitable programmer, e.g.,
MPLAB ICD2.
testing
Once the program is burnt into the
chip and the hardware setup is ready,
the user can test the system. When the
power supply is switched on, message
Welcome is displayed on the LCD
screen. The default password set in the
program is 1234.
To turn on the appliance, press
Open key. The system will ask for
the password. Enter the password as
1234 and press Go. The appliance
should turn on (RC2=1) and the mes-
sage Password Accepted should be
displayed for two seconds followed by
the message Lock Open.
To turn off the appliance, press
Lock. The appliance should immedi-
ately turn off (RC2=0) and the message
Lock Closed should be displayed on
the LCD screen.
To set a new password, press New
key. The system should ask for the cur-
rent and new passwords. Press Go
each time after you enter the four-digit
password. The message Password
Saved should appear for two seconds,
followed by the message Welcome.
Now you can turn on the device by
pressing Open and then entering the
new password that you have set. Key
C acts like Backspace key in a PCs
keyboard.
The only disadvantage of this
system is that the password set by the
user is stored in the RAM and hence it
is lost when the supply is switched off.
When the supply is switched on again,
the system is reset with the default
password 1234.
Construction
A single-side, solder-side PCB layout
for the PIC microcontroller-based elec-
tronic lock is shown in Fig. 4 and its
component layout in Fig. 5.
Connect the 44 matrix keypad and
162 LCD to PIC16F877A microcon-
troller as shown in Fig. 1. Complete
the remaining connections also as
shown in Fig. 1. Connect the appliance
to be controlled to RC2 (pin 17) of Port
C through the relay-driver circuit as
shown in Fig. 3. Connect 6V power
supply from the power supply circuit
to the relay driver circuit. The 5V sup-
ply required by the microcontroller
is obtained from the 7805 regulator
output.
EFY note. The complete project
folder (named Elock.zip) containing
the source code and related fles is
included in this months EFY-CD and
also available on www.efymag.com
website.
electronics for you July 2000
c i r c u i t i d e a s
c i r c u i t i d e a s
M
ost of the power-supply failure
indicator circuits need a sepa-
rate power-supply for them-
selves. But the alarm circuit
presented here needs no ad-
ditional supply source. It em-
ploys an electrolytic capacitor
to store adequate charge, to
feed power to the alarm cir-
cuit which sounds an alarm
for a reasonable duration
when the mains supply fails.
During the presence of
mains power supply, the recti-
fed mains voltage is stepped
down to a required low level.
A zener is used to limit the fl-
tered voltage to 15-volt level.
Mains presence is indicated
by an LED. The low-level DC is used for
charging capacitor C3 and reverse biasing
switching transistor T1. Thus, transistor
T1 remains cut-off as long as the mains
supply is present. As soon as the mains
power fails, the charge stored in the
capacitor acts as a power-supply source
s
.c
. d
w
iv
e
d
i
M.K. ChAnDrA MouLEEswArAn
Power-SuPPly Failure alarm
for transistor T1. since, in the absence
of mains supply, the base of transistor
is pulled low via resistor r8, it conducts
and sounds the buzzer (alarm) to give a
warning of the power-failure.
with the value of C3 as shown, a good-
quality buzzer would sound for about a
minute. By increasing or decreasing the
value of capacitor C3, this time can be
altered to serve ones need.
Assembly is quite easy. The values of the
components are not critical. If the alarm cir-
cuit is powered from any external DC power-
supply source, the mains-supply section up
to points P and M can be omitted from the
circuit. Following points may be noted:
1. At a higher DC voltage level,
transistor T1 (BC558) may pass some col-
lector-to-emitter leakage current, causing
a continuous murmuring sound from the
buzzer. In that case, replace it with some
low-gain transistor.
2. Piezo buzzer must be a continuous
tone version, with built-in oscillator.
To save space, one may use fve small-
sized 1000F capacitors (in parallel) in
place of bulky high-value capacitor C3.
circuit
ideas
136 March 2011 electroni cs for you www. e f y Ma g . c o M
er switch S1. During this alarm mode,
LED2 lights up. R1 and ZD1 ensure
peroper conduction of MOSFET T1.
The alarm sound generator pro-
vides loud acoustic power output to
an 8-ohm, 1W loudspeaker with a 12V
supply. Transistors T2 and T3 form a
complementary amplifier pair with
positive (regenerative) feedback pro-
vided to the base of T2 via R6 and C3.
The circuit oscillates on a frequency set
by the C3-R6 combination and the base
bias voltage of T2.
The base bias of
T2 is determined
by potential-di-
vider resistors R4
and R3. You can
experiment with
different R-C val-
ues to get the out-
put tone of your
choice.
Asemble the
circuit on a gen-
eral-purpose PCB.
After testing it
for proper work-
ing, house it in a
convenient, tam-
per-proof metal box
of proper size. The
proposed alarm unit
(including LEDs and
switches) is shown
in Fig. 5. Fig. 6 shows
the security alarm
rigged to a briefcase
using the security
cable.
EFY note. The
alarm generator part
can be replaced with
any 12V-powered
transistor/IC alarm
circuit without much
diffculty.
During this sleep mode, LED1 lights
up and there is no alarm sound. This
means your luggage is safe.
To test whether the alarm is work-
ing or not, simply press switch S2 mo-
mentarily. If the speaker sounds, the
alram is func-
tioning perfectly
and is ready to
use.
In the ab-
sence of a secu-
rity loop, J1 and
J2 dont short.
MOS F ET T1
( BS170) con-
ducts to ener-
gise relay RL1.
The gr ound
supply is rout-
ed to the alarm
sound generator
via normally-
opened (N/O)
contacts of the
relay. During
this changeover
time, the relay
becomes latched
and the alarm
sounds until it
is reset by pow-
T.K. Hareendran
PULL-PIn SeCUrITY aLarM
S.C. DW
IVEDI
H
ere is a simple and low-cost
circuit of pull-pin security
alarm. While travelling, rig
the alarm unit to your luggage using
a home-made security cable. When
somebody tries to cut or remove the
security cable loop to steal the luggage,
the internal circuitry immediately de-
tects and sounds an audio alarm.
Fig. 1 shows the pull-pin security
alarm circuit. The control part is built
around MOSFET T1, relay RL1 and a
few discrete components. The alarm
sound generator is built around tran-
sistors T2 and T3, speaker LS1 and a
few discrete components. The circuit
is powered by a compact 12V battery.
If possible, try using a 12V, 2.8Ah
rechargeable battery pack (see Fig. 2).
The security cable is shown in Fig. 3.
Working of the circuit is very
simple. The ends of the security cable
are linked to the circuit through RCA
sockets J1 and J2. When key-lock type
power switch S1 (shown in Fig. 4) is
turned to on position, 12V supply
from the battery is provided to the
circuit. As J1 and J2 are shorted by the
security loop, MOSFET T1 (BS170) is
cut off and relay RL1 de-energises.
Fig. 1: Circuit for pull-pin security alarm
Fig. 3: Security cable
Fig. 6: Luggage security Fig. 4: Key-lock type switch
Fig. 2: 12V, 2.8Ah
rechargeable battery
Fig. 5: Proposed
alarm unit
C I R C U I T I D E A S
ELECTRONICS FOR YOU AUGUST 2004
S
U
N
IL
K
U
M
A
R
QUALITY FM TRANSMITTER
TAPAN KUMAR MAHARANA
T
his FM transmitter for your stereo
or any other amplifier provides a
good signal strength up to a dis-
tance of 500 metres with a power
output of about 200 mW. It works
off a 9V battery.
The audio-frequency modula-
tion stage is built around transis-
tor BF494 (T1), which is wired
as a VHF oscillator and modu-
lates the audio signal present at
the base. Using preset VR1, you
can adjust the audio signal level.
The VHF frequency is decided by
coil L1 and variable capacitor
VC1. Reduce the value of VR2 to
have a greater power output.
The next stage is built around
transistor BC548 (T2), which
serves as a Class-A power ampli-
fier. This stage is inductively
coupled to the audio-frequency
modulation stage. The antenna
matching network consists of
variable capacitor VC2 and capacitor C9.
Adjust VC2 for the maximum transmis-
sion of power or signal strength at the
receiver.
L1: 5 turns of 24 SWG wire closely
wound over a 5mm dia. air core
L2: 2 turns of 24 SWG wire closely
wound over the 5mm dia. air core
L3: 7 turns of 24 SWG wire closely
wound over a 4mm dia. air core
L4: 5 turns of 28 SWG wire on an
intermediate-frequency transmitter (IFT)
ferrite core
For frequency stability, use a regulated
DC power supply and house the transmit-
ter inside a metallic cabinet. For higher
antenna gain, use a telescopic antenna in
place of the simple wire. Coils L1 and L2
are to be wound over the same air core
such that windings for coil L2 start from
the end point for coil L1. Coil winding
details are given below:
CIRCUIT
IDEAS
82 MAY 2005 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
CMYK
SANI THEO
S. MOHAN
REMOTE CONTROL FOR
HOME APPLIANCES
C
onnect this circuit to any of
your home appliances (lamp,
fan, radio, etc) to make the
appliance turn on/off from a TV, VCD
or DVD remote control. The circuit can
be activated from up to 10 metres.
The 38kHz infrared (IR) rays
generated by the re-
mote control are re-
ceived by IR receiver
module TSOP1738 of
the circuit. Pin 1 of
TSOP1738 is connected
to ground, pin 2 is con-
nected to the power
supply through resis-
tor R5 and the output
is taken from pin 3. The
output signal is ampli-
fied by transistor T1
(BC558).
The amplified sig-
nal is fed to clock pin 14 of decade
counter IC CD4017 (IC1). Pin 8 of IC1
is grounded, pin 16 is connected to Vcc
and pin 3 is connected to LED1 (red),
which glows to indicate that the ap-
pliance is off.
The output of IC1 is taken from its
pin 2. LED2 (green) connected to pin 2
is used to indicate the on state of the
appliance. Transistor T2 (BC548) con-
nected to pin 2 of IC1 drives relay RL1.
Diode 1N4007 (D1) acts as a freewheel-
ing diode. The appliance to be con-
trolled is connected between the pole of
the relay and neutral terminal of mains.
It gets connected to live terminal of AC
mains via normally opened (N/O) con-
tact when the relay energises. z
CONSTRUCTION
J UNE 2006 WWW. E F Y MA G . C O M
CMYK
R
obotics is a fascinating sub-
jectmore so, if you have to
fabricate a robot yourself. The
field of robotics encompasses a num-
ber of engineering disciplines such as
electronics (including electrical), struc-
tural, pneumatics and mechanical.
The structural part involves use of
frames, beams, linkages, axles, etc. The
mechanical parts/accessories comprise
various types of gears (spurs, crowns,
bevels, worms and differential gear
systems), pulleys and belts, drive sys-
tems (differentials, castors, wheels and
steering), etc. Pneumatics plays a vital
role in generating specific pushing and
pulling movements such as those
simulating arms or leg movements.
Pneumatic grippers are also used with
advantage in robotics because of their
simplicity and cost-effectiveness. The
electrical items include DC and step-
per motors, actuators, electrical grips,
clutches and their control. The elec-
tronics part involves remote control,
sensors (touch sensor, light sensor, col-
lision sensor, etc), their interface cir-
cuitry and a microcontroller for over-
all control function.
Project overview
What we present here is an elemen-
tary robotic land rover that can be con-
trolled remotely using primarily the RF
mode. The RF remote control has the
advantage of adequate range (up to
200 metres with proper antennae) be-
sides being omnidirectional. On the
other hand, an IR remote would func-
tion over a limited range of about 5
metres and the remote transmitter has
to be oriented towards the receiver
module quite precisely. However, the
GP CAPT K.C. BHASIN (RETD),
S.C. DWIVEDI, SUNIL KUMAR
REMOTE-CONTROLLED
LAND ROVERA DIY
ROBOTIC PROJECT
cost involved in using RF modules is
much higher than of IR components
and as such, we have included the re-
placement alternative of RF modules
with their IR counterparts for using
the IR remote control.
The proposed land rover can move
in forward and reverse directions. You
would also be able to steer it towards
left and right directions. While being
turned to left or right, the correspond-
ing blinking LEDs would blink to in-
dicate the direction of its turning. Simi-
larly, during reverse movement, re-
versing LEDs would be lit. Front and
rear bumpers are provided using long
operating lever of micro switches to
switch off the drive motors during any
collision.
The decoder being used for the
project has latched outputs and as such
you do not have to keep the buttons
on remote control pressed for more
than a few milliseconds. This helps
prolong the battery life for remote.
A photograph of the working pro-
totype of the land rover including re-
mote is shown in Fig. 1.
The entire project is split into sec-
tions and each section is explained in
sufficient detail to enable you not only
to fabricate the present design but also
exploit these principles for evolving
your own design with added func-
tions/features.
Forward and reverse movement. To
keep our design as simple as possible,
we have coupled a 30-rpm geared 6V
DC motor to the left front wheel and
another identical motor to the right
front wheel. Both these front motors
are mounted side-by-side facing in op-
posite directions. Wheel rims (5cm di-
ameter) along with rubber wheels are
directly coupled to each of the motor
shafts. This arrangement does not re-
DWI VEDI & S KUMAR
CONSTRUCTION
J UNE 2006 WWW. E F Y MA G . C O M
CMYK
wheel needs to rotate
differentially with re-
spect to its counter-
part. When the car is
moving in a straight
line, the differential
gears do not rotate
with respect to their
axes. However, when
the car negotiates a
turn, the differential al-
lows the two wheels to
rotate differentially with respect to
each other.
3. All the four wheels are used for
driving as well as steering. Examples
are Kyosho (USA) 4-wheel drive/4-
wheel steering electric powered mon-
ster truck chassis.
4. Single front wheel is used for
driving as well as steering; e.g., in a
tricycle.
5. Two driving wheels that are in-
dependently controlled to turn; e.g., in
a tank.
In our project, to keep the things
simple, we have used Method-5 with
some modification. For the rear wheels,
we have made use of a single 5cm dia.
plastic castor wheel, identical to the
ones used in revolving chairs. Such a
wheel turns by 180 when you try to
reverse the direction of the vehicles
motion. This way the movement of the
rover becomes stable in both the for-
ward and reverse directions. The steer-
quire separate axles.
During forward (or reverse) move-
ment of the vehicle, the two wheel
shafts, as viewed from the motor ends,
would move in opposite directions
(one clockwise and the other
anticlockwise). For reversing the direc-
tion (forward and backward), you sim-
ply have to reverse the DC supply po-
larity of the two motors driving the
respective wheels.
Steering control. There are differ-
ent methods available for steering a
robotic vehicle. The commonly used
ones are:
1. Front wheels are used for steer-
ing, while rear wheels are used for
driving; e.g., in tractors.
2. Front wheels are used for steer-
ing as well as driving; e.g., in most
light vehicles. In these vehicles (such
as cars), the front wheels are coupled
using a differential gear arrangement.
It comes into play only when one
ing (clockwise or anticlockwise) mo-
tion is achieved by driving only one
wheel at a time. To turn the vehicle
towards left (as perceived by the
driver) we energise only the right-
hand-side motor, and to turn it to-
wards right we energise only the left-
hand-side motor during turning.
Drive circuit for the motors. Here
is a typical circuit for driving one of
the motors, in forward or reverse di-
rection, coupled to, say, the left-hand
front wheel. Simultaneously, the right-
hand motor has to rotate in the reverse
direction (w.r.t the left-hand motor) for
moving the vehicle in the same direc-
tion. It means that input terminals of
the motor drive circuit for the right-
hand motor have to be fed with re-
verse-polarity control signals com-
pared to those of the left-hand motor
drive circuit.
In the H-bridge motor drive circuit
(see Fig. 2) when A1 input is made
high and A2 is made low, transistor
T1 (npn) is forward biased and driven
into saturation, while transistor T2
(pnp), being reverse-biased, is cut-off.
This extends the batterys positive rail
to terminal-1 of the motor. Simulta-
neously, with input A2 at ground po-
tential, transistor T3 (npn) is cut-off,
while T4 (pnp) is forward biased and
driven into saturation. This results in
ground being extended to terminal-2
of the motor. Thus the motor rotates
in one direction.
Now, if the two inputs are logi-
cally complemented, the motor will
run in the opposite direction. When
both the inputs are at the same logic
level (Gnd or Vcc), the motor is at rest.
Thus we can control the movement
(forward, reverse and stop) as well as
the direction of rotation of the motor
with the help of logic level of the two
control input signals to the motor.
Motor control logic. As per the pre-
ceding explanation, the input logic lev-
els required at terminals A1 and A2 of
the left-hand motor drive circuit and
at input terminals B1 of B2 of the right-
hand motor drive circuit are shown in
Table I.
Table I can be re-arranged as Table
II, which can be further simplified as
Table III. The equivalent hex values of
CONSTRUCTION
J UNE 2006 WWW. E F Y MA G . C O M
CMYK
the binary control signals are indicated
in Table III. It transpires that if we con-
nect (short) input terminals A2 and B1
of the two motor control circuits to-
gether, we can control both the mo-
tors for forward, reverse, left and right
movement of the vehicle using the 3-
bit binary number shown in Table III.
This fact will be used while arriving
at the integrated circuit for controlling
the motors for appropriate movement
of the land rover.
Remote control. For remote control,
we have used Holtek encoder-decoder
pair of HT12E and HT12D employing
RF as well as IR principles. Both of
these are 18-pin DIP ICs. Their pin con-
figurations are shown in the test cir-
cuit of Fig. 3.
Operation of Holtek HT12E and
HT12D. HT12E and HT12D are CMOS
ICs with working voltage ranging from
2.4V to 12V. Encoder HT12E has eight
address and another four address/data
lines. The data set on these twelve lines
(address and address/data lines) is se-
rially transmitted when the transmit-
enable pin TE is taken low. The data
output appears serially on the D
OUT
pin. The data is transmitted four times
in succession. It consists of differing-
length of positive-going pulses for 1
and 0, the pulse-width for 0 being
twice the pulse-width for 1. The fre-
quency of these pulses may lie between
1.5 and 7 kHz depending on the resis-
tor value between OSC1 and OSC2
pins. The internal oscillator frequency
of decoder HT12D is 50 times the os-
cillator frequency of encoder HT12E.
The values of timing resistors con-
nected between OSC1 and OSC2 pins
of HT12E and HT12D, for given sup-
ply voltages, can be found out from
the graphs given in the datasheet of
the respective chips (included in this
months EFY-CD). The resistor values
used in the circuits here are chosen for
approximately 3kHz frequency for the
encoder (HT12E) and 150 kHz for de-
coder HT12D at V
dd
of 5V.
The HT12D receives the data from
the HT12E on its D
IN
pin serially. If
the address part of the data received
matches the levels on A0 through A7
pins four times in succession, the valid
transmission (VT) pin is taken high.
The data on pins AD8 through AD11
of the HT12E appears on pins D8
through D11 of the HT12D. Thus the
device acts a receiver of 4-bit data (16
possible codes) with 8-bit addressing
(256 possible channels).
The test circuit given in Fig. 3 will
help you in checking the functional
serviceability and synchronisation of
the frequency of operation. Once the
frequency of the pair is aligned, on
pressing of push switch S1 on the en-
coder, LED on the decoder should
glow. You can also check the transfer
of data on pins AD8 through AD11
(the data pins of the encoder can be
set as high or low using switches S2
through S5), which is latched on pins
D8 through D11 of the decoder once
TE pin is taken low momentarily us-
ing push switch S1. This completes the
testing of encoder decoder pair of
HT12E and HT12D.
RF transmitter and RF receiver.
The RF transmitter and receiver mod-
ules marketted by Aplus India,
Mumbai have been employed for RF
remote control. The RF transmitter
TX-433 is an AM/ASK transmitter. Its
features include:
1. 5V-12V single supply operation
2. On-off-keying (OOK)/amplitude
shift keying (ASK) data format
3. Up to 9.6kbps data rate
4. +9dBm output power (about
200m range)
5. SAW-based architecture
6. For antenna, a 45cm wire is ad-
equate.
The output power and current
drain of the RF transmitter for Vcc of
5V and 12V are tabulated in Table IV.
(Note. For details of OOK, refer
box).
The pin configuration of the trans-
mitter module is shown in Fig. 4. The
RF receiver RX-433 is a 433MHz mod-
ule. Its pin configuration is shown in
Fig. 5 and technical specifications are
given in Table V.
Remote transmitter. A complete
schematic of the remote control trans-
mitter-encoder circuit is shown in Fig.
TABLE I
Control Logic
Terminals
Motion A1 A2 B1 B2
Forward 1 0 0 1
Reverse 0 1 1 0
Left 0 0 0 1
Right 1 0 0 0
Stop 0 0 0 0
TABLE II
Control Logic
Terminals
Motion A2 B1 B2 A1
Forward 0 0 1 1
Reverse 1 1 0 0
Left 0 0 1 0
Right 0 0 0 1
Stop 0 0 0 0
TABLE III
Control Logic
Terminals
Motion A2/B1 B2 A1 Hex
Forward 0 1 1 3
Reverse 1 0 0 4
Left 0 1 0 2
Right 0 0 0 1
Stop 0 0 0 0
OOK transmitters
OOK is the modulation method of choice
for remote control applications where
power consumption and cost are the
pri mary factors. Because OOK
transmitters draw no power when they
transmit a 0, these exhibit significantly
lower power consumption than FSK
transmitters.
OOK modulation is a binary form of
amplitude modulation. When logic 0
(low data line) is being sent, the
transmitter is off, fully suppressing the
carrier. In this state, the transmitter
current is very low (less than 1 mA).
When logic 1 is being sent, the carrier
is fully on. In this state, the current
consumption of the module is at its
highestabout 4.5 mA with a 3V power
supply.
TABLE IV
Technical Specifications
of TX-433
V
CC
O/P Current
5V DC 0 dBm 1.0 mA
12V DC + 9 dBm 3 mA
CONSTRUCTION
J UNE 2006 WWW. E F Y MA G . C O M
CMYK
6. The receiver ad-
dress to be trans-
mitted can be set
with the help of 8-
way DIP switch DIP-SW2.
When any switch is open the pin
connected to that switch is at logic 1,
and when it is closed the respective
pin is at logic 0. The data pins are
pulled high via resistors R2 through
R5. In this condition, if TE pin is taken
low (by depressing STOP switch), the
binary data transmitted via pins AD8
through AD11 will be 1111 (decimal
15). When any other data pin marked
FWD, REV, LEFT or RIGHT alone is
pressed, a 0 will be sent at that data
position, while other data pins will
represent logic
1 state. The
logic circuitry
at the receiver-
decoder end
will decode
the data ap-
propriately for
controlling the
two motors of
the land rover.
IR-based alternative. The RF
modulator used in the remote can be
easily replaced with the IR modulator
circuit built around IC2 and transistor
T1. The RF/IR selection can be affected
by moving the shorting link of Con-1
connector. Similarly, the RF receiver
module in the RF receiver-decoder can
be replaced with the IR receiver mod-
ule shown in Fig. 7.
For using the IR-based encoder, the
D
OUT
signal pin (pin 17) of HT12E is to
be connected to D
IN
pin 5 of astable
oscillator IC CD4047 for modulating
its output. The frequency of the astable
at output pin 10 is dermined by the
timing components as follows:
Frequency =
This frequency is adjused for 38
kHz with pin 5 held at logic 1. The
modulated 38 kHz, after amplification
by Darlington pair of transistors T1
and T2, drives IRLED1 LD271 (or
equivalent).
RF receiver-decoder. The complete
RF receiver-decoder circuit employing
HT12D is shown in Fig. 7. Assuming
that identical address is selected on the
encoder and the decoder, when any of
the switches on the transmitter
(marked as FWD, REV, RIGHT, LEFT)
is depressed, the corresponding data
TABLE V
Technical Specifications
of RX-433
Parameter Value
Bandwidth 12 MHz
Sensitivity 103 dBm
Data rate 4800 bps
Max data rate 9600 bps
Standby current 1.2 mA
Antenna Whip, strip line or helical
Voltage 4.5V5.5V DC
4.71(R6+VR1)C3
1
Hz
CONSTRUCTION
J UNE 2006 WWW. E F Y MA G . C O M
CMYK
pin of the demodulator will go low.
The data outputs of HT12D are fed to
8-bit priority encoder CD4532 via in-
verters to generate appropriate logic
outputs in conformity with Table III
to control the left-/right-hand motors
for required motion of the land rover
as explained earlier.
However, when STOP button is
pressed on the remote transmitter, all
data pins (D8 through D11) on the de-
coder will latch to the high output
state. After inversion by NAND gates
N1 through N4, all the outputs will be
low and hence EI (pin 5) of CD4532
will go low to force all its outputs to
go low. As a result, both the motors
will stop running.
You may like to verify the code
generated at the outputs of CD4532
with the help of truth table (refer Table
VI). The following is the exact se-
quence of operation at the receiver
(Fig. 7) and the motor driver (Fig. 8)
when a specific push switch is momen-
tarily pressed on the transmitter:
1. Forward. The D8 output (pin
10) of IC3 goes low, which after in-
version by inverter N1 goes high to
switch on the front LEDs (LED2 and
LED3) via driver transistor T6 and
take D3 input (pin 13) of IC5 high.
This causes Q2, Q1 and Q0 going to
logic states 0, 1 and 1, respectively
(as per Table VI), and as a result, both
the motors will run in such directions
as to move the rover in forward di-
rection.
2. Reverse. The D9 output (pin 11)
of IC3 goes low, which after inver-
sion by inverter N2 goes high to
switch on the rear LEDs (LED4 and
LED5) via driver transistor T7 and
take D4 input (pin 1) of IC5 high.
This results in Q2, Q1 and Q0 going
to logic states 1, 0 and 0, respec-
tively (as per Table VI), and as a re-
sult, both the motors will run in such
TABLE VI
Truth Table
Input Output
E1 D7 D6 D5 D4 D3 D2 D1 D0 GS Q1 Q2 Q0 EO
1 X X X X X X X X 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 X X X X X X X 1 1 1 1 0
1 0 1 X X X X X X 1 1 1 0 0
1 0 0 1 X X X X X 1 1 0 1 0
1 0 0 0 1 X X X X 1 1 0 0 0
1 0 0 0 0 1 X X X 1 0 1 1 0
1 0 0 0 0 0 1 X X 1 0 1 0 0
1 0 0 0 0 0 0 1 X 1 0 0 1 0
1 0 0 0 0 0 0 0 1 1 1 0 0 0
X = Dont care Logic 1 = High Logic 0 = Low
CONSTRUCTION
J UNE 2006 WWW. E F Y MA G . C O M
CMYK
PARTS LIST
Semiconductors:
IC1 - HT12E Holtek encoder
IC2 - CD4047 monostable/
astable multivibrator
IC3 - HT12D decoder
IC4 - CD4049 hex inverter/
buffer
IC5 - CD4532 8-bit priority
encoder
IC6 L293D motor driver
TX1 TX-433 RF (ASK)
TX2 LD271 (or equivalent)
RX1 RX-433 RF (ASK)
RX2 TSOP1738 receiver
module
D1-D13 1N4148 switching diode
T1, T3, T6, T7 BC548 npn transistor
T2 2N2222 npn transistor
T4 BC557 pnp transistor
T5 2N2907 pnp transistor
LED1-LED5 - 5mm red LED
LED6, LED7 - Blinking LED
Resistors (all -watt, 5% carbon):
R1 1-mega-ohm
R2-R5, R9, R22 10-kilo-ohm
R6, R16, R17 4.7-kilo-ohm
R7 2.2-kilo-ohm
R8 - 22-ohm, 0.5W
R10, R25-R27 1-kilo-ohm
R11- R15, R21 470-ohm
R18 47-kilo-ohm
R19 3.9-kilo-ohm
R20 22-kilo-ohm
R23 330-ohm
R24 100-ohm
VR1 - 10K preset
Capacitors:
C1, C5, C6 - 10F, 16V
C2 0.1F ceramic disk
C3 390pF ceramic disc
C4 - 100F, 16V
Miscellaneous:
S1-S5 - Push-to-on switch
S6 On/off switch
S7 - On/off rocker switch
SW1-SW2 - 8-way DIP switches
S8, S9 Micro switch (optional)
with long operating lever
A, B - 6V geared motor (30
rpm), shaft dia. 4mm
Bat.1 - 6V battery
Bat.2 - 6V, 4.5Ah battery
*Mechanical:
Kit Part name Qty
part no.
610 4mm dia., 12.7cm
long axle 2
105 1.3cm (0.5-inch)
reverse-angle bracket 2
102 Angle bracket 4
108 Bent strip p.c. 4
922 49cm flanged plate 1
926 146.3cm flat plate 2
760 Brass collar with grub
screws 6
707 5cm pulley (for tyres)
with boss 2
712 Tyre for 5cm pulley 2
817 12mm long (3mm dia.)
bolt 24
819 Nuts for above 24
820a Washer thick (for bolts) 24
X1 5cm dia. castor wheel
(plastic) 1
X2 10cm (3mm dia.) screws 4
*For details/drawing of part numbers, please refer
Entech_Parts.pdf document included in this
high. This results in Q2, Q1 and Q0
going to logic states 0, 0 and 1, re-
spectively (as per Table VI) and as a
result, only the left-hand-side motor
will run and the right-hand-side mo-
tor will be static. This causes the rover
to perform a right turn.
5. Stop. The D8 through D11 out-
puts of IC3 go high and, after inver-
sion by inverters N1 through N4, cause
blocking of diodes D5 through D8. As
a result, ground is extended to EI pin
5 through resistor R17 and all the out-
puts (Q2, Q1 and Q0) of CD4532 go
low to stop both the motors. All the
LEDs also stop glowing.
IR receiver alternative. The RF re-
ceiver module can be easily replaced
with the IR circuitry by moving the
shorting link of Con-2 connector appro-
priately. For the receiver to work in IR
directions as to move the rover in re-
verse (backward) direction.
3. Left. The D10 output (pin 12) of
IC3 goes low, which after inversion
by inverter N3 goes high to switch on
the left blinking LED7 after a second
inversion by inverter/driver gate N6
and makes D2 input (pin 12) of IC5
high. This results in Q2, Q1 and Q0
going to logic states 0, 1 and 0,
respectively (as per Table VI), and as
a result, only the right-hand-side mo-
tor will run and the left-hand-side mo-
tor will be static. This causes the rover
to perform a left turn.
4. Right. The D11 output (pin 13)
of IC3 goes low, which after inversion
by inverter N3 goes high to switch on
the right blinking LED6 after a second
inversion by inverter/driver gate N5
and makes D1 input (pin 11) of IC5
CONSTRUCTION
J UNE 2006 WWW. E F Y MA G . C O M
CMYK
HT12D. The rest of the circuit remains
unchanged for IR operation.
Drive circuit (Fig. 8). For controlling
the two drive motors, we have used the
quad half-H driver circuits contained
inside IC L293D to configure them as
two H-Bridge driver circuits (as ex-
plained with reference to Fig. 2). L293
does not require external free-wheeling
diodes as the same are built into the IC.
The control output from CD4532 of the
receiver/decoder circuit is connected
to the inputs of L293D in accordance
with the logic explained earlier in Table
III. The battery supply for the motor
drive circuit is routed via the normally
mode, it is to be ensured that the trans-
mitter is also working in IR mode. The
output of the IR circuit is to be con-
nected to D
IN
pin 14 of decoder HT12D.
The IR detector comprises IR receiver
module TSOP1738, whose output is am-
plified by Darlington pair of pnp tran-
sistors T4 and T5 before connection to
CONSTRUCTION
J UNE 2006 WWW. E F Y MA G . C O M
CMYK
made contacts of micro switches S8 and
S9, whose operating levers serve as part
of the front and back bumpers of the
land rover. In case these micro switches
are not used, short the switch terminal
points using jumpers.
Construction
Combined actual-size, single-side PCB
for the remote transmitter (Fig. 6) and
the receiver-decoder-driver (Figs 7 and
8) is shown in Fig. 9 and its component-
side layout in Fig. 10. The remote trans-
mitter part can be easily cutout from the
integrated PCB. A suitable FRC connec-
tor arrangement has been made on the
receiver-decoder-driver PCB for extend-
ing connections to the drive motors,
LEDs and battery mounted on the chas-
sis of the land rover.
Mechanical assembly
The working prototype, as shown in
Fig. 1, has been fabricated using
readymade sheet metal parts, wheels,
geared motors, axles, brass collars
(with grub screws), brackets, etc. The
overall dimensions (lengthwidth
height) of the rover, before mounting
the battery and the PCB, are approxi-
mately 1497.5 cm. The mechanical
parts used are shown under the Me-
chanical Parts List. There is much
scope for improving the aesthetics of
this prototype. Hopefully, the enthu-
siasts/hobbyists would devote extra
time and energy to give it a more pro-
fessional appearance.
The mechanical assembly of the
rover is followed by proper placement
of the battery (6V, 4Ah), mounting of
the PCB (over the battery) and finally
plugging the connectors from the bat-
tery, motors and various LEDs
(mounted on the rover) into the corre-
sponding connectors on the PCB be-
fore being able to control various mo-
tions of the land rover remotely using
either RF or IR principlesby simply
shifting the jumpers in the remote
transmitter and receiver PCBs towards
appropriate positions.
Here are some useful hints and se-
quence for successful assembly of the
land rover:
1. The geared motors that we have
used in the prototype have a 12.5mm
plastic flange with threads and a metal
nut for securing it in position. The shaft
(4mm dia.) protrudes from the centre
of the flange. The two flat plates (part
No. 926) used by us had only 4mm
holes (perforations). Thus for securing
the motors onto these plates, the 4mm
holes at 2.5cm position (from the front
and bottom edges) were increased to
13 mm and motors (with shafts facing
in opposite directions) were secured to
the two plates. With 2cm dia. wheels
pushed onto the motor shafts, we had
adequate clearance from ground. Giv-
ing slight clearance from the plate, the
wheel pulleys were secured on the mo-
tor shafts by tightening the grub screws
on boss of the pulleys.
2. After securing the motors and
wheels, we attached two angled brack-
ets part No. 102 (at front and rear-
middle positions) of the two flat plates
(part No. 926) for mounting LEDs (us-
ing Feviquick) for front and rear di-
rections. Also using reverse-angle
brackets (part No. 105), we suitably
mounted the direction-indicating LEDs
on the two flat plates.
3. The next step is to mount 5cm
dia. Castor wheel (plastic) at the rear
of the flanged plate in middle posi-
tion, roughly 2 cm from the edge. (The
flange is to face up.) Again we had to
enlarge a 4mm hole in the required
position to 10mm dia. as the diameter
of the threaded bolt of the castor wheel
is around 9 mm. Use two nuts (one
before passing the bolt through the
hole on the flanged plate and the other
after the flanged plate). This provides
for adjusting the height of castor
wheel, so that all the three wheels on
the rover are at the same level when
fully assembled. The castor wheel
should have clearance for 360
o
move-
ment, when assembled.
4. Join the flanged plate (refer step
3) to the two flat plates (refer steps 1
and 2) so as to form two sides of the
rover. The width of the flanged plate
needs to be increased by 2.54 mm so
that the motor ends do not fowl against
each other and the castor wheel has
360
o
free movement. This is achieved
by securing four bent strips (part
108)two on each side of the flange
plate using 12mm bolts and nuts. Also
use two axles (part No. 610) along with
collars (part No. 760) to maintain par-
allelism of the two side plates.
5. Fix directional LEDs on the strips
using Feviquick and wire/terminate
them on the connectors as per the cir-
cuit diagram of the receiver. Similarly,
terminate connections from the battery
and motors (A and B) onto the con-
nectors, which would mate with their
respective connectors on the receiver
PCB. Make a provision for reversing
the polarity to one of the two motors,
in case you find one of them rotating
in wrong direction due to the wiring
error.
6. Use some thermocole sheet on the
flanged sheet to ensure that the battery
sits over it, maintaining proper balance.
Use four 10cm long screws and nuts
through the flanged plate for mount-
ing the receiver PCB through its four
corner holes. The screws should secure
the battery and the PCB in position.
7. Now insert the connectors from
the battery, LEDs and motors into their
corresponding connectors on the re-
ceiver PCB. This completes the me-
chanical assembly of your rover. Good
luck!
EFY note. Parts of the kit will soon
be available from EFY associates
KitsnSpares.
CONSTRUCTION
60 APRI L 2007 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
D.S. OBEROI AND HARINDER
DHINGRA
REMOTE-CONTROLLED
REAL-TIME CLOCK WITH
DEVICE CONTROLLER
is used to identify whether the button
is really pressed or whether an obstacle
came in between the path of the IR
remote and IR receiver.
Bits A4 down to A0 are used to
identify the device. So a maximum of
SUNIL KUMAR
T
his project makes use of a TV
remote control. Using RC5 cod-
ing, a real-time clock chip is set
to control five different alarm settings.
These settings can also be used to switch
on an external device. Up to eight de-
vices can be controlled with this project.
The circuit is based on ATMEL
ATmega16 microcontroller and
Maxims DS1307 real-time clock chip.
An LCD module allows for user inter-
face.
Circuit description
Fig. 1 shows the block diagram of the
remote-controlled real-time clock with
device controller. It comprises six sec-
tions, namely, IR detector remote con-
trol sensing and decoding unit, real-
time clock, LCD interface, device
switching unit, microcontroller and
power supply unit
The microcontroller unit integrates
all the sub-systems and system soft-
ware operates the system. Fig. 2 shows
the circuit of the device controller.
Remote control section. This circuit
makes use of a Philips TV remote for
device switching and RTC parameter
setting. It uses RC5 coding format,
which is also known as biphase cod-
ing. In RC5-coded signal, each bit has
a uniform duration.
Table I shows how all the com-
mands of RC5 remote control are en-
coded. The first two bits designated
S are start bits, which are used to
adjust and synchronise the receiver.
These bits are used to calculate and
analyse the bit length of other bits.
The third bit is a toggle bit (T),
which toggles every time a button is
pressed at the remote control. This bit
32 devices can be interro-
gated to respond individu-
ally to the same type of cod-
ing without any disturbance.
Bits C5 down to C0 are
control/command bits.
Therefore a maximum of 64
commands can be equipped
in an RC5 type remote. Deci-
mal equivalent of a few com-
mand codes used in this
project are listed at Table II.
Pressing any command/
control button on the remote
generates code signal,
which is received by
IR receiver-demodu-
lator (TSOP1738). The
output of the IR de-
modulator is normally high, which
changes to low when any of the but-
tons on the remote is pressed. It is fed
to PD3 through the I/O interface line
of the microcontroller. The
microcontroller decodes the incoming
Fig. 1: Block diagram of remote-controlled real-time clock
with device controller
TABLE I
RC5 Coding Format
S S T A4 A3 A2 A1 A0 C5 C4 C3 C2 C1 C0
TABLE II
Remote Command Codes
Remote key Numeric value Function
(C5-C0)
0 0 Press this key to start the setting of the RTC.
Volume + 16 Increases the value (of a given field). Used in Alarm Delete Mode
to change the selection to Yes or No
Volume 17 Decreases the value (of a given field). Used in Alarm Delete Mode
to change the selection to Yes or No
Mute 13 Shifts to next field (in RTC setting mode)
TV/AV 56 Starts the RTC functioning. This remote control key acts as Enter key
(confirmation key). Used in alarm mode, to confirm the setting
Power 12 Returns to Display Mode (from alarm mode).This key lets the user to
return to the previous menu; when used in any of the Alarm Menu,
acts as Escape key and cancels the action in Alarm mode
Timer/sleep 38 Enters Alarm menu for setting/deletion/viewing alarm data.
Channel + 32 Scrolls forward alarm setting See of Alarm menu
Channel 33 Scrolls backward alarm setting See of Alarm menu
CONSTRUCTION
62 APRI L 2007 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
microcontroller with the help of tran-
sistor T1. All the information is dis-
played on the LCD, which forms the
basic user interface unit.
Real-time clock. IC DS1307 (IC2)
from Maxim (Dallas Semiconductor) is
a serial RTC chip with calendar func-
tion. This chip also incorporates 56
bytes of NV RAM. Data
and address are trans-
ferred serially through
I
2
C bidirectional bus,
which obviates the need
for a large number of in-
terface lines. The bidirec-
tional data is read and
written with the help of
just two I/O interface
lines.
In this chip, the clock
operates in either 24- or
12-hour format with
AM/PM indicator. In cal-
endar mode, end of the
month is automatically
adjusted for the months
with less than 31 days
and leap year compensa-
tion is valid up to year
2100.
The memory map of
DS1307 (also referred to
as time keeper register
map) is shown in Table
III. For setting the clock
and calendar at power-
on, the data is first writ-
ten to the designated
memory location of the
RTC chip and, during the
normal operation. It is
read back from each spe-
cific memory location
during the clock and cal-
endar display functions.
The alarm settings are
stored in NV RAM; these
can be deleted and al-
tered at any given point
of the operation. All this
is achieved with the help
of the system software. In
the project, only five
alarms have been al-
lowed but the same can
be changed as per re-
quirement; only the
RC5 data stream and subsequent ac-
tions are taken based on the this infor-
mation.
LCD unit. The LCD module (16-
character2-line) is interfaced with the
microcontroller. Data pins 7 through
14 of the LCD module are connected
to port A (PA0 through PA7) of the
microcontroller. Register-select (RS)
pin 4 and enable pin (pin 6) of the LCD
are interfaced with PC1 and PC2 of
the microcontroller, respectively. R/W
pin of the LCD (pin 5) is pulled low
permanently and thus is always in
writing mode. Back light of the LCD
is controlled by PD0 line of the
F
i
g
.
2
:
C
i
r
c
u
i
t
o
f
r
e
m
o
t
e
-
c
o
n
t
r
o
l
l
e
d
r
e
a
l
-
t
i
m
e
c
l
o
c
k
w
i
t
h
d
e
v
i
c
e
c
o
n
t
r
o
l
l
e
r
CONSTRUCTION
ELECTRONI CS FOR YOU APRI L 2007 63 WWW. E F Y MA G . C O M
vice is switched on. The device can be
switched off only by pressing the re-
spective key number on the remote
control.
Controller. The controller unit is
based on ATmega16 low-power, 8-bit
CMOS microcontroller with AVR en-
hanced RISC architecture. This
microcontroller has 16 kB of in-system
programmable flash memory, 512 bytes
on EEPROM, 1 kB of SRAM, two 8-bit
timers, one 16-bit timer, 32 general-pur-
pose I/O lines and 32 general-purpose
working registers. It integrates all the
subsystems to form a complete unit.
Although this microcontroller al-
ready has an RTC counter and I
2
C
lines, we have used a separate RTC
chip and special I
2
C software to
show the functionality with the dedi-
cated RTC chip, which is much easier
to control and manage in terms of time
keeping as well as achieving calendar
functions. Regarding I
2
C, we wanted
to show how the same can be achieved
with the help of the software without
alarm limits have to be changed.
Clock pulse to the RTC is provided
by a 32.768kHz crystal. As per the con-
vention of I
2
C interface communica-
tion, the device address while writing
into DS1307 chip is 0xD0 (in binary
format 11010000) and while reading
the data from DS1307 the device ad-
dress is 0xD1 (in binary format
11010001). Due to this unique device
addressing technique, a number of I
2
C-
interfaced chips can be attached on
SCL and SDA interface lines of RTC.
Thus, at a given time, only one I
2
C de-
vice will respond to the data on the I/
O interface lines.
Device control. Devices are con-
nected to contacts of the relay and re-
lays are controlled through the outputs
of IC4. Port B of IC1 (PB0 through PB7)
is interfaced with pin 8 down to pin 1
of IC4 (ULN2803) to control relays RL1
through RL8, respectively. Five out of
eight devices (device 1 through 5)
switch on with their respective alarm
settings and the remaining three de-
vices switch on directly.
Whenever an alarm is activated for
a particular setting, the respective de-
the use of any specialised hardware
functionality of the microcontroller;
and also help the user to implement
the same on any other microcontroller
that does not have the dedicated facil-
ity of I
2
C interface.
This controller unit first uses serial
data received from the IR detector to
get the information regarding the
pressed key and then takes the appro-
priate action, and also updates the in-
formation on the LCD side-by-side.
When in operational mode, the
microcontroller reads the data from the
RTC chip every one second (achieved
through timer interrupts-compare
mode). During this 1-second interrupt,
it checks for the alarm setting, controls
the snooze, and also updates the time/
date information on the LCD. In be-
tween, it checks the data from the IR
detector and takes action accordingly.
Power supply. Fig. 3 shows the
power supply circuit. The 230V, 50Hz
AC mains power supply is stepped
down by transformer X1 to deliver a
TABLE III
Memory Map of DS1307
Address Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Function Range
00H CH 10 seconds Seconds Seconds 00-59
01H 0 10 minutes Minutes Minutes 00-59
02H 0 12 10 hour 10 hour Hours Hours 1-12
24 PM/AM +AM/PM
00-23
03H 0 0 0 0 0 Day Day 01 07
04H 0 0 10 date Date Date 01 31
05H 0 0 0 10 month Month Month 01-12
06H 10 year Year Year 00-99
07H Out 0 0 SQWE 0 0 RS1 RS0 Control
08H RAM 00H-FFH
568
0 Always reads back as 0
Fig. 3: Power supply
PARTS LIST
Semicondutors:
IC1 - Atmega16 AVR
microcontroller
IC2 - DS1307 real time clock
IC3 - TSOP1738 IR receiver
module
IC4 - ULN2803 darlinton array
IC5 - 7805 5V regulator
IC6 - 78012 12V regulator
T1, T2 - SL100 npn transistor
BR1 - 1A bridge rectifier
- LCD module (162)
Resistors (all -watt, 5% carbon):
R1, R3, R4,
R6, R10 - 10 kilo-ohm
R2 - 220 ohm
R5,R9 - 120 ohm
R7, R11 - 2.2 kilo-ohm
R8 - 330 ohm
VR1 - 10 kilo-ohm preset
Capacitors:
C1, C2 - 10F,16V electrolytic
C3, C7, C8 - 0.1F ceramic disk
C4 - 100F,25V electrolytic
C5 - 1F,16V electrolytic
C6 - 1000F,35V electrolytic
Miscellaneous:
X1 - 230V AC primary to 15V,
500mA secondary trans-
former
S1 - Push-to-on switch
PZ1 - Piezo buzzer
X
TAL
- 32.768 KHz crystal
RL1-RL8 - 12V, 1C/O relay
CONSTRUCTION
64 APRI L 2007 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
secondary output of 15V at 500 mA.
The transformer output is rectified by a
full-wave bridge rectifier BR1, filtered
by capacitor C6, and regulated by IC5
and IC6. IC5 and IC6 output is 5V and
12V, respectively. The regulated 12V is
used for relay-driver IC4 and the rest
of the circuit operates with 5V. Capaci-
tors C7 and C8 bypass any ripple
present in the regulated power supply.
An actual-size, single-side PCB pat-
tern for the remote-controlled real-time
clock with device controller (Fig. 2 and
Fig. 3) is shown in Fig. 8 and its compo-
nent layout in Fig. 9.
Software
The system software is used to achieve
integration and functionality. The soft-
ware for this project is written in C
language and compiled using
WINAVR. WINAVR is available free
of cost for Windows and Linux operat-
ing systems. It is capable of handling
all the AVR functionalities like UART,
timer, ADC, interrupts, etc and offers
the facility of writing the program in
C. The finally obtained Intel hex code
file was burnt into AVRs flash memory
using a suitable programmer. The
microcontroller uses a 4MHz internally
generated clock. To activate, fuse bytes
have to be programmed as follows:
Fuse low byte = D3
Fuse high byte = 99
The software for the entire project
was written in modules in accordance
with the functionality of each sub-
system. The files used in this project
are shown in Table IV.
The ds1307.c file contains the code
for controlling the functions related to
serial DS1307 RTC. The chip uses I
2
C
interface, which essentially uses only
two I/O interface linesSDA and
SCLfor bidirectional address and
data communication. This file essen-
tially uses sub-routines, which have
been indicated in the I2Cmaster.h
header file. Subroutines i2c_write( ) and
i2c_read( ) are used for writing and
reading the data to and from the RTC
chip through DS1307_write( ) and
DS1307_read( ), respectively.
The Assembly code for the com-
plete I
2
C operations and communica-
tion is written in the I2Cmaster.S file,
which has been written for 4.00MHz
operation, and for this reason, the
microcontrollers fuses have been set
to use the internal 4.00MHz clock.
The data stored in the RTC chip is
in BCD format. The BCD data is
changed into binary format for nor-
mal processing and displaying. For this
purpose, the BCD2bin( ) subroutine is
used. Similarly, the user data is first
converted into BCD format with
bin2BCD( ) sub-routine and then writ-
ten into the RTC chip. This file con-
tains all the sub-routines that are used
in rclock.c file modules.
I
2
C-interfaced chips are initiated in
a particular sequence for their proper
functioning, and this has been taken
care of during initialisation and read-
ing/writing data from/to DS1307.
The user alarm settings are stored
in the NV RAM of DS1307 in two
fields, namely, hours and minutes. In
this project, a maximum of five alarm
settings have been allowed but this
number can be increased by changing
the variable MAX_ALARM value (in
lcd.h file).
Whenever the alarm setting data is
to be viewed, altered, deleted or
added, the program checks the user
SRAM area, and based on the value
stored in the ALARM_COUNT_RGST
memory location, further action is per-
mitted. While clock is functioning, the
data from this SRAM area, which has
now been allocated to an array, is
checked and the desired action is taken
when the alarm setting data matches
the current time.
i2cmaster.S and i2cmaster.h. These
files are related to control of the I
2
C
interface communication. The details
of the SCL and SDA pins and I/O in-
terface line are defined in the
i2cmaster.s file and the Assembly code
file is compiled along with other code
files; the parameter to be used in
makefile for this file is ASRC.
lcd.c This file contains the code for
control of functioning of the attached
LCD module. The code controls the
initialisation of the LCD, data writing
on the LCD, and also the movement,
characteristics and location of the cur-
sor. It offers the facility to write data
on the LCD character-by-character or
string-wise. The command set used in
the software is based on the command
set used in the LCD based on Hitachi
HD44780 ICs.
lcd.h This header file contains all
the constant variable values and names
of the subroutines used by various files
used in the software. It clearly indi-
cates which variable can be used as a
global variable and which of the sub-
routines can be used across the soft-
ware files.
rclock.c This file contains the code
that integrates all the subunits together.
It contains the code that will call the
initialisation routines to initialise I
2
C
chip, LCD, microcontroller ports, set
timer and its IRQ, check data from the
IR detector, extract information regard-
ing the key pressed, etc.
Depending upon the key pressed,
the file initiates the change in RTC data
like year, month, day, date, hours and
minutes and also in viewing, deleting
and adding new alarm settings. It takes
control of the devices attached to the
unit and controls their status depend-
ing upon the alarm settings.
All the above-mentioned functions
are implemented in this file by means
of specific implementation of sub-rou-
tines and global variables whereever
required.
All the sub-routines used in the
various files are clearly marked and
commented for their functionalities
TABLE IV
Software Files and
Their Function
File Name Function
.rclock.c Main file which integrates all the
functions of the sub-units of the
project
ds1307.c Contains the code for the
controlling the functions of
DS1307 RTC
.lcd.c Contains the code for controlling
the LCD
.lcd.h Contains the global declarations
and sub-routines, which are used
by other files
.i2cmaster.h Contains sub-routine information
required for I2C communication
.i2cmaster.S Contains code for controlling the
I2C communication (optimised for
4.00 MHz operation)
CONSTRUCTION
ELECTRONI CS FOR YOU APRI L 2007 65 WWW. E F Y MA G . C O M
with codes explained.
The entire project software was
compiled and debugged with
WINAVR development environment,
which is based on avr-gcc 3.3.1
(WinAVR-20030913).
Remote control operation
The entire device operation is con-
trolled through keys of the Philips re-
mote control. The remote keys are used
as shown in Table II. The functions of
these keys are given below.
Key 0 is used to change the setting
of the RTC. When the RTC is func-
tioning normally, it can be switched
to setting mode by pressing the 0 key
and immediately the cursor will blink
on the hour field, indicating that this
value can be changed through volume
up and volume down keys to a de-
sired value.
Keys 1 through 8 are used, during
normal operation, to control the state
of the external devices. Key 1 is used
to control Device 1 and so on. Devices
1 through 5 are switched on according
to the alarm timing also; however,
these can be switched off by pressing
the respective key on the remote con-
trol itself.
Keys 1 through 3 are also used in
the Alarm menu. Key 1 is used to add
a new alarm value to the alarm table.
Key 2 is used to delete the alarm set-
ting for the table (by changing Yes/
No field with volume up/down key).
Key 3 is used to scroll through the
alarm settings by use of channel up
and down keys.
Power key is used for deactivating
the alarm and also returning one setup
back in the Alarm menu. Whenever
you want to return from the Alarms
sub-menu (like New, Del and See), press
this key. Also, this key is used to return
from the Alarm menu to display screen.
Mute key is used to change the
field (from hour to minute to day of
the week to day of the month to month
of the year and, finally, the year and
back to hour and so on and so forth).
Volume Up and Down keys are
used to change the value of a given
field when setting the clock data or
the alarm data.
TV/AV key starts the RTC func-
tioning once the desired settings have
been made. This remote control key
acts as Enter key (confirmation key).
Timer key takes the user to alarm
setting menu.
Clock mode setting
When the RTC is switched on, the
screen display is as shown in Fig. 4.
The second field value shows 40 sec-
onds. These indicated initial values
have been set in subroutine
i2c_initialisation( ). If some other val-
ues are required, the desired values
can be written.
The cursor blinking on the hour
field indicates that value can be
changed through volume up and
down keywhich will now change the
hour value from 0 to 23 hours and
back to 0 again.
Once the desired value of the hour
has been achieved, you can change to
minute field by pressing Mute key.
The change of field is indicated by cur-
sor blinking on the appropriate field
(here minute field). Value of minutes
can be changed from 0 to 59 and
again to 0. Again, after the desired
value has been achieved, the field can
be changed to week day by pressing
Mute key. Now week days can be
changed by pressing volume up and
down keys.
Next field-change data is related to
day of the month (the date can be
changed from 1 to 31) and after this,
the month of the year can be changed
(from January to December). The year
can be changed from 00 to 99. Take
care when setting the month and the
days in that particular month.
The process remains the same
when setting the alarm value also,
where only hour and minute fields are
available for setting. Once the setting
has been made as per the requirement,
TV/AV key can be set and now the
clock will start functioning with the
desired settings. The functioning of the
clock can be observed by change in
the second field.
Alarm setting
As explained earlier, the given design
allows five alarm settings with snooze
facility and control of five devices only.
You can enter the alarm menu by
pressing Timer key. The screen at this
point of operation is shown in Fig. 5.
Through this menu, you can set new
alarm (1New), delete alarm setting
(2Del) and view alarm settings (3See).
The respective menu can be activated
by pressing key 1, 2 or 3. In new setting
mode, if five alarm settings have been
made, the same is indicated by a Full
sign. In case new setting has to be made,
an already exisiting alarm setting has
to be deleted and then only new alarm
setting will be allowed.
To return from New mode to
Alarm menu, press Power key. If
space is available for new alarm set-
ting, you can change hour-field data
and minute-field data by using Vol-
ume Up, Volume Down and Field
keys, i.e., Mute key. Once the desired
Fig. 4: Screen display after switch on
Fig. 5: Screen display after pressing Timer key
Fig. 6: Delete an alarm setting
Fig. 7: View the alarm setting
CONSTRUCTION
66 APRI L 2007 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
settings have been made, pressing the
TV/AV key stores the alarm settings
in the NV RAM of the DS1307 chip.
To delete an alarm setting, first
press key 2. The display will be as
shown in Fig. 6.
The alarm settings/values can be
scrolled with the help of Channel Up
and Channel Down keys. For a set-
ting that is to be deleted, change the
status of the indicator from No to Yes
by Volume Up and Volume Down
keys. Then delete data by pressing TV/
AV key and immediately the message
Deleting Data is displayed, indicating
that one alarm setting has been deleted.
To view the alarm setting data, you
can use key 3 in Alarm menu. The
screen at this point will be as shown
in Fig. 7, which indicates the total num-
ber of alarm settings in the memory
(Tot:) and data being viewed. You can
scroll through the data with the help
of Channel Up/Down key.
As you scroll though the data, the
field Data: indicates the alarm setting
as per the programmed sequence. The
device-control field number will be the
same as Data: field number. (If
Data:5, the device to be controlled
Fig. 8: Actual-size, single-side PCB for the remote-controlled real-time clock with device controller
Fig. 9: Component layout for the PCB
will be 5, and if Data:1 device 1 is
attatched with this data field.) If no
alarm data is found in the memory,
No Alarm Data is shown on the LCD.
In New and Del sub-menus of
Alarm menu, TV/AV key is used to
confirm the desired setting/action. To
cancel settings/actions, press Power
key at any time of the operation.
By default, all the five alarm set-
tings have been made initially through
the software. These values can be
changed in sub-routine dummy( )
found in the ds1307.c file.
As soon as the alarm is activated,
the LCD backlight glows periodically
along with the buzzer sound. Deacti-
vate the alarm with Power key; how-
ever, the respective-controlled device
will continue to be on. The alarm can
be put into snooze mode by pressing
any key on the remote control. In snooze
mode, the buzzer will not sound but
LCD backlight will glow. The snooze
delay can be changed by setting the
constant snooze_delay variable (in the
lcd.h file) to a desired value.
No doubt the alarm time can be
set in any sequence; the external device
will switch on in a sorted time
sequence. For example, if the alarm
time is 01:21' at location-3 and 01:10'
at location-5, device-5 will switch on
at 01:10' and device-3 will switch on
only at 01:21, even though in the
alarm sequence the location of device-
3 is before device-5. When the clock is
switched on, all the controlled external
devices are in switched-off condition.
In snooze mode, the alarm can be
de-activated by pressing Power key.
All the external devices can be
switched off simultaneously by press-
ing S1. This will work only in normal
functioning of the device and not dur-
ing the alarm mode.
The project was assembled on a
general-purpose PCB.
EFY notes. All the software files re-
lated to this article have been included
in this months EFY-CD. For testing
the project, you can use the RC5-for-
mat remote published in EFY March
2007.
D.S. Oberoi is principal design engineer at
DOEACC Centre, Srinagar/Jammu, and Harinder
Dhingra is a lecturer at GCET, Jammu
circuit
ideas
electroni cs for you september 2005 103 www. e f y ma g . c o m
CMYK
Seemant Singh
Power Failure and
reSumPtion alarm
T
his circuit gives audio-visual in-
dication of the failure and re-
sumption of mains power. The
circuit is built around dual timer IC
LM556. When mains is present the bi-
colour LED glows in green colour, and
when mains fails it turns red.
The AC mains is stepped down
by transformer X1 to deliver the sec-
ondary output of 12V at 250 mA. The
transformer output is rectifed by a
full-wave bridge rectifer comprising
diodes D1 through D4, filtered by
capacitor C1 and regulated by IC 7809
(IC1) to give regulated 9V DC to oper-
ate the circuit.
9V battery and pnp transistor T1
have been used here as the power
source for red light indication of the
absence of power. Transistor T1 can be
made to conduct or cut-off easily by
varying preset VR1.
Initially, when mains is present,
pnp transistor T1 is in cut-off state and
therefore bicolour LED1 glows in green
colour.
When power fails, pnp transis-
tor T1 starts conducting and bicolour
LED1 glows in red colour. Due to
non-availability of Vcc voltage at pin
14 of IC2, its output pin 9 remains low
and transistor T3 does not conduct.
However, capacitor C7 (4700F) holds
adequate charge and hence transis-
tor T4 conducts and piezobuzzer PZ1
sounds continuously for around eleven
seconds until capacitor C7 discharges
completely.
When power resumes, bicolour
LED1 glows in green colour and the
buzzer beeps for around 14 seconds.
Dual timer IC LM556 (IC2) sections
have been used here in monostable and
astable modes, respectively.
In the monostable section, location
of the external timing capacitor deter-
mines whether a positive or negative
output pulse is generated. Diode D7
ensures that even a momentary power
loss will cause a pulse to be generated
when the power resumes. With capaci-
tor C3 connected to ground, a positive
output pulse is generated according to
the following relationship:
T = 1.1R5C3.
This positive output is present at
pin 5 of IC2. Since IC2 is a dual-timer
IC, its frst output is directly fed to re-
set pin 10 of second section. Therefore
the second timer of IC2 starts oscillat-
ing. Its frequency of oscillations (F0)
is determined by resistors R6 and R11
and capacitor C6 as follows:
F0=1.4/(R6+2R11)C6.
IC LM556 outputs frequencies
in the form of pulses at its pin 9.
These pulses are coupled to npn
transistor T3, which conducts and
cuts off depending on the output at
pin 9 of IC2. Red LED2 is connected
to pin 9 via current-limiting resis-
tor R7 (270-ohm) to indicate power
resumption.
The collector output of transistor
T3 is directly fed to the base of pnp
transistor T4, due to which base bias-
ing of T4 varies and the buzzer beeps
for around 14 seconds.
T E C H N I D O
Model No:
Robotics in 10 Days
TN -92
Robotics in 10 Days-GOLBO MINI is a FIVE in ONE versatile tool for students to learn basics of Robotics and
electronics in a fast pace . The instructional guide is self explanatory with many full color pictures and video. That
allows user to learn without anyone else`s help.
What all can be learned/made from this kit?
Obstacle Avoider Mobile Controlled Light Activated Edge Avoider Line Follower
www.technido.com
64
What all can be learned/made from this kit?
Learning's
Fundamental of physics
Controlling Motors
About different electronic components
Developing Logic for diving the machine
Wiring of machine
Basics of mechanics
Use of tools and many more.
Constructions
Obstacle Avoiding Robot
Line following Robot
Cell Phone Controlled Robot
Edge Avoiding Robot
Light Controlled Robot and more
T E C H N I D O
Model No:
Robotics in 10 Days
TN -92
www.technido.com
65
Kit Includes:
Modules:
1xIR Sensor Module
1xCell phone controlled module
1xLine follower Module
1xAmbient Light Sensor (Unassembled)
2x lead acid Rechargeable Battery
2x DC Motors
1x Digital Multimeter
1x Wire stripper or cutter
1x Battery Charger Adaptor
1x Soldering paste (FLUX)
1x Soldering Iron
1x forceps
1x Breadboard
Electronic Components
1x7805 IC
1x3mm LED
1x470e resistor
1xL293D IC (Motor Driver IC)
1x74HC04 Inverter IC
1x Caster wheel
2x Motor wheels
2x Motor support strips
1xConnecting wires
1xTwo pin Reliment connector (Charger Battery Connector)
1xChassis-top & bottom Plate
1xSoldering Wire, Heat Sinkable Sleeve, 1000uf capacitor
2xBattery tie clips
1xManual in CD
1xScrew driver
1xAll screws & nuts
CIRCUIT
IDEAS
ELECTRONI CS FOR YOU MAY 2006 87 WWW. E F Y MA G . C O M
CMYK
M
anual buzzers used for quiz
competitions in schools and
colleges create a lot of confu-
sion in identifying the first respondent.
Although there are circuits using PCs
and discrete ICs, they are either too
expensive or limited to only a few
number of players.
The quiz buzzer circuit given here
can be used for up to eight players,
which is maximum in any quiz com-
GOVINDA RAJU TEKUMUDI
SCHOOL/COLLEGE
QUIZ BUZZER
S.C. DWIVEDI
section is IC 74LS373, an octal
latch that is used to transfer
the logic state at data input pins
D0 through D7 to the corresponding
Q0 through Q7 outputs. Data pins D0
through D7 are normally pulled low
by resistors R1 through R8, respec-
tively.
One terminal of push-to-on
switches S1 through S8 is connected
to +5V, while the other terminal is
connected to the respective data input
pins. The switches are to be extended
to the players through cord wire. The
torch bulbs BL1 through BL8 can be
housed in boxes with the front side of
the boxes covered with a white paper
having the name or number of the
contestant written over it for easy
identification. Place the boxes above
the head level so that these can be
seen by the audience also.
When the power is switched on us-
ing switch S9 (provided terminals A
petition. The circuit uses IC 74LS373
and a few passive components that are
readily available in the market.
The circuit can be divided into two
sections: power supply and quiz
buzzer.
Fig. 1 shows the power supply sec-
tion. The regulated 5V power supply
for the quiz buzzer section is derived
from AC mains. The 230V AC mains
is stepped down to 7.5V AC by trans-
former X1, rectified by bridge rectifier
BR1, filtered by C1 and regulated
by regulator
IC1. Capacitor
C2 bypasses
ripples in the
regulator out-
put.
Fig. 2
shows the
quiz buzzer
section. At the
heart of this
Fig. 1: Power supply
Fig. 2: Circuit of school/college quiz buzzer
CIRCUIT
IDEAS
88 MAY 2006 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
CMYK
and B of both the power supply and
quiz buzzer sections are intercon-
nected), the circuit is ready to use.
Now all the switches (S1 through S8)
are open and Q0 through Q7 outputs
of IC 74LS373 are low. As a result, the
gates of silicon-controlled rectifiers
SCR1 through SCR8 are also low.
As soon as a contestant momen-
tarily presses his respective switch, the
corresponding output data pin goes
high. This triggers the corresponding
SCR and the respective bulb glows. At
the same time, the piezobuzzer (PZ1)
sounds as transistor T1 conducts.
Simultaneously, the base of tran-
sistor T2 becomes high to make it con-
duct. Latch-enable (LE) pin 11 of IC2
is tied to ground to latch all the Q0
through Q7 outputs. This restricts fur-
ther change in the output state due to
any change in the state of switches S1
through S8 by any other contestant.
Only one of the eight torch bulbs
glows until the circuit is reset by on/
off switch S9. Note. The complete kit
is available at Kits n Spares outlet.
T E C H N I D O
Model No:
Scoobot
TN -56
Scoobot is designed specially for school kids to enhance their learning and creativity through fun.
What`s so special about this kit?
Its a multifunctional kit: With kit and its modules students can make 10 + machines.
Learning's: This kit is based on CBSE/ICSE class 7 to class 12 physics activities, with animated tutorials of
book concepts.
Modularity: Kit comes in a modular form hence students can exchange modules just as they exchange
video game CDs. Therefore more learning more fun and more relaxation to parents pocket.
Animated Tutorials
www.technido.com
62
video game CDs. Therefore more learning more fun and more relaxation to parents pocket.
Animated Tutorials: Students gets all the guidance and instructions through an animated series of tutorials
with exercises and quizzes at proper interval.
Watch out our promotional video at: http://www.youtube.com/watch?v=lCKDkv47MBo
What all can be learned/made from this kit?
Learning's
Fundamental of physics
Controlling Motors
About different electronic components
Developing Logic for diving the machine
Wiring of machine
Basics of mechanics
Use of tools and many more.
Constructions
Manually Controlled Robot
Obstacle Avoiding Robot
Line following Robot
Cell Phone Controlled Robot
TV remote controlled Robot
Computer Controlled Robot
Voice Controlled Robot
Computer Programmed Robot
Wireless Remote Controlled Robot
Light Controlled Robot and more
Video Demonstrations:
T E C H N I D O
Model No:
Scoobot - Variants
TN -56
Scoobot Beginners Kit:
Experiments Included:
1. Manually Controlled Robot
2. Obstacle Avoiding Robot
3. Edge Avoiding Robot
4.Line following Robot
5.Cell Phone Controlled Robot
6. TV remote controlled Robot
Scoobot Advance Kit:
Experiments Included:
1. Manually Controlled Robot
2. Obstacle Avoiding Robot
3. Edge Avoiding Robot
4.Line following Robot
5.Cell Phone Controlled Robot
6.TV remote Controlled Robot
7.Computer Controlled Robot
8.Voice Controlled Robot
9.Computer Programmed Robot
www.technido.com
63
9.Computer Programmed Robot
10.Wireless Remote Controlled Robot
11.Light Controlled Robot
12. Sound Activated Robot and more
Scoobot Microcontroller Kit:
Experiments Included:
All the experiments included of Advance kit will be implemented using Arduino Board via
C Programming Language
CONSTRUCTION
68 OCTOBER 2007 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
AKSHAY MATHUR
SECURED ROOM ACCESS
SYSTEM
SUNIL KUMAR
S
ecurity is a prime concern in
our day-to-day life. And access
control system forms a vital link
in a security chain.
The microcontroller-based digital
lock presented here is an access con-
trol system that allows only authorised
persons to access a restricted area.
When someone tries to enter the re-
stricted area by entering invalid pass-
words continuously, the system locks
itself and can be unlocked only by the
master user.
The system comprises a small elec-
tronic unit with a numeric keypad,
which is fixed outside the entry door
to control a solenoid-operated lock.
When an authorised person enters a
predetermined number (password) via
the keypad, the relay energises for a
limited time to unlock the solenoid-
operated lock, so door can be pushed/
pulled open. At the end of the preset
delay, the relay de-energises and the
door gets locked again. A prompt mes-
sage is displayed on the LCD module.
Circuit description
The system uses a compact circuitry
built around AVR microcontroller
ATmega8535. The ATmega8535 is a
low-power CMOS 8-bit
microcontroller based on the AVR-en-
hanced RISC architecture. It provides
the following features: 8 kB of in-sys-
tem programmable Flash memory with
read-while-write capabilities, 512-byte
EEPROM, 512-byte SRAM, 32 general
purpose I/O lines, 32 general-purpose
working registers, three flexible timer/
counters with compare modes, and in-
ternal and external interrupts. The
built-in power-on-reset circuitry of the
microcontroller eliminates the need for
external power-on-reset circuit.
Switch S3 is used to reset the sys-
tem, which is accessible only to the
master user. Port D (PD0 through PD7)
is interfaced with the numeric keypad.
Fig. 1: Secured Room Access System
CONSTRUCTION
70 OCTOBER 2007 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
Port C is interfaced with a 16-x2-line
LCD. Four pins (PC4 through PC7) of
Port C are used as data lines for the
LCD module and three lines (PC0
through PC2) are used for controlling
the LCD. Pin 40 (PAO) of port A is
connected to the relay driver circuit
through optocoupler MCT2E (IC3) and
transistor T1.
When port pin PA0 goes high, the
internal transistor of IC3 drives tran-
PARTS LIST
Semiconductor:
IC1 - 7806 6V regulator
IC2 - ATmega8535 AVR
microcontroller
IC3 - MCT2E optocoupler
T1 - BC548 npn transistor
D1-D6 - 1N4007 rectifier diode
LED1 - 5mm light-emitting diode
Resistors (all -watt, 5% carbon):
R1-R4 - 10-kilo-ohm
R5 - 1-kilo-ohm
R6 - 470-ohm
R7 - 100-ohm
VR1 - 10-kilo-ohm preset
Capacitors:
C1 - 1000F, 25V electrolytic
C2 - 0.1F ceramic disk
C3, C4 - 22pF ceramic disk
Miscellaneous:
X1 - 230V AC primary to 9V,
500mA secondary
transformer
S1, S2 - On/off switch
S3-S19 - push-to-on tactile switch
X
TAL
- 8 MHz crystal
RL1 - 6V, 1C/O relay
Batt. - 4.8 volt rechargeable
battery
- LCD module 16 X 2 line
- 6 volt operated solenoid
lock
sistor T1 into
saturation and
relay RL1
energises. As
the solenoid
valve is con-
nected through
n o r m a l l y -
closed (N/C)
contact of the
relay, the sole-
noid coil de-
energises and
the gate is
locked. An
8MHz crystal is
used with two
22pF capacitors
for providing
clock. Preset
VR1 is used to
adjust the con-
trast of the
LCD.
The 230V,
50Hz AC mains
is stepped
down by trans-
former X1 to
deliver a sec-
ondary output
of 9V, 500 mA.
The trans-
former output
is rectified by a
f u l l - w a v e
bridge rectifier
comprising di-
odes D1
through D4, fil-
tered by capaci-
tor C1 and
regulated by IC
7806 (IC1). Use
adequate heat-
sink for 7806 as
the solenoid draws a high current.
LED1 glows when power is on and
resistor R6 acts as the current limiter.
A 16-key numeric keypad for pass-
word entry is connected to the
microcontroller. The keypad is also
used for password change and appli-
cation of master password when re-
quired. To economise the use of I/O
pins, we have used here only eight
pins for scanning and sensing 16 keys.
The keypad is arranged in a 4x4
matrix. There are four scan lines/pins,
which are set in output mode, and four
sense keys, which are used as input
lines to the microcontroller.
At a small time interval, the
microcontroller sets one of the four
scan lines as low and the other three
scan lines as high. Then it checks for
the status of sense lines one by one at
the intersection of a specific scan line
and sense line to find out if any key
has been pressed.
Similarly, after a small time inter-
val, the next scan line is made low and
remaining three scan lines are taken
high, and again all three sense lines
are checked for low level. This way
the microcontroller checks which of the
16 keys is pressed.
Due to the high speed of the
microcontroller, the status of different
keys is checked in less than 100 ms
and a key press is detected and identi-
fied. As the keys are pressed manu-
ally by the user, this delay of 100 ms
is not noticeable. The net result is that
you save on I/O pins of the
microcontroller by sacrificing almost
nothing.
When a person wants to enter the
Fig. 2: A single-side, actual-size PCB layout for secured room access system
Fig. 3: Component layout for the PCB
CONSTRUCTION
72 OCTOBER 2007 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
SOURCE PROGRAM
#asm
.equ __lcd_port=0x15
#endasm
eeprom long int pass_store= 123456,
master_password= 291279;
#include <mega8535.h>
#include <lcd.h>
#include <stdio.h>
#include <delay.h>
#include <kbd.h>
#define relay PORTA.0
int i,j,k,fail=0;
long int id_value, pass_value, pass[6];
bit match=0;
void password()
{i=0;
do{
delay_ms(50);
while(!kbd_read()){}
j=kbd_read();
if(j<11)
{if(j==10) j=0; pass[i]=j;
lcd_gotoxy(5+i,1);
lcd_putsf(*); i++;}
} while(i<6);
delay_ms(100);
pass_value=pass[5]+ 10*pass[4]+ 100*pass[3]+
1000*pass[2]+ 10000*pass[1]+ 100000*pass[0];
}
void pass_change()
{
lcd_clear(); lcd_gotoxy(0,0);
lcd_putsf(Enter New );
lcd_gotoxy(0,1);
lcd_putsf(Password:);
delay_ms(50); k=0;
do{
delay_ms(50);
while(!kbd_read()){}
j=kbd_read();
if(j<11)
{if(j==10) j=0;
pass[k]=j;
k++;
lcd_gotoxy(9+k,1);
lcd_putsf(*);}
} while(k<6);
pass_value=pass[5]+ 10*pass[4]+ 100*pass[3]+
1000*pass[2]+ 10000*pass[1]+ 100000*pass[0];
pass_store=pass_value;
id_value=pass_store;
delay_ms(100);
if(pass_value==id_value){lcd_clear();
lcd_putsf(Password changed);}
else {lcd_clear();
lcd_putsf(Verify failed);}
delay_ms(300);}
void unlock()
{
relay=~relay;lcd_clear();
lcd_gotoxy(1,0);
lcd_putsf(Door Unlocked);
lcd_gotoxy(2,1);
lcd_putsf(Please enter);
delay_ms(300);
for(k=0;k<20;k++)
{lcd_clear();
delay_ms(50);
lcd_gotoxy(1,0);
lcd_putsf(Door Unlocked);
lcd_gotoxy(2,1);
lcd_putsf(Please enter);
delay_ms(50);}
relay=~relay; return;
}
void main()
{
PORTA=0x00;
DDRA=0xFF;
kbd_init();
lcd_init(16);
lcd_clear();
lcd_gotoxy(4,0);
lcd_putsf(Welcome!);
delay_ms(100);
label1: lcd_clear();
lcd_gotoxy(1,0);
lcd_putsf(Enter Password:);
delay_ms(50);
password();
if(pass_value==pass_store){
match=1;
}
else if(pass_value==master_password) {
match=1;
pass_change();
match=0;
fail=0;
goto label1;
}
else {match=0;
}
if(match==1)
{
match=0;
fail=0;
delay_ms(100);
unlock();
goto label1;
}
else
{
lcd_clear();
lcd_putsf(Invalid Password);
match=0;
fail=fail+1;
delay_ms(200);
if(fail==3)
{
lcd_clear();
lcd_gotoxy(1,0);
lcd_putsf(Contact System );
lcd_gotoxy(1,1);
lcd_putsf(Administrator);
}
else
{
goto label1;
}
}
}
room, he enters the 6-digit password,
say 123456. If the password matches
successfully, the gate is unlocked for
15 seconds.
If you want to change the user
password (123456) and enter the mas-
ter password 291279, the system will
ask you to change the user password.
On successfully entering the password,
pin A0 of port A becomes high for 15
seconds, because of which transistor
T1 starts conducting through the emit-
ter of the optocoupler and the relay
energises. The connection between the
solenoid lock and the power supply is
broken and the door is unlocked for
15 seconds.
An actual-size, single-side PCB for
secured room access system (Fig. 1) is
shown in Fig. 2 and its component lay-
out in Fig. 3.
Software
The software for the AVR
microcontroller is written in C lan-
guage and compiled using Code Vi-
sion AVR C compiler. Since this com-
piler does not have library functions
for the keypad, place kbd.h file in the
INC folder of the installation folder
and kbd.lib in the LIB folder of cvavr
folder. This file is included in the pro-
gram and the same can be used.
EFY note. All the software files re-
lating to this article have been included
in this months EFY-CD.
The author is robotics engineer at Erockit Tech-
nologies Pvt Ltd. He can be contacted through
akshaymathur39@yahoo.com.
electronics for you january 2000
c i r c u i t i d e a s
circuit ideas
T
he circuit described here is of an
electronic combination lock for
daily use. It responds only to the
right sequence of four digits that are
keyed in remotely. If a wrong key is
touched, it resets the lock. The lock code
can be set by connecting the line wires to
the pads a, b, c, and d in the fgure. For
example, if the code is 1756, connect line
1 to a, line 7 to b, line 5 to c, line 6 to d
and rest of the lines2, 3, 4, 8, and 9to
the reset pad as shown by dotted lines in
yash d. doshI
the fgure.
The circuit is built around two cd4013
dual-d fip-fop ics. The clock pins of the
four fip-fops are connected to a, b, c,
and d pads. The correct code sequence
for energisation of relay rl1 is realised by
clocking points a, b, c, and d in that order.
The fve remaining switches are connected
to reset pad which resets all the fip-fops.
Touching the key pad switch a/b/c/d briefy
pulls the clock input pin high and the
state of fip-fop is altered. The q output
pin of each fip-fop is wired to
d input pin of the next fip-fop
while d pin of the frst fip-fop
is grounded. Thus, if correct
clocking sequence is followed
then low level appears at q2
output of ic2 which energises
the relay through relay driver
transistor t1. The reset keys
are wired to set pins 6 and
8 of each ic. (Power-on-reset
capacitor c1 has been added
at efy during testing as the
state of q output is indeter-
minate during switching on
operation.)
This circuit can be use-
fully employed in cars so that
the car can start only when
the correct code sequence is
keyed in via the key pad. The
circuit can also be used in
various other applications.
Simple Code loCk
CIRCUIT
IDEAS
ELECTRONI CS FOR YOU FEBRUARY 2007 97 WWW. E F Y MA G . C O M
Fig. 1: Simple water level controller
Fig. 2: Sensor installation in the overhead
tank (OHT)
W
ater-level controllers are
common nowadays. The
one described here is
built around timer NE555 and
inverter buffer CMOS IC CD4049.
It uses readily-available, low-cost
components, and is easy to build
and install on the over-head
tank (OHT) to prevent wastage of
water.
The circuit works off a 12V bat-
tery or 230V AC mains using a 12V
adaptor. The three sensors built
from non-corrosive metal are fitted
to the OHT as shown in Fig. 2 and
connected to the circuit (Fig. 1) at ap-
propriate terminals. Power supply ter-
sors in the OHT and connected the
power supply, the circuit is ready to
use.
Since Vcc terminal is at the bottom
of the tank, when the water level falls
below sensor L,
timer IC2 is
triggered at pin
2 via inverters
N1 and N2 and
its output goes
high. As a re-
sult, the output
of timer IC2
goes high. Re-
lay RL1
energises and
the motor starts
filling water in
the tank. The
motor remains
on even when
the water level
crosses sensor
L.
As water in
the tank rises to
touch sensor H, timer IC2 is re-
triggered at pin 6 via inverters N3
and N4 and as a result, its output
goes low. The relay de-energises and
the motor stops filling water in the
tank. The motor remains off even
when the water level falls below sen-
sor H.
As water is consumed and its level
falls below sensor L, the motor restarts.
Thereafter, the cycle repeats.
You can also manually start and
stop the motor using switch S1.
SUNIL KUMAR
SIMPLE AUTOMATIC
WATER-LEVEL CONTROLLER
S.C. DWIVEDI
minal Vcc is at the bottom of the tank,
sensor terminal L is just above the
bottom of the tank and sensor termi-
nal H is at the top of the tank. After
you have properly installed the sen-
circuit
ideas
electroni cs for you August 2009 117 www. e f y mA g . c o m
P. Venkata Ratnam
SmaRt emeRgency Light
S.C. DW
IVEDI
N
ow you need not fear dark
nights when power breaks
down. Heres a white LED-
based emergency light that automati-
cally turns on when mains power sup-
ply fails.
The circuit consists of power supply,
battery charger and switching sections.
The power supply and charger sections
are built around transformer X1, diodes
D1 and D2, transistor T1, resistors R1
and R2, and zener diode ZD1. The pow-
er supply for the circuit is derived from
AC mains by using 9V-0-9V, 250mA
step-down transformer X1. Diodes D1
and D2 rectify the AC voltage into DC
voltage, which is smoothed by flter ca-
pacitor C1. The unregulated DC voltage
is regulated by transistor T1 along with
resistor R1 and zener diode ZD1. The
regulated DC voltage, via resistor R2,
charges the lead-acid battery. Diode D3
connects the battery power supply to
the switching circuit when mains power
is unavailable.
The switching circuit is built
around an NE555 timer (IC1), which
is wired in monostable mode. When
a low voltage is applied at trigger pin
2 of IC1, the timer activates and its
output pin 3 goes high. It remains in
that state until IC1 is triggered again
at its pin 2.
Light-dependant resistor LDR1 is
connected between the positive supply
of the battery and trigger pin 2 of IC1.
Resistor R3 is connected between pin
2 of IC1 and ground. The resistance
value of LDR1 remains high in dark
(at night) and low in ambient light (in
daytime). This phenomenon is utilised
to control the switching circuit.
Working of the circuit is simple. In
daytime, when ambient light falls on
LDR1, its resistance decreases to make
trigger pin 2 of IC1 high. As a result,
output pin 3 goes low and the LEDs
(LED1 through LED7) remain off.
At night (in the dark), the resistance
of LDR1 increases and a low voltage is
applied to trigger pin 2 of IC1. This
activates the monostable and its output
goes high to make all the LEDs glow.
When mains power is available, re-
set pin 4 of IC1 is grounded via transis-
tor T2 and its output pin 3 remains low.
As a result, the LEDs dont glow. When
mains power fails, transistor T2 does
not conduct and reset pin 4 of IC1 gets
positive supply through resistor R5. As
a result, the output of IC1 goes high to
light up the LEDs. Due to pulsating DC
output at pin 3 of IC1, it can drive seven
LEDs (LED1 through LED7).
Assemble the circuit on a general-
purpose PCB and enclose in a cabinet
with enough space for the battery.
Mount the seven white LEDs on the
front panel of the box. Fix LDR1 away
from the white LEDs to prevent their
light from falling on LDR1.
electronics for you december 2001
c i r c u i t i d e a s
pradeep g.
T
he smoke alarm circuit presented
here is based on the readily avail-
able photon-coupled interrupter
module and timer IC Ne555. The photo
interrupter module is used as the smoke
detector, while timer 555 is wired in
astable confguration as an
AF oscillator for sounding
alarm via a loudspeaker.
In the absence of any
smoke, the gap of photo
interrupter module is clear
and the light from LED
falls on the phototransistor
through the slot. As a re-
sult, the collector of photo-
transistor is pulled towards
ground. This causes reset
pin 4 of IC 555 to go low.
Accordingly, the timer is
reset and hence the alarm
does not sound.
However, when smoke is present in
the gap of the photo interrupter module,
the light beam from LED to the photo-
transistor is obstructed. as a result, the
phototransistor stops conducting and pin
4 (reset) of IC 555 goes high to activate
the alarm.
Note. The unit must be housed inside
an enclosure with holes to allow entry of
smoke.
Smoke AlArm
KS Project Manual
eFY SePteMber 2009
Microcontroller-Based
solar charger
A
s the sources of conventional
energy deplete day by day,
resorting to alternative sources
of energy like solar and wind energy
has become need of the hour.
Solar-powered lighting systems are
already available in rural as well as ur-
ban areas. These include solar lanterns,
solar home lighting systems, solar
streetlights, solar garden lights and
solar power packs. All of them consist
of four components: solar photovoltaic
module, rechargeable battery, solar
charge controller and load.
In the solar-powered lighting sys-
tem, the solar charge controller plays
an important role as the systems
overall success depends mainly on it.
It is considered as an indispensable
link between the solar panel, battery
and load.
The microcontroller-based solar
charge controller described here has
the following features:
1. Automatic dusk-to-dawn opera-
tion of the load
2. Built-in digital voltmeter (0V-20V
range)
3. Parallel- or shunt-type regula-
tion
4. Overcharge protection
5. System status display on LCD
6. Deep-discharge protection
7. Low battery lock
8. Charging current changes to
pulsed at full charge
9. Low current consumption
10. Highly effcient design based on
microcontroller
11. Suitable for 10-40W solar panels
for 10A load
The circuit of the solar charge con-
troller is shown in Fig. 1. It comprises
microcontroller AT89C2051, serial ana-
logue-to-dig-
ital converter
ADC 0 8 3 1 ,
optocoupler
MCT2E, reg-
ulator 7805,
MO S F E T s
BS170 and IR-
F540N, tran-
sistor BC547,
Fig. 1: Circuit of microcontroller-based solar charger
Fig. 2: Pin confgurations of
BC547, BS170 and IRF540
KS Project Manual
eFY SePteMber 2009
LCD and a few discrete components.
Component description is given be-
low.
Microcontroller. Microcontroller
AT89C2051 is the heart of the circuit.
It is a low-voltage, high-performance,
8-bit microcontroller that features 2 kB
of Flash, 128 bytes of RAM, 15 input/
output (I/O) lines, two 16-bit timers/
counters, a fve-vector two-level inter-
rupt architecture, a full-duplex serial
port, a precision analogue comparator,
on-chip oscillator and clock circuitry.
A 12MHz crystal is used for providing
the basic clock frequency. All I/O pins
are reset to 1 as soon as RST pin goes
high. Holding RST pin high for two
machine cycles, while the oscillator is
running, resets the device. Power-on
reset is derived from resistor R1 and
capacitor C4. Switch S2 is used for
manual reset.
Serial ADC. The microcontroller
monitors the battery voltage with the
help of an analogue-to-digital con-
verter. The ADC0831 is an 8-bit succes-
sive approximation analogue-to-digital
converter with a serial I/O and very
low conversion time of typically 32 s.
The differential analogue voltage input
allows increase of the common-mode
rejection and offsetting of the analogue
zero input voltage. In addition, the
voltage reference input can be adjusted
to allow encoding of any smaller ana-
logue voltage span to the full eight bits
of resolution. It is available in an 8-pin
PDIP package and can be interfaced
to the microcontroller with only three
wires.
LCD module. The system status and
battery voltage are displayed on an
LCD based on HD44780 controller. The
backlight feature of the LCD makes it
readable even in low light conditions.
The LCD is used here in 4-bit mode to
save the microcontrollers port pins.
Usually the 8-bit mode of interfacing
with a microcontroller requires eleven
pins, but in 4-bit mode the LCD can be
interfaced to the microcontroller using
only seven pins.
Solar panel. The solar panel used
here is meant to charge a 12V battery
and the wattage can range from 10
to 40 watts. The peak unloaded volt-
age output of the solar panel will be
around 19 volts. Higher-wattage panels
can be used with some modifcations to
the controller unit. Solar panel can be
purchased from A.K. Electronics, Delhi
(Ph: 011-41406775/76).
Rechargeable battery. The solar en-
ergy is converted into electrical energy
and stored in a 12V lead-acid battery.
The ampere-hour capacity ranges from
5 Ah to 100 Ah.
Dusk-to-dawn sensor. Normally, in
PArts List
Semiconductors:
IC1 - AT89C2051 microcontroller
IC2 - ADC0831 analogue-to-digital
converter
IC3 - MCT2E optocoupler
IC4 - 7805, 5V regulator
T1 - BC547 npn transistor
T2 - BS170 n-channel MOSFET
T3 - IRF540 n-channel MOSFET
D1 - 6A4 rectifer diode
D2-D4 - 1N4007 rectifer diode
ZD1 - 7.5V zener diode
Resistors (all -watt, 5% carbon):
R1 - 8.2-kilo-ohm
R2 - 1.2-kilo-ohm
R3, R4, R6-R11 - 10-kilo-ohm
R5 - 20-kilo-ohm
R12 - 330-ohm
Capacitors:
C1 - 100F, 63V electrolytic
C2 - 100F, 16V electrolytic
C3, C7 - 0.1F ceramic disk
C4, C9 - 10F, 16V electrolytic
C5, C6 - 33pF ceramic disk
C8 - 0.01F ceramic disk
Miscellaneous:
S1 - On/off switch
S2 - Push-to-on switch
RL1 - 12V, 1C/O relay
X
TAL
- 12MHz crystal
LCD - 162 line display
Solar panel - 10-40W
F1 - 10A fuse
- 10-pin bergstik SIP
connector (male & female)
Note: 12V Battery and solar panel are not
supplied by Kits n Spare
Fig. 3: A single-side, actual-size PCB layout for microcontroller-based solar charger
Fig. 4: Component layout for the PCB
KS Project Manual
eFY SePteMber 2009
a solar-photovoltaic-based installation
for example, solar home lighting system,
solar lantern or solar streetlightthe
load (the light) is switched on at dusk
(evening) and switched off at dawn
(morning). During daytime, the load is
disconnected from the battery and the
battery is recharged with current from
the solar panel. The microcontroller
needs to know the presence of the solar
panel voltage to decide whether the
load is to be connected to or discon-
nected from the battery, or whether the
battery should be in charging mode
or discharging mode. A simple sensor
circuit is built using a potential divider
formed around resistors R8 and R9,
zener diode ZD1 and transistor T1 for
the presence of panel voltage.
Charge control. Relay RL1 connects
the solar panel to the battery through
diode D1. Under normal conditions, it
allows the charging current from the
panel to fow into the battery. When
the battery is at full charge (14.0V), the
charging current becomes pulsed. To
keep the overall current consumption
of the solar controller low, normally-
closed (N/C) contacts of the relay are
used and the relay is normally in de-
energised state.
Load control. One terminal of
the load is connected to the battery
through fuse F1 and another terminal
of the load to an n-channel power
MOSFET T3. MOFETs are voltage-
driven devices that require virtually no
drive current. The load current should
be limited to 10A. One additional
MOSFET is connected in parallel for
more than 10A load current.
circuit description
Basically, there are two methods of
controlling the charging current: series
regulation and parallel (shunt) regula-
tion. A series regulator is inserted be-
tween the solar panel and the battery.
The series type of regulation wastes
a lot of energy while charging the bat-
tery as the control circuitry is always
active and series regulator requires
the input voltage to be 3-4 volts higher
than the output voltage. The current
and voltage output of a solar panel is
governed by the angle of incidence of
light, which keeps varying.
Parallel regulation is preferred in
solar feld. In parallel regulation, the
control circuitry allows the charging
current (even in mA) to fow into the
battery and stop charging once the bat-
tery is fully charged. At this stage, the
charging current is wasted by convert-
ing into heat (current is passed through
low-value, high-wattage resistor); this
part of the regulation dissipates a lot
of heat.
In this project, we have used paral-
lel regulation technique but instead
of wasting the charging current as
heat, we have made it pulsed and ap-
plied to the battery to keep the battery
topped-up.
After power-on, the microcontroller
reads the battery voltage with the help
of the ADC and displays the values on
the LCD. It monitors the input signal
from the dusk-to-dawn sensor and
activates the load or charging relay
RL1 accordingly. The digital voltmeter
works up to 20V. As Vref of the ADC
is connected to V
CC
(5V), the input volt-
age to the ADC cannot exceed +5V. A
potential divider is used at pin 2 of
the ADC (IC2) using resistors R5, R6
and R7 to scale down the voltage from
0V-20V to 0V-05V. The ADC output is
multiplied four times and displayed on
the LCD as battery voltage.
When the solar panel voltage is
present, the dusk-to-dawn sensor
provides a signal to the microcontrol-
ler, which then displays Charging
message on the LCD. During charging,
the battery voltage is continuously
monitored. When the voltage reaches
14.0V, the microcontroller interrupts
the charging current by energising the
relay, which is connected to MOSFET
BS170 (T2), and starts a 5-minute timer.
During this stage, the LCD shows Bat-
tery Full.
After fve minutes, the relay recon-
nects the panel to the battery. This
Fig. 5: Flow-chart of the source program
KS Project Manual
eFY SePteMber 2009
$MOD51
;LCD4-BITMODECONNECTIONS
RS EQU P1.7 ;LCD REGISTER SELECT
LINE
ENEQUP1.6;LCDENABLELINE
DB4EQUP1.5;
DB5EQUP1.4;
DB6EQUP1.3;
DB7EQUP1.2;
;ADC0831CONNECTIONS
CSEQUP3.0
CLKEQUP3.1
DOEQUP3.2
;INPUT&OUTPUT
DYI EQU P3.4 ; SOLAR PANEL VOLTAGE
SENSOR
CHG_RL EQU P3.5 ; CHARGING CONTROL
RELAY
LD_RLEQUP3.7;LOADCONTROLRELAY
DSEG
ORG0020H
VAL1:DS1
VAL2:DS1
VAL3:DS1
ADC_VAL:DS1
BUF:DS1
CNT1:DS1
CNT2:DS1
IMG:DS1
FLAGS:DS1
OCFBITFLAGS.0;OVERCHARGEFLAG
solar.asm
LBFBITFLAGS.1;LOWBATTFLAG
CSEG
ORG0000H
JMPMAIN
ORG000BH ;TimerInterrupt0
JMPCOUNTDOWN
MAIN:MOVSP,#50H
MOVP3,#0FFH
MOVP1,#0FFH
CLRCHG_RL
CLRLD_RL
LCALLPWR_DELAY
LCALLINIT
SETBCLK
SETBDO
SETBCS
SETBDYI
MOVVAL1,#00H
MOVVAL2,#00H
MOVVAL3,#00H
MOVFLAGS,#00H
LOADCHAR:MOVBUF,#40H
LCALLCMD
MOVDPTR,#RCHAR
REP: CLRA
MOVCA,@A+DPTR
JZSCREEN1
MOVBUF,A
LCALLDAT
INCDPTR
SJMPREP
SCREEN1:MOVBUF,#80H
LCALLCMD
MOVDPTR,#MSG1
HERE:CLRA
MOVCA,@A+DPTR
JZNEXT
MOVBUF,A
LCALLDAT
INCDPTR
SJMPHERE
NEXT:MOVBUF,#0C0H
LCALLCMD
MOVDPTR,#MSG2
HERE1:CLRA
MOVCA,@A+DPTR
JZOVER
MOVBUF,A
LCALLDAT
INCDPTR
SJMPHERE1
OVER:LCALLONE_SEC_DELAY
LCALLONE_SEC_DELAY
LCALLCLEAR
MOVBUF,#0C0H
LCALLCMD
MOVDPTR,#MSG7
HERE2:CLRA
MOVCA,@A+DPTR
JZCONVERT
MOVBUF,A
LCALLDAT
INCDPTR
SJMPHERE2
CONVERT:LCALLDDELAY
CLRCS;INITIATECONVERSION
way, the charging current is pulsed at
the intervals of fve minutes and the
cycle repeats until the panel voltage
is present.
When the panel voltage falls below
the zener diode (ZD1) voltage of the
dusk-to-dawn sensor, the microcon-
troller senses this and activates the
load by switching on MOSFET T3 via
optocoupler IC3 and Load On mes-
sage is displayed.
In this mode, the microcontroller
monitors for low battery. When the
battery voltage drops below 10 volts,
the microcontroller turns off the load
by switching off MOSFET T3 and
Battery LowLoad Off message is
displayed.
Normal l y, when the l oad i s
switched off, the battery voltage
tends to rise back and the load oscil-
lates between on and off states.
To avoid this, the microcontroller
employs a hysteresis control by en-
tering into a lock mode during low-
battery state and comes out of the
lock mode when the dusk-to-dawn
sensor receives the panel voltage (the
next morning). During lock mode, the
microcontroller keeps converting the
ADC value and displays the battery
voltage on the LCD.
construction and testing
Pin confgurations of transistor BC547,
MOSFET BS170 and MOSFET IRF540
are shown in Fig. 2. An actual-size,
single-side PCB for the microcontrol-
ler-based solar charger is shown in
Fig. 3 and its component layout in
Fig. 4. Wire the circuit on the PCB.
Prior to inserting the programmed
microcontroller into the PCB, check
for soldering mistakes like shorts,
and for proper connections using a
multimeter. Mount power MOSFET
IRF540N on a suitable heat-sink. Be-
fore switching on the controller unit,
connect the leads of the battery, load
and solar panel at appropriate places
on the board.
Switch on the unit and the mes-
sage Solar Charge ControllerEFY
is displayed on the LCD for two sec-
onds. The system status messages are
displayed on line 1 of the LCD and the
battery voltage is displayed on line 2.
A small graphic representing the bat-
tery status is also displayed on line 2
of the LCD.
EFY note. 1. If the unit is switched
on without the solar panel connected,
the Battery LowLoad Off mes-
sage is displayed irrespective of the
battery voltage. The display changes
to Charging as soon as the panel is
connected.
2. There will be slight variation in
the voltage displayed because of the
tolerance levels of potential-divider
resistors in the ADC section and Vref
of the ADC being directly connected to
V
CC
(the output of 7805 has an accuracy
of 2-5 per cent) instead of dedicated
temperature-compensated voltage
reference.
software
The source program for the project
is written in Assembly language and
assembled using Metalinks ASM51
assembler, which is freely available on
the Internet for download. It is well
commented for easy understanding
and works as per the fow-chart shown
in Fig. 5. The hex fle solar.hex is to be
burnt into the microcontroller.
KS Project Manual
eFY SePteMber 2009
SETBCLK
CLRCLK;FIRSTCLOCK
SETBCLK
CLRCLK;SECONDCLOCK
MOVA,#00H;CLEARA
MOVR5,#08H;8CLOCKPULSES
AGAIN:MOVC,DO
RLCA
SETBCLK
CLRCLK
DJNZR5,AGAIN
SETBCS
MOVADC_VAL,A
MOVB,#79D
MULAB;PRODUCTINAB
MOVR1,B;HIGHBYTEINB
MOVR2,A;LOWBYTEINA
LCALLHEX2BCD
MOVVAL1,R7
MOVVAL2,R6
MOVVAL3,R5
LCALLSENDVAL2LCD
CHECK:JNB LBF,CHECK2 ; SEE IF ANY
FLAGSARESET,i,eLOWBATTFLAGORBATT
FULLFLAG
JBDYI,CONVERT
CHECK2:JNBOCF,PROCEED
JBDYI,NIGHT
SJMPCONVERT
PROCEED:JBDYI,NIGHT
CLRLD_RL;OFFLOAD
CLRLBF;CLEARLOWBATTFLAG
MOVA,VAL2;SEEIFBATT.ISFULL
XRLA,#04H
JZFULLCHG
CLR CHG_RL ; CONNECT BATT. TO
PANEL
MOVDPTR,#MSG4;DISPLAYCHARGING
MSG
MOVIMG,#00H
LCALLSENDSTAT2LCD
LJMPCONVERT
FULLCHG:SETB OCF ;SET OVERCHARGE
FLAG
SETB CHG_RL ;DISCONNECT BATT.FROM
PANEL
MOV TH0,#03CH ;START 5 MIN TIMER
HERE
MOVTL0,#0B0H;DISCONNECTBATTFROM
PANEL
MOVCNT1,#200D
MOVCNT2,#30D
SETBET0
SETBTR0
SETBEA
MOV DPTR,#MSG5 ; DISPLAY BATT.FULL
MSG
MOVIMG,#01H
LCALLSENDSTAT2LCD
LJMPCONVERT
NIGHT:CLRCHG_RL;RECONNECTBATT.
TOPANEL
CLR TR0 ; STOP TIMER0 INCASE ITS
RUNNING
CLROCF;CLEAROVERCHARGEFLAG
SETBLD_RL;CONNECTLOADTOBATT.
MOVA,VAL1
XRLA,#00H
JZLOWBAT
MOVDPTR,#MSG3;DISPLAYLOADON
MSG
MOVIMG,#02H
LCALLSENDSTAT2LCD
LJMPCONVERT
LOWBAT:SETBLBF
CLR LD_RL ; DISCONNECT LOAD FROM
BATT.
MOVDPTR,#MSG6;DISPLAYBAT.OWAND
LOADOFFMSG
MOVIMG,#03H
LCALLSENDSTAT2LCD
LJMPCONVERT
SENDVAL2LCD:MOVBUF,#0C7H
LCALLCMD
MOVA,VAL1
ORLA,#30H
MOVBUF,A
LCALLDAT
MOVA,VAL2
ORLA,#30H
MOVBUF,A
LCALLDAT
MOVBUF,#.
LCALLDAT
MOVA,VAL3
ORLA,#30H
MOVBUF,A
LCALLDAT
RET
SENDSTAT2LCD: MOVBUF,#080H
LCALLCMD
HERE3: CLRA
MOVCA,@A+DPTR
JZPICT
MOVBUF,A
LCALLDAT
INCDPTR
SJMPHERE3
PICT: MOVBUF,#0CEH
LCALLCMD
MOVBUF,IMG
LCALLDAT
BACK: RET
;********************************
;TIMER0ISR(5MINUTESTIMER)
;********************************
COUNTDOWN: CLRTR0
MOVTH0,#03CH
MOVTL0,#0B0H
SETBTR0
DJNZCNT1,BACK2
MOVCNT1,#200D
DJNZCNT2,BACK2
CLRTR0;OFF5MINTIMER
CLRET0
CLROCF;CLEAROVERCHARGEFLAG
CLR CHG_RL ; RE-CONNECT BATT TO
PANEL
BACK2:RETI
Hex2BCD:MOVR3,#00D
MOVR4,#00D
MOVR5,#00D
MOVR6,#00D
MOVR7,#00D
ACALLH2B
RET
H2B: MOVB,#10D
MOVA,R2
DIVAB
MOVR3,B;
MOVB,#10;R7,R6,R5,R4,R3
DIVAB
MOVR4,B
MOVR5,A
CJNE R1,#00H,HIGH_BYTE ; CHECK FOR
HIGHBYTE
SJMPENDD
HIGH_BYTE: MOVA,#6
ADDA,R3
MOVB,#10
DIVAB
MOVR3,B
ADDA,#5
ADDA,R4
MOVB,#10
DIVAB
MOVR4,B
ADDA,#2
ADDA,R5
MOVB,#10
DIVAB
MOVR5,B
CJNER6,#00D,ADD_IT
SJMPCONTINUE
ADD_IT: ADDA,R6
CONTINUE:MOVR6,A
DJNZR1,HIGH_BYTE
MOVB,#10D
MOVA,R6
DIVAB
MOVR6,B
MOVR7,A
ENDD:RET
ONE_SEC_DELAY:MOVR0,#10D;Onesecond
delayroutine
RZ3:MOVR1,#100D
RZ1:MOVR2,#250D
RZ2:NOP
NOP
DJNZR2,RZ2
DJNZR1,RZ1
DJNZR0,RZ3
RET
PWR_DELAY: ; 15 mSec DELAY FOR LCD TO
INTIALIZEAFTERPOWER-ON
MOVR4,#100D
H2:MOVR3,#250D
H1:DJNZR3,H1
DJNZR4,H2
RET
;******LCDSUBROUTINES********
CMD:PUSHACC;SAVEACCUMULATOR
SETBEN
CLRRS;SELECTSENDCOMMAND
MOVA,BUF;PUTDATABYTEINACC
MOV C, ACC.4 ; LOAD HIGH NIBBLE ON
DATABUS
MOV DB4,C ; ONE BIT AT A TIME
USING...
MOVC,ACC.5;BITMOVEOPERATOINS
MOVDB5,C
MOVC,ACC.6
MOVDB6,C
MOVC,ACC.7
MOVDB7,C
CLREN
NOP
SETBEN;PULSETHEENABLELINE
MOV C, ACC.0 ; SIMILARLY, LOAD LOW
NIBBLE
MOVDB4,C
MOVC,ACC.1
MOVDB5,C
MOVC,ACC.2
MOVDB6,C
MOVC,ACC.3
MOVDB7,C
CLREN
NOP
SETBEN;PULSETHEENABLELINE
LCALLMSDELAY
POPACC
RET
;******LCDSUBROUTINES*******
DAT:PUSHACC;SAVEACCUMULATOR
SETBEN
SETBRS;SELECTSENDDATA
MOVA,BUF;PUTDATABYTEINACC
MOV C, ACC.4 ; LOAD HIGH NIBBLE ON
DATABUS
MOV DB4,C ; ONE BIT AT A TIME
USING...
MOVC,ACC.5;BITMOVEOPERATOINS
MOVDB5,C
KS Project Manual
eFY SePteMber 2009
MOVC,ACC.6
MOVDB6,C
MOVC,ACC.7
MOVDB7,C
CLREN
NOP
SETBEN;PULSETHEENABLELINE
MOV C, ACC.0 ; SIMILARLY, LOAD LOW
NIBBLE
MOVDB4,C
MOVC,ACC.1
MOVDB5,C
MOVC,ACC.2
MOVDB6,C
MOVC,ACC.3
MOVDB7,C
CLREN
NOP
SETBEN;PULSETHEENABLELINENOP
LCALLMSDELAY
POPACC
RET
;******LCDSUBROUTINES******
CLEAR:MOVBUF,#01H
LCALLCMD
RET
;******LCDSUBROUTINES*******
DDELAY:MOVR5,#41D;4.1mSDELAY
QT2: MOVR6,#50D
QT1: DJNZR6,QT1
DJNZR5,QT2
RET
;******LCDSUBROUTINES*******
MSDELAY:MOVR5,#26D
QT22:MOVR6,#50D
QT11:DJNZR6,QT11
DJNZR5,QT22
RET
;******LCDSUBROUTINES*******
INIT:MOVBUF,#30H;FUNCTION
SET-DATABITS,LINES,FONTS
LCALLCMD
ACALLDDELAY;INITIALDELAY4.1MSEC
MOVBUF,#30H;FUNCTIONSET-
DATABITS,LINES,FONTS
LCALLCMD
ACALLDDELAY;INITIALDELAY4.1MSEC
MOV BUF,#30H ; FUNCTION SET - DATA
BITS,LINES,FONTS
LCALLCMD
ACALLDDELAY;INITIALDELAY4.1MSEC
MOV BUF,#28H ;2 LINES 5X7, 4-BIT
MODE
LCALLCMD
MOVBUF,#0CH;DISPLAYON
LCALLCMD
MOV BUF,#01H ; CLEAR DISPLAY, HOME
CURSOR
LCALLCMD
MOVBUF,#06H;SETENTRYMODE
LCALLCMD;INCREMENTCURSORRIGHT,
NOSHIFT
RET
ORG0320H
MSG1: DBSOLARCHARGE,00H
MSG2: DBCONTROLLER-EFY,00H
MSG3: DBLOADON,00H
MSG4: DBCHARGING,00H
MSG5: DBBATTERYFULL,00H
MSG6: DBBAT.LOW-LOADOFF,00H
MSG7: DBVolts:,00H
ORG0400H
RCHAR:DB 04D,31D,17D,31D,17D,31D,
17D,31D;CHARGING
DB 04D,31D,31D,31D,31D,31D,
31D,31D;FULL
DB 31D,31D,14D,04D,04D,14D,
31D,31D;LOAD
DB 04D,31D,17D,17D,17D,17D,
17D,31D;LOWBATT
DB 31D,31D,31D,31D,31D,31D,
31D,31D
DB 31D,31D,31D,31D,31D,31D,
31D,31D
DB 31D,31D,31D,31D,31D,31D,
31D,31D
DB 031D,31D,31D,31D,31D,31D,
31D,31D,00H
END
CIRCUIT
IDEAS
98 APRI L 2006 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
CMYK
T
he world cannot continue to rely
for long on fossil fuels for its
energy requirements. Fossil fuel
reserves are limited. In addition, when
burnt, these add to global warming,
air pollution and acid rain.
So solar photovoltaic systems are
ideal for providing independent elec-
trical power and lighting in isolated
rural areas that are far away from the
power grid. These systems are non-
polluting, dont deplete the natural re-
sources and are cheap in the long run.
The aim of this circuit is to demon-
strate how we can utilise solar light to
electrify the remote areas, i.e., how we
can store the solar energy and then use
it for small-scale lighting applications.
Solar cells generate direct current,
so make sure that DPDT switch S1 is
towards the solar panel side. The DC
voltage from the solar panel is used to
charge the battery and control the re-
lay.
Capacitor C1 connected in parallel
with a 12V relay coil remains charged
in daytime until the relay is activated.
Capacitor C1 is used to increase the
response time of the relay, so switch-
ASHISH AHUJA
SOLAR LIGHTING SYSTEM
S.C. DWIVEDI
ing occurs moments after the voltage
across it falls below 12V. Capacitor C1
also filters the rectified output if the
battery is charged through AC power.
The higher the value of the capacitor,
the more the delay in switching. The
switching time is to be properly ad-
justed because the charging would
practically stop in the early evening
while we want the light to be on dur-
ing late evening.
During daytime, relay RL1
energises, provided DPDT switch S1
is towards the solar panel side. Due to
energisation of relay RL1, the positive
terminal of the battery is connected to
the output of regulator IC 7808 (a 3-
terminal, 1A, 8V regulator) via diode
D1 and normally-open (N/O) contacts
of relay RL1. Here we have used a 6V,
4.5Ah maintenance-free, lead-acid re-
chargeable battery. It requires a con-
stant voltage of approx. 7.3 volts for
its proper charging.
Even though the output of the so-
lar panel keeps varying with the light
intensity, IC 7808 (IC1) is used to give
a constant output of 8V. Diode D1
causes a drop of 0.7V, so we get
approx. 7.3V to charge the battery.
LED1 indicates that the circuit is work-
ing and the battery is in the charging
mode.
At night, there will be no genera-
tion of electricity. The relay will not
energise and charging will not take
place. The solar energy stored in the
battery can then be used to light up
the lamp. A 3W lamp glows continu-
ously for around 6 hours if the battery
is fully charged. Instead of a 3W lamp,
you can also use a parallel array of
serially connected white LEDs and lim-
iting resistors to provide sufficient
light for even longer duration.
In case the battery is connected in
reverse polarity while charging, IC
7808 will get damaged. The circuit in-
dicates this damage by lighting up
LED2, which is connected in reverse
with resistor R2. However, the circuit
provides only the indication of reverse
polarity and no measure to protect the
IC. A diode can be connected in re-
verse to the common terminal of the
IC but this would reduce the voltage
available to the battery for charging
by another 0.7 volt.
There is also a provision for esti-
mating the approximate voltage in the
battery. This has been done by connect-
ing ten 1N4007 diodes (D2 through D11)
CIRCUIT
IDEAS
ELECTRONI CS FOR YOU APRI L 2006 99 WWW. E F Y MA G . C O M
CMYK
in forward bias with the battery. The
output is taken by LED3 across diodes
D2, D3, D4 and D5, which is equal to
2.8V when the battery is fully charged.
LED3 lights up at 2.5 volts or above.
Here it glows with the voltage drop
across the four diodes, which indicates
that the battery is charged. If the bat-
tery voltage falls due to prolonged op-
eration, LED3 no longer glows as the
drop across D2, D3, D4 and D5 is not
enough to light it up. This indicates
that the battery has gone weak. Micro-
switch S1 has been provided to do this
test whenever you want.
If the weather is cloudy for some
consecutive days, the battery will not
charge. So a transformer and full-wave
rectifier have been added to charge the
battery by using DPDT switch S1. This
is particularly helpful in those areas
where power supply is irregular; the
battery can be charged whenever
mains power is available.
ConstruCtion
56 december 2005 electroni cs for you www. e f y ma g . c o m
CMYK
W
hile driving on highways,
motorists should not exceed
the maximum speed limit
permitted for their vehicle. However,
accidents keep occurring due to speed
violations since the drivers tend to ig-
nore their speedometers.
This speed checker will come han-
dy for the highway traffc police as it
will not only provide a digital display
in accordance with a vehicles speed
but also sound an alarm if the vehicle
exceeds the permissible speed for the
highway.
The system basically com-
prises two laser transmitter-LDR
sensor pairs, which are installed
on the highway 100 metres apart,
with the transmitter and the
LDR sensor of each pair on the
opposite sides of the road. The
installation of lasers and LDRs
is shown in Fig. 1. The system
displays the time taken by the
vehicle in crossing this 100m dis-
tance from one pair to the other
with a resolution of 0.01 second,
from which the speed of the ve-
hicle can be calculated as follows:
As per the above equation, for a
speed of 40 kmph the display will read
900 (or 9 seconds), and for a speed of
60 kmph the display will read 600 (or 6
seconds). Note that the LSB of the dis-
play equals 0.01 second and each suc-
ceeding digit is ten times the preceding
Dipanjan Bhattacharjee
SpeeD checker
for highwayS
SUNI L KUMAR
digit. You can similarly calculate the
other readings (or time).
circuit description
Fig. 2 shows the circuit of the speed
checker. It has been designed assuming
that the maximum permissible speed
for highways is either 40 kmph or 60
kmph as per the traffc rule.
The circuit is built around five
NE555 timer ICs (IC1 through IC5),
four CD4026 counter ICs (IC6 through
IC9) and four 7-segment displays (DIS1
through DIS4). IC1 through IC3 func-
tion as monostables, with IC1 serving
as count-start mono, IC2 as count-stop
mono and IC3 as speed-limit detector
mono, controlled by IC1 and IC2 out-
puts. Bistable set-reset IC4 is also con-
trolled by the outputs of IC1 and IC2
and it (IC4), in turn, controls switching
on/off of the 100Hz (period = 0.01 sec-
ond) astable timer IC5.
The time period of timer NE555 (IC1)
count-start monostable multivibrator is
adjusted using preset VR1 or VR2 and
capacitor C1. For 40kmph limit the time
period is set for 9 seconds using preset
VR1, while for 60kmph limit the time
period is set for 6 seconds using preset
VR2. Slide switch S1 is used to select
the time period as per the speed limit
(40 kmph and 60 kmph, respectively).
The junction of LDR1 and resistor R1 is
coupled to pin 2 of IC1.
Normally, light from the laser
keeps falling on the LDR sensor con-
tinuously and thus the LDR offers a
low resistance and pin 2 of IC1 is high.
Whenever light falling on the LDR is
interrupted by any vehicle, the LDR
resistance goes high and hence pin 2 of
IC1 goes low to trigger the monostable.
As a result, output pin 3 goes high for
the preset period (9 or 6 seconds) and
LED1 glows to indicate it. Reset pin 4
is controlled by the output of NAND
Parts List
Semiconductors:
IC1-IC5 - NE555 timer
IC6- IC9 - CD4026 decade
counter/7-segment
decoder
IC10 - CD4011 NAND gate
IC11 - 7812 12V regulator
D1, D2 - 1N4148 switching diode
D3-D6 - 1N4007 rectifer diode
LED1 - Green LED
LED2, LED3 - Red LED
DIS1-DIS4 - LTS543 common-cath-
ode, 7-segment display
Resistors (all -watt, 5% carbon):
R1, R4 - 100-kilo-ohm
R2, R5, R6,
R8, R10,
R11, R14 - 10-kilo-ohm
R3, R7, R13,
R16-R19 - 470-ohm
R9 - 470-kilo-ohm
R12, R15 - 1-kilo-ohm
VR1, VR2 - 100-kilo-ohm preset
VR3 - 20-kilo-ohm preset
Capacitors:
C1 - 100F, 25V electrolytic
C2, C4, C6,
C8, C11 - 0.01F ceramic disk
C3, C13, C15 - 0.1F ceramic disk
C5 - 10F, 25V electrolytic
C7 - 0.47F, 25V electrolytic
C9 - 0.2F ceramic disk
C10 - 1F, 25V electrolytic
C12 - 47F, 25V electrolytic
C14 - 1000F, 35V electrolytic
Miscellaneous:
X1 - 230V AC primary to 0-
15V, 500mA secondary
transformer
PZ1 - Piezobuzzer
LDR1, LDR2 - LDR
S1, S2 - Push-to-on switch
S3 - On/Off switch
- Pointed laser light
Fig. 1: Installation of lasers and LDRs on highway
Speed (kmph) =
Distance
Time
0.1 km
(Reading0.01)/3600
=
Reading (on display) =
or,
36000
Speed
ConstruCtion
58 december 2005 electroni cs for you www. e f y ma g . c o m
CMYK
F
i
g
.
2
:
C
i
r
c
u
i
t
o
f
s
p
e
e
d
c
h
e
c
k
e
r
f
o
r
h
i
g
h
w
a
y
ConstruCtion
60 december 2005 electroni cs for you www. e f y ma g . c o m
CMYK
gate N3 at power-on or whenever reset
switch S2 is pushed.
For IC2, the monostable is triggered
in the same way as IC1 when the vehicle
intersects the laser beam incident on
LDR2 to generate a small pulse for stop-
ping the count and for use in the speed
detection. LED2 glows for the duration
for which pin 3 of IC2 is high.
The outputs of IC1 and IC2 are fed
to input pins 2 and 1 of NAND gate
N1, respectively. When the outputs of
IC1 and IC2 go high simultaneously
(meaning that the vehicle has crossed
the preset speed limit), output pin 3 of
gate N1 goes low to trigger monostable
timer IC3. The output of IC3 is used for
driving piezobuzzer PZ1, which alerts
the operator of speed-limit violation.
Resistor R9 and capacitor C5 decide the
time period for which the piezobuzzer
sounds.
The output of IC1 triggers the
bistable (IC4) through gate N2 at the
leading edge of the count-start pulse.
When pin 2 of IC4 goes low, the high
output at its pin 3 enables astable clock
generator IC5. Since the count-stop
pulse output of IC2 is connected to pin
6 of IC4 via diode D1, it resets clock
generator IC5. IC5 can also be reset via
diode D2 at power-on as well as when
reset switch S2 is pressed.
IC5 is configured as an astable
multivibrator whose time period is de-
cided by preset VR3, resistor R12 and
capacitor C10. Using preset VR1, the
frequency of the astable multivibrator
is set as 100 Hz. The output of IC5 is
fed to clock pin 1 of decade counter/7-
segment decoder IC6 CD4026.
IC CD4026 is a 5-stage Johnson
decade counter and an output decoder
that converts the Johnson code into a
7-segment decoded output for driving
DIS1 display. The counter advances by
one count at the positive clock signal
transition.
The carry-out (Cout) signal from
CD4026 provides one clock after every
ten clock inputs to clock the succeed-
ing decade counter in a multidecade
counting chain. This is achieved by
connecting pin 5 of each CD4026 to pin
1 of the next CD4026.
A high reset signal clears the de-
Fig. 3: Power supply
Fig. 4: Actual-size, single-side PCB layout for the speed checker Fig. 5: Component layout for the PCB
ConstruCtion
62 december 2005 electroni cs for you www. e f y ma g . c o m
CMYK
cade counter to its zero count. Pressing
switch S2 provides a reset signal to pin
15 of all CD4026 ICs and also IC1 and
IC4. Capacitor C12 and resistor R14
generate the power-on-reset signal.
The seven decoded outputs a
through g of CD4026s illuminate
the proper segment of the 7-segment
displays (DIS1 through DIS4) used
for representing the decimal digits 0
through 9. Resistors R16 through R19
limit the current across DIS1 through
DIS4, respectively.
Fig. 3 shows the circuit of the power
supply. The AC mains is stepped down
by transformer X1 to deliver the sec-
ondary output of 15 volts, 500 mA.
The transformer output is rectifed by
a bridge rectifer comprising diodes
D3 through D6, fltered by capacitor
C14 and regulated by IC11 to provide
regulated 12V supply. Capacitor C15
bypasses any ripple in the regulated
output. Switch S3 is used as the on/
off switch. In mobile application of
the circuit, where mains 230V AC is not
available, it is advisable to use an exter-
nal 12V battery. For activating the lasers
used in conjunction with LDR1 and
LDR2, separate batteries may be used.
construction and working
Assemble the circuit on a PCB. An ac-
tual-size, single-side PCB layout for the
speed checker is shown in Fig. 4 and its
component layout in Fig. 5.
Before operation, using a multime-
ter check whether the power supply
output is correct. If yes, apply power
supply to the circuit by fipping switch
S3 to on. In the circuit, use long wires
for connecting the two LDRs, so that
you can take them out of the PCB and
install on one side of the highway,
100 metres apart. Install the two laser
transmitters (such as laser torches) on
the other side of the highway exactly
opposite to the LDRs such that laser
light falls directly on the LDRs. Reset
the circuit by pressing switch S2, so the
display shows 0000. Using switch S1,
select the speed limit (say, 60 kmph) for
the highway. When any vehicle crosses
the frst laser light, LDR1 will trigger
IC1. The output of IC1 goes high for
the time set to cross 100 metres with
the selected speed (60 kmph) and LED1
glows during for period. When the
vehicle crosses the second laser light,
the output of IC2 goes high and LED2
glows for this period.
Piezobuzzer PZ1 sounds an alarm if
the vehicle crosses the distance between
the laser set-ups at more than the se-
lected speed (lesser period than preset
period). The counter starts counting
when the frst laser beam is intercepted
and stops when the second laser beam
is intercepted. The time taken by the
vehicle to cross both the laser beams
is displayed on the 7-segment display.
For 60kmph speed setting, with timer
frequency set at 100 Hz, if the display
count is less than 600, it means that the
vehicle has crossed the speed limit (and
simultaneously the buzzer sounds). Re-
set the circuit for monitoring the speed
of the next vehicle.
Note. This speed checker can
check the speed of only one vehicle at
a time.
cONSTRUcTION
60 November 2008 electroni cs for you www. e f y ma g . c o m
ARUN KUMAR VADLA
Microcontroller-based
Speedometer-Cum-Odometer
SANI THEO
meter-cum-odometer are:
1. Digital readout
2. Speed displayed in km/hour
3. Distance traveled displayed in
kilometres
N
ormally, digital speedometers
are found only in luxury cars
and high-end motorbikes.
Even if your motorbike has a mechani-
cal speedometer, what will you do
when it gets damaged? First, you need
to replace the mechanical worm gear
and then the cable.
Anyway, we describe here how
to build a digital speedometer-cum-
odometer for your motorbike. The
circuit uses a microcontroller, an LCD
display and some commonly available
components. It is a better alternative to
the mechanical speedometer and even
a beginner with minimal skill level can
assemble it.
The features of the digital speedo-
Fig. 1: Circuit of microcontroller-based speedometer-cum-odometer
cONSTRUcTION
electroni cs for you November 2008 61 www. e f y ma g . c o m
available pins of
the microcontrol-
ler are utilised in
the project. This
microcontroller
features 2 kB of
Flash, 128 bytes
of RAM, 15 in-
put/output (I/O)
lines, two 16-bit
timers/counters,
a fve-vector two-
level interrupt
archi tecture, a
full-duplex serial
port, a precision
analogue compa-
rator, on-chip os-
cillator and clock
circuitry.
LCD module.
To display the
speed and dis-
tance traveled, we
have used a 16x2
a l pha nume r i c
LCD based on
HD44780 control-
ler. The backlight
feature of the
LCD allows data
to be visible even
at night. The pin
confguration and
features of this
LCD have earlier
been published in
several is-
sues of EFY.
S e r i a l
EEPROM.
The read-
ings of the
d i s t a n c e
traveled are
s a ve d i n
an external
serial EEP-
ROM. Here,
a 2 4 C0 2
serial EEP-
ROM based
on Philips
I
2
C protocol
Fig. 2: Flow-chart of the program
Fig. 3: Arrangement of reed switch and magnet on the front wheel of motor bike
4. Readings saved in non-volatile
memory (EEPROM)
5. Reliability due to use of the mi-
crocontroller
6. No mechanical wear and tear
7. Home-brewed speed transducer/
sensor
8. Self reset to zero after completion
of 99,999.9 km
9. Easy to build and fx onto the
bike
Calculations
You frst need to know the radius of
the bikes front wheel. The calculations
here are based on Hero Hondas Splen-
dor model. The radius of the front
wheel is 30 cm. (This can vary with the
brand or model.)
Circumference of the wheel= 2r
(where r is in cm)
= 23.1430
= 188.4 cm or 1.884 metres
Speed. Lets assume that in 1 second
the wheel completes one revolution. In
other words, in one second, the bike
has covered 1.88 metres. Therefore the
speed in km/hour:
N1.883600/1000
= N6.784 or N6.8
where N is the number of revolutions
per second. 6.8 is a constant and only
N varies; for example, if N is 5, the
speed equals 5x6.8= 34 km/hour.
Distance. The odometer is updated
every 100 metres. To cover 100 metres,
the wheel is required to make ap-
proximately 53 revolutions (100/1.88).
The microcontroller takes care of the
tasks of revolutions counting, speed
calculation, conversion and display of
results.
Circuit description
The circuit of the microcontroller-based
digital speedometer-cum-odometer is
shown in Fig. 1. The functions of vari-
ous components used in the circuit are
described below.
Mi cr ocont r ol l er . A 20- pi n
AT89C2051 microcontroller from At-
mel is used here because of its low pin
count, affordability and compatibility
with CISC-based 8051 family. All the
cONSTRUcTION
62 November 2008 electroni cs for you www. e f y ma g . c o m
is used.
I
2
C bus protocol. The I
2
C bus con-
sists of two active wires and a ground
connection. The active wires, serial
data line (SDA) and serial clock line
(SCL) are bidirectional.
Every device hooked up to the
bus has its own unique address,
no matter whether it is an MCU,
LCD driver, memory or ASIC. Each
of these chips can act as a receiver
and/or transmitter, depending on
the functionality. Obviously, an
LCD driver is only a receiver, while
a memory or I/O chip can be both
transmitter and receiver.
The I
2
C bus is a multi-master bus.
This means that more than one IC
capable of initiating a data transfer
can be connected to it. The I
2
C pro-
tocol specifcation states that the IC
that initiates a data transfer on the
bus is considered the bus master. Bus
masters are generally microcontrol-
lers. Consequently, all the other ICs
are regarded as bus slaves at that
instant.
Lets assume that the MCU wants
to send data to one of its slaves. First,
the MCU will issue a START condi-
tion. This acts as an attention signal
to all of the connected devices. All
ICs on the bus will listen to the bus
for incoming data. Then the MCU
sends the address of the device it
wants to access, along with an indica-
tion whether the access is a read or
write operation. Having received
the address, all ICs will compare it
with their own address. If it doesnt
match, they simply wait until the bus
is released by the stop condition. If the
address matches, the chip will pro-
duce a response called acknowledge
signal. We have used write operation
in this project.
Once the MCU receives the ac-
knowledge signal, it can start trans-
mitting or receiving data. In our
case, the MCU will transmit data.
When all is done, the MCU will
issue the stop condition. This signals
that the bus has been released and
that the connected ICs may expect
another transmission to start any
moment.
Parts List
Semiconductors:
IC1 - 7805 5V regulator
IC2 - AT89C2051 microcontroller
IC3 - 4N35 optocoupler
IC4 - 24C02 EEPROM
D1 - 1N4007 rectifer diode
LED1 - 5mm light-emitting diode
Resistors (all -watt, 5% carbon):
R1 - 8.2-kilo-ohm
R2-R6 - 10-kilo-ohm
R7 - 330-ohm
R8 - 1-kilo-ohm
R9 - 47-ohm
VR1 - 4.7-kilo-ohm preset
Capacitors:
C1 - 1000F, 25V electrolytic
C2 - 100F, 16V electrolytic
C3 - 0.1F ceramic
C4, C5 - 33pF ceramic
C6 - 10F, 16V electrolytic
Miscellaneous:
CON1 - 2-pin SIP male connector
S1, S2 - SPST on/off switch
S3 - Reed switch
LCD1 - 16x2 EL1602 LCD module
X
TAL1
- 12MHz crystal
Fig. 5: Reed switch and magnet fixed on the front wheel of motor bike
Fig. 4: The materials required to build a PVC contraption
cONSTRUcTION
electroni cs for you November 2008 63 www. e f y ma g . c o m
We have several states on the bus:
start, address, acknowledge, data and
stop. These are all unique conditions
on the bus. In our project, the micro-
controller is the master and the serial
EEPROM is the slave.
The readings are periodically stored
in the EEPROM and the previous read-
ing is retrieved from the EEPROM each
time the bike is started.
Speed sensor. For this project, we
make use of a simple home-made
speed transducer. The rotation of the
wheel is sensed by the combined action
of a reed switch and a magnet fxed on
the wheel. The sensor sends a pulse to
the microcontroller each time a revolu-
tion is made.
Optocoupler. An optocoupler is
used to counter the effects of bounc-
ing when the contact of reed switch
is closed.
Power supply. The power supply
for various parts of the circuit is drawn
from the vehicles 12V battery after re-
ducing it to 5V using a three-terminal
voltage.
Software
The Init_EEPROM and Speedo
source codes of this project are writ-
ten in Assembly language. These
are compiled using an open-source
ASEM-51 assembler to generate the
Init_EEPROM.hex and Speedo.hex
fles. The hex fles are burnt into the
microcontroller chip.
Two internal timers of the mi-
crocontroller are confgured as 8-bit
counters to count the number of
pulses generated by the speed sen-
sor. One timer is used to measure
the distance and the other for speed
calculation.
A software delay of one second
is generated after the speed coun-
ter is triggered. The speed count
value is obtained from the counter
registers. To speed up the process,
a look-up data table is stored in the
ROM that helps the microcontroller
to convert the number of pulses into
the corresponding speed values.
The program flow-chart is shown
in Fig. 2.
The distance counter is incre-
mented every 100 metres. The wheel
has to make 53 revolutions to achieve
this. The distance counter is loaded
with an initial value of 203 (255-53+1)
and is incremented on each revolution.
After 53 counts, the timer overfows
and generates an interrupt to notify
the microcontroller that 100 metres are
covered.
In the interrupt service routine,
the microcontroller updates the cor-
responding DS1 distance variable. In-
stead of saving distance variables after
each cycle, the microcontroller saves
these readings when the vehicle is at
halt (speed is 00.0 km/hour). In other
words, when the vehicle is stopped at
traffc signals or before the ignition key
is turned off, the last reading is saved
to the EEPROM. The same reading
is again retrieved from the EEPROM
when the bike is turned on next time
and the readings are updated for each
trip.
Construction
The reed switch and a magnet
need to be fxed on the front wheel
of the motor bike (Hero Hondas
Splendor). A small circular magnet
(about 2 cm in diametre), normally
used in speakers of small toys, can
be used. Fix the magnet to the cen-
tral drum of the wheel just below
the spokes connected to the drum.
Secure the magnet using hot glue or
Araldite.
For fxing the reed switch, a PVC
pipe contraption needs to be made
so that the magnet and reed switch
are aligned as shown in Fig. 3. The
materials required to build the con-
traption are shown in Fig. 4. Cut a
3.2cm diameter PVC pipe measuring
15.2 cm in length perpendicularly
into two halves. Use only one half of
the PVC pipe. Mount and secure the
reed switch using Araldite and cable
ties on the plastic handle (normally
used in emergency lights). Once it
dries up, solder two wires to the two
opposite end leads of the reed switch.
Fix the plastic handle on the half cut
PVC pipe using screws. Now, place
the pipe on the front shock-absorber
fork such that reed switch faces to-
wards the magnet.
Connect a multimeter, set in
continuity mode, to the two wires
coming from the reed switch. Rotate
the wheel slowly and see whether
the reed switch closes when the
Fig. 6: Speedometer-cum-odometer unit on a bikes handle bar
cONSTRUcTION
64 November 2008 electroni cs for you www. e f y ma g . c o m
magnet passes across it. If it does,
the multimeter will give a continuity
beep. When the magnet moves away
from the reed switch, the beep will
stop, indicating that the reed switch
is open. Make a few trials to fnd the
optimal position for mounting and
fxing the PVC pipe such that the
reed switch works smoothly. Mark
the location on the front shock-ab-
sorber fork.
No w y o u
can fx the PVC
pipe contraption
to the shock-ab-
sorber fork us-
ing hot glue as
shown in Fig.
5. Use liberal
amount of hot
glue to secure it
to the pipe. Care-
fully route the
two wires up to
the bikes handle
bar using cable
ties to secure the
wire. This com-
pletes the sensor
mounting part.
The main cir-
cuit and the LCD
module can be
housed in suit-
able plastic en-
closures, which
are readily avail-
able in electronic
projects shops.
These enclosures
s houl d have
precut slot for
easy mounting
of the LCD pan-
el. If such boxes
are not available,
you can use the
plastic boxes of
electronic chokes
by suitably re-
movi ng some
portions for the
LCD panel.
Power sup-
ply can be taken either directly from
the bikes 12V battery or tapped from
the console which houses horn, head-
light and indicator light switches.
For this, you need to remove the
switch console and identify positive
wire and ground wire using a mul-
timeter. When carrying out this step,
remember to turn the ignition key to
on position. Solder a 60cm two-core
Fig. 7: Actual-size, single-side PCB for the microcontroller-based digital
speedometer-cum-odometer
Fig. 8: Component layout for the PCB
wire to the positive and negative
terminals inside the switch console.
The advantage of taking supply from
the switch console is that the ignition
key controls the power supply to the
main unit without having a separate
on-off switch.
An actual-size, single-side PCB
layout of the microcontroller-based
speedometer-cum-odometer is shown
in Fig. 7 and its component layout in
Fig. 8.
Testing
After all the components are soldered
on the PCB, program the microcon-
troller with Init_EEPROM.hex fle
and place the microcontroller in a
20-pin IC base and switch on the
circuit.
In the first line of the LCD,
INIT_EEPROM appears. After fve
seconds, 00000.0 is displayed in
the second line. This process erases
any previous data and sets the initial
readings in the EEPROM to zero.
Now switch off the supply and
program the microcontroller with
speedo.hex main file. After pro-
gramming, place the microcontroller
back in the circuit and switch on the
supply. The LCD will show Kms:
00000.0 in the frst line and Speed-
Kms/Hr: 00.0 in the second line.
Now, the unit is ready to mount on
your bike.
Connect the two wires coming
from the reed switch and the power
supply wires to the main unit.
Mount the unit at the centre of the
bikes handle bar on top of the U
clamps that secure the handle bar to
the chassis. You can use cable ties to
accomplish this. Mounting arrange-
ment of the unit is shown in Fig. 6.
Now start the bike, take a test
ride and if connections are correct,
the speed and the distance will be
displayed on the LCD. A protective
cover like polythene can be used for
the main unit on rainy days.
EFY note. The source codes for
this article have been included in this
months EFY-CD.
circuit
ideas
electroni cs for you Apri l 2010 93 www. e f y mA g . c o m
W
hat binoculars do to im-
prove your vision, this
personal sound enhancer
circuit does for listening. This light-
weight gadget produces an adjustable
gain on sounds picked up from the
built-in high-sensitivity condenser
microphone. So you can hear what you
have been missing. With a 6V (41.5V)
battery, it produces good results.
As shown in Fig. 1, a small signal
amplifier is built around transistor
BC547 (T1). Transistor T1 and the relat-
ed components amplify the
sound signals picked up by
the condenser microphone
(MIC). The amplifed signal
from the preamplifer stage
is fed to input pin 3 of IC
LM386N (IC1) through
capacitor C2 (100nF) and
volume control VR1 (10-kilo-ohm log).
A decoupling network comprising re-
sistor R5 and capacitor C3 provides the
preamplifer block with a clean supply
voltage.
Audio amplifer IC LM386N (IC1)
T.K. HAREENDRAN
SPY EAR
S.C. DW
IVEDI is designed for operation
with power supplies in
the 4-15V DC range. It
is housed in a standard
8-pin DIL package, con-
sumes very small quies-
cent current and is ideal
for battery-powered
portable applications.
The processed out-
put signal from capaci-
tor C2 goes to one end
of volume control VR1.
The wiper is taken to pin 3 of LM386N
audio output amplifer. Note that the
R6-C4 network is used to RF-decouple
positive-supply pin 6 and R8-C7 is an
optional Zobel network that ensures
high frequency stability when feeding
an inductive headphone load.
Capacitor C6 (22F, 16V) wired
between pin 7 and ground gives ad-
ditional ripple rejection. The output of
LM386N power amplifer can safely
drive a standard 32-ohm monophonic
headphone/earphone.
Assemble the circuit on a small
general-purpose PCB and house in
a suitable metallic enclosure with an
integrated battery holder and head-
phone/earphone socket as shown in
Fig. 2. Fit the on/off switch (S1), vol-
ume control (VR1) and power indicator
(LED1) on the enclosure. Finally, ft the
condenser microphone (MIC) on the
front side of the enclosure and link it to
the input of the preamplifer via a short
length of the shielded wire.
Fig. 2: Compact unit of spy ear
Fig. 1: Circuit for spy ear
c o n s t r u c t i o n
electronics for you october 2004
Mandeep Singh Walia
H
eres a stepper motor controller
based on 89C51 microcontroller to
control the rotation of a DC step-
per motor in clockwise and anti-clockwise
directions. The controller is simple and
easy-to-construct, and can be used in many
applications including machine control and
robotics for controlling the axial rotation in
XY plane. A similar circuit can be added to
control the rotation of the motor in either
XZ or YZ plane.
Fig. 1 shows the block diagram of the
stepper motor control system. The power
supply section (in Fig. 2) consists of a step-
down transformer (7.5V AC, 1A), bridge
rectifer (comprising diodes D1 through
D4), flter capacitors (C1 and C2) and
regulator IC 7805.
We have used here an Atmel make
low-power, high-performance, 8-bit CMOS
microcontroller AT89C51 with 4 kB of Flash
programmable and erasable read-only
memory (PEROM). It has a 128x8-bit inter-
nal RAM, 32 programmable input/output
(I/O) lines and two 16-bit timer/counters.
The on-chip Flash allows the program
memory to be reprogrammed in-system
or by a conventional non-volatile memory
programmer.
stEPPEr Motor controL usinG
89c51 MicrocontroLLEr
c o n s t r u c t i o n
s
A
N
I T
H
E
O
stepper motor coils.
When transistors conduct, 5V (Vcc) is
applied to the coils and the currents fow-
ing through them create magnetic felds
and the motor starts rotating. The magnetic
feld energy thus created is stored in the
coils.
When transistors stop conducting,
power to the coils is cut off, the magnetic
feld collapses and a reverse voltage (called
inductive kickback or back emf) is gener-
ated in the coils. The back emf can be
more than 100 volts. The diodes connected
across the coils absorb the reverse voltage
spike. This voltage, if not absorbed by the
diodes, may produce opposite torque and
cause improper rotation of the motor and
also damage the transistors. You can use
virtually any type of rectifer or switching
diodes of appropriate current and reverse
voltage breakdown rating.
Clock and reset circuit. Two 33pF
capacitors (C4 and C5) are connected to
pins 18 and 19 of the microcontroller,
respectively, with an 11.059MHz piezo-
electric crystal (X
TAL1
) across them. The
By combining a versatile 8-bit CPU
with Flash on a monolithic chip, Atmel
AT89C51 is a powerful, highly fexible and
cost-effective solution to many embedded
control applications. From traffc control
equipment to input devices, computer
networking products and stepper motor
controllers, 89C51 microcontrollers deliver
a high performance with a choice of con-
fgurations and options matched to the
specifc needs of each application.
IC AT89C51 features:
1. 8-bit CPU with math registers A
and B
2. 16-bit program counter (PC) and
data pointer (DPTR)
3. 8-bit program status word (PSW)
4. 8-bit stack pointer (SP)
The control switches for the motor are
connected to Reset and Port P
0.7
pins of the
microcontroller.
Circuit description
Fig. 2 shows the complete circuit of the
stepper motor controller. When power
supply switch S1 is closed, LED1 glows
to indicate the presence of power in the
circuit. Capacitor C3 connected to pin 9
(RST) provides the power-on reset to the
microcontroller.
The stepper motor
is connected to port
pins P2.4 through
P2.7 of the microcon-
troller (IC2) through
t he mot or - dr i ver
circuit consisting of
four Darlington pairs
comprising transis-
tors BC548 and SL100
(T1-T2, T3-T4, T5-T6
and T7-T8). Coils
1 through 4 are the
Semiconductors:
IC1 - 7805 5V regulator
IC2 - AT89C51 microcontroller
T1, T3, T5, T7 - BC548 npn transistors
T2, T4, T6, T8 - SL100 npn transistors
D1-D8 - 1N4001 rectifer diodes
LED1 - Red LED (5mm dia.)
Resistors (all -watt, 5% carbon):
R1 - 100-ohm
R2 - 10-kilo-ohm
R3, R5, R7, R9 - 1-kilo-ohm
R4, R6, R8, R10 - 470-ohm
Capacitors:
C1 - 220F, 25V electrolytic
C2 - 100F, 16V electrolytic
C3 - 10F, 16V electrolytic
C4, C5 - 33pF ceramic disk
C6 - 100F, 16V electrolytic
Miscellaneous:
X1 - 230VAC primary to 0-7.5V,
1A secondary step-down
transformer
- 5V DC stepper motor
Parts List
Fig. 1: Block diagram of the stepper motor control system
tabLe i
Power Consumption of Microcontrollers
iC V
oh
i
oh
V
oi
i
oi
V
il
i
il
V
ih
i
ih
P
t
CMOS 2.4V 60 A 0.45V 1.7 mA 0.9V 10 A 1.9V 10 A 50 mW
NMOS 2.4V 80 A 0.45V 1.7 mA 0.8V 800 mA 2.0V 10 A 800 mW
c o n s t r u c t i o n
electronics for you october 2004
clock frequency of the microcontroller
depends on the frequency of the crystal
oscillator used. Typically, the maximum
and minimum frequencies are 1 MHz
and
16 MHz, respectively, so we should use a
piezoelectric crystal with a frequency in
this range. The speed of the stepper motor
is proportional to the frequency of the in-
put pulses or it is inversely proportional to
the time delay between pulses, which can
be achieved through software by making
use of instruction execution time.
The time taken by any instruction to
get executed can be computed as follows:
where C is the number of cycles an in-
struction takes to execute and F is the
crystal frequency.
The crystal frequency in this circuit
is 11.059 MHz, so the time taken to
execute, say, ADD A, R1 (single-cycle
instruction), is about one microsecond
(s). Use of a 6MHz crystal will bring
down the instruction execution speed to
to 2 s.
When power is applied, the reset input
must frst go high and then low. A resistor-
capacitor combination (R1-C3) is used to
achieve this until the capacitor begins to
charge. At a threshold of about 2.5V, the
reset input reaches a low level and the mi-
crocontroller begins to function normally.
Reset switch (S2) allows you to reset the
program without having to interrupt the
power.
One major feature of 89C51 microcon-
troller is the versatility built into the I/O
circuits that connect the microcontroller to
the outside world. Ports P0 through P3 of
the microcontroller are not capable of driv-
ing loads that require tens of milliamperes
(mA). Logic level current, voltage and
power requirement for different versions of
microcontrollers are given in Table I.
Driver circuit design. The microcon-
troller outputs a current of 1.7 mA. To
drive the coil of a stepper motor requir-
ing a torque of 7 kg-cm, 12V DC and 2
amp/phase, we have to use a driver circuit
that amplifes the current from 1.7 mA to
3 amp.
As mentioned earlier, we have used
BC548 and SL100 as the driver transis-
tors for driving a low-power rated stepper
motor such as the one used in earlier
14cm (5.5-inch) foppy drives. But for a
7 kg-cm stepper motor, a driver circuit us-
ing transistors SL100 and 2N3055 would
be needed to amplify the current to 2.72
amp. Typically, SL100 and 2N3055 each
Time=
C12
F
c o n s t r u c t i o n
electronics for you october 2004
= 2.72 A
Since the stepper motor has four coils,
we need to use four Darlington pairs.
programming
The program is written in Assembly lan-
guage and compiled using ASM51 cross-
assembler. The listing fle is given at the
end of this article. 89C51 microcontroller
is programmed using Atmels Flash pro-
grammer.
One-step rotation of the stepper motor
used in this project equals 1.8
o
. When you
program the motor for 200 steps, the motor
makes one complete revolution, i.e. 360
o
.
In the program, the line MOV R7, #0CAH
Fig. 3: Flow-chart of the program
has a gain (h
fe
) of 40, but 2N3055 can
handle larger current since it belongs
to the family of power transistors. So a
heat-sink is required to dissipate the heat
generated.
The output gain of the Darlington pair
of SL100 and 2N3055 transistors is:
A
Vo
= A
V1
A
V2
= 4040
= 1600
A
Vo
= Io/Iin = 1600
where Io is the output current and Iin is
the input current of the Darlington pair.
Io = 16001.7 mA
defnes the rotation by 202 steps. The
hex number 0CAH equals the decimal
number 202. However, one can change
the number of steps in the program as per
ones requirement.
The step sequence is defned by the
line MOV A, #033H. Table II shows the
step sequence for 100 steps to energise the
windings of the stepper motor in clockwise
and anti-clockwise directions. The rotor of
the stepper motor is in a position of mini-
mum reluctance and maximum fux. Thus
by energising the windings (represented
by A1, A2, B1 and B2), the rotor takes
the position accordingly. In the program,
the instructions RR A and RL A are
used for clockwise and anti-clockwise,
Fig. 4: Actual-size, single-side pcB for stepper motor control
system using 89c51 microcontroller
Fig. 5: component layout for the pcB
tabLe ii
Clockwise step sequence of the Motor
a1 a2 b1 b2 a1 a2 b1 b2 Hex value
0 0 1 1 0 0 1 1 =33h
0 1 1 0 0 1 1 0 =66h
1 1 0 0 1 1 0 0 =CCh
1 0 0 1 1 0 0 1 =99h
anti-clockwise step sequence of the Motor
a1 a2 b1 b2 a1 a2 b1 b2 Hex value
0 0 1 1 0 0 1 1 =33h
1 0 0 1 1 0 0 1 =99h
1 1 0 0 1 1 0 0 =CCh
0 1 1 0 0 1 1 0 =66h
c o n s t r u c t i o n
electronics for you october 2004
STpB1.lST
1 $MOD51
0000 2 ORG 0000H
0000 E580 3 MOV A, P0
0002 33 4 RLC A
0003 500B 5 JNC P12
6
0005 7FCA 7 MOV R7, #0CAH;
0007 7433 8 MOV A, #033H;
0009 F5A0 9 P13: MOV P2, A;
000B 23 10 RL A;
000C 111B 11 ACALL DELAY
000E DFF9 12 DJNZ R7, P13
13
0010 7FCA 14 P12: MOV R7, #0CAH;
0012 7433 15 MOV A, #033H;
0014 F5A0 16 P11: MOV P2, A;
0016 03 17 RR A;
0017 111B 18 ACALL DELAY
0019 DFF9 19 DJNZ R7, P11
20
21
001B 758910 22 DELAY: MOV TMOD, #10H
001E 7B05 23 MOV R3, #05
0020 758B08 24 Z: MOV TL1, #8D
0023 758D01 25 MOV TH1, #1D
0026 D28E 26 SETB TR1
0028 308FFD 27 BACK: JNB TF1, BACK
28
002B C28E 29 CLR TR1
002D C28F 30 CLR TF1
002F DBEF 31 DJNZ R3, Z
0031 22 32 RET
33 END
VERSION 1.2k ASSEMBLY COMPLETE, 0 ERRORS
FOUND q
respectively.
S1 and S3 are toggle switches, while
S2 is a tactile switch. Switch S3 interfaced
to pin 32 of the microcontroller determines
the direction of rotation. When the switch
is opened the motor rotates in clockwise
direction, and when the switch is closed
the motor rotates in anti-clockwise direc-
tion.
For anti-clockwise rotation of the
motor, reset switch S2 is to be pressed
momentarily after S3 is closed (see Fig. 3).
In case you observe an abnormal motion
of the motor either in clockwise or anti-
clockwise direction, pressing reset switch
S2 momentarily will make the motor run
smoothly.
Construction and working
You can assemble the circuit on any gen-
eral-purpose PCB. An actual-size, single-
side PCB for the stepper motor controller is
shown in Fig. 4 and its component layout
in Fig. 5.
Mount a 40-pin IC base for the micro-
controller on the PCB, so you can remove
the chip easily when required. Normally,
six wires of different colours (two being
red) are available for connection to the
stepper motor. The sequence for connect-
ing the stepper motor coils to the driver
card is shown in Fig. 2.
After you are done with the hardware
part, assemble the program (stpb1.asm) us-
ing ASM51 assembler. Load the hex fle gener-
ated by ASM51 into a programmer and burn
it into the chip. Now put the programmed
chip on the IC base on the PCB.
Switch on the power supply to the
circuit using switch S1. If motor rotation
is not stable, press S2 momentarily. If the
motor does not move at all, check the
connections.
Note. The source code and the relevant
fles for this article have been included in
this months EFY-CD.
circuit
ideas
www. e f y ma g . c o m electroni cs for you may 2008 73
D. Mohan KuMar
SunSet LaMp S.C. DWIVEDI
L
DR-based automatic lights
ficker due to the change in light
intensity at dawn and dusk.
So compact fuorescent lamps (CFLs)
are unsuitable in such circuits as
fickering may damage the electronic
circuits within these lamps. The circuit
described here can solve the problem
and switch on the lamp instantly when
the light intensity decreases below a
preset level.
The circuit uses popular timer IC
NE555 (IC1) as a Schmitt trigger to give
the bistable action. The set and reset
functions of the comparators within
the NE555 are used to give the instan-
taneous action. The upper threshold
comparator of IC1 trips at 2/3Vcc,
while the lower trigger comparator
trips at 1/3Vcc. The inputs of both the
threshold comparator and the trigger
comparator of NE555 (pins 6 and 2)
are tied together and connected to the
voltage divider formed by LDR1 and
VR1. The voltage across LDR1 depends
on the light intensity.
In daylight, LDR1 has low resist-
ance and the input voltage to the
threshold comparator goes above
2/3Vcc and its output becomes zero,
which resets the internal fip-fop of
IC1. But the input to the trigger compa-
rator is still more than 1/3Vcc, which
keeps output pin 3 of IC1 low. Triac
BT136 connected to output pin 3 of IC1
remains quiescent due to insuffcient
value of current for fring it. Thus lamp
L1 remains off during daytime.
At sunset, the resistance of LDR1
increases, and the voltage at the input
of the threshold comparator decreases
below 2/3Vcc and that of the trigger
comparator goes below 1/3Vcc. As a
result, the outputs of threshold and
trigger comparators go high, which
sets the fip-fop. This changes output
pin 3 of IC1 from low to high. Triac1
gets the necessary gate current
through resistor R2 and fres.
Thus it completes the power
supply to the lamp through
Triac1. LED1 glows to indicate
the high output state of IC1.
Power supply to the circuit
is directly derived from the
mains through capacitor C4.
This capacitor delivers cur-
rent in the circuit. Diodes D1
and D2 rectify the AC from
capacitor C4 and capacitor
C3 provides the necessary
smoothing. Zener diode ZD1
provides rectifed 15V DC for
the circuit. Bleeder resistor R4
removes the stored voltage of
the capacitor when the circuit
is unplugged.
Assemble the circuit on any gen-
eral-purpose PCB and enclose in a
plug-in type adaptor box. Connect
the live and neutral points to the pins
of the adaptor box. Provide in the box
5mm holes for LDR1 and LED1. Plug
the unit at a place where daylight is
suffcient to inhibit the circuit op-
eration during daytime. Light from
the lamp should not fall on LDR1 at
night.
Caution. The circuit carries 230V
AC and most of its points are at mains
lethal potential. So do not touch any
point in the circuit when it is powered
and adjust the preset only with a plas-
tic or insulated screwdriver.
circuit
ideas
94 December 2009 electroni cs for you www. e f y ma g . c o m
T
oday telephone has become
an integral part of our lives.
It is the most widely used
communication device in the world.
Owing to its immense popularity and
widespread use, there arises a need for
call recording devices, which fnd ap-
plication in call centres, stock broking
frms, police, offces, homes, etc.
Here we are describing a call re-
corder that uses very few components.
But in order to understand its working,
one must frst have the basic knowl-
edge of standard telephone wiring and
a stereo plug.
In India, landline telephones pri-
marily use RJ11 wiring, which has
two wirestip and ring. While tip is
the positive wire, ring is the negative
one. And together they complete the
telephone circuit. In a telephone line,
voltage between tip and ring is around
48V DC when handset is on the cradle
(idle line). In order to ring the phone
for an incoming call, a 20Hz AC cur-
rent of around 90V is superimposed
over the DC voltage already present in
the idle line.
The negative wire from the phone
line goes to IN1, while the posi-
tive wire goes to
IN2. Further, the
negative wire from
OUT1 and the posi-
tive wire from OUT2
are connected to the
phone. All the resis-
tors used are 0.25W
carbon flm resistors
and all the capaci-
tors used are rated for 250V or more.
The negative terminal of To AUX IN
is connected to pin 1 of the stereo jack
while the positive terminal is con-
nected to pins 2 and 3 of the stereo
jack. This stereo jack, in turn, is con-
nected to the AUX IN of any recording
device, such as computer, audio cas-
sette player, CD player, DVD player,
etc. Here we shall be connecting it to
a computer.
When a call comes in, around 90V
AC current at 20Hz is superimposed
over the DC voltage already present in
the idle line. This current is converted
into DC by the diodes and fed to resis-
tor R1, which reduces its magnitude
and feeds it to LED1. The current is
further reduced in magnitude by the
resistor R2 and fed to the right and
left channels of the stereo jack, which
are connected to the AUX IN port of a
computer.
Any audio recording software,
such as AVS audio recorder (available
at: http://www.avs4you.com/AVS-
Audio-Recorder.aspx), Audacity audio
recorder (http://audacity.sourceforge.
net/), or audio recorder (http://www.
audio-tool.net/audio_recorder_for
_free.html), can be used to record the
call. When a call comes in, one needs
to launch the audio recording software
and start recording.
For phone recording, simply con-
nect the stereo jack to the AUX IN
port of the PC. Install the Audacity
audio recorder (different versions are
available for free for different op-
erating systems at http://audacity.
sourceforge.net/) on your PC. Run
the executable Audacity fle. In the
main window, you will fnd a drop-
down box in the top right corner.
From this box, select the AUX option.
Now you are ready to record any call.
As soon as a call comes in, press the
record button found in the Audacity
main window and then pick up the
telephone receiver and answer the
call. Press the stop button once the
call ends. Now go to the fle menu and
select the Export as WAV option and
save the fle in a desired location.
You may change the value of resis-
AlizishAAn KhAtri
telephone cAll recorder
S.C. DW
IVEDI
Fig. 1: Call recorder circuit
Fig. 2: Pin confguration of stereo jack
Fig. 3: RJ connector
circuit
ideas
electroni cs for you December 2009 95 www. e f y ma g . c o m
tor R2 if you want to change the output
volume. You can use a variable resistor
in series with R2 to vary the volume of
the output. The recorded audio clip can
be edited using different options in the
Audacity software.
You can assemble the circuit on a
general-purpose PCB and enclose it in
a small cabinet. Use an RJ11 connec-
tor and stereo jack for connecting the
telephone set and computer (for call
recording). Telephone cords can be
used to connect to the phone line and
the circuit. Use of a shielded cable is
recommended to reduce disturbances
in the recording. These can also be
reduced by increasing the value of R2
to about 15 kilo-ohms.
EFY note. Audacity recording
software is included in this months
EFY-CD under Utilities section.
CirCuit ideas
84
ElEctronics For You octobEr '99
H
ere is a teleremote cir-
cuit which enables
switching on and off
of appliances through telephone
lines. It can be used to switch
appliances from any distance,
overcoming the limited range
of infrared and radio remote
controls.
The circuit described here
can be used to switch up to
nine appliances (corresponding
to the digits 1 through 9 of the
telephone key-pad). The DTMF
signals on telephone instrument
are used as control signals. The
digit 0 in DTMF mode is used
to toggle between the appliance
mode and normal telephone
operation mode. Thus the tele-
phone can be used to switch on
or switch off the appliances also
while being used for normal
conversation.
The circuit uses IC KT3170
(DTMF-to-BCD converter),
74154 (4-to-16-line demult-
iplexer), and fve CD4013 (D
fip-fop) ICs. The working of
the circuit is as follows.
Once a call is established
(after hearing ring-back tone),
dial 0 in DTMF mode. IC1
decodes this as 1010, which is
further demultiplexed by IC2
as output O
10
(at pin 11) of IC2
(74154). The active low output
of IC2, after inversion by an
inverter gate of IC3 (CD4049),
becomes logic 1. This is used
to toggle flip-flop-1 (F/F-1)
and relay RL1 is energised.
Relay RL1 has two changeover
contacts, RL1(a) and RL1(b).
The energised RL1(a) contacts
provide a 220-ohm loop across
the telephone line while RL1(b)
contacts inject a 10kHz tone on
the line, which indicates to the
caller that appliance mode has
been selected. The 220-ohm loop
on telephone line disconnects the ringer
from the telephone line in the exchange.
The line is now connected for appliance
mode of operation.
If digit 0 is not dialed (in DTMF)
after establishing the call, the ring
R.G. KaLe
Teleremote Control
CirCuit ideas
85
ElEctronics For You octobEr '99
continues and the telephone can be used
for normal conversation. after selection
of the appliance mode of operation, if
digit 1 is dialed, it is decoded by IC1
and its output is 0001. This BCD code
is then demultiplexed by 4-to-16-line
demultiplexer IC2 whose corresponding
output, after inversion by a CD4049
inverter gate, goes to logic 1 state. This
pulse toggles the corresponding fip-fop
to alternate state. The fip-fop output
is used to drive a relay (RL2) which
can switch on or switch off the appli-
ance connected through its contacts. By
dialing other digits in a similar way,
other appliances can also be switched
on or off .
Once the switching operation is
over, the 220-ohm loop resistance and
10kHz tone needs to be removed from
the telephone line. To achieve this,
digit 0 (in DTMF mode) is dialed again
to toggle fip-fop-1 to de-energise relay
RL1, which terminates the loop on line
and the 10kHz tone is also disconnected.
The telephone line is thus again set free
to receive normal calls.
This circuit is to be connected in
parallel to the telephone instrument.
cONSTRUcTION
70 May 2010 electroni cs for you www. e f y Ma g . c o M
AnshumAn BezBorAh
PIC16F877A-based Temperature
monitoring system
S.V.N. HARISH K.
T
emperature monitoring and
control is important in indus-
trial environments. Sensors
are widely used for measurement of
temperature. Usually, a temperature
sensor converts the temperature into
an equivalent voltage output. IC LM35
is such a sensor. Here we describe a
simple temperature measurement and
display system based on LM35 sensor
and PIC16F877A microcontroller. The
temperature in degrees Celsius is dis-
played on a 162 LCD.
Fig. 1 shows the functional block
diagram of the PIC16F877A-based
temperature monitoring system. The
key features of this system are:
1. Continuous monitoring of tem-
perature with 1-second update interval
(which can be varied in the program)
2. Temperature measurement us-
ing LM35 precision integrated-circuit
sensor
3. Precise analogue-to-digital con-
version using in-built 10-bit ana-
logue-to-digital converter (ADC) of
PIC16F877A microcontroller
hardware description
Fig. 2. shows the circuit of the tem-
perature monitoring system. The
circuit mainly consists of the LM35
temperature sensor, PIC16F877A mi-
crocontroller and HD44780 controller
based 162 LCD.
The output of the sensor is fed to
the internal ADC of the micocontrol-
ler. Pin 2 of the microcontroller (RA0/
AN0) is channel-1 of the internal ADC.
The analogue voltage output of the
sensor is converted into its equivalent
digital value by the ADC and then its
equivalent degree Celsius value is cal-
culated by the software. The calculated
temperature value is displayed on the
LCD.
LM35 sensor. Fig. 3 shows the pin
confguration of LM35. It is a precision
integrated-circuit centigrade tempera-
ture sensor whose output voltage is
linearly proportional to the Celsius
(Centigrade) temperature. The LM35
thus has an advantage over linear tem-
perature sensors calibrated in degree
Kelvin, as the user is not required to
subtract a large constant voltage from
its output to obtain convenient Centi-
grade scaling. For each degree Celsius
change in temperature, the sensor out-
put changes by 10 mV.
Fig. 1: Block diagram of PIC16F877A-based temperature monitoring system
Fig. 2: Circuit of PIC16F877A-based temperature monitoring system
cONSTRUcTION
electroni cs for you May 2010 71 www. e f y Ma g . c o M
The sensor can measure tempera-
ture in the range of 0 to 100C, i.e., the
output of the sensor varies from 0 to
1000 mV. The LM35 operates over the
temperature range of -55 to +150C,
while the LM35C is rated for a -40C
to +110C range (-10C with improved
accuracy).
Pin layout of the sensor is as fol-
lows:
Pin 1-V
DD
Pin 2-Output of the sensor
Pin 3-V
SS
PIC16F877A microcontroller. IC
PIC16F877A is an 8-bit microcontroller
with 8k14-bit fash program memory,
368 bytes of RAM and many other
extra peripherals like ADC, universal
synchronous asynchronous receiver
transmitter, master synchronous se-
rial port, timers, compare capture and
pulse-width modulation modules, and
analogue comparators. It is based on
the reduced instruction set computer
(RISC) architecture.
The microcontroller processes the
sensor output to compute the tempera-
ture in degree Celsius. The internal
ADC of the microcontroller is used to
convert the analogue output of the sen-
sor into its equivalent digital value.
The internal ADC of the microcon-
troller has eight channels of analogue
i nput and
gives 10-bit
digital out-
put. In this
project, the
r e f e r e n c e
vol t age t o
the ADC is
the same as
the supply voltage to the microcontrol-
ler, i.e., 5V. The resolution of the ADC
can be calculated as follows:
(as it is a 10-bit ADC)
= 5/1023
= 4.887 mV
It means that for 4.887mV change
in the analogue input, the ADC output
changes by binary 1 with a reference
voltage of 5V.
Analogue output of the sensor at its
pin 2 is connected to Port A at RA0 for
conversion into digital equivalent.
The LCD. A 162 LCD based on
HD44780 controller is used for display-
ing the temperature. The control lines
EN, R/W and RS of the LCD module
are connected to pins RA1, RA2 and
RA3 of Port A of the microcontrol-
ler, respectively. The commands and
the data to be displayed are sent to
the LCD module in the nibble mode
from Port D of the microcontroller.
The higher four bits of the LCD (D4
through D7) are connected to the lower
nibble of Port D (RD0 through RD3).
software description
The software code is written in C
language and compiled using Hitech
C cross compiler in MPLAB IDE. The
software performs the following opera-
tions in an infnite loop:
1. Initiate analogue-to-digital con-
version and obtain the result
2. Calculate the equivalent voltage
value from the ADC result
3. Calculate the temperature in de-
gree Celsius from the voltage value
4. Display the temperature on the
LCD
The voltage output (in volts) of the
sensor is:
The temperature in degree Celsius
is:
= Sensor output 100
The Hitech C cross-compiler pro-
vides foating-point library support
that is required for doing the above
calculations.
MPLAB IDE and Hitech C com-
piler. MPLAB IDE is a very power-
ful software development tool for
Microchip products (microcontrol-
lers). It is available for download at
www.microchip.com free of cost.
It consists of tools like text editor,
cross-assembler, cross-compiler and
simulator.
Hitech C cross compiler is meant
for Microchip PIC10/12/16 series of
microcontrollers. Its Lite edition comes
free with newer versions of MPLAB
IDE like MPLAB v8.2 and v8.3. It can
also be downloaded for free from
www.htsoft.com.
Compiling the program using
MPLAB IDE. The steps follow:
1. Create project fle and add source
fles. In the menu bar, click Project
Project Wizard. The project wizard
dialogue box appears. Click Next.
In Next window, select the device
as PIC16F877A from the drop-down
menu. Click Next and select Hitech
Universal Tool suite from the drop-
down menu. Click Next, name your
project fle as tempr and specify its
location. The fle is automatically saved
with .mcp extension. Click Next and
add source fles tempr.c, lcd.c and de-
lay.c to your project. If you want to cre-
ate the source fles on your own, you
can skip the above step. Click Next
Finish button. Now your project is cre-
ated and the source fles are added to
your project.
2. Create and add source files of
your own. After creating the project,
proceed with typing the code. Open
a new text file by clicking New in
File menu. Type the code in the
text editor and save it with .c
ParTs LisT
Semiconductors:
IC1 - 7805 voltage regulator
IC2 - PIC16F877A
microcontroller
IC3 - LM35 temperature sensor
LED1 - 5mm light-emitting diode
Resistors (all -watt, 5% carbon):
R1 - 10-kilo-ohm
R2 - 470-ohm
VR1 - 10-kilo-ohm preset
Capacitors:
C1 - 1000F, 25V electrolytic
C2 - 0.1F ceramic
C3-C4 - 22pF ceramic
Miscellaneous:
X
TAL1
- 4MHz crystal oscillator
D1-D4 - IN4007 diode
S1 - Push-to-on switch
X1 - 230V AC primary to 0-9V,
300mA secondary
transformer
- HD44780 based 162 LCD
display
Fig. 3: Pin confgurations of
7805 and LM35
Resolution =
(1024-1)
Vref
1023
ADC result 5
Sensor output 1000
10
cONSTRUcTION
72 May 2010 electroni cs for you www. e f y Ma g . c o M
extension. You can create source
files tempr.c, delay.c and lcd.c in
this manner. After typing and saving
the code, you have to add the source
files to your project. In Project
menu, click Add Files to Project
and then add the files by browsing
them from the location they are
saved in.
3. Confgure the system. To con-
fgure features like type of oscillator
and WDT, click Configure menu
and then click Confguration Bits. In
the confguration bits window, select
the type of oscillator as XT, and dis-
able all other features like watchdog
timer, power-up timer and brownout
detect.
4. Compile the project. To compile
the software, click Build option in
Project menu. The software is com-
piled and Build Successful message
appears in the output window. After
successful compilation of the program,
the fle tempr.hex is generated.
Downloading the software into
the chip. After compiling the soft-
ware, the hex fle generated can be
Fig. 4: A single-side, actual-size PCB layout for PIC16F877A-based temperature monitoring system
Fig. 5: Component layout for the PCB
downloaded into the chip either us-
ing a locally made programmer (like
JMD programmer) or Microchips
programming kit (PICKit2, PICKit3,
ICD2, ICD3, etc).
We have used Microchip MPLAB
ICD2 (in-circuit debugger) to burn the
program into PIC16F877A microcon-
troller.
The programming can be done
from MPLAB IDE itself by selecting
the kit (MPLAB ICD2) from Program-
mer menu in the menu bar. If you use
a JMD programmer, the hex fle can
be downloaded into the chip using
WinPic800 software. The confguration
bits have to be separately confgured in
WinPic800.
Construction
A single-side, solder-side PCB layout
of the temperature monitoring system
is shown in Fig. 4 and its component
layout in Fig. 5.
A 230V AC primary to 0-9V AC
secondary step-down transformer is
used to step down the 230V mains
supply. The output of the transformer
is rectified using a bridge rectifier
consisting of diodes D1 through D4
and regulated to 5V using 7805 volt-
age regulator. The glowing of the LED
(LED1) indicates the presence of 5V
supply in the circuit.
The analogue output of the tem-
perature sensor LM35 (IC3) from its
pin 2 is connected to RA0/AN0 pin of
PIC16F877A microcontroller (IC2). A
4MHz crystal (X
TAL1
) is connected to
pins 13 and 14 of the microcontroller.
The 16x2 LCD is interfaced with the
microcontroller using Port A and Port
D. The control signals for the LCD are
provided using Port-A pins RA1, RA2
and RA3. The command and data for
the LCD are provided using Port-D
pins RD0 through RD3. The remain-
ing power supply connections are as
shown in Fig. 2.
EFY note. The source code of
this article has been included in
this months EFY-CD. It is also
avai l abl e on www. efymag. com
website.
CirCuit ideas
90
ElEctronics For You octobEr '99
sen for operation of the circuit. To obtain
6V supply one may either use fve Ni-Cd
cells or four dry cells. A charger circuit
is not included here as a host of charger
circuits have appeared in EFY on and
off. However, you may use a standard
bridge rectifer with 7806 as regulator
for the power supply and charger.
Pressing the reset button momen-
tarily pulls all the internal counters
of CD4060 to zero and the timer starts
again. The timer is reliable, accurate,
and consumes about 10 mA of current
when the buzzer is active.
Piezo-electric buzzers are reliable,
rugged, and serve as cheap audio
alarms. They are available for operation
in continuous and intermittent modes,
and also with musical notes. However,
if you ever require louder sound, say for
a classroom, then you have an optional
555 circuit wired up as an astable mul-
tivibrator. This can be brought into
operation by shorting points x-x in the
circuit.
T
hese are the days of competitive
examinations. Nowadays, stu-
dents are required to answer a set
of objective type of questions in a given
time which may extend to 15 minutes,
30 minutes, or one hour. Speed and ac-
curacy win the race. Practice helps in
achieving it.
Here is a timer that gives an alarm
after a preset time of 30 minutes. It also
gives out a few beeps at half the selected
time period. The timer could be pro-
grammed for other periods as well. The
alarm can be reset for a fresh start.
The heart of the circuit is a CMOS
IC CD 4060. It has a built-in oscillator
and a 14-stage divider, wherein the
basic oscillator frequency is divided by
16,384. Here the oscillator frequency
may be set using potmeter VR1 (in
series with resistor R1) and capacitor
C1. Potmeter VR1 is adjusted for a time
period of 15 minutes at output Q12 (pin
2). The output Q13 (pin 3) will go high
after 30 minutes. Use a multi-turn pot-
meter for better accuracy.
When Q13 goes high, the 3-terminal
piezo-buzzer becomes active and gives
out a tone. This buzzer also beeps at
half the time for a few seconds. Transis-
tor T1 prevents further oscillations after
the lapsed time. Red LED1 is used as
activity indicator.
For simplicity, 6-volt supply is cho-
Timer for Students
K.K. MURTY
C I R C U I T I D E A S
ELECTRONICS FOR YOU DECEMBER 2003
Pin Assignments of IC TT6061A
Pin No. Pin name Function description
1 CK System clock input
2 FI 50Hz line frequency
3 V
DD
Power input pin for V
DD
4 TI Touch input
5 CI Sensor control input
6 NC Not connected
7 V
SS
Power input pin for V
SS
8 AT Angle-trigger output
TOUCH DIMMER
S
.C
. D
W
IV
E
D
I
K. KRISHNA MURTY
B
y simply touching this touch dim-
mer you can increase the light in-
tensity of incandescent lamps in
three steps. The touch dimmer is built
around 8-pin CMOS IC TT8486A/TT6061A
specifically manufactured for touch dim-
mer applications.
Initially, when mains switch is on,
the bulb is off. Now, if you touch the
touch plate, the bulb glows dimly. On
second touch, the bulb gives medium light.
At the third touch, the bulb is driven
fully. Another touch puts off the light.
Since the IC is highly sensitive, use a
long wire to connect the IC to the touch
sensor. The circuit uses minimum exter-
nal components. For touch plate, you can
use a simple copper plate of 1cm1cm or
even the end of the lead wire. Touch plate
is coupled to the touch detector through
820pF, 2kV capacitors C1, C2, and C3 con-
nected in series. Internally IC TT6061As
touch signal is connected to the counter/
decoder via a resistor and clock input CK
is connected to the counter/decoder via a
frequency generator.
Line frequency signal is taken through
R4 at pin 2 of IC TT6061A. At zero cross-
ing, the triac (BT136) triggers to drive a
200W bulb.
The 6.8V power supply is taken di-
rectly from mains through resistors R1 and
R3, diode D3, capacitor C4, and zener
diode and fed to power-input pin 3 of the
IC. Capacitors C1, C2, and C3 connected
between touch input pin 4 and touch plate
remove the shock potential from the touch
plate, so do not replace these capacitors
with a single capacitor or with a capacitor
of a lower voltage rating. Mains potential
exists in the circuit. Needless to say, it is
dangerous to touch the circuit when mains
is on.
Note. The IC had been procured by
the author from SM Semiconductors,
Santacruz (W), Mumbai.
CONSTRUCTION
92 JANUARY 2008 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
PROF. K. PADMANABHAN
MICROCONTROLLER-BASED
TACHOMETER
SUNIL KUMAR
A
tachometer is nothing but a
simple electronic digital trans-
ducer. Normally, it is used for
measuring the speed of a rotating
shaft. The number of revolutions per
minute (rpm) is valuable information
for understanding any rotational sys-
tem. For example, there is an optimum
speed for drilling a particular-size hole
in a particular metal piece; there is an
ideal sanding disk speed that depends
on the material being finished. You
may also want to measure the speed
of fans you use.
This easy-to-make photoelectric
tachometer measures the rpm of most
shop-floor tools and many household
machines without any mechanical or
electrical interface.
How it works?
Just point the light-sensitive probe tip
atop the spinning shaft towards the
spinning blade, disk or chuck and read
the rpm. The only requirement is that
tion it such that the intensity of light
reflected from the objects surface
changes as it rotates.
Each time the tape spins past
the probe, the momentary increase
in reflected light is detected by the
phototransistor. The signal processor
and microcontroller circuit counts
the increase in the number of such light
reflections sensed by it and thereby
evaluates the rpm, which is displayed
on the 4-digit, 7-segment display.
The phototransistor is kept inside
a plastic tube, which has a convex lens
fitted at one end. A convex lens of
about 1cm diameter and 8-10cm focal
length is a common item used by
watch repairers and in cine film viewer
toys. It can be obtained from them to
set up the experiment. The
phototransistor is fixed on a piece of
cardboard such that it faces the lens at
a distance of about 8 cm. The leads
from the phototransistor are taken out
you first place a contrasting colour
mask. A strip of white adhesive tape
is ideal on the spinning object. Posi-
Fig. 1: Circuit of microcontroller-based tachometer
PARTS LIST
Semiconductors:
IC1 - AT89C2051
microcontroller
IC2 - ULN2003 current buffer
IC3 - CA3140 operational
amplifier
T1-T4 - BC557 pnp transistors
T5 - 2N2222 npn transistor
T6 - L14F1 photo-transistor
D1 - 1N4007 rectifier diode
DIS1 - KLQ564 4-digit,
7-segment display
Resistors (all -watt, 5% carbon):
R1-R4 - 1-kilo-ohm
R5, R6 - 10-kilo-ohm
R7-R11 - 1.2-kilo-ohm
RNW1 - 10-kilo-ohm resistor
network
VR1 - 4.7-kilo-ohm preset
Capacitors:
C1 - 10F, 16V electrolytic
C2, C5, C6 - 0.1F ceramic disk
C3, C4 - 22pF ceramic disk
Miscellaneous:
S1 - Push-to-on switch
S2 - On/Off Switch
X
TAL
- 12MHz
BATT. - 6V battery
CONSTRUCTION
94 JANUARY 2008 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
and connected in the
circuit shown in Fig. 1.
Fig. 2 shows the suit-
able arrangement of
phototransistor.
The detected signal
is amplified by transis-
tor 2N2222 (T5) and
further amplified by
operational amplifier
CA3140 (IC3). The reference voltage
point for the operational amplifier is
obtained by resistor divider network
comprising R2 and R3. The output
from pin 6 of IC3 is fed to pin 12 of
microcontroller AT89C2051. Note that
pins 12 and 13 of microcontroller
AT89C2051 are the inputs (+ and -) of
its internal analogue comparator. Pin
13 is adjusted to nearly half the sup-
ply voltage using a potential divider
comprising resistor R7 and preset VR1
across the supply.
The pulses picked up by the
phototransistor are sensed by the in-
ternal comparator of AT89C2051 and,
through software, each pulse repre-
senting one rotation of the object is de-
tected. By counting the number of such
pulses, on an average per minute ba-
sis, the RPM is evaluated. It is dis-
played by a software routine to light
up the LED segments of the 4-digit, 7-
segment display.
Circuit description
Fig. 1 shows the circuit of the
microcontroller-based tachometer. The
tachometer comprises AT89C2051
microcontroller, ULN2003 high-current
Darlington transistor array, CA3140
operational amplifier, common-anode
7-segment (4-digit multiplexed) dis-
play and its four anode-driving tran-
sistors.
The AT89C2051 is a 20-pin,
8-bit microcontroller of Intels
8051 family made by Atmel Cor-
poration. Port-1 pins P1.7
through P1.2, and port-3 pin P3.7
are connected to input pins 1
through 7 of ULN2003. Port-1
pins are pulled up with 10-kilo-
ohm resistor network RNW1.
They drive all the seven seg-
ments of the display with the
help of internal inverters.
Fig. 2: Suitable arrangement of phototransistor
Fig. 3: Pin
configuration of
transistor BC557
Port-3 pins P3.0 through P3.3 of the
microcontroller are connected to the
base of transistors T1 through T4, re-
spectively, to select one digit out of
the four at a time and to supply an-
ode-drive currents to the common an-
ode pin of respective digit. Pin con-
figuration of transistor BC557 is shown
in Fig. 3.
When pin P3.0 of microcontroller
IC1 goes low, it drives transistor T1
into saturation, which provides the
drive current to
anode pin 6 of 4-
digit, 7-segment,
common-anode
display DIS1.
Similarly, transis-
tors T2 through
T4, respectively,
provide supply
to common-an-
ode pins 8, 9 and
12 of DIS1. Thus
microcontroller
IC1 drives the
segment in mul-
tiplexed manner
using its port
pins. This is time-
division multi-
plexing process.
Segment data
and display-en-
able pulse for
display are re-
freshed every 5
ms. Thus, the dis-
play appears to
be continuous
even though it
lights up one by
one.
Switch S1 is
used to manually
reset the
microcontroller,
while the power-
on-reset signal
for the
microcontroller is
given by C1 and
R6. A 12MHz
crystal is con-
nected to pins 4
and 5 of IC1 to
Fig. 4: A single-side, actual-size PCB layout for microcontroller-based
tachometer
Fig. 5: Component layout for the PCB
CONSTRUCTION
96 JANUARY 2008 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
TACHO.ASM
$mod51
ORG 0H
AJMP 30H
ORG 0BH ;TIMER 0 INTERRUPT VECTOR
AJMP TIMER0ISR ;Timer 0 Interrupt service rou-
tine address
ORG 30H
MOV SP,#60H ;set stack pointer
MOV P3,#0FFH ;set all port 3 bits high to enable in-
puts also
MOV P1,#03 ;set port 1 to all zeros expect bits 0,1
MOV TMOD,#01100001B ;TIMER 1 - MODE 2
COUNTER,TIMR-0 TO 16 bit timer
BEG: MOV TH0,#0ffH ;TIMER REG.0 IS SET TO 0,
GIVES 64ms
MOV TL0,#-99 ; timer low reg. is also so
setb et0
setb ea
mov 44h,#0
mov 45h,#0
acall delay
ajmp lowsig
delay: mov r2,#10
djnz r2,$ ;wait 20 us
ret
lowsig: jb p3.6,lowsig
call delay
jnb p3.6,$
setb tr0 ; start timer
mov c,p3.6 ;high begins
mov p3.5,c
acall delay
jb p3.6, $
mov c,p3.6 ;low now
mov p3.5,c
acall delay
jnb p3.6,$
mov c,p3.6 ;high begins again
mov p3.5,c
clr tr0 ;stop timer
clr et0 ;and interrupt by timer
mov r3,#0 ;number 600000 or 927c0 hex as Dividend
mov r2,#09h ; 9
mov r1,#27h ;27
mov r0,#0c0h ; c0
mov r5,45h ;divisor is time for one cycle
mov r4,44h
call UDIV32 ;divide 60000/t
mov 40h,r0
mov 41h,r1
mov r1,41h
mov r2,40h
CALL HEX2BCD
mov 50h,#0FFH
call refresh
disp: call refresh1
djnz 50h,disp ; so many times for a visible time limit
jmp beg
;16 Bit Hex to BCD Conversion for 8051 Microcontroller
;This routine is for 16 bit Hex to BCD conversion;
;Accepts a 16 bit binary number in R1,R2 and returns 5
digit BCD in ;R7,R6,R5,R4,R3(upto 64K )
Hex2BCD: ;r1=high byte, r7 most significant digit, R2
= LSByte
MOV R3,#00D
MOV R4,#00D
MOV R5,#00D
MOV R6,#00D
MOV R7,#00D
MOV B,#10D
MOV A,R2
DIV AB
MOV R3,B ;
MOV B,#10 ; R7,R6,R5,R4,R3
DIV AB
MOV R4,B
MOV R5,A
CJNE R1,#0H,HIGH_BYTE ; CHECK FOR HIGH
BYTE
SJMP ENDD
HIGH_BYTE: MOV A,#6
ADD A,R3
MOV B,#10
DIV AB
MOV R3,B
ADD A,#5
ADD A,R4
MOV B,#10
DIV AB
MOV R4,B
ADD A,#2
ADD A,R5
MOV B,#10
DIV AB
MOV R5,B
CJNE R6,#00D,ADD_IT
SJMP CONTINUE
ADD_IT: ADD A,R6
CONTINUE: MOV R6,A
DJNZ R1,HIGH_BYTE
MOV B, #10D
MOV A,R6
DIV AB
MOV R6,B
MOV R7,A
ENDD: ret
DISP1:
REFRESH:; content of 18 to 1B memory locations are
output on LEDs
; only numbers 0 to 9 and A to F are valid data in
these locations
MOV 18H,r3 ; least significant digit
MOV 19H,r4 ; next significant digit
MOV 1AH,r5
MOV 1BH,R6 ; most significant digit (max:9999)
RET
refresh1:
MOV R0,#1bh ; 1b,1a,19,18, holds values for 4 digits
MOV R4,#8 ; pin p3.3_ 0 made low one by one starts
wth 18
mov r7,#2 ; decimal pt.on 3rd digit from left (2 nd
fromright)
PQ2: CALL SEGDISP
dec R0
mov a,r4
rrc a
mov r4,a
jnc pQ2
PV3:RET
SEGDISP:mov dptr,#ledcode
MOV A,@R0
ANL A,#0FH
MOVC A,@A+dptr
segcode:MOV R5,A
ORL A,#03H ; WE WANT TO USE PORT 1 BITS 0
AND 1 FOR INPUT ANLOG
; so retain them high
S3: MOV P1,A ; SEGMENT_PORT
MOV A,R5 ;we use p3.7 for the segment a of display
RRC A ;so get that bit D0into carry
rrc a
mov p3.7,c ;segment a;
S1: MOV A,R4 ; get digit code from r4 00001000
cpl a ;11110111
rrc a ;11111011-1
mov p3.0,c ; output to drive transsitors for digit light-
ing
rrc a ;11111101-1
mov p3.1,c
rrc a ;11111110-1
mov p3.2,c
rrc a ;1111111-0 yes low makes left most digit show
msdigit
generate the basic clock frequency for
the microcontroller. The circuit uses a
6V battery for power supply or alter-
natively a mains derived low voltage
supply. An actual-size, single-side PCB
layout for the tachometer (Fig. 1) is
shown in Fig. 4 and its component lay-
out in Fig. 5.
Testing
The source code of this article is avail-
able at http://www.electronicsforu.
com/efycodes/efy-codes.zip at code
file tacho.hex. Using a programmer,
load the code into the new chip
AT89C2051. (Refer the May 2005 issue
of EFY for article on programmer for
89C51 and 2051.) Then, fit it into the
circuit board and after powering up
the circuit, test it.
For testing, point the probe using
torchlight for illumination of the ro-
tating object. For fans, use the light
from behind. Hold the probe firmly
so as to provide a steady, bright illu-
mination on the object. Even an LED
pen torch could be used here. Avoid
the fluctuating background light from
sources such as tubelight.
Software
The software is written in Assembly
language and assembled using 8051
cross-assembler. It is well commented
and easy to understand. It uses
AT89C2051s internal timer for mea-
suring the period of one cycle of the
rotation in units of 100 microseconds.
Thus if the speed is 1500 rpm, it is 25
rps, and the time taken for one cycle
is 40 ms.
The timer uses an interrupt to count
overflows every 100 microseconds and
so the number counted by the timer
program in this case will be 400. This
is divided by 600,000 (so many 100/
s present in a minute), giving a result
of 1500. This gives the rpm. These
digits are displayed on the 4-digit, 7-
segment display. To perform the divi-
sion, subroutine UDIV32 is employed,
which is a standard subroutine avail-
able for 8051 family for 32-bit number
by 16-bit number division. It has an
accuracy of 5 rpm in a 6000rpm count.
EFY note. The source code of this
article is available at http://
www.electronicsforu. com/efycodes/
efy-codes.zip and will also be included
in EFY-CD of February 2008 issue.
Prof. K. Padmanabhan retired from Alagappa
College of Technology, Guindy, Chennai
CONSTRUCTION
98 JANUARY 2008 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
mov p3.3,c
S5:
S4: ACALL DELAY1 ; let it burn for some time
MOV A,#0ffH ; extinguish the digit after that time
MOV P3,A ; to prevent shadow
s6: RET
ledcode:DB 7EH,0CH,0B6H,9EH,0CCH,0DAH,0FAH
;these are code for the numbers 0 to 9 and A to F
DB 0EH,0FEH,0CEH,0EEH,0F8H,72H,0BCH,0F6H,
0E2H
DELAY1:MOV 55h,#0ffH ; 1ms
N: NOP
DJNZ 55h,N
RET
TIMER0ISR:mov th0,#0ffh
mov tl0,#-90 ; in 100 us steps
push acc
mov a,#1
clr c
add a, 44h ;count time btwn pulses
mov 44h,a
mov a,#0
addc a,45h ;add carry to most sign. byte
mov 45h,a
pop acc
reti
; subroutine UDIV32
;32 bit /16 bit to 32 bit quotient and remainder un-
signed
;input r3,r2,r1,r0 = dividend X
;input r5,r4 = divisor y
;output r3-r0 = quotient Q of X/Y
;r7,r6,r5,r4 =remainder
;alters acc, flags
UDIV32: push 08 ;save reg. bank 1
push 09
push 0AH
push 0BH
push 0CH
push 0DH
push 0EH
push 0Fh
push dpl
push dph
push B
setb RS0 ;select reg.bank 1
mov r7,#0
mov r6,#0
mov r5,#0
mov r4,#0
mov B,#32 ;set loop count
div_lp32:clr RS0 ;selet reg.bank 0
clr C
mov a,r0 ;shift highestbit of X
rlc a
mov r0,a
mov a,r1 ;shift next bit of X
rlc a
mov r1,a
mov a,r2 ;shift next bit of X
rlc a
mov r2,a
mov a,r3 ;shift next bit of X
rlc a
mov r3,a
setb rs0 ;reg. bank 1
mov a,r4 ;lowest bit of remainder
rlc a
mov r4,a
mov a,r5 ;shift next bit of rem
rlc a
mov r5,a
mov a,r6 ;shift next bit of rem
rlc a
mov r6,a
mov a,r7 ;shift next bit of rem
rlc a
mov r7,a
mov a,r4
clr C
subb a,04
mov dpl,a
mov a,r5
subb a,5
mov dph,a
mov a, r6
subb a,#0
mov 06,a
mov a,r7
subb a,#0
mov 07,a
cpl C
jnc div_321
mov r7,7
mov r6,6
mov r5,dph
mov r4,dpl
div_321: mov a,r0
rlc a
mov r0,a ; shift result bit into partial quotient
mov a,r1
rlc a
mov r1,a
mov a,r2
rlc a
mov r2,a
mov a,r3
rlc a
mov r3,a
djnz B,div_lp32
mov 7,r7
mov 6,r6
mov 5,r5
mov 4,r4
mov 3,r3
mov 2,r2
mov 1,r1
mov 0,r0
clr rs0
pop B
pop dph
pop dpl
pop 0Fh
pop 0EH
pop 0Dh
pop 0Ch
pop 0bh
pop 0ah
pop 09
pop 08
ret
END
ConstruCtion
68 February 2008 electroni cs for you www. e F y ma g . c o m
K. Padmanabhan
microcontroller-based
Ultrasonic distance meter
SUNIL KUMAR
T
here are several ways to meas-
ure distance without contact.
One way is to use ultrasonic
waves at 40 kHz for distance measure-
ment. Ultrasonic transducers measure
the amount of time taken for a pulse of
sound to travel to a particular surface
and return as the refected echo.
This circuit calculates the distance
based on the speed of sound at 25C
ambient temperature and shows it
on a 7-segment display. Using it,
you can measure distance up to 2.5
metres.
For this particular application, the
required components are AT89C2051
microcontroller, two 40kHz ultrasonic
transducers (one each for transmitter
higher pulse excitation voltage or a
better transducer.
Here the microcontroller is used to
generate 40kHz sound pulses. It reads
when the echo arrives; it fnds the time
taken in microseconds for to-and-fro
travel of sound waves. Using velocity
of 333 m/s, it does the calculations and
and receiver), current buffer ULN2003,
operational amplifer LM324, inverter
CD4049, four 7-segment displays, fve
transistors and some discreet com-
ponents. The ultrasonic transmitter-
receiver pair is shown in Fig. 1.
Ultrasonic generators use piezo-
electric materials such as zinc or lead
zirconium tartrates or quartz crystal.
The material thickness decides the
resonant frequency when mounted
and excited by electrodes attached on
either side of it. The medical scanners
used for abdomen or heart ultrasound
are designed at 2.5 MHz. In this cir-
cuit, a 40kHz transducer is used for
measurement in the air medium. The
velocity of sound in the air is around
330 m/s at 0C and varies with tem-
perature.
In this project, you excite the ul-
trasonic transmitter unit with a 40kHz
pulse burst and expect an echo from
the object whose distance you want to
measure. Fig. 2 shows the transmitted
burst, which lasts for a period of ap-
proximately 0.5 ms. It travels to the
object in the air and the echo signal
is picked up by another ultrasonic
transducer unit (receiver), also a 40
kHz pre-tuned unit. The re-
ceived signal, which is very
weak, is amplifed several
times in the receiver circuit
and appears somewhat as
shown in Fig. 2 when seen
on a CRO.
Weak echoes also occur
due to the signals being
directly received through
the side lobes. These are
ignored as the real echo
received alone would give
the correct distance. That
is why we should have a
level control. Of course,
the signal gets weaker if
the target is farther than
2.5 metres and will need a
Fig. 1: Ultrasonic transmitter and receiver pair
Fig. 2: The ultrasonic pulse, echo signal and time measurement
ParTs LisT
Semiconductors:
IC1 - AT89C2051
microcontroller
IC2 - ULN2003 current buffer
IC3 - CD4049 hex inverting
buffer
IC4 - LM324 quad operational
amplifer
IC5 - 7815, 15V regulator
IC6 - 7915, -15V regulator
IC7 - 7805, 5V regulator
T1-T4 - BC557 pnp transistor
T5 - 2N2222 npn transistor
D1, D2 - 1N4148 switching diode
D3-D6 - 1N4007 rectifer diode
DIS1-DIS4 - LTS 542 common-anode,
7-segment display
Resistors (all -watt, 5% carbon):
R1, R2 - 2-mega-ohm
R3 - 82-kilo-ohm
R4, R7-R10 - 10-kilo-ohm
R5 - 33-kilo-ohm
R6 - 100-kilo-ohm
R11 - 1-kilo-ohm
R12-R15 - 1.2-kilo-ohm
R16 - 220-ohm
RNW1 - 10-kilo-ohm resistor
network
VR1 - 1-kilo-ohm preset
Capacitors:
C1, C2 - 3.3nF ceramic disk
C7, C10-C12 - 0.1F ceramic disk
C3 - 2.2nF ceramic disk
C4 - 10F, 16V electrolytic
C5, C6 - 22pF ceramic disk
C8, C9 - 1000F, 50V electrolytic
Miscellaneous:
X1 - 230V AC primary to
15V-0-15V, 500mA
secondary transformer
X
TAL
- 12MHz crystal
S1 - Push-to-on switch
S2 - On/off switch
TX1 - 40kHz ultrasonic
transmitter
RX1 - 40kHz ultrasonic receiver
ConstruCtion
70 February 2008 electroni cs for you www. e F y ma g . c o m
up pulse transformer, which steps-up
the transmitter output to 60V (peak-
to-peak).
The echo signal received by the
receiver sensor after refection is very
weak. It is amplifed by quad opera-
tional amplifer LM324. The frst stage
(A1) is a buffer with unity gain. The
received signal is directly fed to the
non-inverting input (pin 3) of A1 and
coupled to the second stage by a 3.3nF
(small-value) capacitor. If you use
the ubiquitous 0.01F capacitor for
coupling, there will be enormous hum
at the output. The second stage of the
inverting amplifer uses a 2-mega-ohm
resistor for feedback. The third stage
is a precision rectifer amplifer with a
gain of 10.
The rectifier functions, unlike a
simple diode, even for signal voltage
of less than 0.6V. The output is fltered
to accept 40kHz frequencies and fed to
pin 12 of microcontroller AT89C2051,
which is an analogue comparator. Pin
13 is the other pin of the comparator
used for level adjustment using preset
VR1.
The ultrasonic transducer outputs
a beam of sound waves, which has
more energy on the main lobe and less
energy (60 dB below the main lobe) on
the side lobes as shown in Fig. 4. Even
this low side-lobe signal is directly
picked up by the receiver unit. So
you have to space the transmitter and
receiver units about 5 cm apart. The
two units are fxed by cellotape onto a
cardboard, with the analogue circuit
at one end.
Microcontroller AT89C2051 is at
the heart of the circuit. Port-1 pins P1.7
through P1.2, and port-3 pin P3.7 are
connected to input pins 1 through 7 of
Fig. 3: Microcontroller based distance meter circuit
shows on the four
7- segment di s-
plays the distance
in centimetres and
millimetres (three
digits for centime-
tres and one for
millimetres).
circuit
description
Fig. 3 shows the
circuit of the mi-
crocontroller-based
distance meter. The
40kHz pulse bursts
from the microcon-
troller are ampli-
fied by transistor
T5. Inverting buff-
er CD4049 drives
the ultrasonic sen-
sor used as the
transmitter. Three
inverters (N1, N2
and N3) are con-
nected in paral-
lel to increase the
transmited power.
This inverted out-
put is fed to an-
other set of three
inverters (N4, N5
and N6). Outputs
of both sets of par-
allel inverters are
applied as a push-
pull drive to the
ultrasonic trans-
mitter.
The positive-
going pulse is ap-
plied to one of the
terminals of the
ultrasonic sensor
and the same pulse
after 180-degree
phase shift is ap-
plied to another
terminal. Thus the
transmitter power
is increased for in-
creasing the range.
If you want to
increase the range
up to 5 metres, use
a ferrite-core step-
Fig. 4: Two dimensional beam pattern of
ultrasonic signal showing main lobe and side
lobe energy levels
ConstruCtion
72 February 2008 electroni cs for you www. e F y ma g . c o m
IC2 (IC ULN2003), respectively. These
pins are pulled up with a 10-kilo-ohm
resistor network RNW1. They drive all
the segments of the 7-segment display
with the help of inverting buffer IC2.
Port-3 pins P3.0 through P3.3 of
the microcontroller are connected
to the base of transistors T1 through
T4 to provide the supply to displays
DIS1 through DIS4, respectively. Pin
P3.0 of microcontroller IC1 goes low
to drive transistor T1 into saturation,
which provides supply to the com-
mon-anode pin (either pin 3 or 8) of
display DIS1. Similarly, transistors T2
through T4 provide anode currents to
the other three 7-segment displays.
Microcontroller IC1 provides the
segment data and display-enable sig-
nal simultaneously in time-division
multiplexed mode for displaying a
particular number on the 7-segment
display unit.
Segment data and display-enable
pulse for the display are refreshed eve-
ry 5 ms. Thus the display appears to be
continuous, even though the individual
LEDs used in it light up one by one.
Using switch S1 you
can manually reset
the microcontroller,
while the power-
on reset signal for
the microcontrol-
ler is derived from
the combination of
capacitor C4 and re-
sistor R8. A 12MHz
crystal is used to
generate the basic
clock frequency for
the microcontroller.
Resistor R16 con-
nected to pin 5 of
DIS2 enables the
decimal point.
The comparator is inbuilt in micro-
controller AT89C2051. The echo signal
will make port-3 pin 3.6 low when it
goes above the level of voltage set on
pin 13. This status is sensed by the mi-
crocontroller as programmed.
When port-3 pin P3.6 goes high, we
know that the echo signal has arrived;
the timer is read and the 16-bit number
is divided by twice the velocity of
sound and then converted into decimal
format as a 4-digit number.
Power supply. Fig. 5 shows the
circuit of the power supply. The 230V
AC mains is stepped down by trans-
former X1 to deliver the secondary
output of 15V-0-15V, 500 mA. The
transformer output is rectifed by a
full-wave bridge rectifer comprising
diodes D3 through D6, fltered by
capacitors C8 and C9 and then regu-
lated by ICs 7815 (IC5), 7915 (IC6)
and 7805 (IC7). Regulators 7815, 7915
and 7805 provide +15V, -15V and
+5V regulated supply, respectively.
Capacitors C10 through C12 bypass
the ripples present in the regulated
power supply.
construction and testing
An actual-size, single-side PCB for the
microcontroller-based distance meter
is shown in Fig. 6 and its component
layout in Fig. 7.
Assemble the PCB and put the
programmed microcontroller into the
socket. After switching on the power
supply and microcontroller automati-
cally getting reset upon power-on,
Fig. 5: Power supply circuit for distance meter
Fig. 6: Actual-size, single-side PCB for the microcontroller-based ultrasonic distance meter
ConstruCtion
electroni cs for you February 2008 73 www. e F y ma g . c o m
pin 8 will pulse at 40kHz bursts. This
can be seen using an oscilloscope.
Give this signal to channel 1 of the
oscilloscope. Adjust the time base to
2 ms per division and set it to trigger
mode instead of normal mode. Adjust
the potmeter on the oscilloscope la-
beled level such that the trace starts
with the burst and appears steady as
shown in Fig. 2.
Connect the transmitter and re-
ceiver ultrasonic units either by a
twisted pair of wire or by a shielded
cable to the board. Give the received
signal to channel 2 of the oscilloscope.
Then, place an A4-size plastic sheet in
front of the ultrasonic transducers and
observe the echo signal. It will appear
as shown in Fig. 2.
The two transducers can be fxed
to a thick cardboard with two wires
leading to the circuittwo 40cm long
shielded cables will do. The laser
pointer is fxed such that it is axial
to the transducers. Channel 2 is con-
nected to pin 12, which is the positive
non-inverting terminal of AT89C2051s
comparator. The negative inverting ter-
minal (pin 13) is connected to a preset
reference. Adjust the preset such that
the voltage is 0.1V-0.2V at pin 13. This
will enable detection of weak echoes
also.
When the echo signal goes above
Fig. 7: Component layout for the PCB
the level of reference voltage set on pin
13, it will make P3.6 low; the arrival of
echo is sensed by the program using
jnb p3.6 (jump not bit) instruction.
software
The software is written in Assembly
language and assembled using 8051
cross-assembler. It is well commented
and easy to understand.
The pulse train for 0.5 ms is started
by making pin 8 high and low alter-
nately for 12.5 microseconds so that the
pulse frequency is 40 kHz. After 25 such
pulses have passed, a waiting time is
given to avoid direct echoes for about
20 s. Then the signal is awaited, while
the timer runs counting time in micro-
seconds. When the echo arrives, port-3
pin P3.6 goes high, the timer reads and
the 16-bit number is divided by twice
the velocity and converted into decimal
format as a 4-digit number.
If the echo does not arrive even
after 48 milliseconds, the waiting loop
is broken and the pulse train sequence
is started once again. If the echo comes
within this time, it is displayed for half
a second before proceeding to another
measurement. Thus, the display ap-
pears continuous and ficker-free.
other uses
Simply by changing this program, the
same unit can be made to detect mov-
ing objects (such as cars racing on the
street) and fnd their range and speed.
It can also be used with suitable addi-
tional software as a burglar alarm unit
for homes or offces.
EFY note. All the relevant fles of
this project are included in this months
EFY-CD.
ultrsnd.asm
Program listing:
$mod51
ORG 0H
AJMP 30H
ORG 0BH ;TIMER 0 INTERRUPT VECTOR
; AJMP TIMER0ISR ;Timer 0 Interrupt
service routine address
ORG 30H
MOV SP,#60H ;set stack pointer
MOV P3,#0FFH ;set all port 3 bits high
to enable inputs also
MOV P1,#03 ;set port 1 to all zeros
expect bits 0,1
MOV TMOD,#01100001B ;TIMER 1 - MODE 2
COUNTER,TIMR-0 TO MODE 1
BEG: MOV TH0,#0H ;TIMER REG.0 IS SET TO
0, GIVES 64ms
MOV TL0,#0 ; timer low reg. is also so
;TOTAL CYCLE TIME IS 64.6ms ,350m/s
gives 0.35mx65=22.5m
; up and down 10 metres say! .35 m/ms,
.35 mm/us, 1mm per 3 micros
; up and down .35/2 mm/us = 1/6 mm/us
; VELOCITY OF SOUND IN AIR IS 350 M/S
; AFTER 100 TIMES, WE HAVE TO STOP
TRANSMITTING FOR A TIME OF ABOUT .1 S
; SO WE STOP FOR THIS AMOUNT OF TIME
and expect an echo.
mov r2,#25 ; 25 pulses 26 us =.53 ms
(343m/s*.5ms=17cm)
pulse: setb p3.4 ;generates 40KHz
mov r1,#5
djnz r1,$
clr p3.4
mov r1,#5
djnz r1,$ ;wait for 13 us
djnz r2, pulse ;20pulses
setb tr0 ;start timer
ConstruCtion
74 February 2008 electroni cs for you www. e F y ma g . c o m
mov r0,a
mov a,r7 ;get rem. saved before the
mov r3,a ;last subtraction.
mov a,r6
mov r2,a
ret
;16 Bit Hex to BCD Conversion for 8051
Microcontroller
; This routine is for 16 bit Hex to BCD
conversion;
;Accepts a 16 bit binary number in
R1,R2 and returns 5 digit BCD in
;R7,R6,R5,R4,R3(upto 64K )
Hex2BCD: ;r1=high byte ;r7 most sig-
nifcant digit
;R2 = LSByte
MOV R3,#00D
MOV R4,#00D
MOV R5,#00D
MOV R6,#00D
MOV R7,#00D
MOV B,#10D
MOV A,R2
DIV AB
MOV R3,B ;
MOV B,#10 ; R7,R6,R5,R4,R3
DIV AB
MOV R4,B
MOV R5,A
CJNE R1,#0H,HIGH_BYTE ; CHECK FOR HIGH
BYTE
SJMP ENDD
HIGH_BYTE: MOV A,#6
ADD A,R3
MOV B,#10
DIV AB
MOV R3,B
ADD A,#5
ADD A,R4
MOV B,#10
DIV AB
MOV R4,B
ADD A,#2
ADD A,R5
MOV B,#10
DIV AB
MOV R5,B
CJNE R6,#00D,ADD_IT
SJMP CONTINUE
ADD_IT: ADD A,R6
CONTINUE: MOV R6,A
DJNZ R1,HIGH_BYTE
MOV B, #10D
MOV A,R6
DIV AB
MOV R6,B
MOV R7,A
ENDD: ret
DISP1:
REFRESH: ; content of 18 to 1B memory
locations are output on LEDs
; only numbers 0 to 9 and A to F are
valid data in these locations
mov r1,41h
mov r2,40h
CALL HEX2BCD
MOV 18H,r3 ; least signifcant digit
MOV 19H,r4 ; next signifcant digit
MOV 1AH,r5
mov r2,#10
djnz r2,$ ;wait 20 us
check_echo:
jnb p3.6,checktimeout
MOV 40h,TL0 ; read timer count
MOV 41h,TH0
mov r0,40h
mov r1,41h
mov r3,#0
mov r2,#6
call UDIV16 ;divide by 6
mov 40h,r0
mov 41h,r1
mov 50h,#25
disp: call disp1 ; show the value on
LED
djnz 50h,disp ; so many times for a
visible time limit
jmp beg
checktimeout: mov a,th0
cjne a,#0c0h,check_echo ;upto 4 metres
jmp beg
;subroutine UDIV16
;16 bit/16bit unsigned divide
;input r1,r0 =dividend X
;input r3,r2 =divisor Y
;output r1,r0 =quottient q of x/y
;output r3,r2 = remainder
; alters acc,r4-47,fags,dptr
UDIV16: mov r7,#0 ;clear partial re-
mainder
mov r6,#0 ;
mov B,#16 ;set loop count
div_loop: clr C ;clear carry fag
mov a,r0 ; shift the highest bit of
dividend into
rlc a
mov r0,a
mov a,r1
rlc a
mov r1,a
mov a,r6 ;... the lowest bit of partial
remainder
rlc a
mov r6,a
mov a,r7
rlc a
mov r7,a
mov a,r6
clr C
subb a,r2
mov dpl,a
mov a,r7
subb a,r3
mov dph,a
cpl C
jnc div_1 ;update partial reaminder
if borrow
mov r7,dph
mov r6,dpl ; update parital reminder
div_1: mov a,r4
rlc a
mov r4,a
mov a,r5
rlc a
mov r5,a
djnz B,div_loop
mov a,r5
mov r1,a ; put qt. in r0,r1
mov a,r4
MOV 1BH,R6 ; most signifcant digit
(max:9999)
refresh1: MOV R0,#1bh ; 1b,1a,19,18,
holds values for 4 digits
MOV R4,#8 ; pin p3.3_ 0 made low one by
one starts wth 18
mov r7,#2 ; decimal pt.on 3rd digit
from left (2 nd fromright)
PQ2: CALL SEGDISP
deC R0
mov a,r4
rrc a
mov r4,a
jnc pQ2
PV3:
RET
SEGDISP:
mov dptr,#ledcode
MOV A,@R0
ANL A,#0FH
MOVC A,@A+dptr
segcode:
MOV R5,A
ORL A,#03H ; WE WANT TO USE PORT 1 BITS
0 AND 1 FOR INPUT ANLOG
; so retain them high
S3: MOV P1,A ; SEGMENT_PORT
MOV A,R5 ;we use p3.7 for the segment
a of display
RRC A ;so get that bit D0into carry
; cpl c
; mov p3.5,c ; dec pt is D0 bit that is
wired to p3.5
rrc a
mov p3.7,c ;segment a;
S1: MOV A,R4 ; get digit code from r4
00001000
cpl a ;11110111
rrc a ;11111011-1
mov p3.0,c ; output to drive transsi-
tors for digit lighting
rrc a ;11111101-1
mov p3.1,c
rrc a ;11111110-1
mov p3.2,c
rrc a ;1111111-0 yes low makes leftmost
digit show msdigit
mov p3.3,c
S5:
S4: ACALL DELAY1 ; let it burn
for some time
MOV A,#0ffH ; extinguish
the digit after that time
MOV P3,A ; to prevent shadow
s6: RET
ledcode:
DB 7EH,0CH,0B6H,9EH,0CCH,0DAH,0FAH
DB 0EH,0FEH,0CEH,0EEH,0F8H,72H,0BCH,0
F6H,0E2H
;these are code for
the numbers 0 to 9 and A to F
DELAY1: MOV R1,#0ffH
N: NOP
DJNZ R1,N
RET
END
C I R C U I T I D E A S
ELECTRONICS FOR YOU APRIL 2004
S
U
N
IL
K
U
M
A
R
T
he most frequently used device in
electronic workshops and laborato-
ries is a universal power supply that
provides a variable, fluctuation-free out-
put. Here we present a variable power sup-
ply with digital control that is simple and
easy to construct.
The circuit is built around an adjust-
able 3-terminal positive-voltage regulator
IC LM317, CMOS decade counter IC
CD4017, timer IC NE555 and 3-terminal
fixed negative-voltage regulator LM7912.
The AC mains supply is stepped down
by transformer X1 to deliver a secondary
output of 12V-0-12V AC, 1A. The output
of the transformer is rectified by a
full-wave rectifier comprising diodes
D1 through D4. Capacitors C1 through C4
are connected in parallel to rectifier
VARIABLE POWER SUPPLY WITH
DIGITAL CONTROL
MANESH T. MATHEW
diodes to bypass undesired spikes and
provide smooth and fluctuation-free power.
Capacitors C5 and C13 are used as
filters to eliminate ripple. Here both nega-
tive and positive half cycles are used to
obtain positive as well as negative
DC output. LED1, along with current-
limiting resistor R1, is used for mains on
indication.
Timer IC NE555 (IC1) is wired as an
astable multivibrator. It generates clock
pulses when switch S2 is pressed. The out-
put of IC1 is connected, via an RC net-
work, to the clock input of counter IC
CD4017 (IC2).
IC CD4017 is a decade ring counter.
Each of its ten outputs goes high one by
one when a clock pulse is received. The
outputs of IC CD4017 are connected to
the bases of transistors T1 through T10,
respectively, as shown in the figure. LED3
through LED11 are used here to indicate
the voltage levels. The collectors of tran-
sistors T2 through T10 are connected to
presets VR1 through VR9, respectively,
which are used to set the output voltage.
Adjustable voltage regulator IC LM317
(IC4) develops 1.25V nominal reference
voltage (V
REF
) between its output and the
adjustable terminal. The reference voltage
appears across resistor R16. When the volt-
age is constant, a constant current flows
through one of the output-setting variable
resistors (VRset, VR1 through VR9), giv-
ing an output voltage at pin 2 of IC4 as
follows:
V
OUT
=1.25(1+VRset/R16).
Presets VR1 through VR9 are adjusted
to get the desired output voltage. The col-
lector of transistor T1 is directly connected
to ADJ terminal (pin 1) of IC4, so the
output voltage of IC4 will be the voltage
C I R C U I T I D E A S
ELECTRONICS FOR YOU APRIL 2004
resulting in different output voltages. By
using a properly calibrated digital multim-
eter you can easily adjust the presets to
obtain 1.5V to 12V.
A fixed, negative 12V DC can be ob-
tained by using fixed, negative-voltage
regulator IC LM7912 (IC3). Thus the
power supply unit can be used for circuits
requiring both negative and positive DC
voltages.
When CD4017 is reset by pressing
switch S3, the output voltage becomes
across fixed resistor R16, which is equal
to 1.25V. When switch S3 is pressed, pin
3 of IC2 goes high and the output voltage
becomes 1.2V.
When switch S2 is pressed, the output
of IC1 goes high. As a result, the outputs
of IC2 go high one by one as a ring
counter. Since presets VR1 through VR9
are connected at the collectors of transis-
tors T2 through T10, respectively, differ-
ent output resistances appear between the
adjustable and ground terminals of IC4,
1.2V and all the voltage-indication LEDs
turn off.
Assemble the circuit on any general-
purpose PCB and enclose it in a suitable
cabinet. Use suitable heat-sinks for
regulators IC3 and IC4. Since pin configu-
rations of the regulators are different,
never fix both regulators on the same
heat-sink. For S2 and S3, using
microswitches will enhance the beauty of
the unit. LED2 is used to indicate the
negative 12V DC voltage.
circuit
ideas
84 February 2006 electroni cs for you www. e F y ma g . c o m
CMYK
U
sing this circuit, you can ob-
tain the following voltages
(approx.) at a current limited
to one ampere: 3.3V, 5V, 6V, 9V, 12V
and 15V.
The AC mains is stepped down by
transformer X1 to deliver the second-
ary output of 18V AC at a maximum
current of 1A dependant upon the
load. The transformer output is recti-
fed by the bridge rectifer comprising
diodes D1 through D4, filtered by
capacitor C1 and fed to regulator IC
LM317, which is a 3-terminal positive
regulator capable of providing 1.2V to
37 volts at 1.5A current to the load.
Resistor R13 and selected combina-
tions of resistors R1 through R12 are
used to produce approximately 3.3V,
5V, 6V, 9V, 12V and 15V at the output.
The desired resistors are selected by
switching into conduction one of the
six pnp transistors T1 through T6 by
grounding the corresponding transistor
base using rotary switch S1.
For example, to get regulated 3.3V,
simply rotate the knob of rotary switch
to 3.3V position. Consequently, transis-
Sunil Kumar
VerSatile Power SuPPly
tor T1 is forward biased to switch resis-
tors R1 and R2 (in series) across Adj pin
of LM317 and ground to produce 3.3V.
Other voltages can be produced in
the same way by using rotary switch
S1. Capacitor C2 bypasses any ripple
in the output. Diode D5 is used as the
protection diode. Use a heat-sink for
dissipation of heat from IC LM317. The
fuse-rated lamp provides protection
against short circuit.
This 1A rated power supply can
be used for testing of various circuit
ideas as well as construction projects
published in EFY.
CIRCUIT
IDEAS
ELECTRONI CS FOR YOU NOVEMBER 2005 103 WWW. E F Y MA G . C O M
CMYK
T
his vibration detector is realised
using readily available, low-
cost components. One of its
many applications is in a rolling shut-
ter guard for offices and shops. The
detector will sense vibration caused by
activities like drilling and switch on
the connected load (bulb, piezobuzzer,
etc) to alert you.
The circuit works off a 6V battery
or 6V regulated power supply and
uses a piezoceramic element as the
vibration detector. The same is easily
available from electronics/telephone
component vendors or you can take it
out from an active buzzer.
Initially, when the power is
switched on, decade counter IC1 is re-
set by power-on-reset components C2
and R1. As a result, Q0 output (pin 3)
of IC1 goes high and
the entire circuit is in
idle state. LED1 indi-
cates the power sta-
tus.
In the event of
vibrations, IC2 is
clocked by the
pulses from the
piezoceramic element
connected to its
clock pin 14. Q1
through Q9 outputs
of IC2 are fed to re-
lay-driver switching
transistor T1 through
diodes D1 through D9 connected in
OR mode.
Immediately after clocking, any of
the outputs Q1 through Q9 would go
high and npn transistor T1 would con-
duct. As a result, SCR1 is fired through
T.K. HAREENDRAN
SENSITIVE VIBRATION
DETECTOR
S. C. DWI VEDI
Fig. 1: Circuit of the sensitive vibration detector
Fig. 2: Pin
configuration of
SCR1 BT169 and
back view of the
piezo element
Fig. 3: Arrangement for rolling shutter guard
for shops, offices and banks
its gate. This, in turn, energises relay
RL1. The relay contacts can be used
to switch any alarm device to indicate
vibration detection. The circuit can
be reset by momentarily pressing
switch S1.
Zener diodes ZD1 and ZD2 at the
clock input of IC1
are used for protec-
tion against high
voltage input. In
the case of repeated
false triggering of
IC1, add a 100nF ca-
pacitor in parallel to
the piezoceramic
element.
The pin con-
figuration of SCR
BT169 and the
back view of the
piezo element are
shown in Fig. 2. Fig.
3 shows suggested
location of the vi-
bration detector for
rolling shutters of
banks, shops,
etc. z
cONSTRUcTION
74 June 2010 electroni cs for you www. e f y ma g . c o m
the input from push-to-on switches S1
through S8. Pins of Port P1 are pulled
high via resistor network RNW1. Port
pins P2.0 through P2.4 are confgured
to receive the decoded DTMF signal
from DTMF receiver MT8870. The
functions of the corresponding switch-
es (S1 through S8) and cellphone keys
are shown in Table I.
The DTMF decoder is used for de-
coding the mobile signal. It gets DTMF
tone from the mobile headsets speaker
pins and decodes it into 4-bit digital
signal. The DTMF decoder is operated
with a 3.579MHz crystal (X
TAL2
). In
DTMF receiver MT8870 (IC3), capaci-
tor C12 is used to flter the noise and
resistors R6 and R7 help to amplify
the input signal using the internal
amplifer.
Pin 16 of IC3 connected to resistor
R5 provides the early steering output.
It goes high immediately when the dig-
ital algorithm detects a valid tone pair
(signal condition). Any momentary
loss of signal condition causes ESt to
return to low state.
Pin 17 of IC3 connected to capacitor
C11 is bidirectional, acting as steering
input/guard time output (St/GT). A
AzArudeen AnifA
Cellphone-Based device Control with
Voice Acknowledgement
sunil kumar
H
ere is a circuit that lets you
operate your home appli-
ances like lights and water
pump from your offce or any other
remote place. So if you forgot to switch
off the lights or other appliances while
going out, it helps you to turn off the
appliance with your cellphone. Your
cellphone works as the remote control
for your home appliances. You can
control the desired appliance by press-
ing the corresponding key. The system
also gives you voice acknowledgement
of the appliance status.
Circuit description
Fig. 1 shows the circuit for cellphone-
based device control with voice ac-
knowledgement. It comprises micro-
controller AT89C51, DTMF decoder
MT8870, voice recording/playback
device APR9600 and a few discrete
components.
Microcontroller AT89C51 is at the
heart of the circuit. It is a low-power,
high-performance, 8-bit microcontrol-
ler with 4 kB of fash programma-
ble and erasable read-only memory
(PEROM) used as on-chip program
memory, 128 bytes of RAM used as
internal data memory, 32 individu-
ally programmable input/output (I/O)
lines divided into four 8-bit ports, two
16-bit programmable timers/counters,
a fve-vector two-level interrupt archi-
tecture, on-chip oscillator and clock cir-
cuitry. A 11.0592MHz crystal (X
TAL1
) is
used to provide basic clock frequency
for the microcontroller. Capacitor C3
and resistor R3 form the power-on
reset circuit, while push-to-on switch
S20 is used for manual reset.
Port pins P1.0 through P1.7 of the
microcontroller are confgured to get
Parts List
Semiconductors:
IC1 - AT89C51 microcontroller
IC2 - APR9600 voice recording
and playback device
IC3 - MT8870 DTMF receiver
IC4 - ULN2003 relay driver
IC5 - 7806, 6V regulator
D1-D5 - 1N4007 diode
LED1-LED3 - 5mm LED
Resistors (all -watt, 5% carbon):
R1-R3 - 10-kilo-ohm
R4, R6, R15 - 100-kilo-ohm
R5 - 470-kilo-ohm
R7 - 220-kilo-ohm
R8 - 39-kilo-ohm
R9, R10 - 4.7-kilo-ohm
R11 - 1-kilo-ohm
R12 - 220-kilo ohm
R13, R14, R16 - 470-ohm
RNW1, RNW2 - 10-kilo-ohm resistor
network
Capacitors:
C1, C2 - 33pF ceramic disk
C3 - 10F, 16V electrolytic
C4, C6-C8,
C11, C15 - 0.1F ceramic disk
C5 - 4.7F, 16V electrolytic
C9, C10 - 22F, 50V electrolytic
C12 - 0.22F polyster
C13, C14 - 0.47F polyster
C16 - 1000F, 35V electrolytic
Miscellaneous:
S1-S16, S20 - Push-to-on switch
S17, S18 - 2-way DIP switch
S19 - SPDT switch
S21 - On/off switch
X
TAL1
- 11.0592MHz crystal
X
TAL2
- 3.579MHz crystal
RL1-RL6 - 6V, 1C/O relay
MIC1 - Electret mic
LS1 - 1W, 16-ohm speaker
CON1 - Mobile phone headset
connector
voltage greater than threshold of the
steering logic V
TSt
detected at St causes
the device to register the detected tone
pair. The guard time output resets the
external steering time constant, and its
state is a function of ESt and the volt-
Table I
Functions of Switches and
Mobile Keys
Switches Mobile Function
key
S1 1 SelectDevice1;On/Off
S2 2 SelectDevice2;On/Off
S3 3 SelectDevice3;On/Off
S4 4 SelectDevice4;On/Off
S5 5 SelectDevice5;On/Off
S6 6 SelectDevice6;On/Off
S7 * Initialisetoinformthe
statusofthedevice
S8 # On/offthevoicealert
cONSTRUcTION
76 June 2010 electroni cs for you www. e f y ma g . c o m
F
i
g
.
1
:
C
i
r
c
u
i
t
f
o
r
c
e
l
l
p
h
o
n
e
-
b
a
s
e
d
d
e
v
i
c
e
c
o
n
t
r
o
l
w
i
t
h
v
o
i
c
e
a
c
k
n
o
w
l
e
d
g
e
m
e
n
t
cONSTRUcTION
electroni cs for you June 2010 77 www. e f y ma g . c o m
R1, respectively. Here, we are using
two control sources, switches and mo-
biles key. DIP switches S17 and S18
select the control sources as shown in
Table II.
Pin 2.5 of Port P2 is confgured to
show the rest status. That is, if none of
the control sources is selected by DIP
switches S17 and S18, LED1 glows.
Resistor R14 limits the current through
LED1.
Voice acknowledgement is pro-
vided by the APR9600 (IC2). It is a
single-chip voice recording and play-
back device that can record and play
multiple messages at random or in
sequential mode for 60 seconds. The
user can select sample rates with cor-
responding-quality recording lengths.
Microphone amplifer, automatic gain
control (AGC) circuits, internal anti-
aliasing flter, internal output amplifer
and message management are some of
the features of the APR9600.
Here the APR9600 is confgured in
random-access mode, which supports
two, four and eight messages of fxed
durations. The length of each message
is the total recording length available
divided by the total number of memo-
ry segments/tracks enabled.
Audio processor APR9600 can store
up to eight voice messages. Port P0
pins and P2.7 are confgured to com-
municate with IC2. Port P0 pins
trigger selection of the message.
Port pin P2.7 is the input signal to
identify whether the voice message
is playing or not.
Pins P3.0 through P3.5 of Port
P3 control the devices with the
help of relays RL1 through RL6 via
relay driver IC4.
A speaker is connected to IC2
for audio output. The speaker
output drives the mic input of the
mobile for audio acknowledge-
ment. An electret microphone
MIC1 is connected to IC2 to record
the voice in IC2. LED2 fashes to
show the busy status of IC2 dur-
ing recording and playback. The
audio messages to be recorded in
APR9600, by using trigger switch-
es S9 through S16, are shown in
Table III. SPST switch S19 is closed
for recording and switch S19 is
opened for playback.
Fig. 3 shows the power sup-
Table II
Control Source Selection
Using DIP Switches
S17 S18 Control status
0 0 Reststatus
0 1 Switchesonly
1 0 Mobileonly
1 1 Switchesandmobile
Fig. 3: Power supply circuit
Fig. 2: Pin confguration of mobile headset
Fig. 4: A single-side, actual-size PCB layout for cellphone-based device control with voice
acknowledgement
age at St.
Port P3 pins P3.6 and P3.7 of IC1
are confgured to select the control
source for the devices. These are con-
nected to DIP switches S17 and S18
and pulled high via resistors R2 and
cONSTRUcTION
78 June 2010 electroni cs for you www. e f y ma g . c o m
Table III
Voice Recording Chart
Switch Trigger of IC Voice
S9 1 NameofDevice1
S10 2 NameofDevice2
S11 3 NameofDevice3
S12 4 NameofDevice4
S13 5 NameofDevice5
S14 6 NameofDevice6
S15 7 StatusOn
S16 8 StatusOff
Table IV
DTMF Value of Mobile Keys
Key StD Q3 Q2 Q1 Q0
1 H 0 0 0 1
2 H 0 0 1 0
3 H 0 0 1 1
4 H 0 1 0 0
5 H 0 1 0 1
6 H 0 1 1 0
* H 1 0 1 1
# H 1 1 0 0
ply circuit. The 230V AC mains is
stepped down by transformer X1 to
deliver the secondary output of 9V,
500 mA. The transformer output is
rectifed by a full-wave bridge recti-
fer comprising diodes D1 through
D4, fltered by capacitor C16 and then
regulated by IC 7806 (IC5). Capaci-
tor C15 bypasses the ripples present
in the regulated 6V power supply.
LED3 acts as a power-on indicator
and resistor R16 limits the current
through LED3.
An actual-size, single-side PCB
for cellphone-based device control
with voice acknowledgement is
shown in Fig. 4 and its component
layout in Fig. 5.
recording and playback
To record the voice in IC2, follow Table
III. Close SPST switch S19 to make pin
27 of IC2 low. Thereafter, press and
hold switches S9 through S16 to record
corresponding voice messages. LED2
fashes to indicate audio recording.
For playback of any device status,
open SPST switch S19 and press the
corresponding switch (S9 through S16).
The recorded audio can be heard from
the speaker connected to pins 14 and
15 of IC2. Fig. 2 shows the pin confgu-
ration of mobile headset.
Software
The program (Device_Control.BAS)
for the microcontroller is written
using BASCOM microcontroller
programming software. In the
program, frst, initialise the ports
(P0-P3) for corresponding controls.
Thereafter, declare the variables for
the program. After declaration, as-
sign some initial value to variables.
Here, microcontroller ports are
initialised to make all the devices
off initially.
After that, the main function
checks through Do loop which
control source has been enabled by
using DIP switch pins. If you select
switch S17, it searches the input
from the mobile only. If you select
switch S18, it searches the input
from the switches (S1 through S8)
only. If you enable both switch S17
and switch S18, it searches the inputs
from switches and mobile. Else, the
rest-status LED1 glows. Refer to Table
II to select the control source.
The mobile signal is decoded into
the DTMF signal by IC3. The DTMF
output for each mobile key (used in
this project) pressed is shown in Table
IV.
After getting the input from the
switches or mobile, the program goes
to the device_action subroutine and
executes the corresponding action
(refer Table I).
The device_action subroutine
changes the status of the device and
calls the voice_alert subroutine. The
voice_alert subroutine checks the
device status and device name from
the source input and controls the cor-
responding pins of IC2. First, it selects
the voice signal for the device name.
After playing that, it selects on/off
status of corresponding device as men-
tioned in Table III.
If you press * key followed by the
device number on your mobile hand-
set, it will not change the status of that
device and inform the current device
status. If you press device number
Fig. 5: Component layout for the PCB
cONSTRUcTION
electroni cs for you June 2010 79 www. e f y ma g . c o m
device_control.bas
$large
$regfle = 89c51cc.DAT
$crystal = 11059200
DECLERATION OF FUNCTIONS
Declare Sub Keypad
Declare Sub Device_action
Declare Sub Voice_alert
Declare Sub Dtmf_input
INPUT FROM DTMF DECODER
Dtmf_a Alias P2.4
Dtmf_b Alias P2.3
Dtmf_c Alias P2.2
Dtmf_d Alias P2.1
Dtmf_ack Alias P2.0
INPUT FROM KEYPAD
Key_1 Alias P1.0
Key_2 Alias P1.1
Key_3 Alias P1.2
Key_4 Alias P1.3
Key_5 Alias P1.4
Key_6 Alias P1.5
Key_a Alias P1.6
Key_v Alias P1.7
OUTPUT TO AUDIO SELECTION
Aud_1 Alias P0.0
Aud_2 Alias P0.1
Aud_3 Alias P0.2
Aud_4 Alias P0.3
Aud_5 Alias P0.4
Aud_6 Alias P0.5
Aud_on Alias P0.6
Aud_off Alias P0.7
Aud_rewind Alias P2.6
INPUT FROM APR9600
Aud_busy Alias P2.7
OUTPUT TO DEVICE
Device_1 Alias P3.0
Device_2 Alias P3.1
Device_3 Alias P3.2
Device_4 Alias P3.3
Device_5 Alias P3.4
Device_6 Alias P3.5
CONTROLLING MODE SELECTION
Device_a Alias P3.6
Device_b Alias P3.7
DECLARING VARIABLES
Dim Keypad_value As Byte
Dim Device_1_status As Bit
Dim Device_2_status As Bit
Dim Device_3_status As Bit
Dim Device_4_status As Bit
Dim Device_5_status As Bit
Dim Device_6_status As Bit
Dim Common_status As Bit
Dim Voice As Bit
Dim Status_enable As Bit
INTIALIZING VALUES
Keypad_value = 15
Aud_1 = 1
Aud_2 = 1
Aud_3 = 1
Aud_4 = 1
Aud_5 = 1
Aud_6 = 1
Aud_on = 1
Aud_off = 1
Aud_rewind = 0
Device_1_status = 0
Device_2_status = 0
Device_3_status = 0
Device_4_status = 0
Device_5_status = 0
Device_6_status = 0
Device_1 = 0
Device_2 = 0
Device_3 = 0
Device_4 = 0
Device_5 = 0
Device_6 = 0
Voice = 1
Do
If Device_a = 0 And Device_b = 0 Then
P2.5 = 0
Elseif Device_a = 0 And Device_b = 1
Then
P2.5 = 1
Call Keypad
If Keypad_value < 9 Then
Call Device_action
End If
Elseif Device_a = 1 And Device_b = 0
Then
P2.5 = 1
Call Dtmf_input
If Keypad_value < 9 Then
Call Device_action
End If
Elseif Device_a = 1 And Device_b = 1
Then
P2.5 = 1
Call Keypad
Call Dtmf_input
If Keypad_value < 9 Then
Call Device_action
End If
End If
followed by * key on your mobile
handset, it will change the status of
that device and inform the changed
device status. # key controls the
voice_control subroutine and acts like
a mute key.
EFY note. The source code of
this project has been included in this
months EFY-CD and is also available
on www.efymag.com website.
cONSTRUcTION
80 June 2010 electroni cs for you www. e f y ma g . c o m
If Status_enable = 1 Then
While Keypad_value > 7
If Device_b = 1 Then
Call Keypad
End If
If Device_a = 1 Then
Call Dtmf_input
End If
Wend
Call Voice_alert
Status_enable = 0
End If
Loop
Sub Keypad
If Key_1 = 0 Then
Keypad_value = 1
Bitwait Key_1 , Set
Elseif Key_2 = 0 Then
Keypad_value = 2
Bitwait Key_2 , Set
Elseif Key_3 = 0 Then
Keypad_value = 3
Bitwait Key_3 , Set
Elseif Key_4 = 0 Then
Keypad_value = 4
Bitwait Key_4 , Set
Elseif Key_5 = 0 Then
Keypad_value = 5
Bitwait Key_5 , Set
Elseif Key_6 = 0 Then
Keypad_value = 6
Bitwait Key_6 , Set
Elseif Key_a = 0 Then
Keypad_value = 7
Bitwait Key_a , Set
Elseif Key_v = 0 Then
Keypad_value = 8
Bitwait Key_v , Set
Else
Keypad_value = 15
End If
End Sub
Sub Device_action
If Keypad_value = 1 Then
Device_1_status = Not Device_1_status
Device_1 = Device_1_status
Call Voice_alert
Elseif Keypad_value = 2 Then
Device_2_status = Not Device_2_status
Device_2 = Device_2_status
Call Voice_alert
Elseif Keypad_value = 3 Then
Device_3_status = Not Device_3_status
Device_3 = Device_3_status
Call Voice_alert
Elseif Keypad_value = 4 Then
Device_4_status = Not Device_4_status
Device_4 = Device_4_status
Call Voice_alert
Elseif Keypad_value = 5 Then
Device_5_status = Not Device_5_status
Device_5 = Device_5_status
Call Voice_alert
Elseif Keypad_value = 6 Then
Device_6_status = Not Device_6_status
Device_6 = Device_6_status
Call Voice_alert
Elseif Keypad_value = 7 Then
Keypad_value = 15
Status_enable = 1
Elseif Keypad_value = 8 Then
If Voice = 1 Then
Voice = 0
Elseif Voice = 0 Then
Voice = 1
End If
End If
Keypad_value = 15
End Sub
Sub Dtmf_input
If Dtmf_ack = 1 Then
Bitwait Dtmf_ack , Reset
If Dtmf_d = 0 And Dtmf_c = 0 And Dtmf_
b = 0 And Dtmf_a = 1 Then
Keypad_value = 1
Elseif Dtmf_d = 0 And Dtmf_c = 0 And
Dtmf_b = 1 And Dtmf_a = 0 Then
Keypad_value = 2
Elseif Dtmf_d = 0 And Dtmf_c = 0 And
Dtmf_b = 1 And Dtmf_a = 1 Then
Keypad_value = 3
Elseif Dtmf_d = 0 And Dtmf_c = 1 And
Dtmf_b = 0 And Dtmf_a = 0 Then
Keypad_value = 4
Elseif Dtmf_d = 0 And Dtmf_c = 1 And
Dtmf_b = 0 And Dtmf_a = 1 Then
Keypad_value = 5
Elseif Dtmf_d = 0 And Dtmf_c = 1 And
Dtmf_b = 1 And Dtmf_a = 0 Then
Keypad_value = 6
Elseif Dtmf_d = 1 And Dtmf_c = 0 And
Dtmf_b = 1 And Dtmf_a = 1 Then
Keypad_value = 7
Elseif Dtmf_d = 1 And Dtmf_c = 1 And
Dtmf_b = 0 And Dtmf_a = 0 Then
Keypad_value = 8
Else
Keypad_value = 15
End If
End If
End Sub
Sub Voice_alert
If Voice = 1 And Keypad_value < 7 Then
If Keypad_value = 1 Then
Common_status = Device_1_status
Aud_1 = 0
Wait 1
Aud_1 = 1
Elseif Keypad_value = 2 Then
Common_status = Device_2_status
Aud_2 = 0
Wait 1
Aud_2 = 1
Elseif Keypad_value = 3 Then
Common_status = Device_3_status
Aud_3 = 0
Wait 1
Aud_3 = 1
Elseif Keypad_value = 4 Then
Common_status = Device_4_status
Aud_4 = 0
Wait 1
Aud_4 = 1
Elseif Keypad_value = 5 Then
Common_status = Device_5_status
Aud_5 = 0
Wait 1
Aud_5 = 1
Elseif Keypad_value = 6 Then
Common_status = Device_6_status
Aud_6 = 0
Wait 1
Aud_6 = 1
End If
Bitwait Aud_busy , Set
Wait 5
If Common_status = 1 Then
Aud_off = 0
Wait 1
Aud_off = 1
Elseif Common_status = 0 Then
Aud_on = 0
Wait 1
Aud_on = 1
End If
Bitwait Aud_busy , Set
End If
End Sub
c o n s t r u c t i o n
electronics for you september 2004
K. Krishna Murty
D
igital voice processing chips with
different features and coding tech-
niques for speech compression and
processing are available on the market
from a number of semiconductor manu-
facturers. Advanced chips such as Texas
instruments TMS320C31 can implement
various voice-processing algorithms includ-
ing code-excited linear prediction, adaptive
differential pulse-code modulation, A law
(specifed by California Council for Inter-
national Trade), law (specifed by Bell
Telephone) and vector sum-excited linear
prediction.
On the other hand, APR9600 single-
chip voice recorder and playback device
from Aplus Integrated Circuits makes
VoicE rEcorDing AnD PLAYBAcK
using APr9600 chiP
c o n s t r u c t i o n
S
U
N
L
K
U
M
A
R
Fig. 1 shows the functional block
diagram of IC APR9600. Complete chip
management is accomplished through
the device control and message control
blocks.
Voice signal from the microphone (see
Fig. 2) is fed into the chip through a dif-
ferential amplifer. It is further amplifed
by connecting Ana_Out (pin 21) to Ana_In
(pin 20) via an external
DC blocking capacitor C1.
A bias signal is applied to
the microphone and to save
power during playback, the
ground return of this bias
network can be connected
to the normally open side
of the record switch. Both
Mic.in and Mic.Ref (pins 18
and 19) must be coupled to
use of a proprietary analogue storage
technique implemented using fash non-
volatile memory process in which each cell
is capable of storing up to 256 voltage lev-
els. This technology enables the APR9600
to reproduce voice signals in their natural
form.
The APR9600 is a good standalone
voice recorder or playback IC with non-
volatile storage and playback capability for
32 to 60 seconds. It can record and play
multiple messages at random or in sequen-
tial mode. The user can select sample rates
with consequent quality and recording
time trade-off. Microphone amplifer, auto-
matic gain control (AGC) circuits, internal
anti-aliasing flter, integrated output ampli-
fer and messages management are some
of the features of the APR9600 chip.
Fig. 1: Functional block diagram of IC APR9600
Semiconductors:
IC1 - APR9600 voice processor
IC2 - LM386 low-power audio
amplifer
T1-T3 - BC557 pnp transistor
D1 - 1N4001 rectifer diode
LED1-LED3 - Red LED
Resistors (all -watt, 5% carbon, unless
stated otherwise):
R1, R2, R4-R8,
R16, R17 - 100 kilo-ohm
R3, R10 - 390-ohm
R9 - 220-kilo-ohm
R11 - 1-ohm
R12(A) - 33-kilo-ohm
R12(B) - 5-kilo-ohm
R13, R14 - 4.7-kilo-ohm
R15 - 1-kilo-ohm
Capacitors:
C1, C3, C4, C6,
C8, C9, C11 - 0.1F ceramic disk
C2 - 4.7F, 16V electrolytic
C5 - 22F, 16V electrolytic
C7 - 100F, 16V electrolytic
C10 - 0.47F, 63V electrolytic
C12 - 100F, 25V electrolytic
C13 - 100F, 10V electrolytic
Miscellaneous:
S1-S9 - Push-to-on switch
S10-S12 - On/off switch
LS1 - 8-ohm, 0.5W speaker
- Condenser microphone
Parts List
tabLe i
Modes selection
Mode MseL1 MseL2 /M8_Option
Random-access, 2 fxed-duration messages 0 1 Pull this pin to VCC through 100k resistor
Random-access, 4 fxed-duration messages 1 0 Pull this pin to VCC through 100k resistor
Random-access, 8 fxed-duration messages 1 1 Becomes the /M8 message trigger input pin
Tape-mode, normal operation 0 0 0
Tape-mode, auto-rewind operation 0 0 1
c o n s t r u c t i o n
electronics for you september 2004
the microphone network
through capacitors.
Re c or di ng s i g -
nal from the external
source can also be fed
directly into the chip
using Ana_In (pin 20),
but the connection be-
tween Ana_In (pin 20)
and Ana_out (pin 21)
is still required for
playback. An internal
anti-aliasing filter au-
tomatically adjusts its
response according to
the sampling frequency
selected. Then the sig-
nal is processed into
t he memor y ar ray
through a combination
of the sample-and-hold
circuit and analogue
read/write circuit. The
incoming voice signals
are sampled and the
instantaneous voltage
samples are stored in
the non-volatile flash
memory cells in 8-bit
binary encoded format.
During playback,
the stored signals are
ret ri eved f rom t he
memor y, smoot hed
to form a continuous
signal, low-pass fil-
tered and then ampli-
fed. The signal level at
the speaker terminals
SP+ and SP- (pins 14
and 15, respectively) is
at about 12mW power
into 16-ohm impedance. The output from
pin 14 (SP+) is further amplifed by the
low-power amplifer using LM386 (IC2) as
shown in the fgure. The recorded message
is reproduced into speaker LS1.
An internal oscillator provides sam-
pling clock to the APR9600. The fre-
quency of the oscillator and sampling rate
depend on the value of resistor R12
[R12(A)+R12(B)] connected across OSCR
(pin 7) of the chip and the ground.
Table II shows the sampling frequen-
cies corresponding to different resistor
values, as well as the resulting input band-
width and duration of recording. Higher
sampling rates improve the voice quality
but they also increase the bandwidth re-
quirement and thus reduce the duration.
Lower sampling rates use fewer memory
Fig. 2: Random-access mode confguration
cells and effectively increase the record-
ing/playback duration of the device. The
RC network (comprising resistor R9 and
capacitor C2 connected) at pin 19 sets the
AGC attack time. (The attack time is de-
fned as the delay present before the AGC
circuit begins to adjust gain.)
Message management. The APR9600
chip supports the following message
modes:
1. Random-access mode with 2, 4
or 8 messages within the total recording
time.
2. Tape mode with two options: auto
rewind and normal opera-
tion.
The modes are defned
by pins 24 (MSEL1), 25
(MSEL2) and 9 (/M8_Op-
tion) as shown in Table I,
and cannot be mixed.
An important feature
of the APR9600 chip is in-
dication of changes in the
device status through beeps
superimposed on the device
tabLe ii
reference rosc Values and Corresponding
sampling Frequencies
ref rosc sampling input Duration
frequency bandwidth
84k 4.2 kHz 2.1 kHz 60 sec
38k 6.4 kHz 3.2 kHz 40 sec
24k 8.0 kHz 4.0 kHz 32 sec
Note. Rosc table above is for reference only, different lots of ICs will have
somewhat different Rosc value performance
c o n s t r u c t i o n
electronics for you september 2004
output; for example, the start of recording
is indicated by a beep, so the person can
now start speaking into the microphone.
This feature is enabled by making pin 11
(BE) high.
General functional description.
On power up, pin 23 (CE) is pulled
low through resistor R7 to enable the
device for operation. Toggling this pin
by switch S9 also resets several message
management features. Pin 27 (RE) is
pulled low to enable recording and
it is pulled high for playback. To start
recording/playback, switch the appropri-
ate trigger pin as described later. Glow-
ing of LED1 indicates that the device is
busy and no commands can be cur-
rently accepted. The LED is driven by pnp
transistor T1, which is connected to pin 10
(Busy) of the chip. LED2 indicates record-
ing in each individual memory segment.
It is driven by pin 22 (strobe) through
transistor T2.
random-access mode
As mentioned earlier, the random-access
mode supports 2, 4 or 8 messages of fxed
durations. It allows easy indexing of mes-
sages as they can be recorded or played
randomly. The length of each message is
the total recording length available (as de-
fned by the selected sampling rate) divided
by the total number of memory segments/
tracks enabled (as per Table I).
Recording of sound. The circuit for
recording/playback of eight fxed-duration
messages in random-access mode is shown
Fig. 3: Circuit for recording/playback in tape mode with auto-rewind option
in Fig. 2. Pins 9 (M8_Op-
tion), 24 (MSEL1) and
25 (MSEL2) are pulled
high through resistors
R1, R6 and R5, respec-
tively. When switch S10
is closed, record pin 27
(RE) goes low to enable
recording of the message
from the microphone.
The maximum length of
the eight sound tracks is
7.5 seconds each.
Now to start record-
ing the first message,
press switch S1 and hold
it in this position. A beep
sound is heard and LED2
blinks. You can now
speak into the condenser
mic. The recording will
terminate if switch S1 is
released or if the record-
ing time exceeds 7.5
seconds. Similarly, press
switches S2 through S8
to record other sound
tracks. For recording of
two or four sound tracks
of fixed duration, the
status of pins 9, 24 and
25 is as per Table I.
Playback of sound
tracks. Open switch
S10 to make pin 27
high while keeping other
switches in the same
positions as in record-
ing. Toggling switches
S1 through S8 causes
playback of particular
sound tracks. Pressing
the same switch again or switch S9 termi-
nates playback of the sound track. Pressing
any other switch (S1 through S8) while a
sound track is being played causes a new
sound track to be played. If the switch is
held pressed, the particular sound track
will play continuously.
tape mode
The tape mode operation is much
like the conventional cassette tape
recorder, but with auto-rewind and normal
operation options. In auto-rewind mode,
the device automatically rewinds to the
beginning of the message immediately after
recording or playing the message. In normal
mode, it must be switched for rewind.
Sound recording in tape mode with
c o n s t r u c t i o n
electronics for you september 2004
Fig. 4: Circuit for recording/playback in tape mode with normal option
auto-rewind option. Fig. 3 shows the circuit
for recording/playback in tape mode with
auto-rewind option. In this confguration,
pins 24 (MSEL1) and 25 (MSEL2) are con-
nected to ground, whereas pin 9 is pulled
high through resistor R1. Close switch S10
to enable the recording of message. Press
switch S9 to reset the sound track counter to
zero. Now press switch S1 and hold it in this
position. A beep sound is heard and LED2
starts blinking. This means you can speak
into the mic. Recording will terminate when
switch S1 is released or if the recording time
exceeds 60 seconds. Press switch S1 again
and again to record second, third, fourth
and other consecutive sound tracks. Each
sound track may have a different length but
the total length of all sound tracks cannot
exceed 60 seconds. When LED3 lights up
during recording, it indicates the end of
memory array.
Playback in tape mode with auto-
rewind option. Open switch S10 to pull
Fig. 5: Combined actual-size, single-side PCB for circuits of Figs 2, 3 and 4
pin 27 high while keep-
ing other switches in the
same positions as appli-
cable during recording.
Toggle switch S1 repeat-
edly to play consecutive
sound tracks. Press switch
S9 to reset the sound track
counter to zero. During
playback, LED3 indicates
that all recorded messages
have been played.
Recording in tape
mode with normal op-
tion. Fig. 4 shows the
circuit for recorcding/
playback in tape mode
with normal option. Con-
nect pins 24 (MSEL1), 25
(MSEL2) and 9 (M8_op-
tion) to ground. Close
switch S10 to enable the
recording of message.
Press switch S9 to reset
the sound track counter
to zero. The normal-mode
recording is similar to the
rewind-mode recording,
except that after swich
S1 is released, the sound
counter doesnt increment
itself to the next sound
track location. To record
the first sound track,
press switch S1 and hold
it in this position. A beep
sounds and LED2 blinks.
Now you can speak into
c o n s t r u c t i o n
electronics for you september 2004
Fig. 6: Component layout for the PCB
sage will be recorded at the location of the
frst message.
Playback in tape mode with normal
option. Open switch S10 to pull pin 27
high while keeping other switches in
the same positions as during recording
operation. First, press switch S9 to reset
the sound track counter to zero. Now
momentarily press switch S1 to play the
frst sound track. Momentarily pressing of
switch S1 again and again will still play
the frst sound track. The sound track
counter can be incremented to play the
next sound track by momentarily pressing
switch S13.
The combined actual-size, single-side
PCB for the circuits of Figs 2, 3 and 4 is
shown in Fig. 5 and its component layout
in Fig. 6.
To obtain the confguration of Fig. 2,
connect connector Con1 to Con2 using
burgstick connectors with ribbon cable
or simply using jumper wires. Similarly,
confguration of Fig. 3 or Fig. 4 can be
realised by connecting Con1 to Con3 or
Con4. Note that switch S1 is common for
all confgurations.
the microphone. To record the next mes-
sage, release switch S1 and toggle switch
S13. Now press switch S1 again and hold
in this position. A beep sounds and LED2
blinks. This means you can speak into
the microphone to record the message. In
case you press switch S1 without toggling
switch S13 to record the message, the mes-
CirCuit ideas
77
ElEctronics For You august '99
Water Level Controller
cum Motor Protector
N
owadays, usage of overhead
tank (OHT) with an electrically
operated water pump is a com-
mon sight. The pump, being a costly
item, should be protected against dam-
age due to high and low voltages. People
fnd it very inconvenient to switch off the
pump even when their OHT starts over-
fowing, specially when they are busy
or it is raining. This circuit provides a
solution for all such problems. The main
features of this circuit are:
1. Low and high voltage cut-off
2. Automatic switching off of motor
when overhead tank is full
3. Use of convenient push-to-on but-
tons for switching on and switching off
of motor.
The heart of the circuit is IC
CD4011, which has four inverter gates.
When the circuit gets 12V power supply,
limits, as explained below.
When the voltage level rises above
a pre-determined value, input to gate
N3 becomes high and its output become
low, which turns off transistor T2 and
also the relay. When the voltage level
drops below a pre-determined value,
output of gate N4 becomes high, which
turns off transistor T3 and relay RL1.
Thus when the mains AC voltage (or the
DC voltage sample derived from mains)
is above or below certain limits, which
could damage the pump motor, the sup-
ply to the motor is cut-off.
D2 provides a constant DC voltage
to IC1.
For setting the low voltage cut-off,
adjust potmeter VR2 in such a way
that when supply voltage goes be-
low 190V, output of N4 goes high.
Similarly, for setting the high volt-
age cut-off, adjust potmeter VR1
in such a way that when supply
voltage goes above 250V, output
of N3 goes low. The high and low
cut-off voltages can be changed
according to the requirement for a
given motor.
Two wires are needed to connect
the circuit to the sensors which are
ftted in the OHT. Sensors must be
ftted as shown in fgure. A simple
power supply circuit is also shown
here. The circuit can be assembled
on a general-purpose PCB and
housed in an eliminator case which
is easily available in the market.
Use good-quality insulated wire to
connect sensor to the circuit.
RAmAkRISHNAN k.
capacitor C1 pulls input of N1 low, and
this causes the output of N2 to go low.
This state is latched by resistor R1 and
transistor T1 is biased to cut-off state,
and hence both relay RL1 and motor m
are in off state.
When we push switch S1 momen-
tarily, the input of inverter gate N1
becomes high and output of gate N2 also
becomes high. As a result, transistor T1
turns on and both relay RL1 and mo-
tor are activated (provided transistors
T2 and T3 are forward biased). When
water level in OHT touches the sensors,
input of N1 become low, which turns
relay RL1 off and the motor stops.
The motor can be turned off manu-
ally also by pushing switch S2 at any
time. Transistors T2 and T3 are both
forward biased if the line voltage is
within certain low and high voltage
CI R CU I T I D E A S
ELECTRONICS FOR YOU MARCH 2003
S
A
N
I T
H
E
O
T
his circuit allows you to watch your
favourite TV programmes late at
night without disturbing other fam-
ily members. As against imported stereo
wireless TV headphones available in the
market for around Rs 1200, it costs just
Rs 30, or even less, if the components are
taken from a discarded transistor receiver,
with no compromise on performance.
The unit is basically a simple FM trans-
mitter housed in a plastic or metal enclo-
sure. Transistor T1 acts as an audio pream-
plifier. Transistor T2 works as an FM os-
cillator and modulator in conjunction with
other passive components. Trimmer capaci-
tor VC1 connected across inductor L1 can
be varied to achieve the desired frequency.
Inductor L1 comprises 4 to 6 turns of
closely wound 25SWG enamelled copper
wire on a 4mm dia. air core. A 20-30cm
long wire serves as an antenna.
Most modern TVs are nowadays
WI RELESS TV HEADPHONE CI RCUI T
PRADIPTA BANERJEE
equipped with audio-in/ out and video-in/
out RCA sockets. Using an RCA-to-RCA
cord, connect the audio output of your TV
to the transmitters input. Adjust the gain
of the audio preamplifier with the help of
preset VR1 for clear reception in a por-
table FM receiver equipped with an ear-
phone socket. Use a good-quality earphone.
This transmitter draws only a few mil-
liamperes of current and doesnt require
on/ off switch. It can be fabricated on a
small piece of stripboard. All connectors
should be firm and as short as possible to
prevent unwanted oscillations. The circuit
operates off two AA-size penlight torch cells.
The circuit is meant for mono recep-
tion. EFY note. All TVs dont have head-
phone jacks.
circuit
ideas
100 october 2008 electroni cs for you www. e f y ma g . c o m
N
ormally, home appliances are
controlled by means of switch-
es, sensors, etc. However,
physical contact with switches may be
dangerous if there is any shorting.
The circuit described here requires
no physical contact for operating the
appliance. You just need to move
your hand between the infrared LED
(IR LED1) and the phototransistor
(T1). The infrared rays transmitted by
IR LED1 is detected by the phototran-
sistor to activate the hidden lock, fush
system, hand dryer or else.
This circuit is very stable and sensi-
tive compared to other AC appliance
control circuits. It is simple, compact
and cheap. Current consumption is
low in milliamperes.
The circuit is built around an IC
CA3140, IRLED1, phototransistor and
other discrete components. When regu-
Navpreet SiNgh tuNg
WireLeSS SWitCh
S.C. DW
IVEDI
lated 5V is connected to the circuit, IR
LED1 emits infrared rays, which are
received by phototransistor T1 if it is
properly aligned. The collector of T1
is connected to non-inverting pin 3 of
IC1. Inverting pin 2 of IC1 is connected
to voltage-divider preset VR1. Using
preset VR1 you can vary the reference
voltage at pin 2, which also affects sen-
sitivity of the phototransistor.
Op-amp IC1 amplifes the signal
received from the phototransistor.
Resistor R3 controls the base current of
transistor BC548 (T2). The high output
of IC1 at pin 6 drives transistor T2 to
energise relay RL1 and switch on the
appliance, say, hand dryer, through the
relay contacts.
The working of the circuit is simple.
In order to switch on the appliance,
you simply interrupt the infrared rays
falling on the phototransistor through
your hand. During the interruption,
the appliance remains on through the
relay. When you remove your hand
from the infrared beam, the appliance
turns off through the relay.
Assemble the circuit on any gen-
eral-purpose PCB. Identify the resistors
through colour coding or using the
multimeter. Check the polarity and pin
confguration of the IC and mount it
using base. After soldering the circuit,
connect +5V supply to the circuit.
c i r c u i t i d e a s
electronics for you April 2004
Zener diode tester
P. Venkata Ratnam
T
his zener diode tester can be used
to check zener diodes of 3.3V to
18V. The breakdown voltage of the
unknown zener diode is indicated on the
precalibrated dial of potmeter VR1. The
tester can also identify the polarity of
zener diodes.
The power supply section comprising
transformer X1, rectifer diode D1, flter
capacitor C1, resistor R1, transistor T1
and zener diodes ZD1 and ZD2 provides
approximately 20V DC stabilised voltage
to the sensor section. The sensor circuit
comprises resistors R2 and R3, potmeter
VR1, red LED1 and transistor T2.
When linear potmeter VR1 is adjusted
such that the voltage at its wiper arm (red
crocodile clip) exceeds the breakdown
voltage of the zener diode, the zener diode
conducts and applies the bias voltage at
the base of transistor T2, which causes
red LED1 to light up. When the voltage at
the wiper arm (red clip) is less than the
breakdown voltage, the zener diode does
not conduct and red LED1 does not glow.
For calibration of the zener diode tes-
ter, initially set the pointer knob of potme-
ter VR1 towards zero-resistance position.
Short red clip of the potmeter and black
clip of the transistor and switch on the
tester. Rotate the pointer knob of potmeter
VR1 slowly in clockwise direction until
LED1 just starts to glow. Mark this setting
of the knob on the paper dial as 0V.
Now connect a known zener diode of
3.3V between both the clips (red clip to
the cathode and black clip to the anode of
the zener diode) as shown in the fgure.
Rotate the knob of potmeter VR1 further in
clockwise direction until LED1 just starts
to glow. Mark this setting of the knob on
the paper dial as 3.3V. Likewise, calibrate
the dial of potmeter VR1 for other values
of zener diodes by connecting known zener
diodes to the tester. Now the tester is ready
for use.
For testing an unknown zener diode,
connect it across the clips in correct polar-
ity and rotate the knob of potmeter VR1
until red LED1 just starts to glow. The
voltage shown by the pointer knob on the
dial at this setting is the breakdown voltage
value of the zener diode under test.
If the zener diode is connected
in reverse polarity (red clip to the an-
ode and black clip to the cathode), the
LED glows brightly at all settings of
the knob above the zero reading, indi-
cating that the zener diode is wrongly
connected. The anode and cathode termi-
nals of rectifer diodes can also be identi-
fed in this way. Do not touch the clips
while testing.