Sie sind auf Seite 1von 236

KS Project Manual

eFY june 2009


Microcontroller-based
dc Motor controller
M
otion control plays
a vital role in in-
dustrial automa-
tion. Manufacturing plants
in industries like chemical,
pharmaceutical, plastic and
textile, all require motion
control. And it may be a fat-
belt application, fow-control
application or mixing of
substances. Different types
of motorsAC, DC, servo or
stepperare used depend-
ing upon the application. Of
these, DC motors are widely
used because controlling
a DC motor is somewhat
easier than other kinds of
motors.
The motion of a DC mo-
tor is controlled using a DC
drive. DC drive changes the
speed and direction of mo-
tion of the motor. Some of
the DC drives are just a recti-
fer with a series resistor that
converts standard AC supply
into DC and gives it to the
motor through a switch and
a series resistor to change
the speed and direction of
rotation of the motor. But
many of the DC drives have
an inbuilt microcontroller
that provides programmable
facilities, message display
on LCD, precise control and
also protection for motors.
Using the DC drive you can
program the motion of the
motor, i.e., how it should
rotate.
Here are some of the
features of this DC motor
controller:
1. Controlled through
microcontroller AT89C51
2. Message displayed on
the LCD module
F
i
g
.

1
:

C
i
r
c
u
i
t

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

D
C

m
o
t
o
r

c
o
n
t
r
o
l
l
e
r

KS Project Manual
eFY june 2009
3. Start,
s t op and
change of
direction of
the motor
controlled
by pushbut-
ton switch-
es and in-
dicated by
LED
4 .
C h a n g e s
the running
mode of the motor to continuous, re-
versible or jogging
5. Changes the speed of the motor
6. Time settings are possible for
forward and reverse running of the
motor
circuit description
Fig. 1 shows the circuit of the micro-
controller-based DC motor controller.
At the heart of the DC motor controller
is microcontroller AT89C51. Port pins
P0.0 through P0.7 of the microcontrol-
ler are interfaced with data pins D0
through D7 of the LCD module, re-
spectively. Port pins P3.0, P3.1 and P3.2
control the LCD operation through
enable (E), register-select (RS) and
read/write (R/
W) pins, respec-
tively. Contrast
of the LCD is set
by preset VR1.
Port pins P1.0
through P1. 7
are connected
to switches S1
through S8 for
performing the
various opera-
tions.
Power-on reset signal for the mi-
crocontroller is generated by the com-
bination of capacitor C1 and resistor
R1. Switch S9 provides manual reset to
the microcontroller. A 12MHz crystal
provides the basic clock frequency to
the microcontroller. Capacitors C2 and
C3 provide stability to the oscillator.
EA pin (pin 31) of the microcontroller
is connected to 5V to enable internal
access. Port pins P2.0 through P2.3 of
the microcontroller are used for LED
indication of run, stop, clockwise and
anti-clockwise rotation. Port pins P2.4
through P2.6 are connected to the inputs
of inverters N3, N2 and N1 of 74LS04
(IC2). The output of inverter N3 is used
to trigger pin 2 of NE555 timer.
Timer NE555 is confgured as a
monostable and its time period is de-
cided by preset VR2 and capacitor C4.
When pin 2 of NE555 goes low, output
pin 3 becomes high for the predeter-
mined period.
The output of NE555 is connected
to pole P of relay RL1. Normally-open
(N/O) contacts of relay RL1 are con-
nected to N/O1 and N/C2 contacts of
relay RL2. N/C1 and N/O2 contacts
of RL2 are connected to ground. The
outputs of inverters N2 and N1 drive
relays RL1 and RL2 with the help of
transistors T1 and T2, respectively. D1
and D2 act as free-wheeling diodes.
Poles P1 and P2 of RL2 are connected
to IN1 and IN2 pins of motor driver
L293D. OUT1 and OUT2 of L293D
drive motor M.
Fig. 2 shows the power supply
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 rectifer comprising
diodes D3 through D6, fltered by ca-
pacitor C6 and then regulated by ICs
7805 (IC5) and 7806 (IC6). Capacitors
C7 and C8 bypass the ripples present
in the regulated 5V and 6V power sup-
plies. LED5 acts as a power-on indica-
tor and resistor R10 limits the current
through LED5.
The proposed panel arrangement
for the microcontroller-based DC mo-
tor controller is shown in Fig. 3.
An actual-size, single-side PCB for
the microcontroller-based DC motor
controller is shown in Fig. 4 and its
component layout in Fig. 5.
operation
The eight pushbutton switches are con-
nected for eight different functions as
shown in the table.
When S1 is pressed, the micro-
controller sends low logic to port pin
P2.5. The high output of inverter N2
drives transistor T1 into saturation
and relay RL1 energises. So the output
of NE555 is fed to inputs IN1 and IN2
of L293D through both the contacts of
relay RL2. Now at the same time, after
RL1 energises, the microcontroller
starts generating PWM signal on port
pin P2.4, which is fed to trigger pin
2 of NE555 through inverter N3. The
base frequency of the generated PWM
signal is 500 Hz, which means the time
period is 2 ms (2000s). The output
pulse width varies from 500 s to 1500
s. The R-C time constant of the mon-
ostable multivibrator is kept slightly
less then 500 s to generate exactly the
same inverted PWM as is generated by
the microcontroller.
When switch S2 is pressed, port-pin
P2.5 goes high and RL1 de-energises to
stop the motor.
When switch S3 is pressed, relay
Fig. 2: Circuit of the power supply
Functions of
Different Switches
Switch Function
S1 Tostartmotor
S2 Tostopthemotor
S3 Changethemode
S4 Changethedirection
S5 Increasespeed
S6 Decreasespeed
S7 Increasetime
S8 Decreasetime
Fig. 3: Proposed panel arrangement for the DC motor controller
KS Project Manual
eFY june 2009
RL2 energises. Pin IN1 of motor driver
L293D receives the PWM signal and
pin IN2 connects to ground. As a re-
sult, the motor rotates in one direction
(say, clockwise).
When switch S4 is pressed again,
relay RL2 de-energises. Pin IN2 of
motor driver L293D receives the PWM
signal and pin IN1 connects to ground.
The motor now rotates in opposite di-
rection (anti-clockwise).
When switch S3 is pressed, differ-
ent modes are selected in cyclic manner
as given below:
1. Continuous mode. The motor ro-
tates continuously with the set speed
in either direction
2. Reversible mode. The motor re-
verses automatically after the set time
3. Jogging mode. The motor rotates
for the set time in either direction and
then stops for a few seconds and again
rotates for the set time. It is also called
pulse rotation
Switches S5 and S6 are used to set
the speed of the motor, either in in-
creasing order or decreasing order, in
continuous mode only.
Switches S7 and S8 are used to set
the time either in increasing order or
decreasing order.
software
The program is written in C language
and compiled using Keil Vision3 com-
piler. It is well commented and easy
to understand. The program has three
major sections: initialisation and key
press, display and motor control.
Initialisation and key press. It con-
sists of the main function that initialises
timers, ports, LCD module and LED in-
dication and then waits for key press.
When any key is pressed, the program
calls that particular function.
In the main function, frst the ports
are initialised as input/output, then the
LCD is initialised and cleared. At pow-
er-on reset or manual reset, message
DC motor controller is displayed on
the LCD and LED1 through LED4 turn
off. When start switch S1 is pressed,
message Motor Start is displayed for
a second, and then the mode and cur-
rent speed are displayed. Run LED and
clockwise-direction LED are on. Now
the program waits for key press. When
any key is pressed, the program jumps
to one of the functions (start, direction,
mode, etc).
Fig. 4: A single-side, actual-size PCB layout for the microcontroller-based DC motor controller
Fig. 5: Component layout for the PCB
Display. It uses the following func-
tions:
1. writecmd function sends com-
KS Project Manual
eFY june 2009
mand byte to the LCD. It takes one
argument byte and sends it to P0.
2. writedata function sends data
byte to be displayed on the LCD. It also
takes one argument byte and sends it
to P0.
3. writestr function writes the
whole string (message) on the LCD. It
takes pointer as an argument that points
address of the frst character of the
string, then through the pointer it sends
all the characters one by one to P0.
4. busy function checks the status
of the busy fag of the LCD. If the fag
is set, the LCD is not ready and the pro-
gram remains within the loop. When
the fag is reset, the LCD is ready and
the program comes out of the loop.
Motor control. It uses the following
functions:
1. start function starts motor rota-
tion in one of the modes (continuous,
reversible or jogging). The mode is
selected by mode-selection fag m. As
explained earlier, in continuous mode
the motor keeps rotating with the set
speed. In reversible mode, the motor
changes direction automatically after
the set time. In jogging mode, the mo-
tor rotates for the set time, stops for a
few seconds and then rotates.
2. stop function stops rotating the
motor and displays the message on
the LCD module. This is indicated by
glowing of the stop LED.
3. direction function increments
the counter by 1 every time and
checks whether the count is even or
odd. If the count is even, it selects
clock-wise direction, and if the count is
odd, it selects anticlockwise direction.
This is also indicated on direction CLK
and ACLK LEDs.
4. mode function changes modes
in cyclic manner. It increases mode-
selection fag m every time. If m=0
it selects continuous mode, if m=1 it
Parts List
Semiconductors:
IC1 - AT89C51 microcontroller
IC2 - 74LS04 hex inverter
IC3 - NE555 timer
IC4 - L293D motor driver
IC5 - 7805, 5V regulator
IC6 - 7806, 6V regulator
T1, T2 - BC548 npn transistor
D1-D6 - 1N4007 rectifer diode
LED1-LED5 - 5mm LED
Resistors (all -watt, 5% carbon):
R1 - 10-kilo-ohm
R2-R5 - 2-kilo-ohm
R6-R10,
R12, R13 - 220-ohm
R11 - 1-kilo-ohm
VR1, VR2 - 10-kilo-ohm preset
Capacitors:
C1 - 10F, 16V electrolytic
C2, C3 - 33pF ceramic disk
C4, C7, C8 - 0.1F ceramic disk
C5 - 0.01F ceramic disk
C6 - 1000F, 25V electrolytic
Miscellaneous:
X1 - 230V AC primary to 9V,
500mA secondary
transformer
X
TAL
- 12MHz crystal
RL1 - 6V, 1C/O relay
RL2 - 6V, 2C/O relay
M - 6V DC motor
S1-S9 - Push-to-on switch
LCD module - 162 line
- 14-pin bergstik SIP
Connector (male & female)
#include<reg51.h>
#include <string.h>
sbit rs = P3^1;
// rs pin of LCD
sbit en = P3^0;
// en pin of LCD
sbit rw = P3^2;
// rw pin of LCD
sbit b = P0^7;
// busy fag
sbit led1=P2^0;
// run indicator
sbit led2=P2^1;
// stop indicator
sbit led3=P2^2;
// clockwise direction indicator
sbit led4=P2^3;
// anticlockwise direction indicator
sbit PWM=P2^4;
// PWM output
sbit RL1=P2^5;
// relay 1 pin
sbit RL2=P2^6;
// relay 2 pin
dcmd.c
unsigned int x=10; / /
ontime
unsigned int y=10; / /
offtime
unsigned int m=0;
// mode
unsigned int d=0;
// direction
unsigned int t=100;
// time
unsigned int r=0;
// run fag
void start(void);
// function initilization
void mode(void);
void direction(void);
void incspeed(void);
void decspeed(void);
void inctime(void);
void dectime(void);
void time(unsigned int);
void delay(unsigned int);
void keydly(void);
void busy(void);
void writecmd(unsigned char a)
// send command to LCD
{

busy();
// check busy fag
rs = 0;
// select command register
rw = 0;
// write enable
P0 = a;
// send byte to LCD
en = 1;
// apply strobe pulse
en = 0;
}
void writedata(unsigned char b)
// send data to LCD
{

busy();
selects reversible mode and if m=2 it
selects jogging mode. If m=3 it is reset
to 0 again and selects continuous
mode and likewise.
5. incspeed function increases the
width of the pulse by 100 s. The gener-
ated PWM is of 500 Hz. That means total
time is 2 ms=2000 s. The width of the
pulse is varied from 500 s to 1500 s in
steps of 100 s. To display the speed, the
variable is frst converted into speed fac-
tor 1 to 9 and then into ASCII.
6. decspeed function is the same
as incspeed but here the width of the
pulse is decreased by 100 s.
7. inctime function increases the
reversible time of the motor by one
second. It increases the variable in mul-
tiples of 20. To display it on the LCD
module, it is frst divided by 20 and
then converted into ASCII.
8. dectime function is the same as
inctime but it decreases reversible
time by one second.
Delay. It uses the following func-
tions:
1. keydly function generates a
fx delay of around 50 ms for key de-
bouncing.
2. delay function generates a vari-
able delay by timer 0. The basic delay is
of 100 s. It is rotated in loop from fve
to 15 times to generate minimum 500s
and maximum 1500s delay.
3. time function again generates a
variable delay by timer 1. The basic delay
is of 50 ms. It is rotated in multiples of 20
from 20 to 180 to generate minimum 1-
second and maximum 9-second delay.
KS Project Manual
eFY june 2009
// check busy fag
rs = 1;
// select data register
rw = 0;
// write enable
P0 = b;
// write enable
en = 1;
// send byte to LCD
en = 0;
// apply strobe pulse

}
void busy()
// check busy fag of
LCD
{
en = 0;
// disable display
P0 = 0xFF;
// P0 as input
rs = 0;
// select command register
rw = 1;
// read enable
while(b==1)
// if busy bit is 1
{
en=0;
// remain withine loop
en=1;
}
en=0;

}
void writestr(unsigned char *s)
// send string message to LCD
{
unsigned char l,i;
l = strlen(s);
// get length of string
for(i=0;i<l;i++)

{
writedata(*s);
// till the length of string
s++;
// send characters one
by one
}
}
void start()
// start rotating motor
{
if(m==0)
// for m=0 start continuous
mode
{
RL1=0;
// switch on RL1
r=1;
// set run fag
P1=0xFF;
// send all 1s to P1
while(P1==0xFF)
// till no key is pressed
{
led1=1;
// indication on run LED
PWM=1;
// send high logic to PWM pin
delay(x);
// on time delay
PWM=0;
// now send low logic to PWM
delay(y);
// off time delay
}
}
else if(m==1)
// for m=1 start reversible mode
{
r=1;
// set run fag
P1=0xFF;
// send all 1s to P1

while(P1==0xFF) // till no key is
pressed
{


led1=1; // run LED=1

led3=1;

led4=0;

PWM=1; // send high on PWM pin

RL2=1; // select one direction

RL1=0; // switch on RL1

time(t); // wait for desired time

RL1=1; // switch off RL1

led1=0; // run LED=0;

time(20); // wait for 1 sec

led1=1; // again run LED=1

led3=0;

led4=1;

RL2=0; // select other direction

RL1=0; // switch on RL1

time(t); // wait for desire time

RL1=1; // switch off RL1

led1=0; // run LED=0

time(20); // wait for 1 sec
}

PWM=0;

}
else if(m==2)
// for m=2 start jogging mode
{

r=1; // reset run fag

P1=0xFF; // send all 1s to P1

while(P1==0xFF) // till no key is
pressed
{

led1=1;

PWM=1; // send high on PWM pin

RL1=0; // switch on RL1

time(t); // wait for 1 sec

RL1=1; // switch off RL1

PWM=0; // send low on PWM pin

led1=0;

time(20);
}

}
}
void direction()
// alter the direction
{
keydly();
// key debounce delay
d++;
// increment count
if((d%2)==0)
// check for even or odd
{
led3=1;
// indicate on LEDs
led4=0;
RL2=1;
// switch ON / OFF RL2
}
else
{
led3=0;
led4=1;
RL2=0;
}
}
void mode()
// change mode of rotation
{
keydly();
// key debounce delay
writecmd(0x80);
// display message on frst line
frst column
m++;
// increment count
if(m==3) m=0;
// if it is 3 reset it
if(m==0)
{ writestr(mode:continuous
); // otherwise display mode
time(15);
}
else if(m==1)
{writestr(mode:reversible );
time(15);
}
else if(m==2)
{writestr(mode:jogging );
time(15);
}
}
void decspeed()
// increase speed
{
int z;
keydly(); / /
key debounce
writecmd(0xC0); / /
select second line on LCD
if(y<14) / /
if not max pulse width
{
x--;
y++; / /
increase it convert it in to
z=y-5+0x30; / /
1 to 10 scale and ASCII
writestr(speed: ); // dia-
play speed on LCD
writedata(z);
writestr( );
}
else if(y==14)
writestr(min speed: 9 );//
if max speed display message
}
void incspeed() / /
increase speed
{
int w;
keydly();
writecmd(0xC0); // key de-
bounce
if(y>6) / /
if not minimum width
{
x++;
y-- ; // decrease
it
w=y-5+0x30; // do same
as above
writestr(speed: );
writedata(w);
writestr( );
}
else if(y==6)
writestr(max speed: 1 ); //
if min speed display message
}
void inctime() / /
increase time
{
int p;
keydly(); / /
key debounce delay
writecmd(0xC0);


if(t<180) / /
if not max time
{
KS Project Manual
eFY june 2009
t+=20; / /
increase it by 1 sec
p=t/20;
p=p+0x30; / /
convert it in to ASCII
writestr(time: ); //
display it
writedata(p);
w r i t e s t r ( s e c
);
}
else if(t==180)
writestr(max time: 9 sec);
// if max time display message
}
void dectime() / /
decrease time
{
int q;
keydly(); / /
key debounce delay
writecmd(0xC0);
if(t>20) / /
if not min time
{
t-=20; / /
decrease it
q=t/20;
q=q+0x30; / /
do same as above
writestr(time: );
writedata(q);
w r i t e s t r ( s e c
);
}
else if(t==20)
writestr(min time: 1 sec);
// if min time display message
}
void keydly() / /
key debounce delay
{
int a,b;
for(a=0;a<50;a++)
for(b=0;b<1000;b++);
}
void time(unsigned int c) // change
time in seconds
{
int k;
TL1 = 0xAF;
// use timer 1
TH1 = 0x3C;
// to generate 50 ms delay
TR1 = 1; / /
start timer
for(k=0;k<=c;k++) / /
rotate loop in multiples of 20
{
while(TF1==0); / /
wait till timer overfow
TF1 = 0; / /
reset the fag
TL1 = 0xAF;
// reload it
TH1 = 0x3C;
}
TR1 = 0; / /
stop timer
}
void delay(unsigned int c1) // change
time in micro seconds
{
int a;
TH0=0x9B; / /
select timer 0
TL0=0x9B; / /
to generate 100 micro second delay
TR0=1; / /
start timer

for(a=0;a<c1;a++) / /
rotate loop between 5 to 15
{
while(TF0==0); / /
wait until timer overfow
TF0=0; / /
reset the fag
}
TR0=0; / /
stop timer
}
void main()
{
TMOD=0x12; // timer1 in 16
bit,timer 0 in 8 bit auto reload mode
P2=0xE0; / /
LEDs off, relays OFF
P0=0x00; / /
P0, P3 output ports
P3=0x00;
writecmd(0x3C); / /
initilize LCD
writecmd(0x0E);
writecmd(0x01);
writecmd(0x84); / /
display message
writestr(DC Motor); // DC motor
controller in
writecmd(0xC3); / /
center of LCD
writestr(Controller);
agin:P1=0xFF; / /
P1 as input port
while(P1==0xFF); / /
wait until any key press
loop:switch(P1)
{
case 0xFE:
// for frst key
keydly();
// key debounce
writecmd(0x01);
writestr(motor start);
time(50);
// wait for 2.5 sec
writecmd(0x80);
writestr(mode:continuous
);// display current mode and speed
writecmd(0xC0);
writestr(speed: 5 );
led1=1; / /
Run LED ON
led2=0; / /
stop LED OFF
led3=1; / /
clockwise direction ON
led4=0; / /
anticlockwise direction OFF
start(); / /
sart rotating motor
break;
case 0xFD:
// for second key
keydly();
// key debounce
r=0;
// run fag reset
writecmd(0x01);
writestr(motor stop);// dis-
play message
led1=0; / /
Run OFF
led2=1; / /
stop LED ON
led3=0; / /
clockwise direction OFF
led4=0; / /
anticlockwise direction OFF
PWM=0; / /
low logic to PWM pin
RL1=1; / /
relay1 off
break;
case 0xFB:
// for third key
mode(); / /
select mode
if(r==1) start(); / /
jump to start if run fag is set
break;
case 0xF7:
// for fourth key
direction(); / /
change direction
if(r==1) start(); // jump to
start if run fag is set
break;
case 0xEF:
// for ffth key
incspeed(); / /
increase speed
if(r==1) start(); // jump to
start if run fag is set
break;
case 0xDF:
// for sixth key
decspeed(); / /
decrease speed
if(r==1) start(); // jump to
start if run fag is set
break;
case 0xBF:
// for seventh key
inctime();
// increase time
if(r==1) start(); // jump to
start if run fag is set
break;
case 0x7F:
// for eigth key
dectime();
// decrease time
if(r==1) start(); // jump to
start if run fag is set
break;
}
if(r==1) goto loop; / /
if run fag is set jump of key detect
else goto agin; / /
if not jump to again
}

GURSHARANJEET SINGH KALRA


SUNI L KUMAR
WATER-LEVEL CONTROLLER-
CUM-MOTOR PROTECTOR
M
any a time we forget to
switch off the motor push-
ing water into the overhead
tank (OHT) in our households. As a
result, water keeps overflowing until
we notice the overflow and switch the
pump off. As the OHT is usually kept
on the topmost floor, it is cumber-
some to go up frequently to check the
water level in the OHT.
Heres a microcontroller-based wa-
ter-level controller-cum-motor protec-
tor to solve this problem. It controls
on and off conditions of the motor
depending upon the level of water in
the tank. The status is displayed on an
LCD module. The circuit also protects
the motor from high voltages, low volt-
ages, fluctuations of mains power and
dry running.
Circuit description
Fig. 1 shows the circuit of the
microcontroller-based water-level con-
troller-cum-motor protector. It com-
prises operational amplifier LM324,
microcontroller AT89C51, optocoupler
PC817, regulator 7805, LCD module
and a few discreet components.
The AT89C51 (IC2) is an 8-bit
microcontroller with four ports ( 32
I/O lines), two 16-bit timers/counters,
on-chip oscillator and clock circuitry.
Eight pins of port-1 and three pins of
port-3 are interfaced with data and
control lines of the LCD module. Pins
P3.0, P3.1 and P3.6 are connected to
RS (pin 4), R/W (pin 5) and E (pin
6) of the LCD, respectively. Pin EA
(pin 31) is strapped to Vcc for inter-
nal program executions. Switch S2 is
used for backlight of the LCD mod-
ule.
Power-on-reset is achieved by con-
necting capacitor C8 and resistor R14
to pin 9 of the microcontroller. Switch
S1 is used for manual reset.
The microcontroller is operated
with a 12MHz crystal. Port pins P2.0
through P2.2 are used to sense the
water level, while pins P2.3 and P2.4
are used to sense the under-voltage
and over-voltage, respectively. Pin
P3.4 is used to control relay RL1 with
the help of optocoupler IC3 and tran-
sistor T5 in the case of under-volt-
age, over-voltage and different wa-
ter-level conditions. Relay RL1 oper-
ates off a 12V supply. Using switch
S3, you can manually switch on the
motor.
The LM324 (IC1) is a quad opera-
tional amplifier (op-amp). Two of its
op-amps are used as comparators to
detect under- and over-voltage. In nor-
mal condition, output pin 7 of IC1 is
low, making pin P2.3 of IC2 high.
When the voltage at pin 6 of N1 goes
below the set reference voltage at pin
5 (say, 170 volts), output pin 7 of N1
goes high. This high output makes pin
P2.3 of IC2 low, which is sensed by
the microcontroller and the LCD mod-
ule shows low voltage.
In normal condition, pin 1 of N2 is
high. When the voltage at pin 2 of N2
goes above the set voltage at pin 3,
output pin 1 of N2 goes low. This low
signal is sensed by the microcontroller
and the LCD module shows high volt-
age.
Presets VR1 and VR2 are used for
calibrating the circuit for under- and
over-voltage, respectively.
The AC mains is stepped down by
transformer X1 to deliver a secondary
output of 12V at 500 mA. The trans-
former output is rectified by a full-
wave bridge rectifier comprising di-
odes D5 through D8, filtered by ca-
pacitor C2, and used for the under-
and over-voltage detection circuitry.
The transformer output is also rec-
tified by a full-wave bridge rectifier
comprising diodes D1 through D4, fil-
tered by capacitor C1 and regulated
by IC4 to deliver regulated 5V for the
circuit.
When water in the tank rises to
come in contact with the sensor, the
base of transistor BC548 goes high.
This high signal drives transistor
BC548 into saturation and its collector
goes low. The low signal is sensed by
PARTS LIST
Semiconductors:
IC1 - LM324 quad op-amp
IC2 - AT89C51 microcontroller
IC3 - PC817 optocoupler
IC4 - 7805, 5V regulator
T1-T4 - BC548 npn transistor
T5 - SL100 npn transistor
D1-D14 - 1N4007 rectifier diode
Resistors (all -watt, 5% carbon):
R1, R2, R7,
R11, R12 - 1-kilo-ohm
R3, R9 - 560-kilo-ohm
R4, R5, R8 - 2.7-kilo-ohm
R6 - 330-ohm
R10 - 470-ohm
R13 - 100-ohm
R14 - 10-kilo-ohm
R15-R17 - 100-kilo-ohm
R18-R20 - 2.2-kilo-ohm
R21, R22 - 33-ohm
RNW1 - 10-kilo-ohm resistor
network
VR1, VR2 - 470-ohm preset
VR3 - 10-kilo-ohm preset
Capacitors:
C1-C3 - 1000F, 35V electrolytic
C4 - 220F, 16V electrolytic
C5, C6 - 33pF ceramic disk
C7 - 100F, 35V electrolytic
C8 - 10F, 16V electrolytic
Miscellaneous:
X1 - 230 AC primary to 12V,
500mA secondary
transformer
RL1 - 12V, 1C/O relay
X
TAL
- 12MHz crystal
S1 - Push-to-on switch
S2, S3 - On/off switch
- LCD module (116)
CONSTRUCTION
FEBRUARY 2007 WWW. E F Y MA G . C O M
port pins of
mi crocont rol l er
IC2 to detect
empty tank, dry
sump and full tank,
respectively.
An actual-size,
single-side PCB for
the water-level
controller-cum-mo-
tor protector (Fig.
1) is shown in Fig.
2 and its compo-
nent layout in Fig.
3.
Operation
When water in the
tank is below sen-
sor A, the motor
will switch on to
fill water in the
tank. The LCD
module will show
motor on. The
controller is pro-
grammed for a 10-
minute time inter-
val to check the
dry-run condition
of the motor. If wa-
ter reaches sensor
B within 10 min-
utes, the
mi crocont rol l er
comes out of the
dry-run condition
and allows the mo-
tor to keep pushing
water in the tank.
The motor will
remain on until
water reaches sen-
sor C. Then it will
stop automatically
and the
mi crocont rol l er
will go into the
standby mode. The
LCD module will
show tank full fol-
lowed by standby
mode after a few
seconds. The
standby mode
message is dis-
played until water
CONSTRUCTION
FEBRUARY 2007 WWW. E F Y MA G . C O M
in the tank goes below sensor A.
In case water does not reach sen-
sor B within 10 minutes, the
microcontroller will go into the dry-
running mode and stop the motor for
5 minutes, allowing it to cool down.
The LCD module will show dry-
sump1.
and if the dry-run condition still per-
sists, the display will show dry-
sump3 and the microcontroller will
not start the motor automatically. Now
you have to check the line for water
and manually reset the microcontroller
to start operation.
In the whole procedure, the
microcontroller checks for high and
low voltages. For example, when the
voltage is high, it will scan for about
two seconds to check whether it is a
fluctuation. If the voltage remains high
after two seconds, the microcontroller
will halt running of the motor. Now it
will wait for the voltage to settle down.
After the voltage becomes normal, it
will still check for 90 seconds whether
the voltage is normal or not. After nor-
mal condition, it will go in the standby
mode and start the aforementioned
procedure.
Practical applications
This controller is useful for single-phase
operated motor-pumps and the pumps
that suck water from the ground water
tank. A small push-to-off manual
switch in series with sensor A can also
make it useful for pumps that suck
water from Jal Boards supply. Because
of the particular timing of this water
supply, the controller must be switched
on within the timing of the water sup-
ply and switched off when water is not
being supplied.
When the controller is on during
the supply timings, it will wait for the
tank to get empty before starting the
motor. However, you can also start the
motor using the pushbutton. The mo-
tor will turn on ignoring the status of
the water level and will go through
the aforementioned procedure.
Sensor positions in the
tank
Four non-corrosive metallic sensors are
installed in the tank as shown in Fig.
1. Sensor COM is connected to Vcc
supply from the circuit. Sensor A de-
tects the empty tank to start the mo-
tor. Sensor B detects dry-running con-
dition of the motor and sensor C de-
tects the full tank to stop the motor.
Make sure that sensor B is around 2
cm above sensor A to check the dry-
After five minutes, the
microcontroller will again switch on
the motor for 10 minutes and check
the status at sensor B. If water is still
below sensor B, it will go into the dry-
running mode and the LCD module
will show dry-sump2.
The same procedure will repeat,
CONSTRUCTION
FEBRUARY 2007 WWW. E F Y MA G . C O M
running condition properly.
Calibration
Care must be taken when calibrating
for under- and over-voltages. Always
calibrate when the relay is in on po-
sition. If you calibrate in the standby
mode, it will trip at a voltage nearly
10 volts lower than the set voltage
due to the loading effect.
Software
The source code is written in Assem-
bly language and assembled using
8051 cross-assembler. The generated
Intel hex code is burnt into
microcontroller AT89C51 using a suit-
able programmer. The software is well-
commented and easy to understand.
All the messages are displayed on the
LCD module.
EFY note. All the software files of
this article have been included in this
months EFY-CD.
1 $MOD51
0000 02002F 2 START: LJMP MAIN_PGR ;GO TO MAIN
PROGRAMME
002F 3 ORG 002FH
002F 7438 4 MAIN_PGR: MOV A, # 38H ;INITIALIZE LCD
0031 1200A0 5 LCALL WR_LCD
0034 740F 6 MOV A, #0FH
0036 1200A0 7 LCALL WR_LCD
0039 7406 8 MOV A, #06H
003B 1200A0 9 LCALL WR_LCD
003E 7401 10 MOV A, #01H
0040 1200A0 11 LCALL WR_LCD
0043 7480 12 MOV A, #80H
0045 1200A0 13 LCALL WR_LCD
0048 7453 14 MOV A, #53H ;WRITE DATA
TO LCD
004A 1200C0 15 LCALL LCD_RAM ;i.e., STANDBY-
MODE
004D 7454 16 MOV A, #54H
004F 1200C0 17 LCALL LCD_RAM
0052 7441 18 MOV A, #41H
0054 1200C0 19 LCALL LCD_RAM
0057 744E 20 MOV A, #4EH
0059 1200C0 21 LCALL LCD_RAM
005C 7444 22 MOV A, #44H
005E 1200C0 23 LCALL LCD_RAM
0061 7442 24 MOV A, #42H
0063 1200C0 25 LCALL LCD_RAM
0066 7459 26 MOV A, #59H
0068 1200C0 27 LCALL LCD_RAM
006B 74B0 28 MOV A, #0B0H
006D 1200C0 29 LCALL LCD_RAM
0070 74C0 30 MOV A, #0C0H ;JUMP TO 9TH
POSITION
0072 1200A0 31 LCALL WR_LCD ;OR SECOND
LINE
0075 744D 32 MOV A, #4DH ;ENTER DATA
AGAIN
0077 1200C0 33 LCALL LCD_RAM
007A 744F 34 MOV A, #4FH
007C 1200C0 35 LCALL LCD_RAM
007F 7444 36 MOV A, #44H
0081 1200C0 37 LCALL LCD_RAM
0084 7445 38 MOV A, #45H
0086 1200C0 39 LCALL LCD_RAM
0089 02010A 40 LJMP SCAN ;GO TO 010AH
00A0 41 ORG 00A0H
00A0 1200F0 42 WR_LCD: LCALL SETT ;CHECK FOR
READY STATUS
OF LCD
00A3 F590 43 MOV P1,A ;MOVE CONTENTS
OF A TO PORT 1
00A5 C2B0 44 CLR P3.0 ;WRITE
COMMANDS TO
LCD
00A7 C2B1 45 CLR P3.1
00A9 D2B7 46 SETB P3.7
00AB C2B7 47 CLR P3.7
00AD 22 48 RET ;RETURN TO
PROGRAMME
00C0 49 ORG 00C0H
00C0 1200F0 50 LCD_RAM: LCALL SETT ;CHECK
READY STATUS
OF LCD
00C3 F590 51 MOV P1,A ;MOVE
CONTENS OF A
TO PORT 1
00C5 D2B0 52 SETB P3.0 ;WRITE TO
DISPLAY RAM
OF LCD
WATER.LST
00C7 C2B1 53 CLR P3.1
00C9 D2B7 54 SETB P3.7
00CB C2B7 55 CLR P3.7
00CD 22 56 RET ;GO TO
PROGRAMME
00F0 57 ORG 00F0H
00F0 C2B7 58 SETT: CLR P3.7
00F2 7590FF 59 MOV P1, #0FFH ;SET PORT1 FOR
INPUT
00F5 00 60 NOP ;DELAY
00F6 C2B0 61 CLR P3.0
00F8 D2B1 62 SETB P3.1
00FA C2B7 63 L1: CLR P3.7
00FC D2B7 64 SETB P3.7
00FE 2097F9 65 JB P1.7,L1 ;IF NOT READY
JUMP TO 00FA H
0101 C2B7 66 CLR P3.7
0103 22 67 RET ;BACK TO
PROGRAMME
010A 68 ORG 010AH
010A D276 69 SCAN: SETB 76H ;SET USER FLAGS
010C D277 70 SETB 77H
010E D278 71 SETB 78H
0110 75A0FF 72 MOV P2,#0FFH ;SET PORT2 FOR
INPUT
0113 30A420 73 L4: JNB P2.4,L2 ;IF H/V THEN
GOTO 0136 H
0116 30A372 74 JNB P2.3,L3 ;IF L/V THEN
GOTO 018B H
0119 30A0F7 75 JNB P2.0,L4 ;SCAN FOR
TANK TO BE
EMPTY
011C 8012 76 SJMP L130 ;GOTO 0130 H
011E 120750 77 LOOP: LCALL TMR_10MIN ;CALL 10 MIN.
TIMER
0121 307867 78 JNB 78H,L3 ;L/V THEN
GOTO 018B H
0124 30770F 79 JNB 77H,L2 ;H/V THEN GOTO
0136 H
0127 20765E 80 JB 76H,L5 ;DRY SUMP
THEN GOTO
0188 H
012A 20A2FD 81 JB P2.2,$ ;WAIT UNTILL
TANK FULL
012D 020260 82 LOOP1: LJMP TANK_FULL ;GOTO TANK
FULL DISPLAY
0130 C2B5 83 L130: CLR P3.5 ;START MOTOR
0132 0202D0 84 LJMP DIS_M_ON ;DISPLAY
MOTOR ON
0135 00 85 NOP ;BLANK SPACE
0136 1201D8 86 L2: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
0139 20A4D7 87 JB P2.4,L4 ;STILL H/V
THEN GOTO
0113 H
013C D2B5 88 LOOP2: SETB P3.5 ;H/V THEN OFF MOTOR
013E 00 89 NOP
013F 00 90 NOP
0140 1202B3 91 LCALL INI_LCD ;INITIALIZE LCD
0143 7448 92 MOV A, #48H ;DISPLAY HIGH-
VOLTAGE
0145 1200C0 93 LCALL LCD_RAM
0148 7449 94 MOV A, #49H
014A 1200C0 95 LCALL LCD_RAM
014D 7447 96 MOV A, #47H
014F 1200C0 97 LCALL LCD_RAM
0152 7448 98 MOV A, #48H
0154 1200C0 99 LCALL LCD_RAM
0157 74B0 100 MOV A, #0B0H
0159 1200C0 101 LCALL LCD_RAM
CONSTRUCTION
FEBRUARY 2007 WWW. E F Y MA G . C O M
015C 7456 102 MOV A, #56H
015E 1200C0 103 LCALL LCD_RAM
0161 744F 104 MOV A, #4FH
0163 1200C0 105 LCALL LCD_RAM
0166 744C 106 MOV A, #04CH
0168 1200C0 107 LCALL LCD_RAM
016B 74C0 108 MOV A, #0C0H ;MOVE TO 9TH
CHARACTER
016D 1200A0 109 LCALL WR_LCD
0170 7454 110 MOV A, #54H
0172 1200C0 111 LCALL LCD_RAM
0175 7441 112 MOV A, #41H
0177 1200C0 113 LCALL LCD_RAM
017A 7447 114 MOV A, #47H
017C 1200C0 115 LCALL LCD_RAM
017F 7445 116 MOV A, #45H
0181 1200C0 117 LCALL LCD_RAM
0184 020490 118 LJMP CHK_HV ;GOTO 0490 H
0187 00 119 NOP ;BLANK SPACE
0188 020226 120 L5: LJMP M_STOP ;GOTO 0226 H
018B 1201D8 121 L3: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
018E 20A382 122 JB P2.3,L4 ;VOLTAGE OK
THEN GOTO
0113 H
0191 D2B5 123 LOOP3:SETB P3.5 ;STOP MOTOR IF
ON
0193 1202B3 124 LCALL INI_LCD ;INITIALIZE LCD
0196 744C 125 MOV A, #04CH ;DISPLAY LOW-
VOLTAGE
0198 1200C0 126 LCALL LCD_RAM
019B 744F 127 MOV A, #04FH
019D 1200C0 128 LCALL LCD_RAM
01A0 7457 129 MOV A, #57H
01A2 1200C0 130 LCALL LCD_RAM
01A5 74B0 131 MOV A, #0B0H
01A7 1200C0 132 LCALL LCD_RAM
01AA 7456 133 MOV A, #56H
01AC 1200C0 134 LCALL LCD_RAM
01AF 744F 135 MOV A, #04FH
01B1 1200C0 136 LCALL LCD_RAM
01B4 744C 137 MOV A, #04CH
01B6 1200C0 138 LCALL LCD_RAM
01B9 7454 139 MOV A, #54H
01BB 1200C0 140 LCALL LCD_RAM
01BE 74C0 141 MOV A, #0C0H ;GOTO 9TH
CHARACTER
01C0 1200A0 142 LCALL WR_LCD
01C3 7441 143 MOV A, #41H ;START DISPLAY
AGAIN
01C5 1200C0 144 LCALL LCD_RAM
01C8 7447 145 MOV A, #47H
01CA 1200C0 146 LCALL LCD_RAM
01CD 7445 147 MOV A, #45H
01CF 1200C0 148 LCALL LCD_RAM
01D2 0204B0 149 LJMP CHK_LV ;GOTO 04B0 H
01D5 00 150 NOP
01D6 00 151 NOP
01D7 00 152 NOP
01D8 153 ORG 01D8H
01D8 7B03 154 DLY_2SEC: MOV R3, #03H
01DA 7CFF 155 L8: MOV R4, #0FFH
01DC 7DFF 156 L7: MOV R5, #0FFH
01DE 00 157 L6: NOP
01DF 00 158 NOP
01E0 00 159 NOP
01E1 00 160 NOP
01E2 00 161 NOP
01E3 00 162 NOP
01E4 DDF8 163 DJNZ R5,L6 ;01DEH
01E6 DCF4 164 DJNZ R4,L7 ;01DCH
01E8 DBF0 165 DJNZ R3,L8 ;01DAH
01EA 22 166 RET ;BACK TO
PROGRAMME
0226 167 ORG 0226H
0226 D2B5 168 M_STOP: SETB P3.5 ;STOP MOTOR
0228 1202B3 169 LCALL INI_LCD ;INITIALIZE LCD
022B 7444 170 MOV A, #44H ;START FILLING
DISPLAY RAM
OF LCD
022D 1200C0 171 LCALL LCD_RAM
0230 7452 172 MOV A, #52H
0232 1200C0 173 LCALL LCD_RAM
0235 7459 174 MOV A, #59H
0237 1200C0 175 LCALL LCD_RAM
023A 74B0 176 MOV A, #0B0H
023C 1200C0 177 LCALL LCD_RAM
023F 7453 178 MOV A, #53H
0241 1200C0 179 LCALL LCD_RAM
0244 7455 180 MOV A, #055H
0246 1200C0 181 LCALL LCD_RAM
0249 744D 182 MOV A, #04DH
024B 1200C0 183 LCALL LCD_RAM
024E 7450 184 MOV A, #50H
0250 1200C0 185 LCALL LCD_RAM
0253 74C0 186 MOV A, #0C0H ;MOVE TO 9TH
CHARACTER OF
LCD
0255 1200A0 187 LCALL WR_LCD
0258 7431 188 MOV A, #31H ;START WRITING
AGAIN
025A 1200C0 189 LCALL LCD_RAM
025D 020300 190 LJMP L300 ;GOTO 0300 H
0260 D2B5 191 TANK_FULL: SETB P3.5 ;STOP MOTOR
0262 00 192 NOP ;BLANK SPACES
FOR FURTHER
EXPANSION
0263 00 193 NOP
0264 00 194 NOP
0265 00 195 NOP
0266 00 196 NOP
0267 00 197 NOP
0268 00 198 NOP
0269 1202B3 199 LCALL INI_LCD ;INITIALIZE LCD
026C 7454 200 MOV A, #54H ;WRITE TO
DISPLAY RAM
OF LCD
026E 1200C0 201 LCALL LCD_RAM
0271 7441 202 MOV A, #41H
0273 1200C0 203 LCALL LCD_RAM
0276 744E 204 MOV A, #4EH
0278 1200C0 205 LCALL LCD_RAM
027B 744B 206 MOV A, #4BH
027D 1200C0 207 LCALL LCD_RAM
0280 74B0 208 MOV A, #0B0H
0282 1200C0 209 LCALL LCD_RAM
0285 7446 210 MOV A, #46H
0287 1200C0 211 LCALL LCD_RAM
028A 7455 212 MOV A, #55H
028C 1200C0 213 LCALL LCD_RAM
028F 744C 214 MOV A, #4CH
0291 1200C0 215 LCALL LCD_RAM
0294 74C0 216 MOV A, #0C0H ;GOTO 9TH
CHARACTER OF
LCD
0296 1200A0 217 LCALL WR_LCD
0299 744C 218 MOV A, #4CH ;START
DISPLAYING
AGAIN
029B 1200C0 219 LCALL LCD_RAM
029E 1201D8 220 LCALL DLY_2SEC ;DISPLAY IT FOR
2 SECONDS
02A1 020000 221 LJMP START ;GOTO
STANDBY MODE
02B3 222 ORG 02B3H
02B3 7438 223 INI_LCD:MOV A, # 38H
02B5 1200A0 224 LCALL WR_LCD
02B8 740F 225 MOV A, #0FH
02BA 1200A0 226 LCALL WR_LCD
02BD 7406 227 MOV A, #06H
02BF 1200A0 228 LCALL WR_LCD
02C2 7401 229 MOV A, #01H
02C4 1200A0 230 LCALL WR_LCD
02C7 7480 231 MOV A, #80H
02C9 1200A0 232 LCALL WR_LCD
02CC 22 233 RET ;BACK TO
PROGRAMME
02CD 00 234 NOP
02CE 00 235 NOP
02CF 00 236 NOP
02D0 1202B3 237 DIS_M_ON: LCALL INI_LCD ;INITIALIZE LCD
02D3 744D 238 MOV A, # 4DH ;WRITE INTO
DISPLAY RAM
OF LCD
02D5 1200C0 239 LCALL LCD_RAM
02D8 744F 240 MOV A, #04FH
02DA 1200C0 241 LCALL LCD_RAM
02DD 7454 242 MOV A, #54H
02DF 1200C0 243 LCALL LCD_RAM
02E2 744F 244 MOV A, #04FH
CONSTRUCTION
FEBRUARY 2007 WWW. E F Y MA G . C O M
02E4 1200C0 245 LCALL LCD_RAM
02E7 7452 246 MOV A, #52H
02E9 1200C0 247 LCALL LCD_RAM
02EC 74B0 248 MOV A, #0B0H
02EE 1200C0 249 LCALL LCD_RAM
02F1 744F 250 MOV A, #04FH
02F3 1200C0 251 LCALL LCD_RAM
02F6 744E 252 MOV A, #04EH
02F8 1200C0 253 LCALL LCD_RAM
02FB 02011E 254 LJMP LOOP ;BACK TO MAIN
PROGRAMME
AT 011E H
02FE 00 255 NOP
02FF 00 256 NOP
0300 120320 257 L300: LCALL TMR_5MIN ;CALL 5
MINUTES TIMER
0303 020550 258 LJMP MAIN ;GOTO MAIN
PROGRAMME
AT 0550 H
0320 259 ORG 0320H
0320 7A03 260 TMR_5MIN: MOV R2,#03H
0322 7BFF 261 L12: MOV R3, #0FFH
0324 7CFF 262 L11: MOV R4, #0FFH
0326 7DFF 263 L10: MOV R5, #0FFH
0328 00 264 L9: NOP
0329 00 265 NOP
032A 00 266 NOP
032B 00 267 NOP
032C DDFA 268 DJNZ R5, L9 ;0328
032E DCF6 269 DJNZ R4, L10 ;0326
0330 DBF2 270 DJNZ R3, L11 ;0324
0332 DAEE 271 DJNZ R2, L12 ;0322
0334 22 272 RET ;BACK TO MAIN
PROGRAMME
0430 273 ORG 0430H
0430 30A209 274 L430: JNB P2.2,L43C ;IF TANK FULL
GOTO 043C H
0433 30A409 275 JNB P2.4,L43F ;H/V THEN
GOTO 043F H
0436 30A30F 276 L436: JNB P2.3,L448 ;L/V THEN
GOTO 0448 H
0439 80F5 277 L439: SJMP L430 ;GOTO 0430 H
043B 00 278 NOP
043C 02012D 279 L43C: LJMP LOOP1 ;ACK TO MAIN
PROGRAMME
043F 1201D8 280 L43F: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
0442 20A4F1 281 JB P2.4, L436 ;IF NOT H/V
THEN GOTO
0436 H
0445 02013C 282 LJMP LOOP2 ;H/V THEN
GOTO 013C H
0448 1201D8 283 L448: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
044B 20A3EB 284 JB P2.3, L439 ;IF NOT L/V
THEN GOTO
0439 H
044E 020191 285 LJMP LOOP3 ;IF L/V THEN
GOTO 0191 H
0490 286 ORG 0490H
0490 00 287 CHK_HV: NOP
0491 00 288 NOP
0492 120500 289 L492: LCALL DLY_2MIN ;WAIT FOR 2
MINUTES
0495 30A4FA 290 JNB P2.4,L492 ;CHECK FOR
H/V AGAIN
0498 020000 291 LJMP START ;GOTO START
AGAIN
04B0 292 ORG 04B0H
04B0 00 293 CHK_LV: NOP
04B1 00 294 NOP
04B2 120500 295 L4B2: LCALL DLY_2MIN ;WAIT FOR
2 MINUTES
04B5 30A3FA 296 JNB P2.3, L4B2 ;CHECK FOR
L/V AGAIN
04B8 020000 297 LJMP START ;GOTO START
AGAIN
0500 298 ORG 0500H
0500 7AFF 299 DLY_2MIN: MOV R2, #0FFH
0502 7BFF 300 L502: MOV R3,#0FFH
0504 7CFF 301 L504: MOV R4,#0FFH
0506 00 302 L506: NOP
0507 00 303 NOP
0508 00 304 NOP
0509 00 305 NOP
050A DCFA 306 DJNZ R4, L506
050C DBF6 307 DJNZ R3, L504
050E DAF2 308 DJNZ R2, L502
0510 22 309 RET ;BACK TO MAIN
PROGRAMME
054D 310 ORG 054DH
054D 020642 311 M_START: LJMP SUB_BR ;SUB BRANCH
DUE TO SPACE
PROBLEM
0550 30A447 312 MAIN: JNB P2.4, L59A ;CHECK FOR
HIGH VOLTAGE
0553 30A34D 313 JNB P2.3, L5A3 ;CHECK FOR
LOW VOLTAGE
0556 C2B5 314 CLR P3.5 ;IF VOLTAGE OK
THEN START
MOTOR
0558 1202B3 315 LCALL INI_LCD ;INITIALIZE LCD
055B 744D 316 MOV A, #04DH ;START WRITING
TO DISPLAY
RAM OF LCD
055D 1200C0 317 LCALL LCD_RAM
0560 744F 318 MOV A, #04FH
0562 1200C0 319 LCALL LCD_RAM
0565 7454 320 MOV A, #54H
0567 1200C0 321 LCALL LCD_RAM
056A 744F 322 MOV A, #4FH
056C 1200C0 323 LCALL LCD_RAM
056F 7452 324 MOV A, #52H
0571 1200C0 325 LCALL LCD_RAM
0574 74B0 326 MOV A, #0B0H
0576 1200C0 327 LCALL LCD_RAM
0579 744F 328 MOV A, #4FH
057B 1200C0 329 LCALL LCD_RAM
057E 744E 330 MOV A, #4EH
0580 1200C0 331 LCALL LCD_RAM
0583 120750 332 LCALL TMR_10MIN ;ENTER INTO
10 MINUTES
TIMER
0586 307820 333 JNB 78H, C_LV; 05A9H ;LOW
VOLTAGE
THEN GOTO
05A9 H
0589 307714 334 JNB 77H, C_HV; 05A0H ;HIGH
VOLTAGE THEN
GOTO 05A0 H
058C 20761D 335 JB 76H, DRY ;05ACH ;IF TANK
DRY THEN
GOTO 05AC H
058F 30A2BB 336 L58F: JNB P2.2, M_START ;TANK FULL
THEN GOTO
054D H
0592 30A405 337 JNB P2.4, L59A ;HIGH VOLTAGE
THENGOTO
059A H
0595 30A30B 338 L595: JNB P2.3, L5A3 ;LOW VOLTAGE
THEN GOTO
05A3 H
0598 80F5 339 L598: SJMP L58F ;REPEAT FROM
058F H
059A 1201D8 340 L59A: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
059D 20A4F5 341 JB P2.4, L595 ;IF NOT H/V
THEN GO BACK
TO 0595 H
05A0 02013C 342 C_HV: LJMP LOOP2 ;STILL H/V
THEN GOTO
013C H
05A3 1201D8 343 L5A3: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
05A6 20A3EF 344 JB P2.3, L598 ;IF NOT L/V
THEN GO BACK
TO 0598 H
05A9 020191 345 C_LV: LJMP LOOP3 ;STILL L/V THEN
GOTO 0191 H
05AC D2B5 346 DRY: SETB P3.5 ;STOP MOTOR
05AE 1202B3 347 LCALL INI_LCD ;INITIALIZE LCD
05B1 7444 348 MOV A, #44H ;START WRITING
TO DISPLAY
RAM OF LCD
05B3 1200C0 349 LCALL LCD_RAM
05B6 7452 350 MOV A, #52H
05B8 1200C0 351 LCALL LCD_RAM
05BB 7459 352 MOV A, #59H
05BD 1200C0 353 LCALL LCD_RAM
05C0 74B0 354 MOV A, #0B0H
CONSTRUCTION
FEBRUARY 2007 WWW. E F Y MA G . C O M
05C2 1200C0 355 LCALL LCD_RAM
05C5 7453 356 MOV A, #53H
05C7 1200C0 357 LCALL LCD_RAM
05CA 7455 358 MOV A, #55H
05CC 1200C0 359 LCALL LCD_RAM
05CF 744D 360 MOV A, #4DH
05D1 1200C0 361 LCALL LCD_RAM
05D4 7450 362 MOV A, #50H
05D6 1200C0 363 LCALL LCD_RAM
05D9 74C0 364 MOV A, #0C0H ;GOTO 9TH
CHARACTER OF
LCD
05DB 1200A0 365 LCALL WR_LCD
05DE 7432 366 MOV A, #32H ;START WRITING
AGAIN
05E0 1200C0 367 LCALL LCD_RAM
05E3 120320 368 LCALL TMR_5MIN ;WAIT FOR 5
MINUTES
05E6 30A447 369 JNB P2.4,HV ; 0630H ;H/V THEN
GOTO 0630 H
05E9 30A34D 370 JNB P2.3,LV ; 0639H ;L/V THEN
GOTO 0639 H
05EC C2B5 371 CLR P3.5 ;IF VOLTAGE OK
THEN START
MOTOR
05EE 1202B3 372 LCALL INI_LCD ;INITILIZE LCD
05F1 744D 373 MOV A, #4DH ;START WRITING
TO DISPLAY
RAM OF LCD
05F3 1200C0 374 LCALL LCD_RAM
05F6 744F 375 MOV A, #4FH
05F8 1200C0 376 LCALL LCD_RAM
05FB 7454 377 MOV A, #54H
05FD 1200C0 378 LCALL LCD_RAM
0600 744F 379 MOV A, #4FH
0602 1200C0 380 LCALL LCD_RAM
0605 7452 381 MOV A, #52H
0607 1200C0 382 LCALL LCD_RAM
060A 74B0 383 MOV A, #0B0H
060C 1200C0 384 LCALL LCD_RAM
060F 744F 385 MOV A, #4FH
0611 1200C0 386 LCALL LCD_RAM
0614 744E 387 MOV A, #4EH
0616 1200C0 388 LCALL LCD_RAM
0619 120750 389 LCALL TMR_10MIN ;GOTO
MINUTES TIMER
061C 307820 390 JNB 78H, L63F ;L/V THEN
GOTO 063F H
061F 307714 391 JNB 77H, L636 ;H/V THEN
GOTO 0636
0622 207622 392 JB 76H, L647 ;STILL DRY SUMP
THEN GOTO
0647 H
0625 30A21A 393 L625: JNB P2.2, SUB_BR ;0642H ;TANK
FULL THEN
GOTO 0642 H
0628 30A405 394 JNB P2.4, HV ;0630H ;H/V THEN
GOTO 0630 H
062B 30A30B 395 N_HV: JNB P2.3, LV ;0639H ;L/V THEN
GOTO 0639 H
062E 80F5 396 N_LV: SJMP L625 ;REPEAT FROM
0625 H
0630 1201D8 397 HV: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
0633 20A4F5 398 JB P2.4, N_HV ;062BH ;IF NOT H/V
THEN GOTO
062B H
0636 02013C 399 L636:LJMP LOOP2 ;STILL H/V
THEN GOTO
013C H
0639 1201D8 400 LV: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
063C 20A3EF 401 JB P2.3, N_LV ;062EH ;IF NOT L/V
THEN GOTO
062E H
063F 020191 402 L63F: LJMP LOOP3 ;STILL L/V THEN
GOTO 0191 H
0642 D2B5 403 SUB_BR: SETB P3.5 ;STOP MOTOR
0644 020260 404 LJMP TANK_FULL ;TANK FULL
THEN GOTO
0260 H
0647 D2B5 405 L647: SETB P3.5 ;STOP MOTOR
0649 00 406 NOP
064A 00 407 NOP
064B 1202B3 408 LCALL INI_LCD ;INITIALIZE LCD
064E 7444 409 MOV A, #44H ;START WRITING
TO DISPLAY
RAM OF LCD
0650 1200C0 410 LCALL LCD_RAM
0653 7452 411 MOV A, #52H
0655 1200C0 412 LCALL LCD_RAM
0658 7459 413 MOV A, #59H
065A 1200C0 414 LCALL LCD_RAM
065D 74B0 415 MOV A, #0B0H
065F 1200C0 416 LCALL LCD_RAM
0662 7453 417 MOV A, #53H
0664 1200C0 418 LCALL LCD_RAM
0667 7455 419 MOV A, #55H
0669 1200C0 420 LCALL LCD_RAM
066C 744D 421 MOV A, #4DH
066E 1200C0 422 LCALL LCD_RAM
0671 7450 423 MOV A, #50H
0673 1200C0 424 LCALL LCD_RAM
0676 74C0 425 MOV A, #0C0H ;GOTO 9TH
CHARACTER OF
LCD
0678 1200A0 426 LCALL WR_LCD
067B 7433 427 MOV A, #33H ;START WRITING
AGAIN
067D 1200C0 428 LCALL LCD_RAM
0680 80FE 429 SJMP $ ;STAY HERE
UNTILL
MANUAL RESET
0750 430 ORG 0750H
0750 7A05 431 TMR_10MIN: MOV R2, #05H
0752 7BFF 432 L752: MOV R3, #0FFH
0754 7CFF 433 L754: MOV R4, #0FFH
0756 7DFF 434 L756: MOV R5, #0FFH
0758 00 435 L758:NOP
0759 00 436 NOP
075A 00 437 NOP
075B 00 438 NOP
075C 00 439 NOP
075D DDF9 440 DJNZ R5, L758
075F DCF5 441 DJNZ R4, L756
0761 30A40C 442 JNB P2.4,L770 ;H/V THEN
GOTO 0670 H
0764 30A311 443 L764: JNB P2.3, L778 ;L/V THEN GOTO
0678 H
0767 30A116 444 L767: JNB P2.1, L780 ; NOT DRY SUMP
THEN GOTO
0680 H
076A DBE8 445 L76A: DJNZ R3, L754
076C DAE4 446 DJNZ R2, L752
076E 22 447 RET ;BACK TO MAIN
PROGRAMME
076F 00 448 NOP
0770 1201D8 449 L770: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
0773 30A412 450 JNB P2.4, 0788H ;STILL H/V
THEN GOTO
0788 H
0776 80EC 451 SJMP L764 ; NOT H/V
THEN GOTO
0764 H
0778 1201D8 452 L778: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
077B 30A30D 453 JNB P2.3, 078BH ;STILL L/V THEN
GOTO 078B H
077E 80E7 454 SJMP L767 ;NOT L/V THEN
GOTO 0767 H
0780 1201D8 455 L780: LCALL DLY_2SEC ;WAIT FOR 2
SECONDS
0783 30A108 456 JNB P2.1, 078EH ;STILL NOT DRY
SUMP THEN
GOTO 078E H
0786 80E2 457 SJMP L76A ;OTHERWISE
GOTO 076A
0788 C277 458 CLR 77H ;CLEAR FLAG
77H FOR H/V
078A 22 459 RET
078B C278 460 CLR 78H ;CLEAR FLAG
78H FOR L/V
078D 22 461 RET
078E C276 462 CLR 76H ;CLEAR FLAG
76H FOR DRY
SUMP CHECK
0790 22 463 RET
464 END
VERSION 1.2k ASSEMBLY COMPLETE, 0 ERRORS FOUND z
c i r c u i t i d e a s
ELECTRONICS FOR YOU July 2004
64
T
his code lock is useful for appliances
requiring exclusive or authorised use
by those who know the preset code.
If desired, the code can be changed.
The circuit doesnt require addi-
tional AND or NOT gate operations at
the outputs. It uses two pairs of 4-way
8-DIGIT CODE LOCK FOR
APPLIANCE SWITCHING
Maneesh Chadha
S
.C
. D
w
iv
e
D
i
c i r c u i t i d e a s
DIP switches. The code is set using DIP
switches DIP3 and DIP4. Then these two
switches are hidden inside the assembly.
With DIP3 and DIP4, up to 256 code com-
binations are possible. The unlocking code
is set by the user using DIP switches DIP1
and DIP2, which is compared with the
preset code entered earlier via DIP3 and
DIP4. If the two codes match, transistor
T1 conducts.
The codes are compared using two
cascaded 4-bit magnitude comparator ICs
(IC1 and IC2). If the input nibble pres-
ent at DIP1 matches with preset DIP3
nibble, output pin 6 of IC1 (connected to
input pin 3 of IC2)
goes high. Now if
nibble present at
DIP2 matches with
the preset nibble
at DIP4, pin 6 of
IC2 also goes high.
This high output
drives transistor T1
and the appliance
turns on via relay
contacts.
After use, dis-
turb the positions
of DIP1 and DIP2 so
that the appliance
cant be operated by
unauthorised per-
sons. This will also
switch the appliance
off.
The circuit works
off a 5V DC power
supply. Hidden switch
S0 can be used to
manually turn on/off
the appliance if you
have forgotten the
preset code.
Caution. You
may use this code
lock at your own
risk. After all, a clever intruder will try all
256 possible combinations one after the
other to break the secret code.
c i r c u i t i d e a s
electronics for you february 2004
3) of IC1 is kept at half the supply voltage
(around 4.5V) by the potential divider
comprising resistors R2 and R3 of 100
kilo-ohms each. The inverting input (pin
2) of IC1 is kept low through the shorted
plug at the socket. As a result, the voltage
at the non-inverting input is higher than
at the inverting input and the output of
IC1 is high.
The output from pin 6 of IC1 is fed to
trigger pin 2 of IC NE555 (IC2) via coupling
capacitor C1 (0.0047 F). IC2 is confgured
as a monostable. Its trigger pin 2 is held
high by resistor R4 (10 kilo-ohms). Nor-
mally, the output of IC2 remains low and
the alarm is off. Resistor R6, along with
capacitor C3 connected to reset pin 4 of
IC2, prevents any false triggering. Resistor
R5 (10 mega-ohms), preset VR (10 mega-
ohms) and capacitor C2 (4.7 F, 16V) are
timing components. With these values, the
output at pin 3 of IC2 is about one minute,
which can be increased by increasing either
the value of capacitor C2 or preset VR.
When there is an attempt at snatching,
the plug connected to the circuit detaches.
At that moment, the voltage at the invert-
ing input of IC1 exceeds the voltage at the
non-inverting input and subsequently its
output goes low. This sends a low pulse to
trigger pin 2 of IC2 to make its output pin
3 high. Consequently, the alarm circuit
built around IC UM3561 (IC3) gets the
supply voltage at its pin 5.
IC UM3561 is a complex ROM with
an inbuilt oscillator. Resistor R8 forms
the oscillator component. Its output is
fed to the base of single-stage transistor
amplifer BD139 (T1) through resistor R9
(1 kilo-ohm).
The alarm tone generated from IC3 is
amplifed by transistor T1. A loudspeaker
is connected to the collector of T1 to
produce the alarm. The alarm can be put
off if the plug is inserted into the socket
again. Transistor T1 requires a heat-sink.
Resistor R7 (330 ohms) limits the cur-
rent to IC3 and zener diode ZD1 limits the
supply voltage to IC3 to a safe level of 3.3
volts. Resistor R9 limits the current to the
base of T1.
The circuit can be easily constructed
on a vero board or general-purpose PCB.
Use a small case for housing the circuit
and 9V battery. The speaker should be
small so as to make the gadget handy.
Connect a thin plastic wire to the plug
and secure it in your hand or tie up some-
where else so that when the bag is pulled,
the plug detaches from the socket easily.
anti-Bag-snatching alarm
D. Mohan KuMar
H
ere is a simple alarm circuit to
thwart snatching of your valuables
while travelling. The circuit
kept in your bag or suitcase sounds a
loud alarm, simulating a police horn, if
someone attempts to snatch your bag or
suitcase. This will draw the attention of
other passengers and the burglar can be
caught red handed.
In the standby mode, the circuit is
locked by a plug and socket arrangement
(a mono plug with shorted leads plugged
into the mono-jack socket of the unit).
When the burglar tries to snatch the bag,
the plug detaches from the units socket to
activate the alarm.
The circuit is designed around op-amp
IC CA3140 (IC1), which is confgured as a
comparator. The non-inverting input (pin
c i r c u i t i d e a s
electronics for you April 2003
S
.C
. D
w
iv
e
D
i
T
his simple and inexpensive
anti-theft circuit for vehicles
sounds an alarm simulating
a police siren whenever someone
attempts theft of your vehicle.
The alarm sounds continuously
for a few seconds even when the
intruder switches off the ignition
key. The circuit uses only a few
components and can be easily as-
sembled and installed on a car with
negative grounding.
The circuit consists of an SCR-
based trigger circuit and audio
alarm circuit. When the ignition key
of the vehicle is switched off, base
voltage of transistor T1 is low and
it remains turned off. When the ignition
key is switched on for starting the vehicle,
a positive voltage is applied to the base
of transistor T1 through diode D1, switch
S2, and resistor R1, which slowly charges
capacitor C1. As a result, the base voltage
of T1 rises. As soon as the biasing voltage
crosses cut-in voltage, T1 turns on and SCR
fres, giving 12V DC to the alarm circuit.
The alarm circuit is built around the
siren-sound generator ROM UM3561 (IC1).
It has a built-in oscillator, whose oscillation
depends on resistor R5. Resistor R6 and
aNti-tHeFt aLarM FOr VeHicLes
D. Mohan KuMar
zener diode ZD1 limit the voltage to IC1 to
a safer level of 3.3V. The output from IC1
is fed to a transistor amplifer built around
transistors T2 and T3.
The circuit gives suffcient time delay
to switch on the alarm and to leave the
vehicle. The alarm, once triggered, will
sound until switch S1 is pressed to switch
off the power supply.
Capacitor C2 is provided to sound the
alarm even when the intruder switches off
the ignition key. When the ignition key is
switched off immediately, C2 discharges
through R4 and keeps the alarm activated
for half a minute. Reset switch S3 can be
used to reset the alarm if needed.
The circuit can be assembled on a vero
board. Use a small heat-sink for transistor
T1. Connect point A to the ignition switch
terminal that goes to the ignition coil. The
hidden switch S1 is used for power on/off
and switch S2 enables the circuit.
Note. Keep switches S1 and S2 on be-
fore leaving the vehicle. And dont forget
to switch off S1 and S2 before starting the
vehicle.
The circuit costs around Rs 50.
Fig. 1: Multi-switch doorbell with indicators
cONSTRUcTION
56 November 2009 electroni cs for you www. e f y ma g . c o m
DayananD Sharma
aT89C52-BaSeD roBoCar
sani theo
Switch S1 is used for turning on the
circuit to run the robot. An additional
flter circuit, comprising a resistor and
a capacitor for each IR sensor, is used
for preventing interference with noise
signals. Switch S2 acts as a hardware
reset for the microcontroller in case the
robot is not running properly.
The microcontroller AT89C52 (IC4)
is responsible for taking decisions if
Fig. 1: Arrangement of IR LEDs and sensors on the front PCB
Parts List
Semiconductors:
IC1 - 7805, 5V regulator
IC2, IC3 - L293D motor driver
IC4 - AT89C52 microcontroller
IC5 - NE555 timer
T1 - 2N2222 npn transistor
IRL1-IRL5 - 5mm IR LED
LED1 - 5mm red LED
Q1-Q3 - TSOP1738 IR sensor
Resistors (all -watt, 5% carbon unless
stated otherwise):
R1 - 3.9-ohms, 2W
R2 - 10-kilo-ohms
R3, R4 - 3.3-kilo-ohms
R5 - 470-ohms
R6-R10 - 22-ohms
R11-R13 - 100-ohms
R14-R21 - 82-kilo-ohms or resistor
network
R22 - 1-kilo-ohms
VR1 - 5.1-kilo-ohms preset
Capacitors:
C1, C10 - 0.1F/25V electrolytic
C2 - 10F/25V electrolytic
C3, C4 - 33pF ceramic
C7-C9 - 4.7F/25V electrolytic
Miscellaneous:
BATT - 4V3 rechargeable battery
X
TAL1
- 14Mhz crystal
S1 - SPDT on/off switch
S2 - Tactile switch
M1 - 12V DC motor
M2 - 12V bipolar stepper motor,
7.5/step
- Four wheels each of
75mm dia
- Chassis 265150mm
- Heat sink for 7805
- Pulley and belt
- Connectors and wires
a
robot can be defned as an
electro-mechanical system
with the capability of sens-
ing its environment, manipulating it
and acting according to the prepro-
grammed sequence. It is a machine
that appears intelligent due to the
instructions it receives from a compu-
ter inside it which handles multiple
tasks. This article features a car robot
RoboCarwhich uses a microcontrol-
ler to detect obstacles and manipulate
its direction as per the inputs from
three infra-red (IR) sensors mounted
in front of the car.
Basic components
of roboCar
The heart of the system is a micro-
controllerAtmel AT89C52. It is
programmed to accept inputs from its
port p0 to sense the obstacles around it
and control the steering to avoid any
collision.
There are three TSOP1738 IR sen-
sors (Q1, Q2 and Q3) used in this
projectone at the centre and the
remaining two on the left and right
to detect obstructions, if any, in front
of the RoboCar (Fig. 1). In case of an
obstacle, or a potential collision, the
microcontroller controls the steering
through a bipolar stepper motor which
is driven by an L293D motor driver IC.
L293D is a quadruple half-H driver IC
with an output current rating of 600mA
at voltages ranging from 4.5V to 36V.
A DC motor is used for moving the
car forward and backward, depending
on the signals received from the three
IR sensors. These sensors are used in
any remotely-operated home appliance
like TV, DVD player, etc. The IR sen-
sor TSOP1738 operates at a frequency
of 38 kHz. NE555 timer IC is used
for generating a pulse of 38 kHz and
transmitted through IR LEDs. There
are fve IR LEDstwo each on the
left and right and one on the front of
the robot. The refected IR that beams
from the obstacles are received by the
sensors and sent to the microcontroller.
The microcontroller is programmed in
such a way that it takes the decision
and changes the path of the robot as
per the sensors inputs to avoid the
obstacles.
Circuit description
The schematic diagram of an AT89C52-
based RoboCar is shown in Fig. 2.
This RoboCar is powered by a 12V
rechargeable battery connected to a
5V regulator IC 7805 (IC1) through a
current limiter R1. This 5V is used for
supplying power to the microcontrol-
ler AT89C52, IC NE555 and IR sensors
TSOP1738.
cONSTRUcTION
58 November 2009 electroni cs for you www. e f y ma g . c o m
any obstacle is detected by the IR sen-
sors. It drives the stepper motor (M1)
so that the car changes track to avoid a
collision with the obstacle.
Port 0 (P0.0 through P0.7) of the
microcontroller is used as the input
port that is connected to the sensors.
Each of these port pins (P0.0 to P0.7)
is pulled high through pull-up resis-
tors R14-R21. Note that port pins P0.3
through P0.7 are not used in this ap-
plication. You can use them to extend
the application to make it a line fol-
lowing robot by using similar sensors
and making some changes in the code.
Port 1 (P1.0 through P1.3) is used for
driving the stepper motor through the
driver IC L293D (IC2) and port 3 (P3.0
and P3.1) is used for driving the DC
motor (M2) for forward or backward
motion through another L293D (IC3)
driver IC.
Each sensor used here is a 3-pin
modular device, where the frst and
second pins are negative and positive
supply terminals respectively and the
third pin is the output terminal. A flter
circuit comprising a 100-ohm resis-
tor and a 4.7F capacitor is used for
powering each sensor. Normally, the
output of the sensor is high. When an
IR pulse of frequency 38 khz falls on
the IR sensor, its output goes low. This
low output is sensed by Port 0 of the
microcontroller and an action is taken
as per preprogrammed instructions.
Pin 31 of the microcontroller has to
be pulled high so that it can fetch the
codes from its internal memory. But
if any external memory is used in the
circuit, the pin should be pulled low.
Here, R2 and C2 are used for the
power-on reset function. As soon as
the power is switched on, a high pulse
is applied to pin 9 of the microcontrol-
ler to reset it. This action initiates the
program and the RoboCar starts mov-
ing forward.
how a roboCar works
As soon as the circuit is powered on,
the controller IC4 fetches the codes
from its internal memory and sets its
pin 10 high and pin 11 low. This signal F
i
g
.

2
:

S
c
h
e
m
a
t
i
c

d
i
a
g
r
a
m

o
f

A
T
8
9
C
5
2
-
b
a
s
e
d

R
o
b
o
C
a
r

cONSTRUcTION
60 November 2009 electroni cs for you www. e f y ma g . c o m
is fed to pin 2 and pin 7 of IC3, which
drives the DC motor in one direction.
This enables the car to move forward.
IC5 is wired as an astable multivibrator
to generate a 38kHz pulse.
The 38kHz pulses are amplifed
by transistor T1 to drive fve IR LEDs.
The IR sensors and LEDs are arranged
in such a way that the output of the
sensors is high where there is no ob-
stacle near the car. But if there is any
obstacle, the transmitted IR signals from
the IR LED are refected back from the
obstacle that comes in the way. This
makes the sensor output go low. This
low output signal is fed to port 0 of the
microcontroller. The output of sensor
Q1 is connected to P0.0, Q2 to P0.1 and
Q3 to port P0.2.
As soon as the output of the left
sensor Q1 is pulled low to P0.0=0, the
controller alters the spin of the DC mo-
tor, makes port P3=0 and stops the DC
motor, thereby stopping the car for a
moment. Then it drives port 1 in such a
way that the stepper motor is rotated to
the right, and the front steering wheels
are also turned right, while the car con-
tinues to move forward. After a few sec-
onds, the controller drives the stepper
motor in the reverse direction (turning
it left), which brings the steering wheels
to the straight position and moves the
car forward. Similar is the case when
an obstacle is de-
tected at the right
sensor Q2.
In case there
is an obstacle
in the front, the
centre sensor Q3
sends a low signal
to port pin P0.2.
This makes port
P3=0 and the car
stops. The steer-
ing wheels are
turned left mak-
ing port P3.0=0
and P3.1=1, which moves the car in
backward direction with the steering
still turned. After a few seconds, the
DC motor is stopped by making port
P3=0. The steering is set in the straight
position and the car moves forward by
making the port P3.0=1 and P3.1=0.
Thus, when the port P3.0=0 and
P3.1=1, the car moves in the reverse
direction; when P3.0=1 and P3.0=0, the
car moves in the forward direction and
when P3.0=0 and P3.1=0, the car stops.
Construction
Fig. 3 shows the plan view of the
mechanical model of the car. The rear
wheel is driven by a belt, pulley and a
DC motor. The pulley and drive belt
for the rear wheels are taken from the
HP Business Inkjet 1000 ink tank pump
assembly.
If the polarity of the DC is reversed,
the motor spins in the opposite direc-
tion. The same concept is used for driv-
ing the DC motor. The front wheels
are mounted on a fbre gear which can
be rotated in both directions using a
gear and a stepper motor. The gears
are taken from an old HP DeskJet 3325
paper-feed printer assembly and the
stepper motor for steering control is
taken from an old Epson Inkjet 460
printer assembly.
I n or der t o
avoid collision or
friction between
the main car chas-
sis and the wheels,
enough space has
been provided be-
tween them for
their free rotation.
The front PCB is
mounted at a height
to avoid collision
with front wheels
while turning. Two
gears are used for
reducing the speed
when the car is run-
ning on a rough
surface. The main
chassis is made of a
thick fbre board.
Fig. 3: Plan view of the mechanical model of the RoboCar
Fig. 4: A single-side, actual-size PCB layout for the AT89C52-based RoboCar
cONSTRUcTION
electroni cs for you November 2009 61 www. e f y ma g . c o m
The circuit is assembled on a gen-
eral-purpose PCB or on a PCB layout.
The actual size, single-side PCB layout
is shown in Fig. 4 and its component
layout in Fig. 5.
The main PCB and the front PCB
can be separated by cutting along the
dotted line shown in the PCB layout.
The front PCB assembly is mounted
on the front side of the robot as shown
in Fig. 3. It is attached frmly on the
main chassis board with nuts, bolts and
spacers. The main PCB is also mounted
on the chassis board with nuts and bolts
and spacers. Three 4V rechargeable bat-
tery cells, taken from a laptop, can be
placed between the main PCB and the
chassis board (Fig. 6). The charger input
charging terminal has been provided in
the PCB for charging the battery.
The main PCB and the front PCB
are connected through CON1 and
CON2 with suitable
length of wires.
Software
The software code
is written in C lan-
guage using the
free small device C
compiler or SDCC.
You can download
SDCC from the link
http://sourceforge.
net/projects/sdcc/
fles/, free of cost.
The compiler cre-
ates some issues
in Windows XP.
In this project the
code is compiled in
a Windows 98 SE
environment. The
generated hex code
is then burnt into
the microcontroller unit (MCU) using
a suitable Atmel 89 series programmer
such as one from Sunrom Technologies
or Frontline Electronics. You should
not remove the microcontroller from
the zero insertion force (ZIF) socket
until the programming is complete.
Steps for installation
1. Install SDCC using SDCC-2.9.0-setup
fle. It will automatically install under
c:\Program Files\SDCC
2. Copy Robo1.c fle under C:\
Program Files\SDCC\Robocar
3. Open the MSDOS prompt and
give the above path
4. Type SDCC Robo1.c against the
DOS prompt to compile it. If no errors
are found in the code, it will generate
the .lst and .ihx fles in the same direc-
tory where the robo1.c fle is located
5. Convert the Robo1.ihx fle to
generate the robo1.hex fle using pack.
ihx as:
packihx robo1.ihx>robo1.hex.
6. Use the robo1.hex fle to program
the MCU
Precaution
Once all the parts are assembled, it
is necessary to check the operational
Fig. 5: Component layout for the PCB
Fig. 6: Authors prototype of RoboCar
cONSTRUcTION
62 November 2009 electroni cs for you www. e f y ma g . c o m
Robo1.c
#include <at89x52.h>
void delay_ret(void);
void delay_step(void);
void left(void);
void right(void);
int i,j,k;
void main(void)
{
P0=0xFF; /*initialise P0 as input
for sensor*/
for (i=0;i<10000;i++);
while(1)
{
P3=0xF2; /*move forward*/


switch(P0) /*check status of
port P1*/
{
case(0xFB):
P3=0xF1; /*apply reverse direction
to stop car*/
for (i=0;i<30000;i++);
P3=0x00; /*stop
car*/
right(); /*turn
right*/
P1=0;
P3=0xF1; /*move reverse*/
delay_ret(); /*delay*/
delay_ret(); /*delay*/
left(); /*return to center*/
P1=0;
P3=0x00; /*stop the car*/
for (i=0;i<3000;i++); /*wait a while*/
P3=0xF2; /*move forward*/
break;
case(0xFE):
P3=0xF1; /*apply reverse direction
to stop car*/
delay_ret();
P3=0x00; /*stop
car*/
left(); /*turn
left*/
P1=0;
P3=0xF2; /*move ahead*/
delay_ret(); /*wait for some time*/
right(); /*return to center posi-
tion*/
P1=0;
break;
case(0xFD):
P3=0xF1; /*apply reverse direction
to stop car*/
delay_ret();
P3=0x00; /*stop
car*/
right(); /*turn
right*/
P1=0;
P3=0xF2; /*move ahead*/
delay_ret(); /*wait for some time*/
left(); /*return to center posi-
tion*/
P1=0;
break;
}
}
}
void delay_ret(void) /*delay
routine to wait before*/
{ /*steer-
ing is returned back to straight*/
int x,t;
for (t=0;t<600;t++)
{
for (x=0;x<400;x++);
}
}
void delay_step(void) /*delay
routine for controlling speed of step-
per*/
{
int j;
for (j=0;j<500;j++);
}
void left(void) /*turn
steering left*/
{
for (k=0;k<9;k++)
{
P1=0x05;
delay_step();
P1=0x09;
delay_step();
P1=0x0A;
delay_step();
P1=0x06;
delay_step();
}
P1=0x00;
}
void right(void) /*turn
steering right*/
{
for (k=0;k<9;k++)
{
P1=0x05;
delay_step();
P1=0x06;
delay_step();
P1=0x0A;
delay_step();
P1=0x09;
delay_step();
}
P1=0x00;
}
function of the car on the repair bench
itself before leaving it to move on the
ground. You can lift the car, switch on
the power and check the operation by
putting your hand near the sensor to
ensure each sensor is working perfect-
ly. You can adjust the range of sensing
by varying the preset VR1. It is not
recommended to keep the range very
long because this would cause the car
to keep moving forward and backward
as it senses any obstacle, even far away
from it. Once you are sure that the car
is operating well, you can leave it to
move freely.
EFY note. The source code of this
article is included in this months
EFY-CD.
COMPONENTS. PRODUCTS. MACHINERY.
ConstruCtion
52 March 2006 electroni cs for you www. e f y Ma g . c o M
CMYK
C
ountdown timers can be con-
structed using discrete digital
ICs including up/down coun-
ters and/or 555 timers. If you wish
to incorporate various facilities like
setting the count, start, stop, reset and
display facilities, these circuits would
require too many ICs.
Here is a simple design based
on 20-pin Atmel AT89C2051 micro-
controller that performs countdown
operation for up to 99 minutes with
two 7-segment displays showing the
actual time left. During the activity
period, a relay is latched and a fash-
ing LED indicates countdown timings
progress.
Four tactile, push-to-on switches
K.S. SanKar
aT89C2051-BaSED
COUnTDOWn TIMEr
SUNI L KUMAR
Fig. 1: Circuit of AT89C2051-based countdown timer
Fig. 2: Power supply circuit
are used to start/stop and to set the
initial value for countdown operation.
The timing value can also be changed
while the counting is still in progress.
Auto-repeat key logic also works,
i.e., if you hold Up or Down key
continuously, the timing as shown on
7-segment LED displays changes at a
faster rate. The program code in hex is
only 800 bytes long, while AT89C2051
microcontroller can take up to 2 kB of
code.
This program can be easily modi-
fed to suit users requirements. The
hex code should be burnt into the
chip using any universal programmer
ConstruCtion
54 March 2006 electroni cs for you www. e f y Ma g . c o M
CMYK
suitable for Atmel AT89C2051
chip.
Circuit description
The circuit of the coundown
timer is shown in Fig. 1. The
microcontroller used is Atmel
AT89C2051 (IC1), which is
a 20-pin device with 2 kB of
program memory. Port 1 is
used to drive two 7-segment
displays through ICs CD4511
(IC2 and IC3), which are
BCD-to-7-segment convert-
ers. A 6MHz crystal is used
for timing. Timer 0 is used
as an internal counter and
increments a variable every
second. This variable is used
in the project for providing
accurate timing.
The software waits for Start switch
to be pressed to start timing operation.
It can be stopped anytime by pressing
Stop switch momentarily.
Up and Down set switches are
used for setting the time (in minutes),
as displayed on 7-segment display.
This function is directly handled by
interrupts 0 and 1 in the software. The
Start, Stop, Up and Down switches are
connected to port 3. Port 3 does not
have the bit p3.6 and it is ignored.
A fashing LED connected to port
3.4 shows that the timing activity is in
progress.
Relay energisation pin 11 is con-
nected to a driver transistor to switch
on a 5V relay that can activate any
electrical device. (A different external
voltage (9 to 12V) can also be used to
power the relay and driver transistor
T2, after disconnecting the 5V supply
at the junction of relay RL1 and the
cathode of D1.)
The BCD code for units is output at
pins P1.0 through P1.3 and for tens at
pins P1.4 through P1.7. All these eight
pins are pulled high through 10-kilo-
ohm resistors of RNW1. These pins are
coupled to A through D input pins
Fig. 4: An actual-size, single-side PCB layout for
AT89C2051-based countdown timer
Fig. 5: Component layout for the PCB
Fig. 3: Flow-chart for countdown
timer
Parts List
Semiconductors:
IC1 - AT89C2051 microcon-
troller
IC2, IC3 - 4511 BCD-to-7-
segment latch/decod-
er/driver
IC4 - 7805 5V regulator
T1, T2 - BC547 npn transistor
LED1 - Red LED
D1-D5 - 1N4007 rectifer diode
DIS1, DIS2 - LTS543 common-cath-
ode, 7-segment display
Resistors (all -watt, 5% carbon):
R1-R6 - 10-kilo-ohm
R7, R8 - 4.7-kilo-ohm
R9 - 220-ohm
R10-R23 - 470-ohm
RNW1 - 10-kilo-ohm resistor
network
Capacitors:
C1 - 10F, 16V electrolytic
C2, C3 - 22pF ceramic disk
C4 - 1000F, 35V electrolytic
C5 - 0.1F ceramic disk
Miscellaneous:
X1 - 230V AC primary to 9V
AC, 250mA secondary
transformer
S1 - On/off switch
S2-S6 - Push-to-on tactile
switch
ConstruCtion
56 March 2006 electroni cs for you www. e f y Ma g . c o M
CMYK
followed by 1000F smoothing capaci-
tor C4 feeding regulator 7805 (IC4). C5
is used for bypassing any ripple from
the output of the regulator.
An actual-size, single-side PCB for
the circuit of countdown timer (Fig.
1) including its power supply (Fig. 2)
is shown in Fig. 4 and its component
layout in Fig. 5.
Software
The software is written using BAS-
COM-51. (For detailed informa-
of BCD-to-7-sement decoder driver
IC3 (for units) and IC2 (for tens). The
segment-driving outputs of IC3 and
IC2 are coupled to 7-segment, com-
mon-cathode displays DIS2 (units)
and DIS1 (tens), respectively.
The 5V regulated power supply
for the circuit is provided by a conven-
tional circuit comprising step-down
transformer X1, which steps down
mains 230V AC to 9V AC. This output
is rectifed by a bridge rectifer com-
prising 1N4007 diodes D2 through D5

99 min countdown relay timer


language used: BASCOM-51 from www.mcselec.
com
Micro controller used= Atmel AT89C2051
- by K.S.Sankar www.mostek.biz
16-1-2006
defne crystal speed
$crystal = 6000000
$regfle = 89c2051.dat
defne variables
Dim I As Byte
Dim Sec_count As Byte
Dim Min_count As Byte
Dim Clock_word As Word
Dim Setmode As Bit
declare function used
Declare Sub Fn7seg(_i As Byte)
Dim _i As Byte
=-=-=-=-=-=-=-=-=-=
declare interrupt routines
On Int0 Int0_int
On Int1 Int1_int
Enable Interrupts
Enable Int0
Enable Int1
enable the interrupts
=-=-=-=-=-=-=-=-=-=
defne alias names for start / stop switches
Sw_start Alias P3.0
Sw_stop Alias P3.1
up /down switches are connected to int0 and int1
Switch_up P3.2 ( int0)
Switch_down P3.3 ( int1)
Relay_out Alias P3.7
Led_out Alias P3.4
make ports 0
P1 = 0
P3 = &B00111111
p1 port to ic4511 bcd -> 7 seg convertor ( 2 displays)
p3 as input and output port
confgure timer0
Confg Timer0 = Timer , Gate = Internal , Mode = 2
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
dont start timer0 here
Begin:
wait for sw-start press
or interupts up/down to take place
Setmode = 0
Relay_out = 0
Led_out = 0
Sec_count = 0
CDTIMER.BAS
P1 = _ans
Waitms 30
End If
End Sub
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
A Flashing Led When Timing Is In Progress
1 sec on and 1 sec off
Led_out = Led_out Xor 1
End If
If Sec_count = 60 Then
Sec_count = 0
Incr Min_count
End If
Return
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Rem The Interrupt Handler For The Int1 Interrupt
Int1_int:
DOWN
Stop Timer0
Setmode = 1
Incr Min_count
If Min_count >= 99 Then Min_count = 98
I = 99 - Min_count
Call Fn7seg(i)
Waitms 100
Return
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Rem The Interrupt Handler For The Int0 Interrupt
Int0_int:
UP
Stop Timer0
Setmode = 1
Decr Min_count
If Min_count = 255 Then Min_count = 0
If Min_count = 0 Then Min_count = 0
I = 99 - Min_count
Call Fn7seg(i)
Waitms 100
Return
End
this program when compiled creates a binary fle
of just 802 bytes with only 8 variables defned in
the program
if such a user friendly language can create compact
code
I wonder why people still struggle to write in op
codes or
languages full of semi-collons.....
that is left to the reader to c
end of program -=-=-=-=-=-=- written in bascom-51
=-=-=-=-=-=-=-=

end of program -=-=-=-=-=-=-
Min_count = 0
I = 0
=-=-=-=-=-=-=-=
Begin1:
Call Fn7seg(i)
If Sw_start = 0 Then
Goto Begin2
End If
If Sw_stop = 0 Then
While Sw_stop = 0
Wend
Relay_out = 0
Sec_count = 0
Goto Begin
End If
Goto Begin1
Begin2:
relay on
Setmode = 0
Relay_out = 1
Start Timer0
Begin3:
I = 99 - Min_count
Call Fn7seg(i)
If I = 0 Then
Goto Over
End If
If Sw_start = 0 Then
Start Timer0
Setmode = 0
End If
If Sw_stop = 0 Then
Goto Over
End If
Goto Begin3
Over:
Stop Timer0
Relay_out = 0
Goto Begin
end of main program
=-=-=-=-=-= function below - -
Sub Fn7seg(_i As Byte)
Dim _ans As Byte
display on two 7 seg
_ans = Makebcd(_i)
P1 = _ans
If Setmode = 1 Then
if in set mode make display ficker
P1 = 255
blankout the display
Waitms 30
turn it on again
tion about it, please go through the
authors Real-time Clock Using Mi-
crocontroller article published in Jan.
2005 issue of EFY.) The fow-chart for
the timer is shown in Fig. 3. The project
can be converted into a 0-99 second
timer by making suitable changes in
the source code.
The source program cdtimer.bas
in BASCOM-51, along with suit-
able comments, is given below. The
same is also included in this months
EFY-CD.
c i r c u i t i d e a s
electronics for you october 2004
88
C
onsider that a school has a total of
eight periods with a lunch break
after the fourth period. Each period
is 45 minutes long, while the duration of
the lunch break is 30 minutes.
To ring this automatic school bell to
start the frst period, the peon needs to
momentarily press switch S1. Thereafter,
the bell sounds every 45 minutes to indi-
cate the end of consecutive periods, except
immediately after the fourth period, when
it sounds after 30 minutes to indicate that
the lunch break is over. When the last
period is over, LED2 glows to indicate that
the bell circuit should now be switched off
manually.
In case the peon has been late to start
the school bell, the delay in minutes can
be adjusted by advancing the time using
switch S3. Each pushing of switch S3
advances the time by 4.5 minutes. If the
school is closed early, the peon can turn
the bell circuit off by momentarily pressing
switch S2.
The bell circuit contains timer IC
NE555 (IC1), two CD4017 decade coun-
ters (IC2 and IC3) and AND gate CD4081
automatic school Bell
Raj KumaR mondal
S
.C
. D
w
iv
e
D
i
(IC4). Timer IC1 is wired as an astable
multivibrator, whose clock output pulses
are fed to IC2. IC2 increases the time
periods of IC1 (4.5 and 3 minutes) by
ten times to provide a clock pulse to IC3
every 45 minutes or after 30 minutes,
respectively. When the class periods
are going on, the outputs of IC3 switch
on transistors T1 and T2 via diodes D4
through D12.
Resistors R4 and R5 connected in series
to the emitter of npn transistor T2 decide
the 4.5-minute time period of IC1. The
output of IC1 is further connected to pin
14 of IC2 to provide a period with a dura-
tion of 45 minutes. Similarly, resistors R2
and R3 connected in series to the emitter
of npn transistor T1 decide the 3-minute
time period of IC1, which is further given
to IC2 to provide the lunch-break duration
of 30 minutes.
Initially, the circuit does not ground
to perform its operation when 12V power
supply is given to the circuit.
When switch S1 is pressed momen-
tarily, a high enough voltage to fre silicon-
controlled resistor SCR1 appears at its gate.
When SCR1 is fred, it provides ground
path to operate the circuit after resetting
both decade counters IC2 and IC3. At the
same time, LED1 glows to indicate that
school bell is now active.
When switch S2 is pressed mo-
mentarily, the anode of SCR1 is again
grounded and the circuit stops operating.
In this condition, both LED1 and LED2
dont glow.
When the eighth period is over, Q9
output of IC3 goes high. At this time,
transistors T1 and T2 dont get any volt-
age through the outputs of IC2. As a re-
sult, the astable multivibrator (IC1) stops
working.
The school bell sounds for around 8
seconds at the end of each period. One
can increase/decrease the ringing time
of the bell by adding/removing diodes
connected in series across pins 6 and 7
of IC1.
The terminals of the 230V AC
electric bell are connected to the nor-
mally-open (N/O) contact of relay RL1.
The circuit works off a 12V regulated
power supply. However, a battery source
for back-up in case the power fails is also
recommended.
ConstruCtion
68 december 2006 electroni cs for you www. e f y ma g . c o m
Parts List
Semiconductor:
IC1 - 7805,5Vregulator
IC2 - AT89C2051
microcontroller
IC3 - CD4050hexnon-
invertingbuffer
T1 - BC548npntransistor
IRX1 - TSOP1738IRreceiver
module
D1-D5 - 1N4007rectiferdiode
LED1-LED5 5mmLED
IRLED1,
IRLED2 IRLED
Resistors (all -watt, 5% carbon):
R1,R11-R14 - 330-ohm
R2 - 220-ohm
R3-R8 - 10-kilo-ohm
R9 - 4.7-kilo-ohm
R10 - 150-ohm
R15 - 1.2-kilo-ohm
Capacitors:
C1 - 1000F,25Velectrolytic
C2,C3 - 10F,16Velectrolytic
C4,C5 - 22pFceramicdisk
Miscellaneous:
X1 - 230VACprimaryto
7.5V,300mAsecondary
transformer
RL1 - 6V,1C/Orelay
S1,S2 - On/offswitch
S3 - Push-to-onswitch
BATT. - 6Vbattery
- Solenoid(operated
with6V)
i
n manual fush systems, the user
presses a button, which opens a
fush valve allowing mains-pres-
sure water to fow into the bowl, or
sometimes the user presses directly
a fush lever (a handle connected to
a fushometer). The valve contains a
pneumatic mechanism that closes it
afterapresettime.
Today, manual fush system has
been replaced with a sensor-operated
system that automatically fushes the
fxturewhentheuserdeparts.
The microcontroller-based auto-
maticfushsystempresentedhereuses
aninfraredsensortodetectauserap-
proachingthefxture,thenitwaitsun-
K.S. SanKar
SUNI L KUMAR
tiltheuserdeparts.Asolenoidisused
to actuate the fush from a 6V power
supplywithbatterybackupinsidethe
unitthatalsopowersthesensorcircuit.
Thisfushsystemisfullycontrolledby
amicrocontroller.Italsofushesbefore
the person departs if the person is
present for more than the preset time
(5minutes).
Installationofthismicrocontroller-
basedautomaticfushsystemisshown
in Fig. 1. The IR transmitter LED and
the IR receiver modules are mounted
side by side such that when the user
approaches the mechanism, the IR
receivermodulereceivestheIRsignal
refected off the person. A solenoid-
operated water valve is used in the
system.
Circuit description
Fig. 2 shows the circuit of the micro-
controller-based fush control system.
It is built around Atmel 89C2051 mi-
crocontroller that controls the process
ofautomaticallyfushingthetoilet.
The AT89C2051 is an 8-bit micro-
controller with 2 kB of fash-based
program memory, 128 bytes of RAM,
15 input/output lines, two 16-bit
timers/counters, on-chip oscillator
and clock circuitry. A 6MHz crystal
is used for providing clock. Port
pins P1.0 through P1.4 of the micro-
controllerareconnectedtobuffersN1
throughN5ofCD4050via10-kilo-ohm
pull-upresistors,respectively.
All the input/output (I/O) pins
are reset to 1 as soon as RST (pin
9) goes high on pressing switch S3.
Holding the RST pin high for two
machine cycles while the oscillator is
running resets the device. Power-on-
reset is achieved by capacitor C2 and
resistorR9.
Pin12(P1.0)ofmicrocontrollerIC2
MiCroController-baSed
autoMatiC FluSh SySteM
Fig. 1: Installation of the automatic flush system
ConstruCtion
electroni cs for you december 2006 69 www. e f y ma g . c o m
provides the 38kHz
cl ock f requency,
whichisbufferedby
N1 to drive the two
parallel IR-LEDs.
These IR-LEDs act
astheinfraredsignal
transmitter. Resis-
tor R10 limits the
current through the
LEDs.PortpinsP1.1,
P1.2, P1.3 and P1.4
are used for indica-
tionofstandby,alert,
active and fush, re-
spectively. Port pin
P1.4alsodrivesrelay
RL1throughtransis-
torT1.DiodeD5acts
as a free-wheeling
diode. The solenoid
coil operated off 6V
is connected to the
contacts of relay
RL1.
Externalinterrupt
0 (INT0) is used to
receive the refected
IR signal. INT0 (pin 6) of the micro-
controllerispulledupwithresistorR3
andconnectedtopin3ofTSOP1738IR
receivermodule.
Pin 2 of TSOP1738 is pulled
high with resistor R2, while pin 1 is
grounded. In the IR receiver module
TSOP1738, the PIN diode and the
preamplifier are assembled on the
lead frame, and the epoxy package is
designedasanIRflter.Thedemodu-
latedoutputfromthereceivermodule
canbedirectlydecodedbythemicro-
controller.
The IR-LEDs continuously trans-
mittheIRsignalandstandbyLED2is
always on. When any person comes
neartheIR-LEDs,theIRreceivermod-
ulereceivestherefectedIRsignaland
alert LED3 lights up. If the alert LED
glows for 5 seconds, the active LED
(LED4) lights up, indicating that the
circuit is now ready to fush. This 5-
secondtimeallowsforvalidationofthe
Fig. 2: Circuit of microcontroller-based flush control system
Fig. 3: Actual-size, single-side PCB of microcontroller-based flush control
system
Fig. 4: Component layout for the PCB
ConstruCtion
70 december 2006 electroni cs for you www. e f y ma g . c o m
$regfle=89c2051.dat
themicrocontrollersincludefle
$crystal=6000000
6mhzcrystalused
defnevariablesbelow
DimJAsByte
DimIrrecdAsBit,IAsByte
DimKAsByte
DimLAsBit
DeclareSubFn38k6(periodAsByte)
DimPeriodAsWord
Irrecd=0
anothernameforportp1.0
IrportAliasP1.0
makeallports0
P1=0
P3=255
makeport-3highforinterrupttowork
oninterrupt-callint0_intfuction
OnInt0Int0_int
SetTcon.0
intenabled
EnableInterrupts
Beg1:
showstandbymodeonport-1(yellowledon)
P1.1=1
enabletheint0toworknow
EnableInt0
CallFn38k6100
callthesubroutinetosendoutabeam
ofIRat38khzfreq
intwouldhavetakenplaceifirrecd
DisableInt0
disabletheintnow
checkifintoccured
IfIrrecd=0Then
nointoccured
sogobacktostandbymode
P1.1=0
fashstandbyled
Waitms100
waitfor(1/10thofasecond)
GotoBeg1
EndIf
hereintrecd
waitforabout5secstogetintoalertmode
ir beam should be refected for this period of
5secs
Irrecd=0
Flush.bas
P1.2=1
alertledonnow
belowforloopwillworkforapprox5seconds
ForJ=1To30
Irrecd=0
EnableInt0
CallFn38k6100
callthesubroutinetosendoutabeamofIRat
38khzfreq
intwouldhavetakenplaceifirrecd
DisableInt0
checkifintoccured
IfIrrecd=0Then
nointoccured
sooutofloop-refectiveobjectgone
GotoNothing
EndIf
Waitms100
NextJ
hereirhasbeenrecdfor5secs
soturnonfushfor10seconds
AfterObjectHasMovedAway
waitforobecttomoveaway
belowforloopwillworkforapprox5minutes
P1.3=1
ForI=1To35
activeledon
ForJ=1To60
Irrecd=0
EnableInt0
CallFn38k6100
callthesubroutinetosendoutabeamofIRat
38khzfreq
intwouldhavetakenplaceifirrecd
DisableInt0
checkifintoccured
IfIrrecd=0Then
nointoccured
sooutofloop-refectiveobjectgone
ExitFor
getoutoftheFORloop
EndIf
Waitms100
NextJ
NextI
timeperiodoversofush
orobjecthasmovedawaywithin5minutes
P1.4=1
fushledandbuzzeronfor10seconds
Wait5
Wait5
P1=0
allledsoff
getbacktostart
Waitms100
GotoBeg1
Nothing:
noirrecdduringthe5minalertperiod
soobjecthasmovedaway
gobacktostart
P1=0
Waitms100
GotoBeg1
=-=-=-=-subroutinesbelow=-=-=-=-=-=-=
SubFn38k6(periodAsWord)
parameter1000=1secondapprox
function to oscillate a port pin at 38,000 times
asec
DimIiAsByte,JjAsByte,KkAsByte
DimPeriodsAsWord
Periods=Period/100
Ii=0
WhileIi<Periods
IncrIi
Jj=0
WhileJj<5
IncrJj
Kk=0
WhileKk<255
IncrKk
Irport=1
NOP
Irport=0
NOP
NOP
Wend
Wend
Wend
EndSub
Rem The Interrupt Handler For The Int0 Inter-
rupt
Int0_int:
programcomeshereifint0occurs
Irrecd=1
justsetafagandgetback
letthemainprogramhandlethefagcondition
Return
potusebytheperson.Whentheperson
goesaway,thefushisactivatedfor10
seconds, which is indicated by LED5.
If the person is there for more than 5
minutes, the system fushes once and
the software goes back to waiting for
theobjecttomoveaway.
The 5V regulated power supply
forthecircuitisprovidedbyaconven-
tionalcircuit.TheACmainsisstepped
down by transformer X1 to deliver
a secondary output of 7.5V, 300mA,
whichisrectifedbyafull-waverecti-
fercomprisingdiodesD1throughD4,
fltered by capacitor C1 to eliminate
ripplesandregulatedbyIC7805(IC1)
toprovideregulated5Vpowersupply
forthecircuit.LED1actsasthepower
indicator. Relay coil and solenoid coil
arepoweredby6Vunregulatedpower
supply. A 6V rechargeable battery is
usedforpowerbackup.
Anactual-size,single-sidePCBfor
the microcontroller-based automatic
fushsystem(Fig.2)isshowninFig.3
anditscomponentlayoutinFig.4.
the software
The software for fush system is writ-
ten in Basic language and compiled
usingBascom-8051version.Thedemo
versionofBascom-8051isavailableon
websitewww.mcselec.com/in-
dex.php?option=com_docman&task
=doc_download&gid=166&Itemid=
54.
First, instruct the compiler to
use 89C2051.dat for microcontroller
AT89C2051 by statement $regfile.
After this, instruct the compiler to
overridethecrystalfrequencyoptions
setting by statement $crystal. Then
declarethevariablesasbits,bytesand
words.Initialiseport-1to0andport-
3to1.(Port-3actsastheinputport.)
Enabletheinterruptafterinitialisation.
NowwritethesubroutineFn38K6to
generate38kHzfrequencyfortransmis-
sionoftheIRsignal.
StandbyLEDglowswhenexternal
interruptINT0ishigh,i.e.,thereisno
interruptionofIRtransmission.When
INT0 goes low, i.e., the transmission
is interrupted, alert LED glows. After
5seconds,activeLEDlightsup.When
thepersonmovesaway(nointerrupt)
within 5 minutes, the system fushes
for 10 seconds. Otherwise, it fushes
every5minutesifthepersonisthere.
Wait and waitms statements pro-
videthedelayinsecondsandmillisec-
onds,respectively.Delaytimebasically
dependsonthecrystalfrequency.
EFY note.Thesourcecodeandoth-
errelevantflesofthisarticlehavebeen
includedinthismonthsEFY-CD.
circuit
ideas
126 January 2008 electroni cs for you www. e f y ma g . c o m
H
ere is a white-LED-based
emergency light that offers
the following advantages:
1. It is highly bright due to the use
of white LEDs.
2. The light turns on automatically
when mains supply fails, and turns off
when mains power resumes.
3. It has its own battery charger.
When the battery is fully charged,
charging stops automatically.
The circuit comprises two sections:
charger power supply and LED driver.
The charger power supply section is
built around 3-terminal adjustable
regulator IC LM317 (IC1), while the
LED driver section is built around
transistor BD140 (T2).
In the charger power supply
section, input AC mains is stepped
down by transformer X1 to deliver
9V, 500 mA to the bridge rectifer,
which comprises diodes D1 through
D4. Filter capacitor C1 eliminates
ripples. Unregulated DC voltage is
fed to input pin 3 of IC1 and provides
charging current through diode D5
and limiting resistor R16. By adjusting
preset VR1, the output voltage can be
adjusted to deliver the required charg-
ing current.
When the battery gets charged to
6.8V, zener diode ZD1 conducts and
charging current from regulator IC1
fnds a path through transistor T1 to
ground and it stops charging of the
battery.
The LED driver section uses a total
of twelve 10mm white LEDs. All the
LEDs are connected in parallel with a
100-ohm resistor in series with each.
The common-anode junction of all
the twelve LEDs is connected to the
collector of pnp transistor T2 and the
emitter of transistor T2 is directly con-
nected to the positive terminal of 6V
battery. The unregulated DC voltage,
produced at the cathode junction of
diodes D1 and D3, is fed to the base
of transistor T2 through a 1-kilo-ohm
resistor.
When mains power is available,
the base of transistor T2 remains high
and T2 does not conduct. Thus LEDs
are off. On the other hand, when
mains fails, the base of transistor T2
becomes low and it conducts. This
makes all the LEDs (LED1 through
LED12) glow.
The mains power supply, when
a v a i l a b l e ,
c har ges t he
bat t er y and
keeps the LEDs
off as transis-
tor T2 remains
cut-off. During
mains failure,
the chargi ng
section stops
worki ng and
the battery sup-
ply makes the
LEDs glow.
As s e mbl e
the circuit on
a general-pur-
pose PCB and
encl ose i n a
cabi net wi th
enough space
for battery and
switches. Mount the LEDs on the cabi-
net such that they light up the room. A
hole in the cabinet should be drilled to
connect 230V AC input for the primary
of the transformer.
EFY lab note. We have tested the
circuit with twelve 10mm white LEDs.
You can use more LEDs provided the
total current consumption does not
exceed 1.5A. Driver transistor T2 can
deliver up to 1.5A with proper heat-
sink arrangement.
S.C. DwiveDi
AUTOMATiC LOw-POweR
eMeRGeNCY LiGHT
SUNI L KUMAR
Fig. 1: Automatic high intensity LED-based emergency light
Fig. 2: Pin configurations of LM317, BD140 and
BC548
c i r c u i t i d e a s
electronics for you December 2002
IC1 is triggered and its output pin 3 goes
high to activate the melody circuit and triac
BT136. LED1 acts as a zener diode, reducing
the voltage for IC2 (UM66 melody generator)
to 3.3V, a safer level.
The melody circuit is built around the
well-known melody generator IC UM66.
The musical tone generated by the IC is
amplifed by the transistor amplifer com-
prising transistors T2 and T3. Triac BT136
is used in the circuit to operate a 230V bulb
of up to 500W rating. Resistor R5 regulates
the gate current of the triac.
Assemble the circuit on a veroboard
and enclose it in a cabinet. Keep the
loudspeaker away from the microphone to
avoid undesired triggering. Be careful while
connecting and testing the circuit, as some
parts of the circuit are at mains potential.
The polarity of mains (live and neutral)
should be the same as shown in the circuit.
If IC1 shows unwanted triggering, connect
a 4.7k resistor and 4.7F electrolytic ca-
pacitor between its pin 4 and ground.
Note. The circuit can be easily modifed
for use as a burglar alarm.
This circuit costs around Rs 100.
D. Mohan KuMar
T
his simple, low-cost circuit automati-
cally switches on the porch light
when your car enters the porch. The
light remains on for a predetermined time
period and automatically switches off.
While you park your vehicle safely, a sweet
melody can also be heard.
The circuit is based on the popular timer
S
.C
. D
w
iv
e
D
i
automatic Porch Light with meLody
IC 555. In the circuit, sound is converted
to electrical signal, which is used for trig-
gering the IC. Usually, trigger pin 2 of the
IC remains high. When pin 2 goes low, it
triggers the monostable built around IC 555.
Once triggered, output pin 3 of monostable
IC1 goes high and stays in this state for a
known duration, which can be controlled
by varying the value of timing components
(potmeter VR1 or capacitor C4).
The condenser microphone picks up the
sound signals from the horn and converts
these to electrical signals. The electrical
signals are amplifed by transistor amplifer
T1. During negative transition of the signal
at the collector of transistor T1, monostable
CONSTRUCTION
AUGUST 2007 WWW. E F Y MA G . C O M
and a small square box on the top of
the rectangular box, respectively. The
program output user interface is
shown here in the screenshot.
Hardware interface
Fig. 1 shows the block diagram of the
automatic time manager (ATM) and
Fig. 2 shows the circuit diagram of the
interfacing unit. Here, we are con-
cerned with only two connections: pin
2 and a ground pin of the parallel port.
Pin 2 corresponds to the first data bit
D0 in 8-bit data bus of the parallel
port.
The whole unit is powered by a
6V DC regulated supply. LED1 is the
power-on indicator.
IC MCT2E isolates the PC from the
main interfacing unit in case any short-
circuit occurs. Thus, it acts as a safety
device and protects the PC.
IC LM555 (IC2) timer is configured
in monostable mode of operation. A
low transition at its pin 2 will trigger
the timer. IC2 timer can be triggered
ADEEB RAZA
PC-BASED AUTOMATIC
TIME MANAGER
M
any articles have been pub-
lished in EFY for control
ling devices through a PCs
parallel port or line printer (LPT)
port. Here is another project for con-
trolling a school bell or a scheduled
shift-timing alarm of a factory auto-
matically. The load connected to the
output of the project can be an elec-
tric bell or a hooter. The timing can
be programmed for every day sched-
ule as per individual requirement.
A Windows-based program devel-
oped in Microsoft Visual Basic pro-
gramming language is used for con-
trolling an electric bell or hooter
through an electromagnetic relay. It
has been designed for Windows XP.
The graphics have been included
so that the master clock shows the real
clock time on the PCs screen. At the
same time, it shows alarm clock tim-
ing for triggering the timer circuit for
activating the bell or hooter.
The alarm timings, on/off con-
trols and their activation sequence can
be set by the user as per his require-
ment through 48 numbers of settings
that is, 24 settings for alarm time dis-
play on the screen and 24 for enabling
or disabling the
timer circuit.
The alarm time
as well as bell
or hooter on/
off timer can
be set by
simple clicking
the bigger rect-
angular box
PARTS LIST
Semiconductor:
IC1 - 7806 6V regulator
IC2 - 555 timer
IC3 - MCT2E optocoupler
LED1-LED3 - 5mm light-emitting diode
T1 - BC547 npn transistor
D1-D5 - 1N4007 rectifier diode
Resistors (all -watt, 5% carbon):
R1 - 330-ohm
R2,R3 - 10-kilo-ohm
R4 - 470-ohm
R5, R6 - 1-kilo-ohm
VR1 - 100-kilo-ohm
Capacitor:
C1 - 100F, 25V electrolytic
C2 - 0.1F ceramic
C3, C5 - 0.01F ceramic
C4 - 100F, 16V electrolytic
Miscellaneous:
X1 - 230V AC primary to 9V,
250mA secondary trans-
former
CON1 - 25-pin D-type parallel-port
male connector
RL1 - 6V, 1C/O PCB-mounted
relay
CONSTRUCTION
AUGUST 2007 WWW. E F Y MA G . C O M
only if the alarm time is set to 1 in
enable condition in the software. If the
alarm time is set to enable condition,
you will get a one-second long beep
sound from the PCs speaker and a
high pulse at pin 2 of the parallel port
of the PC. A high pulse output at pin
2 of the LPT port will cause momen-
tary glowing of signal LED2 and
conduction of transistor inside
optocoupler IC MCT2E. The conduc-
tion of this transistor sends a low pulse
to pin 2 of 555 timer IC2.
When timer IC2 gets triggered, its
output pin 3 goes high and holds the
relay for 30 seconds. Output pin 3 of
timer IC2 is connected to relay driver
BC547. The load is controlled through
the relay contacts to switch on or off.
The load-on time duration can be
set through a 100-kilo-ohm potentiom-
eter (VR1) upto 60 seconds or more.
The load (school bell or hooter) is con-
nected to the pole of the relay. When
the relay energises, the pole comes in
contact with the N/O, and connects
230V AC across the load. This turns
on the load for a brief predetermined
time set through 555 timer circuit.
An actual-size, single-side PCB lay-
out for the PC-based automatic time
manager circuit is shown in Fig. 3 and
its component layout in Fig. 4.
Software program
In the program, master clock time or
real-time clock is represented by Time,
alarm times are represented by AT1
through AT24, and timer enable/dis-
able for alarm times are represented as
T1 to T24, respectively. AT1 through
AT24, and T1 through T24, are stored
in a file name called HTIME. This
data is fixed and continuously com-
pared with the actual time of master
clock.
Whenever master clock time is
equal to alarm time and alarm time is
set to enable condition, you will get a
one-second long beep sound from the
PCs speaker and a high pulse at pin 2
of the 25-pin D-type parallel port con-
nector of the PC. This pulse is used to
control the load connected across the
relay in the interfacing circuit.
The logic of the ATM program is
very easy:
Compare Master Clock Time and
Set Alarm Time
If T1=1, Alarm Time No.1 is en-
abled. If T1=0, Alarm Time No.1 is dis-
abled.
A sample program to display
CONSTRUCTION
AUGUST 2007 WWW. E F Y MA G . C O M
the first alarm timer setting is
given below:
Label4.Caption = AT1
If AT1 = Time then T = 1
If T + T1 = 2 then pat = 1 This will give a beep
sound through PC speaker
AEPData = Val(pat) Set PAT= 0 or PAT=1
Here, when PAT= 0, the load will
be in off condition, and when
PAT=1, the load will be in on
condition. The statement AEPOut
(Data) will give a high output at
pin 2 of the LPT port.
For details on LPT port, you
may refer to Device Control
Through PCs Parallel Port Using
Visual Basic project published in
EFYs March 2005 issue.
Testing of software and
hardware interface
1. Install Microsoft Visual Basic 6
on your computer.
2. Fabricate the interface circuit
on the PCB.
3. Connect the male connector
pin 2 (D0) and ground (pins 18
through 25) to female connector
on the PC.
4. Launch Visual Basic from
the desktop and develop the ap-
plication as shown in the
screenshot. Save the project file
with extension .vbp
5. Run the program
6. Set master clock time and
alarm time.
7. Click ATM setting to know
more about setting and help.
Alternatively, you can use
ATMINSTALL.zip file included in the
EFY-CD. Unzip ATMINSTALL.zip file
and you will get a folder name ATM-
Win-Installer. In this folder, you will
get a setup program. Clicking setup
file will install this project automatically
in Program Files folder of Windows
with the name Project1 folder along
with other relevant files and drivers.
You can also create a Win-Installer
program as follows: Open Microsoft
Visual Studio folder. In the folder
VB98, you will get another folder
Wizards, which contains another
folder PDWizard. In folder
PDWizard, you will
get a program
file named
PDCMDLN. EXE.
Clicking the
PDCMDLN.EXE will
create Win-install soft-
ware for any of your
Visual Basic projects.
In case you have
additional software
and services installed
in your PC with Win-
dows XP, you may ob-
serve a problem that
pin 2 of the parallel
port is high every five
seconds. To solve the
problem, there is a
SuperProserver ser-
vices in the system
under Control Panel
/Admi ni s t r a t i ve
Tools which has to be
disabled before run-
ning the program.
EFY. All the rel-
evant files of this
project have been in-
cluded in this months
EFY-CD. z
c i r c u i t i d e a s
electronics for you March 2003
Lead-acid battery charger
with voLtage anaLyser
D. Mohan KuMar
N
owadays maintenance-free lead-acid
batteries are common in vehicles,
inverters, and UPS systems. If the
battery is left in a poor state of charge, its
useful life is shortened. It also reduces the
capacity and rechargeability of the battery.
For older types of batteries, a hygrometer
can be used to check the specifc gravity
of the acid, which, in turn, indicates the
charge condition of the battery. However,
you cannot use a hygrometer for sealed-
type maintenance-free batteries. The only
way to know their charge level is by check-
ing their terminal voltage.
The circuit presented here can re-
plenish the charge in a battery within
6-8 hours. It also has a voltage analysing
circuit for quick checking of voltage before
start of charging, since overcharging may
damage the battery. The voltage analyser
gives an audio-visual indication of the bat-
tery voltage level and also warns about the
critical voltage level at which the battery
requires immediate charging.
The charger circuit consists of a stan-
dard step-down 12V AC (2-amp) transform-
er and a bridge rectifer comprising diodes
D1 through D4. Capacitor C1 smoothes the
AC ripples to provide a clean DC for charg-
ing the battery.
The battery voltage analyser circuit
is built around the popular quad op-amp
LM324 that has four separate op-amps
(A through D) with differential inputs.
Op-amps have been used here as compara-
tors. Switch S2 is a pushswitch, which is
pressed momentarily to check the battery
voltage level before charging the battery.
The non-inverting terminals of op-amps
A through D are connected to the positive
supply rail via a potential divider chain
comprising resistors R1 through R5. Thus
the voltage applied to any non-inverting
input is the ratio of the resistance between
that non-inverting terminal and ground to
the total resistance (R1+R2+R3+R4+R5).
The resistor chain provides a positive volt-
age of above 5V to the non-inverting inputs
of all op-amps when battery voltage is 12.5V
or more. A reference voltage of 5V is applied
to the inverting inputs of op-amps via 5V
zener diode ZD1.
When the circuit is connected to the
battery and pushswitch S2 is pressed (with
S1 open), the battery voltage is sampled by
the analyser circuit. If the supply voltage
sample applied to the non-inverting input
of an op-amp exceeds the reference voltage
applied to the inverting inputs, the output
of the op-amp goes high and the LED con-
nected at its output lights up.
The different levels of battery voltages
are indicated by LED1 through LED4. All
the LEDs remain lit when the battery is
fully charged (above 12.5V). The buzzer
connected to the output of IC1 also sounds
(when S2 is pressed with S1 kept open) as
long as the voltage of battery is above 9.8V.
If the voltage level goes below 9.8V, the
buzzer goes off, which indicates that its
time to replace
t he bat t ery.
The status of
LEDs for dif-
ferent battery
vol t ages i s
shown in the
table.
The circuit
Battery voltage Status of LEDs Comments
Red Green Yellow Orange
<9.8V Off Off Off Off Buzzer off
>9.8V On Off Off Off Danger level
11.5V On On Off Off Low level
12.0V On On On Off Normal level
12.5V On On On On High level
c i r c u i t i d e a s
electronics for you March 2003
can be assembled on a general-purpose
PCB or a veroboard. Use 4mm wire and
crocodile clips to connect the charger to
the battery. A 2.5-amp fuse connected
to the output of the charger protects the
analyser circuit against accidental polarity
reversal.
The circuit costs around Rs 120 with
all accessories.
do-it-yourself
KitsnSpares
OVERVIEW
The purpose of the Battery Low Indicator is to give a
visual indication when a battery has been discharged below
a specifc level. This is especially crucial for re-chargeable
batteries that should not be discharged below a certain
voltage level. This lower voltage limit depends upon the
type of the battery. The Battery Low Indicator circuit can be
typically used for 12V batteries to give an indication of the
battery voltage falling below the pre-set value. The indica-
tion is in the form of a fickering LED.
COMPONENT DESCRIPTION
Dual Comparator IC LM319:
The LM319 is a precision high-speed dual comparator
fabricated on a single monolithic chip. It is designed to
operate over a wide
range of supply volt-
ages down to a single
5 V logic supply and
ground. Although de-
signed primarily for
applications requiring
operation from dig-
ital logic supplies, the
LM319 series are fully
specified for power
supplies up to 15 V.
Of its two inde-
pendent comparators,
the Battery Low Indica-
tor uses only one for comparing the battery voltage to the
reference voltage. The comparator being used in the circuit
accepts inputs from pin4 (non-inverting) and pin5 (invert-
ing) while the corresponding output is generated at pin12.
This comparator output (at pin12) is responsible for holding
the reset pin of the NE555 timer IC either high or low,
depending upon which the NE555 may or may not run as
a multi-vibrator.
Single Timer IC NE555:
The NE555 is a precision timing circuit capable of pro-
Battery Low Indicator
ducing accurate time delays
or oscillations (pulses). The
NE555 usually operates in two
modes- mono-stable mode (for
producing a single pulse when
triggered) and the astable mode
(for generating pulses or oscil-
lations, with the desired duty
cycle). The threshold (Pin6) and trigger (Pin2) level for
the NE555 are normally two-thirds and one-third, respec-
tively, of VCC. However, connecting the trigger input to the
threshold input causes the NE555 to run as a multi-vibrator.
This is known as the astable mode of operation whereby
pulses or oscillations are generated, the frequency and duty
cycle of which can be controlled independently with two
external resistors and a single external capacitor.
The Battery Low Indicator uses the reset function of the
NE555 to implement the visual indication mechanism. The
reset pin of NE555 is active low i.e. when the voltage on
this pin falls below 0.7V (approximately) it makes the out-
put low too (0V), overriding all the other inputs. However,
when the reset pin is held high in the astable mode, the out-
put (pin3) of the NE555 becomes high and oscillations are
generated at this pin which can be used to drive loudspeak-
ers, motors, piezoelectric transducers, LEDs, etc.
Zener Diode (for Voltage Reference):
A Zener diode permits current not only in the forward
direction (like a normal diode) but also in the reverse direc-
tion, if the voltage is larger than the breakdown voltage
known as Zener knee voltage or Zener voltage.
Reverse-biased Zener diode will ex-
hibit a controlled breakdown and allow
the current to keep the voltage across
the Zener diode at the Zener voltage.
For example, a diode with a Zener
breakdown voltage of 3.2 V will exhibit
a voltage drop of 3.2 V if reverse bias
voltage applied across it is more than
its Zener voltage. The Zener diode is
therefore ideal for applications such as
the generation of a reference voltage
or as a voltage stabilizer for low-cur-
rent applications. When connected in
parallel with a variable voltage source so that it is reverse
biased, a Zener diode conducts when the voltage reaches
the diodes reverse breakdown voltage. From that point on,
the relatively low impedance of the diode keeps the voltage
across the diode at that value.
Fig. 1: Block diagram of the Battery Low Indicator
Fig. 3: Pin-out of a NE555
Timer IC
Fig. 2: Pin-Out of the Dual Comparator
IC LM319
Fig. 4: Orientation
and Representation of
Zener Diode
do-it-yourself
KitsnSpares
5V Voltage Regulator IC 7805:
The 7805 is a three-terminal positive regula-
tor with a fxed output voltage of 5V. The 7805
employs internal current limiting, thermal shut
down and safe operating area protection, mak-
ing it essentially indestructible. If adequate heat
sinking is provided, they can deliver over 1A
output current. In the Battery Low Indicator
circuit, both IC1 (dual comparator LM319) and
IC2 (NE555 timer) operate off regulated +5V DC
generated by voltage regulator IC 7805 (IC3).
Single-pole double-throw (SPDT) toggle
switch:
A SPDT toggle switch may be used as a simple on-off
switch by connecting the COM termi-
nal and either of the A or B terminals
shown in the diagram. The terminals A
and B are interchangeable, so switches
are usually not labeled. The terminal
which is connected in the circuitry
comes to be known as the on position
of the toggle switch.
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
voltage by dividing it. They are also used as pull-up resis-
tors in electronic logic circuits to ensure that inputs to logic
systems settle at expected logic levels if external devices are
disconnected or high-impedance. They may also be used at
the interface between two different types of logic devices,
possibly operating at different power supply voltages.
Capacitors:
Capacitors store electric charge. They are used with re-
sistors in timing circuits because it takes time for a capacitor
to fll with charge. Capacitors are also used to smooth vary-
ing DC supplies by acting as a reservoir of charge. They are
also used in flter circuits because capacitors easily pass AC
(changing) signals but they block DC (constant) signals.
Note: Electrolytic capacitors are polarized and they 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 heart of the Battery Low Indicator circuit is the
dual comparator IC LM319 (denoted as IC1 here) which
compares the batterys voltage to a reference voltage level.
Only one of the two independent comparators that are a
part of the LM319 is used in the circuit. The two inputs to
this comparator are:
1. Reference voltage which is applied to the non-
inverting input pin (4). It is held constant at approximately
1.2V by the Zener diode D1.
2. Batterys voltage which is applied via a potential
divider arrangement built around resistors R2, R3 and pre-
set VR1 and fed to the inverting input pin (5).
The corresponding output is generated at pin12 of IC1.
Pre-set VR1 is very important as it sets the voltage level at
which a visual indication of the low battery level is gener-
ated. For example: If the battery under test is of 12V and an
indication is required as soon as the battery voltage falls
below 10.5V, the voltage at the inverting input (pin5 of IC1)
should be adjusted to 1.2V using preset VR1.
Initially, when the battery is fully charged, the volt-
age at the inverting input (pin5) of IC1 is higher than the
non-inverting input (pin4- voltage level held constant at
approximately 1.2V by D1). This causes the output at pin
12 of IC1 to remain low. The reset pin (pin4) of NE555 timer
Fig. 6: SPDT Toggle
Switch Notations
Fig. 5: Pin-
out of 7805
Voltage
Regulator
Component Identifcation
Resistors
(R1-R8)
Zener Diode (D1)
IC Sockets
Printed Circuit Board (PCB)
Ceramic Capacitors
(C2, C3, C4, C1 and C5)
SPDT Toggle
Switch (S1)
Voltage
Regulator
(IC3)
Capacitors
(C5, C7)
Preset
(VR1)
IC1
Comparator
IC2
Timer
SPDT Toggle
(On/Off Switch)
Connections
to battery
under test
Completed prototype after assembling the components and soldering
Red
LED
do-it-yourself
KitsnSpares
(IC2) is connected to the output pin of
IC1 and hence, a low gets applied to it
correspondingly. Since the reset pin is
active low, the NE555 is reset continu-
ously and oscillations are not generated
at its output (pin3). As a result, LED1
does not start blinking.
Considering the example values,
when the battery voltage falls below
10.5V, the voltage at the inverting in-
put (pin4) of IC1 becomes lower than
the non-inverting input (pin5) and the
output at pin12 of IC1 goes high. This
applies a high to the connected reset
pin of IC2 (NE555 timer) and the astable
multi-vibrator built around IC2 starts
generating oscillations. LED1 is con-
nected to the output pin (pin3) of IC2
and hence blinks to indicate that the bat-
tery voltage is low and that the battery
needs to be charged before further use.
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 tem-
perature 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 sol-
der 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. Capacitors
3. Zener Diode and LED
4. Jumper Links
5. IC Sockets
6. Variable Resistor (Pre-set)
7. Voltage Regulator IC
8. SPDT Toggle Switch
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 component 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 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 the connection of
jumper wires on the PCB. These are
denoted on the PCB with the letter J
along straight lines indicating the drills
where they are to be soldered.
It is preferable to use multi-
thread wires for the jumper links, rather
than single thread copper wires since
they tend to break upon soldering.
Please note that the footprint of the SPDT toggle
switch does not match the drills provided on the PCB. This
is because such components are connected using wires and
only some of all the pins/legs of the relay/switch are to be
soldered onto the PCB. Please refer to the previous compo-
nent description to fgure out these connections.
Pay attention to the polarity of components like
diodes and electrolytic capacitors before soldering.
The pins of the IC sockets may have to be adjusted
and bent in order to insert them into the drill-holes prior to
soldering. The IC sockets and not the IC itself are soldered
onto the PCB for easy testing and debugging.
IC holders/sockets should be soldered with the
notch at the correct end.
PRE-TEST
Do not insert the ICs into their sockets yet. First, note
the polarity of the battery under test (also take note that
the battery low indicator cannot be used for batteries with
output voltage greater than 14V). Next, connect this battery
under test to the circuit and measure the voltage across pin8
(+V cc) and pin1 (GND) on the socket of IC2 i.e. the NE555
timer. It should read approximately 5V. Similarly the volt-
age across pin11 (+V cc) and pin3 (GND) of IC1 (comparator
LM319) should also be 5V. If these readings are ok then re-
move the battery and insert the ICs. Take care to not to bend
any of the IC pins while doing so. Accidentally applying a
voltage to the circuit that is greater than the bearable limit
can burn the ICs or some other sensitive component.
TESTING
Connect the battery once again so as to apply the
battery voltage to the circuit.
Parts List
Semiconductors:
IC1 - LM319 Dual Comparator
IC2 - NE555 Multi-vibrator/Timer
IC3 - 7805 DC Voltage Regulator
D1 - 2.2V Zener Diode
LED1 - Red LED
Resistors (all -watt, 5% carbon unless
stated otherwise):
R1 - 470 kilo-ohm
R2, R5, R7 - 100 kilo-ohm
R3 - 10 kilo-ohm
R4, R6 - 1 kilo-ohm
R8 - 470 ohm
VR1 - 10 kilo-ohm Preset
Capacitors:
C1, C6 - 0.01F, Ceramic Disk
C2, C3, C4 - 0.1F, Ceramic Disk
C5, C7 - 1F, 10V electrolytic
Miscellaneous:
S1- SPDT Toggle (On/Off) Switch
Printed Circuit Board (PCB)
do-it-yourself
KitsnSpares
To perform a test on the battery low indication
mechanism, the circuit frst needs to be calibrated so as to
set a voltage value at which it would indicate a low bat-
tery through the blinking LED. Connect a supply voltage
between 4 to 14V at which you want the battery low indica-
tion. For example this value is 9V. After the circuit has been
powered, check the voltage at pin4 (non-inverting input) of
IC1. This should be approximately 1.2 Volts.
Next, check the voltage at pin5 (inverting input)
of IC1. This will usually be more than the voltage at pin4.
In this condition, the output pin (pin12) of IC1 is held low
at approximately 0.34V and the LED is not glowing/blink-
ing.
While monitoring the voltage at pin5, rotate the
preset and note the voltage drop at this pin. As soon as
the voltage at pin5 falls below that at pin4 (approximately
1.2V), the LED will start to blink and the voltage at output
pin12 will go high. This output voltage level should ap-
proximately be equal to 4.95 Volts.
Leave the preset setting at this position. Now, the circuit
has been calibrated to indicate a battery low if its voltage
falls below 9V. Check by applying a battery of less than 9V
output. The LED should blink.
The circuit can be calibrated for any value between 4-
14V by following the above procedure.
TROUBLESHOOTING
If the circuit is not working as desired then proceed as
below:
It is preferable to begin trouble-
shooting process from output stage
onwards and then proceed to the
input side. To begin, apply a high
(5V) to reset pin4 of the NE555 timer.
Since the reset pin is active low, this
should cause the output at pin3 to
oscillate and the LED should start
blinking. If this mechanism is working
as described then the circuit stages be-
yond IC2 are working fne. If not then
proceed with the next step.
Next, check for the voltage
change at pin 12 of IC1. When Vpin4 <
Vpin5 of IC1, the output should be low
(approx. 0.34V). On the other hand,
when Vpin4> Vpin5 the output volt-
age should be high (approx. 4.95V). If
this kind of switching between volt-
age levels is taking place then your
IC is working. If voltage changes do not take place then
there may be problem in the IC. If the IC appears to have
heated then replace it. Check the soldering for any shorting
points.
Check the polarity and connection of components
like diodes and capacitors. Also, verify whether all the re-
sistances being used are of the required value. Make sure
that you have the right components in the right place.
Further, remove the IC from the IC socket and
check that no IC pins are bent up under the body of the
ICs. This can sometimes happen when inserting ICs into
sockets.
Once the circuit problem has been resolved your Battery
Low Indicator is ready to be installed and used.
TRY THIS OUT NEXT!
The Battery Low Indicator implemented here provides
a mechanism for visual indication only. The circuit can be
easily modifed to include a piezoelectric buzzer to give
audible indication every time the battery voltage falls below
the set-level. Further, the voltage range can be increased by
incorporating a different Zener diode (with a greater break-
down voltage) and a large preset in place of VR1.
CONTACT DETAILS
For full range of available kits, take a look at our web-
site: www.kitnspares.com
Fig. 7: Circuit Diagram of the Battery Low Indicator
Documented by Aditi Goswami
ConstruCtion
78 January 2007 electroni cs for you www. e f y ma g . c o m
AkshAy MAthur, kuldeep
singh nAglA
Microcontroller-bAsed
bidirectionAl Visitor
counter
the entry/exit point of a company but
has a wide range of applications that
provide information to management
on the volume and fow of people
throughout a location. A primary
method for counting the visitors in-
volves hiring human auditors to stand
and manually tally the number of visi-
tors who pass by a certain location. But
human-based data collection comes at
great expense.
Here is a low-cost microcontroller-
based visitor counter that can be used
to know the number of persons at a
place. All the components required are
readily available in the market and the
circuit is easy to build.
Two IR transmitter-receiver pairs
are used at the passage: one pair
comprising IR transmitter IR TX1 and
receiver phototransistor T1 is installed
at the entry point of the passage, while
the other pair comprising IR transmit-
ter IR TX2 and phototransistor T2 is
installed at the exit of the passage. The
IR signals from the IR LEDs should
continuously fall on the respective
phototransistors, so proper orientation
of the transmitters and phototransistors
is necessary.
circuit description
Fig. 1 shows the transmitter-receiver
set-up at the entrance-cum-exit of the
SUNI L KUMAR
V
isitor counting is simply a
measurement of the visitor
traffic entering and exiting
offices, malls, sports venues, etc.
Counting the visitors helps to maxi-
mise the effciency and effectiveness of
employees, foor area and sales poten-
tial of an organisation.
Visitor counting is not limited to passage along with block diagram.
Two similar sections detect interrup-
tion of the IR beam and generate clock
pulse for the microcontroller. The
microcontroller controls counting and
displays the number of persons present
inside the hall.
Fig. 2 shows the circuit of the
microcontroller-based visitor coun-
ter, wherein the transmitter and the
receiver form the IR detection circuit.
Control logic is built around transis-
tors, operational amplifer LM324 (IC1)
and fip-fop (IC2).
When nobody is passing through
the entry/exit point, the IR beam
continuously falls on phototransistor
T1. Phototransistor T1 conducts and
the high voltage at its emitter drives
transistor T3 into saturation, which
makes pin 3 of comparator N1 low and
fnally output pin 1 of comparator N1
is high.
Now if someone enters the place,
frst the IR beam from IR TX1 is inter-
rupted and then the IR beam from IR
TX2. When the beam from IR TX1 is
interrupted, phototransistor T1 and
transistor T3 cut-off and pin 3 of com-
parator N1 goes high.
The low output (pin 1) of compara-
tor N1 provides negative trigger pulse
to pin 1 of J-K fip-fop IC2(A). At this
moment, the high input at J and K
Fig. 1: Transmitter-receiver set-up at the entrance-cum-exit of the passage
Parts List
Semiconductors:
IC1 - LM324 quad op-amp
IC2 - 74LS76 J-K fip-fop
IC3 - AT89C52
microcontroller
IC4 - 7805 5V regulator
T1, T2 - L14F1 npn phototransis-
tor
T3, T4 - 2N3904 npn transistor
IR TX1, IR TX2 - IR transmitting LED
BR1 - 1A bridge rectifer
DIS1-DIS3 - LTS543 CC 7-segment
display
Resistors (all -watt, 5% carbon):
R1, R2 - 68-ohm
R3, R4 - 6.8-kilo-ohm
R5, R6 - 100-ohm
R7, R8, R10,
R11 - 10-kilo-ohm
R9 - 4.7-kilo-ohm
R12-R32 - 220-ohm
VR1, VR2 - 20-kilo-ohm preset
RNW1 - 10-kilo-ohm resistor
network
Capacitors:
C1, C2 - 0.2F ceramic disk
C3, C4 - 33pF ceramic disk
C5 - 10F, 16V electrolytic
C6 - 470F, 25V electrolytic
C7 - 0.1F ceramic disk
Miscellaneous:
XTAL - 12MHz crystal
X1 - 230V primary to 7.5V,
250mA secondary trans-
former
S1 - Push-to-on switch
S2 - On/off switch
ConstruCtion
electroni cs for you January 2007 79 www. e f y ma g . c o m
F
i
g
.

2
:

C
i
r
c
u
i
t

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

v
i
s
i
t
o
r

c
o
u
n
t
e
r

ConstruCtion
80 January 2007 electroni cs for you www. e f y ma g . c o m
Fig. 3: Power supply circuit
pins of flip-flop
IC2(A) toggles its
output to low. On
the other hand,
the low input at
J and K pins
of IC2(B) due to
clock pin 1 of
IC2(A) and J in-
put (pin 9) and
K input (pin 12) of IC2(B) are con-
nected to pin 1 of comparator N1. The
negative-going pulse is applied to clock
pin 6 of IC2(B) when the person inter-
rupts the IR beam from IR TX2. There
is no change in the output of IC2(B)
flip-flop. This triggers the external
interrupt INT0 (pin 12) of microcon-
troller AT89C52.
The AT89C52 is an 8-bit micro-
controller with 8 kB of fash-based
program memory, 256 bytes of RAM,
32 input/output lines, three 16-bit
timers/counters, on-chip oscillator
and clock circuitry. A 12MHz crystal is
used for providing clock.
Ports 0, 1 and 2 are confgured
for 7-segment displays. Port-0 pin is
externally pulled up with 10-kilo-ohm
resistor network RNW1 because port-
0 is an 8-bit, open-drain, bidirectional,
input/output (I/O) port. Port-1 and
port-2 are 8-bit bidirectional I/O ports
with internal pull-ups (no need of ex-
ternal pull-ups).
Port pins 3.0 and 3.1 are confgured
to provide the set pulse to J-K fip-fops
IC2(A) and IC2(B), respectively. Exter-
nal interrupts INT0 and INT1 receive
the interrupt pulse when the person in-
terrupts the IR beams. Resistor R9 and
capacitor C5 provide power-on-reset
pulse to the microcontroller. Switch S1
is used for manual reset.
When the microcontroller is re-
Fig. 4: Pin
configuration
of L14F1 and
transistor 2N3904
s e t , t h e
flip-flops are
b r o ug ht i n
s e t s t a t e
t hr ough t he
microcontroller
at software run
time by making
their set pin
high for a mo-
ment.
The value
of the counter
increments by
1 when the
interrupt ser-
vice routine for
INT0 is execut-
ed. The output
of the corre-
sponding J-K
flip-flop is set
to high again
by making its
set input pin
l ow t hrough
the microcon-
troller. The mi-
cro-controller is
confgured as a
negative-edge-
triggered inter-
rupt sensor.
Similarly, if
somebody exits
the place, frst
the IR beam
from IR TX2
is interrupted
and then the
IR beam from
IR TX1. When
the beam from
IR TX2 is interrupted, output pin
7 of comparator N2 goes low. This
Fig. 5: An actual-size, single-side PCB for the microcontroller-based visitor
counter (Fig. 2) including its power supply (Fig. 3)
Fig. 6: Component layout for the PCB
provides clock pulse to pin 6 of J-K
fip-fop IC2(B).
ConstruCtion
electroni cs for you January 2007 81 www. e f y ma g . c o m
#include <AT89x52.h>
int i=0,j,k,l,m,a[]={63,6,91,79,102,109,125,7,127,111};
void enter (void) interrupt 0
{
i++;
if(i>999) i=999;
P3_1=0;
for(m=0;m<=1000;m++);
P3_1=1;
}
void exit (void) interrupt 2
{
visitor.c
i;
if(i<0) i=0;
P3_0=0;
for(m=0;m<=1000;m++);
P3_0=1;
}
void main()
{
IE = 133;
TCON = 5;
P3_0=1;
P3_1=1;
i=0;
while(1)
{
j=i%10;
k=i/10;
l=i/100;
k=k-l*10;
P2=a[j];
P0=a[k];
P1=a[l];
}
}
At this moment, the high input
at J and K pins of fip-fop IC2(B)
toggles its output to low. On the other
hand, the low input at J and K pins
of IC2(A) due to clock pin 6 of IC2(B)
and J input (pin 4) and K input (pin
16) of IC2(A) are connected to pin 7 of
comparator N2.
The negative-going pulse is ap-
plied to clock pin 1 of IC2(A) when the
person interrupts the IR beam from IR
TX1. There is no change in the output
of IC2(A) fip-fop. This triggers the
external interrupt INT1 (pin 13) of
microcontroller AT89C52. The value
of the counter decrements by 1 when
interrupt service routine for INT1 is ex-
ecuted. The output of the correspond-
ing J-K fip-fop is set to high again by
making its set input pin low through
the microcontroller.
The circuit is powered by regu-
lated 5V. Fig. 3 shows the circuit of
the power supply. The AC mains is
stepped down by transformer X1 to
deliver secondary output of 7.5V,
250mA, which is rectifed by bridge
rectifer BR1, fltered by capacitor C6
and regulated by IC 7805 (IC4). Ca-
pacitor C7 bypasses any ripple in the
regulated output.
construction
An actual-size, single-side PCB for the
microcontroller-based visitor counter
(Fig. 2) including its power supply (Fig.
3) is shown in Fig. 5 and its component
layout in Fig. 6.
software
The software for the visitor counter
is written in C language and
compiled using C51 Keil compiler.
The demo version of this compiler
i s avai l abl e for free on t he
website www.keil.com. It can
compile programs up to 2 kB only,
which is suffcient for writing most
programs.
EFY note. The source code and
other relevant files of this article
have been included in this months
EFY-CD.
electronics for you september 2000
c i r c u i t i d e a s
G
enerally, when an equipment in-
dicates no power, the cause may
be just a blown fuse. Here is a
circuit that shows the condition of fuse
through LEDs. This compact circuit is
very useful and reliable. It uses very few
components, which makes it inexpensive
too.
Under normal conditions (when fuse
is alright), voltage drop in frst arm is 2V
+ (2 x 0.7V) = 3.4V, whereas in second
Fig. 2). An optocoupler is used to trigger
the siren. When the fuse blows, red LED
glows. Simultaneously it switches on
the siren.
In place of a bicolour LED, two LEDs
of red and green colour can be used.
Similarly, only one diode in place of D1
and D2 may be used. Two diodes are used
to increase the voltage drop, since the
two LEDs may produce different voltage
drops.
arm it is only 2V. So
current fows through
the second arm, i.e.
through the green
LED, causing it to
glow; whereas the red
LED remains off.
When the fuse
blows off, the supply
to green LED gets
blocked, and because
only one
LED i s
i n t he
ci rcui t ,
the red LED glows. In case
of power failure, both LEDs
remain off.
This circuit can be easily
modifed to produce a siren
in fuse-blown condition (see
AShUToSh KUmAr SinhA
Blown Fuse IndIcator
circuit
ideas
126 February 2011 electroni cs for you www. e F y ma g . c o m
S.C. DwiveDi
Call Bell with
welCOMe
inDiCatiOn
SUNIL KUMAR
press call bell switch S1
momentarily, it triggers
both the timers (IC1 and
IC2) simultaneously. IC1
produces a high output
at its pin 3 for about
fve seconds. transistor
t2 conducts and pi-
ezobuzzer PZ1 sounds
for about fve seconds
indicating that there is
somebody at the door.
At the same time, IC2
too produces a high out-
put at its pin 3 for about
two minutes. transistor
t1 conducts to enable
the alphanumeric dis-
plays. the word WEL-
COME is displayed
for about two minutes
as DIS1 through DIS7
ground via transistor T1.
I f swi t ch S1 i s
pressed again within
these two minutes, pi-
ezobuzzer PZ1 again
sounds for fve seconds
and the display con-
tinues to show WEL-
COME.
Assemble the com-
plete circuit on a gen-
eral-purpose PCB and
house in a small cabinet
with call bell switch S1
and LED1 mounted on
the front panel. At the
rear side of the cabinet,
connect a DC socket for
the adaptor. Install the
complete unit (along
with the display) at the
entrance of your house.
Connect the 6V bat-
tery or 6V adaptor for
H
ere is a simple call bell circuit
that displays a welcome mes-
sage when somebody presses
the call bell switch momentarily. the
alphanumeric display can be ftted
near the call bell switch.
the circuit is built around two
555 ICs (IC1 and IC2), seven KLA511
common-anode alphanumeric displays
(DIS1 through DIS7) and a few discrete
components. For easy understanding,
the entire circuit can be divided into
two sections: controller and display.
the controller section is built around
IC1 and IC2, while the display section
is built around alphanumeric displays
(DIS1 through DIS7).
As shown in the circuit, both IC1
and IC2 are wired as monostable
multivibrators having time periods
of around 5 seconds and 2 minutes,
respectively. You can change the
time period of IC1 by changing the
values of resistor R12 and capacitor
C3. Similarly, the time period of IC2
can be changed by changing the val-
ues of resistor R2 and capacitor C1.
Alphanumeric displays DIS1 through
DIS7 are wired such that they show
WELCOME when the output of IC2
goes high.
the circuit is powered by a 6V bat-
tery. Else, you can use the 6V, 300mA
power adaptor that is readily available
in the market. the 6V battery or power
adaptor provides regulated 6V re-
quired to operate the circuit. A 6V DC
socket is used in the circuit to connect
the output of the adaptor if you dont
use the battery.
Working of the circuit is simple.
First, power-on the circuit using switch
S2. LED1 glows to indicate presence of
power supply in the circuit. Now if you
circuit
ideas
electroni cs for you February 2011 127 www. e F y ma g . c o m
cuit assembly including alphanumeric
displays (installed at the entrance) by
covering it properly.
2. the complete kit for this cir-
cuit is available with EFY associates
kitsnspares.
powering the circuit. Confgure switch
2 (used to enable/disable the call bell)
in a switch board at a suitable location
inside your house. If you dont use a
battery, connect the power adaptor
to the DC socket on the rear of the
cabinet. Close switch S2 only when
you want to activate the circuit with
battery. Otherwise, keep it open when
the 6V adaptor is in use.
EFY note. 1. To avoid any shorting
during rain, waterproof the entire cir-
circuit
ideas
electroni cs for you January 2011 117 www. e f y ma g . c o m
M
ost thefts happen after mid-
night when people enter the
second phase of sleep called
paradoxical sleep. Here is a smart
security circuit for your cash box that
thwarts the theft attempt by activating
an emergency beeper. The circuit can
also be used to trigger any external
burglar alarm unit.
The cash box guard circuit (shown
in Fig. 1) is built around IC CD4060
(IC1), which has an inbuilt oscillator
and divider. The basic oscillator is con-
fgured by a simple resistor-capacitor
(R-C) network. IC CD4060 divides this
oscillator frequency into binary divi-
sions, which are available as outputs.
In light, reset pin 12 of IC1 remains
low, which enables the oscillator built
around IC1. However, in the dark, it
goes high, which resets the counter
making all the outputs low. This also
stops oscillations of the internal oscil-
lator.
Working of the circuit is simple. If
the cash box is closed, the interior will
be dark. Hence in the dark, the light-
dependant resistor (LDR1) resets IC1
and it stops oscillating and counting.
At the same time, pins 13 and 14 of
IC1 go low. So neither the piezobuzzer
(PZ1) sounds, nor the relay (RL1) en-
ergises, indicating that the cash box
is closed.
If someone tries to open the door
of the cash box, lightmost probably
from the burglars pen torchfalls
on LDR1 ftted into the cash box. As
a result, LDR1 conducts and pin 12
of IC1 goes low. IC1 starts oscillating
and counting. With the present tim-
ing R-C components (at pins 9, 10 and
T.K. Hareendran
CaSH BOX GUard
S.C. DW
IVEDI
11), the output timing at pin 14 of IC1
is two-three seconds. Hence pin 14 of
IC1 goes high for two seconds after the
door is opened and goes low for an-
other two seconds. So the piezobuzzer
(PZ1) sounds for two seconds and then
falls silent for the following two sec-
onds. This cycle repeats until the cash
box is closed.
An optional relay is added for a
remotely located audio/visual alert
system. For that, a relay driver circuit
built around npn transistor BC548 (T2)
is used. The relay is energised by the
output from pin 13 of IC1 for about
four seconds after the door is opened
and then de-energised for the follow-
ing four seconds. You can use this re-
lay to activate another remotely located
audio/visual alert system.
After assembling the circuit on a
small PCB, house it in a small tamper-
proof box (refer Fig. 2) leaving a little
window for LDR1 and a small opening
for the piezobuzzer (PZ1). Now ft the
unit inside the cash box (refer Fig. 3)
with LDR1 pointing towards the door
of the cash box.
EFY note. 1. The relay latching
facility can be added to the circuit by
replacing transistor T2 with a suit-
able silicon-controlled rectifer such
as BT169.
2. By changing the value of resistor
R1, you can adjust the light detection
sensitivity of the circuit.
3. If you want to use a 3-pin
piezobuzzer device, remove buzzer-
driver npn transistor T1 and connect
trigger pin of the buzzer directly to
pin 14 of IC1. Also connect the positive
and negative terminals of the buzzer to
respective positive and negative points
of the circuit.
4. Photo-transistor 2N5777 can be
used in place of the 10mm LDR1.
5. The complete kit for this circuit is
available with KitsnSpares.
Fig. 1: Cash box guard circuit
Fig. 3: Unit ftted inside the cash box and also
connected to an external alarm Fig. 2: Assembled unit
CELL PHONE DETECTOR
This handy, pocket-size mobile transmission detector can sense the presence of an activated mobile phone from
distance of oneand- a-half metres. So it can be used to prevent use of mobile phones in examination halls, confidential
rooms, etc. It is also useful for detecting the use of mobile phone for spying and unauthorised video transmission.
The circuit can detect both the incoming and outgoing calls, SMS and video transmission even if the mobile phone is
kept in the silent mode. The moment the bug detects RF transmission signal from an activated mobile phone, it starts
sounding a beep alarm and the LED blinks. The alarm continues until the signal transmission ceases. An ordinary RF
detector using tuned LC circuits is not suitable for detecting signals in the GHz frequency band used in mobile phones. The
transmission frequency of mobile phones ranges from 0.9 to 3 GHz with a wavelength of 3.3 to 10 cm. So a circuit detecting
gigahertz signals required for a mobile bug.

Here the circuit uses a 0.22F disk capacitor (C3) to capture the RF signals from the mobile phone. The lead length
of the capacitor is fixed as 18 mm with a spacing of 8 mm between the leads to get the desired frequency. The disk capacitor
along with the leads acts as a small gigahertz loop antenna to collect the RF signals from the mobile phone.
Op-amp IC CA3130 (IC1) is used in the circuit as a current-to-voltage converter with capacitor C3 connected between
its inverting and non-inverting inputs. It is a CMOS version using gate-protected p-channel MOSFET transistors in the input
to provide very high input impedance, very low input current and very high speed of performance.The output CMOS
transistor is capable of swinging the output voltage to within 10 mV of either supply voltage terminal.
Capacitor C3 in conjunction with the lead inductance acts as a transmission line that intercepts the signals from the
mobile phone. This capacitor creates a field, stores energy and transfers the stored energy in the form of minute current to
the inputs of IC1.This will upset the balanced input of IC1 and convert the current into the corresponding output voltage.
Capacitor C4 along with high-value resistor R1 keeps the non-inverting input stable for easy swing of the output to
high state. Resistor R2 provides the discharge path for capacitor C4.Feedback resistor R3 makes the inverting input high
when the output becomes high. Capacitor C5 (47pF) is connected across strobe (pin 8) and null inputs (pin 1) of IC1 for
phase compensation and gain control to optimise the frequency response.
When the mobile phone signal is detected by C3, the output of IC1 becomes high and low alternately according to the
frequency of the signal as indicated by LED1. This triggers monostable timer IC2 through capacitor C7. Capacitor C6
maintains the base bias of transistor T1 for fast switching action. The low-value timing components R6 and C9 produce
very short time delay to avoid audio nuisance.
Assemble the circuit on PCB and enclose in a small box like junk mobile case. As mentioned earlier, capacitor C3
should have a lead length of 18 mm with lead spacing of 8 mm.Carefully solder the capacitor in standing position with equal
spacing of the leads. The response can be optimised by trimming the lead length of C3 for the desired frequency. You may
use a short telescopic type antenna.Use the miniature 12V battery of a remote control and a small buzzer to make the gadget
pocket-size. The unit will give the warning indication if someone uses mobile phone within a radius of 1.5 metres.


ConstruCtion
www. e f y ma g . c o m 62 july 2008 electroni cs for you
P. RaghavendRa PRaSad and
K. SuSRam Rahul
CellPhone-oPeRated
land RoveR
C
onventionally, wireless-con-
trolled robots use RF circuits,
which have the drawbacks of
limited working range, limited fre-
quency range and limited control. Use
of a mobile phone for robotic control
can overcome these limitations. It
provides the advantages of robust
control, working range as large as the
coverage area of the service provider,
no interference with other controllers
and up to twelve controls.
Although the appearance and
capabilities of robots vary vastly,
all robots share the features of a me-
chanical, movable structure under
some form of control. The control of
robot involves three distinct phases:
preception, processing and action.
Generally, the preceptors are sensors
mounted on the robot, processing is
done by the on-board microcontrol-
ler or processor, and the task (action)
is performed using
motors or with some
other actuators.
Project
overview
In this project, the
robot is controlled
by a mobile phone
that makes a call to
the mobile phone at-
tached to the robot. In
the course of a call, if
any button is pressed,
a tone corresponding to the button
pressed is heard at the other end of
the call. This tone is called dual-tone
multiple-frequency (DTMF) tone.
The robot perceives this DTMF tone
Fig. 2: Circuit diagram of microcontroller-based cellphone-operated land rover
Fig. 1: Block diagram of cellphone-operated land rover
Parts List
Semiconductors:
IC1 - MT8870 DTMF decoder
IC2 - ATmega16 AVR
microcontroller
IC3 - L293D motor driver
IC4 - 74LS04 NOT gate
D1 - 1N4007rectiferdiode
Resistors (all -watt, 5% carbon):
R1, R2 - 100-kilo-ohm
R3 - 330-kilo-ohm
R4-R8 - 10-kilo-ohm
Capacitors:
C1 - 0.47F ceramic disk
C2, C3, C5, C6 - 22pF ceramic disk
C4 - 0.1F ceramic disk
Miscellaneous:
X
TAL1
- 3.57MHz crystal
X
TAL2
- 12MHz crystal
S1 - Push-to-on switch
M1, M2 - 6V, 50-rpm geared
DC motor
Batt. - 6V, 4.5Ah battery
ConstruCtion
www. e f y ma g . c o m electroni cs for you july 2008 63
with the help of the phone stacked in
the robot.
The received tone is processed by
the ATmega16 microcontroller with the
help of DTMF decoder MT8870. The
decoder decodes the DTMF
tone into its equivalent bi-
nary digit and this binary
number is sent to the micro-
controller. The microcontrol-
ler is preprogrammed to
take a decision for any
given input and out-
puts its decision to motor
drivers in order to drive
the motors for forward
or backward motion or
a turn.
The mobi l e t hat
makes a call to the mo-
bile phone stacked in the
robot acts as a remote. So
this simple robotic project
does not require the con-
struction of receiver and
transmitter units.
DTMF signaling is
used for telephone sign-
aling over the line in the
voice-frequency band to
the call switching centre.
The version of DTMF
used for telephone tone
di al i ng i s known as
Touch-Tone.
DTMF assigns a spe-
ci fi c frequency (con-
sisting of two separate
tones) to each key so
that i t can easi l y be
identified by the elec-
tronic circuit. The signal
generated by the DTMF
encoder is a direct al-
gebraic summation, in real time, of
the amplitudes of two sine (cosine)
waves of different frequencies, i.e.,
pressing 5 will send a tone made
by adding 1336 Hz and 770 Hz to the
other end of the line. The tones and
assignments in a DTMF system are
shown in Table I.
Circuit description
Fig. 1 shows the block diagram of the
microcontroller-based mobile phone-
operated land rover. The important
components of this rover are a DTMF
decoder, microcontroller and motor
driver.
An MT8870 series DTMF decoder
is used here. All types of the MT8870
series use digital counting techniques
to detect and decode all the 16 DTMF
tone pairs into a 4-bit code output. The
built-in dial tone rejection circuit elimi-
nates the need for pre-fltering. When
the input signal given at pin 2 (IN-) in
single-ended input configuration is
recognised to be effective, the correct
4-bit decode signal of the DTMF tone is
transferred to Q1 (pin 11) through Q4
(pin 14) outputs.
Table II shows the DTMF data
output table of MT8870. Q1 through
Q4 outputs of the DTMF decoder (IC1)
are connected to port pins PA0 through
PA3 of ATmega16 microcontroller
(IC2) after inversion by N1 through N4,
respectively.
The ATmega16 is a low-power,
8-bit, CMOS microcontroller based on
the AVR enhanced RISC architecture. It
provides the following features: 16 kB
of in-system programmable Flash pro-
gram memory with read-while-write
Table III
actions Performed Corresponding to the Keys Pressed
Number Output of HT9170 Input to the Output from action
pressed DTMF decoder microcontroller microcontroller performed
by user
2 002 0FD 089 Forwardmotion
00000010 11111101 10001001
4 004 0XFB 085 Leftturn
00000100 11111011 10000101 Rightmotorforwarded
Leftmotorbackwarded
6 006 0XF9 08A Rightturn
00000110 11111001 10001010 Rightmotorbackwarded
Leftmotorforwarded
8 008 0XF7 086 Backwardmotion
00001000 11110111 10000110
5 005 0XFA 000 Stop
00000101 11111010 00000000
Table II
DTMF Data Output
low High Digit Oe D3 D2 D1 D0
group (Hz) group (Hz)
697 1209 1 H L L L H
697 1336 2 H L L H L
697 1477 3 H L L H H
770 1209 4 H L H L L
770 1336 5 H L H L H
770 1477 6 H L H H L
852 1209 7 H L H H H
852 1336 8 H H L L L
852 1477 9 H H L L H
941 1336 0 H H L H L
941 1209 * H H L H H
941 1477 # H H H L L
697 1633 A H H H L H
770 1633 B H H H H L
852 1633 C H H H H H
941 1633 D H L L L L
ANY L Z Z Z Z
Table I
Tones and assignments
in a DTMF System
Frequencies 1209 Hz 1336 Hz 1477 Hz 1633 Hz
697Hz 1 2 3 A
770Hz 4 5 6 B
852Hz 7 8 9 C
941Hz * 0 # D
Fig. 3: Top view of the land rover
ConstruCtion
www. e f y ma g . c o m 64 july 2008 electroni cs for you
capabilities, 512 bytes of EEPROM, 1kB
SRAM, 32 general-purpose input/out-
put (I/O) lines and 32 general-purpose
working registers. All the 32 registers
are directly connected to the arithmetic
logic unit, allowing two independent
registers to be accessed in one single
instruction executed in one clock cy-
cle. The resulting architecture is more
code-effcient.
Outputs from port pins PD0
through PD3 and PD7 of the mi-
crocontroller are fed to inputs IN1
through IN4 and enable pins (EN1
and EN2) of motor driver L293D,
respectively, to drive two geared DC
motors. Switch S1 is used for manual
reset. The microcontroller output is
notsuffcienttodrivetheDCmotors,
so current drivers are required for mo-
tor rotation.
The L293D is a quad, high-cur-
rent, half-H driver designed to pro-
vide bidirectional drive currents of
up to 600 mA at voltages from 4.5V to
36V. It makes it easier to drive the DC
motors. The L293D consists of four
drivers. Pins IN1 through IN4 and
OUT1 through OUT4 are input and
output pins, respectively, of driver 1
through driver 4. Drivers 1 and 2, and
drivers 3 and 4 are enabled by enable
pin 1 (EN1) and pin 9 (EN2), respec-
tively. When enable input EN1 (pin
1) is high, drivers 1 and 2 are enabled
and the outputs corresponding to
their inputs are active. Similarly, en-
able input EN2 (pin 9) enables drivers
3 and 4.
An actual-size, single-side PCB
for cellphone-operated land rover is
shown in Fig. 4 and its component
layout in Fig. 5.
Software description
The software is written in C language
and compiled using CodeVision AVR
C compiler. The source program is
converted into hex code by the compil-
er. Burn this hex code into ATmega16
AVR microcontroller.
The source program is well com-
mented and easy to understand. First
includetheregisternamedefnedspe-
cifcallyforATmega16andalsodeclare
the variable. Set port A as the input
and port D as the output. The program
will run forever by using while loop.
Under while loop, read port A and
test the received input using switch
statement. The corresponding data
will output at port D after testing of the
received data.
Working
In order to control the robot, you
need to make a call to the cell phone
attached to the robot (through head
phone) from any phone, which sends
DTMF tunes on pressing the numeric
buttons. The cell phone in the robot
is kept in auto answer mode. (If the
mobile does not have the auto answer-
ing facility, receive the call by OK
key on the rover-connected mobile
and then made it in hands-free mode.)
So after a ring, the cellphone accepts
the call.
Now you may press any button
on your mobile to perform actions as
listed in Table III. The DTMF tones
thus produced are received by the
cellphone in the robot. These tones are
fed to the circuit by the headset of the
cellphone. The MT8870 decodes the
received tone and sends the equiva-
lent binary number to the microcon-
troller. According to the program in
the microcontroller, the robot starts
moving.
When you press key 2 (bi-
nary equivalent 00000010) on your
mobile phone, the microcontroller
outputs 10001001 binary equiva-
lent. Port pins PD0, PD3 and PD7
are high. The high output at PD7 of
the microcontroller drives the motor
driver (L293D). Port pins PD0 and
PD3 drive motors M1 and M2 in
forward direction (as per Table III).
Similarly, motors M1 and M2 move
for left turn, right turn, backward
motion and stop condition as per
Table III.
Construction
Whenconstructinganyrobot,onema-
jor mechanical constraint is the number
Fig. 4: An actual-size, single-side PCB layout for cellphone-operated land rover Fig. 5: Component layout for the PCB
ConstruCtion
www. e f y ma g . c o m 66 july 2008 electroni cs for you
Robot.C
Source program:
Robit.c
#include <mega16.h>
void main(void)
{
unsigned int k, h;
DDRA=0x00;
DDRD=0XFF;
while (1)
{
k =~PINA;
h=k & 0x0F;
switch (h)
{
case 0x02: //if I/P is 0x02
{
PORTD=0x89;//O/P 0x89 ie Forward
break;
}
case 0x08: //if I/P is 0x08
{
PORTD=0x86; //O/P 0x86 ie Backward
break;
}
case 0x04:
{
PORTD=0x85; // Left turn
break;
}
case 0x06:
{
PORTD=0x8A; // Right turn
break;
}
case 0x05:
{
PORTD=0x00; // Stop
break;
}
}
}
}
of motors being used. You can have ei-
ther a two-wheel drive or a four-wheel
drive. Though four-wheel drive is more
complex than two-wheel drive, it pro-
vides more torque and good control.
Two-wheel drive, on the other hand, is
very easy to construct.
Top view of a four-wheel-driven
land rover is shown in Fig. 3. The
chassis used in this model is a
1018cm
2
sheet made up of parax.
Motorsarefxedtothebottomofthis
sheet and the circuit is affxed frmly
on top of the sheet. A cellphone is also
mounted on the sheet as shown in the
picture.
In the four-wheel drive system,
the two motors on a side are control-
led in parallel. So a single L293D
driver IC can drive the rover. For this
robot, beads affxed with glue act as
support wheels.
Further applications
This land rover can be further im-
proved to serve specifc purposes. It
requires four controls to roam around.
The remaining eight controls can be
confgured to serve other purposes,
withsomemodifcationsinthesource
program of the microcontroller.
Note. The source code of this arti-
cle has been included in this months
EFY CD.
CONSTRUCTION
ELECTRONI CS FOR YOU J ULY 2005 65 WWW. E F Y MA G . C O M
CMYK
V. MARIYAPPAN
COMPUTERISED ELECTRICAL
EQUIPMENT CONTROL
Fig. 1 shows the circuit for inter-
facing the PCs parallel port to the de-
vices to be controlled. The parallel port
outputs the control signals generated
by the software. The control signals
are not continuous but a single clock
pulse. For every on or off control,
only a single clock pulse is sent from
the parallel port to the circuit.
Data pins D0 through D7 of the
parallel port are connected to pin 1 of
optocouplers IC5 through IC12 via re-
sistors R1 through R8, respectively.
Optocouplers ensure complete isola-
tion of the parallel ports data pins
from the relay driver circuit.
Each optocoupler consists of an
infrared light-emitting diode (LED)
and an npn phototransistor. When a
high going pulse is available on the
data pin, the internal LED drives the
phototransistor of optocoupler MCT2E
and it provides a clock pulse to the
corresponding flip-flop (IC CD4013)
section.
IC CD4013 is a dual D-type flip-
flop with independent set, clear and
clock inputs and a single output. It ac-
cepts data when its clock pin is low
and transfers it to the output on the
positive-going edge of the clock. The
high Q output of the flip-flop drives
the corresponding transistor to
energise the relay and switch on/off
the device.
The flip-flops are set up for toggle
mode by connecting their D inputs to
Q outputs. Set inputs of all the flip-
flops are grounded. Switch S1 is used
to reset the flip-flops manually.
Fig. 2 shows the circuit of the
power supply. The AC mains is
stepped down by transformer X1 to
deliver secondary output of 9V at 250
mA. The transformer output is recti-
fied by full-wave bridge rectifier BR1,
C
ontrolling electrical devices
from a PC is great fun. Here
is a Windows-based program
written in C language for controlling
up to eight devices from the PCs par-
allel port termed as printer port (LPT).
The program accepts the input in deci-
mal numbers and outputs at the data
output pins of the PCs parallel port
for controlling the connected devices.
PCs parallel port
The parallel port is made up of three
ports, namely, data port, status port
and control port. It is found on the
back of the PC as a D-type, 25-pin fe-
male connector. Here, we are con-
cerned only with data lines D0 through
D7 terminated at pins 2 through 9.
The data port is a write-only port,
which means it can be used only to
output data. Pins 18 through 25 of the
connector are grounded. Control port
is read/write capable, which means it
can be used both for outputting and
inputting some data to/from the ex-
ternal hardware. Status port is a read-
only port, which means it can be used
only to read data from the external
hardware.
Table below shows pin details of
the standard parallel port (SPP) and
their traditional usage. The base ad-
dress of the first parallel port (LPT1)
is 378 (hex) or 888 (decimal). The data
port of the parallel port can be accessed
at its base address. The status port can
be accessed at base address + 1, i.e.,
0379 hex (or 889 decimal). The control
port can be accessed at base address +
2, i.e., 037A hex (or 890 decimal). In
case you are using LPT2 port, then
substitute the base address of LPT2 as
0278 (hex) in place of 0378 (hex).
Pin Details of the Parallel Port
Pin number Traditional use Port name Read/Write Port address Port bit
2-4 Data out Data port W Base D0-D2
5-9 Data out W Base D3-D7
1 Strobe Control port R/W Base+2 C0
14 Auto feed R/W Base+2 C1
16 Initialise R/W Base+2 C2
17 Select input R/W Base+2 C3
15 Error Status port R Base+1 S3
13 Select R Base+1 S4
12 Paper end R Base+1 S5
10 ACK R Base+1 S6
11 Busy R Base+1 S7
SUNI L KUMAR
PARTS LIST
Semiconductor:
IC1-IC4 - CD4013 D-type flip-flop
IC5-IC12 - MCT2E optocoupler
IC13 - 7805 5V regulator
T1-T8 - BC548 npn transistor
D1-D8 - 1N4007 rectifier diode
BR1 - 1A, bridge rectifier
Resistors (all -watt, 5% carbon, unless
stated otherwise):
R1-R8 - 100-ohm
R9-R17 - 10-kilo-ohm
Capacitors:
C1 - 1000F, 25V electrolytic
C2 - 0.1F ceramic
Miscellaneous:
RL1-RL8 - 5V, 100-ohm, 1C/O relay
S1 - Push-to-on switch
X1 - 230V AC primary to 9V,
250mA secondary trans-
former
- 25-pin D-type parallel-port
male connector
CONSTRUCTION
66 J ULY 2005 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
CMYK
Fig. 1: Circuit diagram for computerised electrical equipment control
CONSTRUCTION
ELECTRONI CS FOR YOU J ULY 2005 67 WWW. E F Y MA G . C O M
CMYK
Fig. 2: Power supply circuit
Fig. 3: Screenshot of the main screen for computerised
electrical equipment control
filtered by capacitor
C1 and regulated by
IC13 to provide regu-
lated 5V supply. Ca-
pacitor C2 bypasses
any ripple in the regu-
lated output.
Before attempting
to control the devices,
the program
(Control.exe) is to be
run. A screen as
shown in Fig. 3 ap-
pears which shows
the current status of
each device (on=1,
off=0). To switch on a
device, press the cor-
responding device
number on the key-
board. This makes a
high control pulse
available on the data
pin of the respective parallel-port pin
and the toggle flip-flop switches from
off state to on state to energise the
relay and switch on the device. The
status of the corresponding device on
screen changes automatically.
Similarly, to turn the device off,
press the device number on the key-
board. This again makes a high con-
trol pulse available on the data pin and
the corresponding toggle flip-flop
switches from on state to off state
to de-energise the relay and turn the
device off.
The program can be terminated
simply by pressing the E key, but be-
fore that you should turn all the de-
vices off. If you try to terminate the
program without shutting down any
of the devices, the message Please
shutdown all the equipment will ap-
pear on the screen for a short period
followed by the main screen.
Fig. 4: Combined actual-size, single-side PCB layout for computerised
electrical equipment control and power supply circuits
Fig. 5: Component layout for the PCB
CONSTRUCTION
68 J ULY 2005 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
CMYK
CONTROL.C
/*COMPUTERISED ELECTRICAL EQUIPMENT CON-
TROL*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
void tone(void);
int p=0x0378;
char ex[23]={"Created by V.MARIYAPPAN"};
int j;
char ex1[34]={"For Further Details & Improvements"};
int k;
char ex2[40]={"Contact: Email-
marietech2003@yahoo.co.in"};
int l;
char ex3[23]={"Programming Language: C"};
int m;
int u[10];
int i;
static a,b,c,d,e,f,g,h;
char no;
clrscr();
textcolor(15);gotoxy(20,6);
cprintf("COMPUTERISED ELECTRICAL EQUIPMENT
CONTROL");
textcolor(11);gotoxy(20,7);
cprintf("-----------------------------------------");
textcolor(11);gotoxy(10,10);
cprintf("EQUIPMENT NO: 1 2 3 4 5 6 7
8");
textcolor(11);gotoxy(10,12);
cprintf("STATUS: %d %d %d %d %d %d
%d %d",a,b,c,d,e,f,g,h);
textcolor(10);gotoxy(9,16);
cprintf("FOR 'ON' AND 'OFF' AN EQUIPMENT PRESS
CORRESPONDING EQUIP.NO.");
textcolor(11);gotoxy(28,18);
cprintf("STATUS 0=OFF STATUS 1=ON");
textcolor(12);gotoxy(32,20);
cprintf("FOR EXIT PRESS 'E'\n");
no=getch();
switch(no)
{
case '1':
a=!a;
tone();
outportb(p,1);
delay(500);
outportb(p,0);
break;
case '2':
b=!b;
tone();
outportb(p,2);
delay(500);
outportb(p,0);
break;
case '3':
c=!c;
tone();
outportb(p,4);
delay(500);
outportb(p,0);
break;
case '4':
d=!d;
tone();
outportb(p,8);
delay(500);
outportb(p,0);
break;
case '5':
e=!e;
tone();
outportb(p,16);
delay(500);
outportb(p,0);
break;
case '6':
f=!f;
tone();
outportb(p,32);
delay(500);
outportb(p,0);
break;
case '7':
g=!g;
tone();
outportb(p,64);
delay(500);
outportb(p,0);
break;
case '8':
h=!h;
tone();
outportb(p,128);
delay(500);
outportb(p,0);
break;
case 'e':
if((a|b|c|d|e|f|g|h)==1)
{
clrscr();
textcolor(10);gotoxy(20,12);
cprintf("PLEASE SHUT DOWN ALL THE EQUIP-
MENTS");
sound(200);
delay(500);
nosound();
delay(3000);
break;
}
else
{
clrscr();
for(j=0;j<23;j++)
{
textcolor(10);gotoxy(20+j,12);
cprintf("%c",ex[j]);
sound(3000+j);
delay(30);
nosound();
}
for(m=0;m<23;m++)
{
textcolor(10);gotoxy(20+m,13);
cprintf("%c",ex3[m]);
sound(1800+m);
delay(30);
nosound();
}
for(k=0;k<34;k++)
{
textcolor(10);gotoxy(20+k,14);
cprintf("%c",ex1[k]);
sound(2000+k);
delay(30);
nosound();
}
for(l=0;l<40;l++)
{
textcolor(10);gotoxy(20+l,15);
cprintf("%c",ex2[l]);
sound(2500+l);
delay(30);
nosound();
}
printf("\n\n\n\nPress any key");
getch();
outportb(p,0);exit(0);
}
case 'E':
if((a|b|c|d|e|f|g|h)==1)
{
clrscr();
textcolor(10);gotoxy(20,12);
cprintf("PLEASE SHUT DOWN ALL THE EQUIP-
MENTS");
sound(200);
delay(500);
nosound();
delay(3000);
break;
}
else
{
clrscr();
for(j=0;j<23;j++)
{
textcolor(10);gotoxy(20+j,12);
cprintf("%c",ex[j]);
sound(2500+j);
delay(30);
nosound();
}
for(m=0;m<23;m++)
{
textcolor(10);gotoxy(20+m,13);
cprintf("%c",ex3[m]);
sound(3500+m);
delay(30);
nosound();
}
for(k=0;k<34;k++)
{
textcolor(10);gotoxy(20+k,14);
cprintf("%c",ex1[k]);
sound(3000+k);
delay(30);
nosound();
}
for(l=0;l<40;l++)
{
textcolor(10);gotoxy(20+l,15);
cprintf("%c",ex2[l]);
sound(3500+l);
delay(30);
nosound();
}
printf("\n\n\n\nPress any key");
getch();
outportb(p,0);exit(0);
}
default:
clrscr();
sound(500);
delay(100);
nosound();
textcolor(11);gotoxy(30,12);
cprintf("INVALID KEY PRESSED");
textcolor(11);gotoxy(33,14);
cprintf("WAIT 2 SECONDS");
delay(3000);
break;
}
main();
}
void tone(void)
{
sound(1000);
delay(100);
nosound();
} z
In case you press any invalid key
(not used in the software), the mes-
sage Invalid key pressed wait 2 sec-
onds is displayed followed by the
main screen.
The combined single-side PCB lay-
out for the equipment control and
power supply circuits is shown in Fig. 4
and and its component layout in Fig. 5.
EFY note. The source code and ex-
ecutable file of this project have been
included in this months EFY-CD.
ConstruCtion
96 March 2007 electroni cs for you www. e f y Ma g . c o M
Gp Capt. (Retd) K.C. Bhasin
desiGn YouR own in-
fRaRed Remote
electrical or mag-
netic interference,
the infrared sig-
nal is somewhat
subject to interfer-
ence from sunlight
and other infrared
sources as also fu-
orescent lights.
encoding methods
Multitudes of different methods/for-
mats/protocols for encoding the actual
key/command/instruction data have
evolved. Early IR command codes
comprised fve or six bits of informa-
SUNI L KUMAR
M
ost of the home appliances
like TV sets, stereo systems,
CD/DVD players/recorders,
air-conditioners, microwave ovens,
multimedia computers and set-top
boxes come with an IR remote control.
An infrared remote offers several
advantages:
1. It is a cost-effective signaling
system.
2. Unlike radio-frequency-based
control devices, it is not subject to any
stringent regulation and restriction.
3. It is a line-of-sight system with a
range of 5 to 10 metres, hence its radia-
tion stays confned to a single room in
which it is used. It thus prevents inter-
ference between units operating in dif-
ferent rooms even when using identical
device address and command code.
4. A relatively broad modulation
frequency range is available using in-
expensive ASICs and components.
5. It is generally insensitive to in-
terference from external electrical or
magnetic felds.
6. It offers relatively high energy
effciency, which enhances the battery
life.
7. Infrared emitters and detectors
are inexpensive and readily available.
Limitations are:
1. Line-of-sight propagation be-
comes a limitation when you need to
control a device from another room.
2. Infrared is subject to mutual
interference from multiple sources
in the same room as most consumer
IR transmissions use a wavelength of
either 880 or 940 nm (corresponding to
the two commonly available IR-emit-
ting LED types). This limitation can be
tackled by using different sub-carrier
frequencies to modulate the light sig-
nals coupled with different encoding
schemes to carry the data content.
3. Although largely immune to
tion, which was adequate to encode a
set of 32 or 64 key functions as simple
binary values. With proliferation of the
remote-controlled devices, addition of
a device address or system code made
it possible to operate multiple devices
in the same room using the same com-
mand/instruction encoding scheme.
For example, if we have fve address
or system bits and six command bits,
we can operate 32 devices using 64
commands for each device, which may
be used for identical or totally different
functions in each specifc device.
The NEC format features error
control. It is of primary concern to
prevent false operation rather than
correct the wrong operation. In its
most basic format, the transmitter
repeats each IR data frame (explained
later) some minimum number of times.
The receiver compares the decoded
data from two or more consecutive
frames and ignores the signal if they
are not identical. Sony, for example,
uses such an approach in its standard
IR protocol called SIRCS (short for
Sony infrared control system). This
technique is simple to implement and
quite reliable.
Another popular solution is to
send both the command value and its
inverse. The receiver then compares
the two halves of the received data and
Fig. 1: Logic 1 format
Fig. 2: Logic 0 format
Fig. 3: Leader format Fig. 4: Repeat format
Fig. 5: Typical NEC transmission (above) and expanded view of first frame (below)
ConstruCtion
98 March 2007 electroni cs for you www. e f y Ma g . c o M
ries of abbreviated repeat signals (9ms
burst, followed by 2.25ms space ter-
minated with 560s burst) after every
108 ms for as long as the key remains
pressed. Since the repeat frame signal
consists of only a short blip instead of
the whole data frame, a key held down
for a long period uses less energy than
in many other encoding schemes.
The advantage of this approach
is conservation of battery power.
However, if the receiver misses the
frst frame for any reason, no recovery
is possible as the subsequent signal
pulses are devoid of any data. The key
has to be released and pressed again
before anything happens. Also, error
detection in this approach requires use
of data feld and inverse data feld.
features of neC format
1. 8-bit long addresses and 8-bit long
commands are transmitted twice
however, the second (lower-order)
address byte is not necessarily an exact
complement of the frst (higher-order)
address byte, while the second com-
mand byte is a true complement of the
frst command byte. Thus a total of 64k
(2
16
) addresses and 256 (2
8
) commands
are possible. (Note. The LSB of the bit
pattern is transmitted frst, followed
by higher-order bits.)
2. Pulse-distance modulation
Fig. 6: A complete schematic of NEC remote employing 32 keys
Fig. 7: Format of remote modulated output from pin 5 of encoder IC
(Note. Three linked resistors for achieving address 0076H and shaded keys for the command
codes as shown in Fig. 6 were used for the Digital Audio Processor project published in EFY
Feb. 2005). The software for that digital audio processor has accordingly been modifed and is
given in this months EFY-CD. Parts list and PCB details are given in this article.)
ignores the command if they are not
complement of each other. NEC uses
such a format.
The third method makes use of
a checksum, which generally results
in a more compact frame size than
sending the data and its inverse. This,
however, requires a more complex
receiver-decoding algorithm. This for-
mat is used by General Instruments.
Some other encoding schemes include
built-in redundancy to facilitate error
checking without the use of any added
data feld.
Majority of the Asian manufac-
turers such as Pioneer, Onkyo, Akai,
Canon, Goldstar, Hitachi, Kenwood,
NEC, Teac and Yamaha use NEC
format. Exceptions are Sony, Sharp,
Toshiba and Philips. In this article,
we shall focus on NEC and Phil-
ips RC5 formats, which are more
commonly used. For both of these
formats, dedicated encoder chips
are available from a number of
manufacturers.
neC-format remotes
The actual data frame is sent only once
in the NEC format, followed by a se-
Parts List
(NEC rEMotE)
Semiconductors:
IC1 - CD6121 remote Tx 20-pin
SMT
T1 - BC548 npn transistor
IR LED1 - LD271 or equivalent IR
LED
LED1 - Red LED
Resistors (all -watt, 5% carbon):
R1 - 330-ohm
R2 - 1-kilo-ohm
R3 - 2.2-ohm, 0.5W
R4, R5, R6 - (100-kilo-ohm)
Capacitors:
C1, C2 - 220pF ceramic disk
C3 - 47F, 10V electrolytic
Miscellaneous:
K2, K3, K6
K14, K15,
K19, K28 - Tactile switch(10x10mm)
X
TAL
- 455kHz (2-pin) ceramic
resonator
BAT. - 2x1.5V=3V
- 2-cell battery holder
- PCB, etc
ConstruCtion
100 March 2007 electroni cs for you www. e f y Ma g . c o M
the use of external diodes and resistors
and 32 command codes (expandable
to 64 commands through SEL pin). A
complete schematic employing 32 keys
is shown in Fig. 6.
The shaded keys, linked resistors
and bold lines indicate the compo-
nents, keys, etc used for the remote
of digital audio processor (published
in EFY Feb. 2005). These fix the
address output as 0076H, while
command codes used for the project
are given in the box inside the sche-
matic.
Determining the output code. It
is necessary to confgure the circuit
to output code corresponding to any
of the possible 65,535 addresses and
any of the frst 32 commands (000000b
through 011111b, i.e., decimal 0
through 31) or next 32 commands
(100000b through 111111, i.e., decimal
32 through 63).
fixing the address output
(refer Fig. 7)
Higher 8-bit address. Column lines
C0 through C7 (pins 19 through 12)
determine the corresponding bit value.
If a column line is left open (i.e., not
connected to CCS pin 20 via diode),
the corresponding bit is 0. If it is con-
nected to CCS pin 20 via diode, the
corresponding bit is 1.
Lower 8-bit address. Lower eight
bits will be the complement of higher
eight bits unless the corresponding line
is pulled to Vcc. Else, those particular
bits will have the same logic value
as their higher 8-bit address coun-
scheme is employed.
3. To improve noise rejection,
the pulses are modulated at a carrier
frequency of 38 kHz, so the IR receiver
module chosen for the reception should
have an optimum response frequency
of 38 kHz. (The 38kHz modulated
pulse is termed here as burst.)
4. Logic-1 bit time (Fig. 1) is 2.25
ms (i.e., burst period of 560s + space/
rest period of 1690 s).
5. Logic-0 bit time (Fig. 2) is 1.12
ms (i.e., burst period of 560s + space/
rest period of 560 s).
6. Leader code preceding the ad-
dress feld comprises 9ms burst fol-
lowed by 4.5ms space during data
frame as shown in Fig. 3 or a 9ms burst
followed by 2.25ms space followed by
560s burst during a repeat frame as
shown in Fig. 4.
The data frame comprises leader
code, address, address, command and
command bits and an additional 560s
burst. The data frame length is variable
between 58.5 and 76.5 ms depending
upon the number of logic-0 and logic-1
bits contained in a frame and so also is
the gap length between the last com-
mand bit and repetition frame. The gap
is minimum 32 ms and maximum 49.5
ms (Fig. 5).
A number of manufacturers make
compatible ASICs for NEC-format
code transmission (PD6121, CD6121,
PT2221 and HT6221, all equivalent to
each other) by employing minimal ex-
ternal components. These ICs allow se-
lection of up to 65,536 device addresses
(also, called custom-codes) through
terpart.
Example. Assume that the device
address is 8435H, where 84H is the
higher 8-bit address and 35H is the
lower 8-bit address.
84H in binary is 0010 0001 (read
it from right to left). It transpires that
column lines C7 and C2 (pins 12 and
17) need to be made 1 using diodes
between these two pins and CCS pin
20 (cathodes facing pin 20).
Now examine the lower 8-bit ad-
dress corresponding to 35H or 1010
1100 (read it from right to left). Com-
pare it with the higher eight bits (0010
0001). We observe that bits C0, C4, C5
and C7 are complementary, while bits
C1, C2, C3 and C6 are identical (not to
be complemented). Hence pull up the
pins corresponding to bits C1, C2, C3
and C6 (pins 18, 17, 16 and 13) to Vcc
via 100-kilo-ohm resistors.
8-bit command (also called data).
With D7/SEL (pin 7) shorted to Vcc,
the most signifcant bit (MSB) of the
command is set to 0. The command
code (and its complement) is automati-
cally generated (along with leader and
address code, as already set) when a
row (R0 through R3) is momentarily
shorted to the respective column lines
C0 through C7 using switches/keys
marked K1 through K32.
The command code is 1 less than
the key No., i.e., K1, when pressed,
generates decimal 0, while K32 will
generate decimal 31 (11111000b, read
from right to left) or 1FH. You can
similarly fnd out the command/data
code generated by other keys. If you
short D7/SEL (pin 7) to ground, add
decimal 128 (80H) to the code gener-
ated otherwise.
Circuit description
Part of the circuit for generation of
address and command signals has al-
ready been explained in the preceding
paragraphs. IC1 can operate off a 2V-
3.3V battery (two cells of 1.5V each).
The carrier frequency is determined
by the frequency of the crystal/ceramic
resonator connected across pins 8 and
9. It is one-twelfth of the frequency of
the crystal/resonator. With a 455kHz
resonator, the carrier frequency is ap-
proximately 38 kHz.
Soldering the Small SMT Parts
To solder small SMT parts such as resistors, capacitors, inductors, transistors and ICs,
proceed as follows:
1. Add a small amount of flux to the area and add a small amount of the solder to one
pad.
2. Pick up the component using tweezers, ensuring that the component is horizontal.
Alternatively, just move the component until it is close to the final position.
3. Whilst holding the component with your tweezers, melt the solder on the pad and
put the component into position.
4. Remove the iron but continue holding the component until the solder solidifies. Check
to see that the component is sitting flat on the PCB. If not, re-melt the solder whilst
pushing gently on top of the component with tweezers.
5. Solder the other side of the component. Re-melt the first solder joint and let it
solidify.
6. Check your work under magnification. The joint should be shining and concave. If
you added too much solder, wick up with a small solder wick and try again.
ConstruCtion
102 March 2007 electroni cs for you www. e f y Ma g . c o M
CCS (pin 20) is custom-code-select
(or device-address-select) input pin.
Pin 11 is the lamp/LED output, which
goes low when any key is pressed. The
modulated output is available at DOUT
pin 5, which is used for driving an IR
LED for transmission of the modulated
output in the form of IR signals.
An actual-size, single-side PCB
layout for remote control of the digital
audio processor published in EFY Feb.
2005 is shown in Fig. 8 and its compo-
nent layout in Fig. 9.
philips RC5-format remote
The RC5 code (known as biphase
code) comprises 14 serial bits as fol-
lows: two start bits, one toggle bit
(which changes every time a new but-
ton is pressed on the remote), fve ad-
dress bits as the system/device address
and six command/instruction/data
bits for the pressed key. This frame of
14 serial bits is repeated only once after
a time interval of 88.9 ms (i.e. duration
of 50 bits), while a command key on
the remote remains pressed.
In the biphase modulation tech-
nique, every bit consists of two parts,
which are never the same. So a bit is
always a high-to-low or a low-to-high
transition (or phase change), which
occurs exactly in the middle of the
bit-time.
In RC5 code, 1 represents a low-
to-high transition and 0 represents a
high-to-low transition. For all the bits,
the most signifcant bit is transmitted
frst. The duration of each bit is 1.778
ms (with the change in phase occur-
ring at 0.889 ms), and the total time
of a full RC5 code, i.e., frame period,
is 24.892 ms (14x1.778 ms). The space
(rest period) between the end of the
preceding frame and the start of
the next frame equals the duration
Table I
Systems and Their
address Numbers (5-bit)
System address equipment
(in decimal)
0 Tv set 1
1 Tv set 2
2 videotext
3 Expansion for Tv 1 and 2
4 Laser video player
5 video recorder 1 (vCR 1)
6 video recorder 2 (vCR 2)
7 Reserved
8 SAT 1
9 Expansion for vCR 1 or 2
10 SAT 2
11 Reserved
12 Cd video
13 Reserved
14 Cd photo
15 Reserved
16 Audio preamplifier 1
17 Receiver/tuner
18 Tape/cassete recorder
19 Audio preamplifier2
20 Cd
21 Audio rack
22 Audio SAT receiver
23 dCC recorder
24 Reserved
25 Reserved
26 Writable Cd
26-31 Reserved
Fig. 9: Component layout of remote control PCB
Parts List
(PhiLiPs rC-5 rEMotE)
Semiconductors:
IC1 - SC3010 RC5 encoder
T1 - BC548 npn transistor
IR LED1 - LD271 or equivalent
Resistors (all -watt, 5% carbon):
R1 - 1-kilo-ohm
R2 - 2.2-ohm, 0.5W
R3 - 1-kilo-ohm
Capacitors:
C1 - 47F, 10V electrolytic
Miscellaneous:
X
TAL
- 455kHz ceramic
resonator
- 2-pin male/female
connector for battery
- Two-cell (pencil) holder
- 3-pin SIP connector (M)
with shorting link
- 2510mm tactile
switches (N/O type)
- PCB
Fig. 8: Actual-size, single-side PCB layout for remote control digital audio processor
ConstruCtion
104 March 2007 electroni cs for you www. e f y Ma g . c o M
of 50 bits or 88.9
ms. Repetition
period is equal
to frame period
plus space pe-
riod, which thus
equals 113.792
ms.
The time re-
lationship and
typical bit pat-
terns are shown
Table II
Commands and Functions
(6-bit)
Command Description of function
(in decimal)
0-9 Numeric keys 0-9
12 Standby
13 Mute
14 Presets
16 volume up
17 volume down
18 Brightness +
19 Brightness
20 Colour saturation +
21 Colour saturation
22 Bass up
23 Bass down
24 Treble +
25 Treble
26 Balance right
27 Balance left
48 Pause
50 Fast reverse
52 Fast forward
53 Play
54 Stop
55 Record
63 System select
71 dim local display
77 Linear function (+)
78 Linear function ()
80 Step up
81 Step down
82 Menu on
83 Menu off
84 display A/v sys status
85 Step left
86 Step right
87 Acknowledge
88 Pip on/off
89 Pip shift
90 Pip main swap
91 Strobe on/off
92 Multi strobe
93 Main frozen
94 3/9 multi scan
95 Pip select
96 Mosaic multi pip
97 Picture dNR
98 Main stored
99 Pip strobe
100 Recall main picture
101 Pip freeze
102 Pip step up
103 Pip step down
118 Sub mode
119 Options bus mode
123 Connect
124 disconnect
Fig. 10: The time relationship and typical bit pattern conforming to standard Philips RC5 protocol
IP = Input with p-channel
pull-up transistor
Od = Output with open
drain n-channel transistor
Table III
Pin Signals/Functions of IC SC3010
Pin no. Symbol I/O Description Note
1 K17 IP Key-sense input pin
2 SMS I System-mode-selection input pin
3-6 C0-C3 IP Key-sense input pins
7 Md
OUT
O Generated output data pin modulated with
1/12 oscillator frequency at a 25 per cent
duty factor
8 d
OUT
O Generated output data pin
9-13 KO7-KO3 Od Scan driver pins
14 v
SS
Power Negative power supply
15-17 KO2-KO0 Od Scan driver pins
18 OSC I Oscillator input pin
19 T2 I Test pin 2
20 T1 I Test pin 1
21-27 KI0-KI6 IP Key-sense input pins
28 v
dd
Power Positve power supply
Fig. 11: Data output format
ConstruCtion
106 March 2007 electroni cs for you www. e f y Ma g . c o M
in Fig. 10.
For neatness,
only the en-
ve l ope i s
shown, while
the carri er
frequency of
36 kHz with
50% dut y
cycle is sepa-
rately shown
in the right-
hand corner
at the bott-
tom. There are 24 pulses of 36 kHz
during the on period (0.889 ms) of
any bit.
In the market, you can easily
find RC5-compatible chips from
a number of manufacturers (SAA3010
from Philips, SC3010 from Silan Semi-
conductors, PT2210 from Princeton
Technology, SL3010 from System Logic
Semiconductor, etc).
With five bits used for sys-
t em/addr es s s el ec t i on, you
may sel ect/address 32 di ffer-
ent systems. System addresses
have been st andar di sed f or
i de nt i f yi ng s pe c i f i c e qui p-
ment types (refer Table I). With
next six bits used for key com-
mands/data, it is possible to have a
set of 64 di fferent commands
for each of the 32 systems. There
is also a possibility of using
up to 128 commands. This is
achieved by assigning the second
start bit a value of 0 (rather
than 1). Thus when the second
bit is 0, 64 is added to the
command value defned by six
command bits.
Typical command values (in
decimal) are shown in Table II.
Most of the available RC5 encoder
chips can be used for 64 commands
only as both start bits are prepro-
grammed to a value of 1.
As soon as the encoder IC
senses depression of a key, key
debounce time (=16-bit dura-
tion =28.448 ms) starts. This is
followed by scan time (=2-bit
duration=3.556 ms) and then the
actual code consisting of 14 bits
starts. On completion of the frst
code frame of 14 bits, there is a
gap of 88.889 ms and then the 14-bit
code repeats. The data output format
is shown in Fig. 11.
Most of the RC5 encoder chips
as mentioned above are available
in 28-pin surface-mount packages.
Pin signals/functions are shown in
Table III.
Circuit description
Fig. 12 shows the circuit of RC-5 en-
coder for selecting one of 32 system
addresses (using shorting link, rather
than a tactile switch). For system selec-
tion, scan-driver pins 17, 16, 15, 13, 12,
11, 10 and 9 for scan lines KO0 through
KO7, respectively) need to be con-
nected to key-sense inputs C0 through
C3 (terminating at pins 3 through 6),
respectively (only one at a time).
Fig. 13 shows a shorting-link ar-
rangement enabling selection of either
TV1 (system address 0) or TV2 (sys-
tem address 1). The system address
(decimal), as shown in Table II, equals
the address represented by each dot in
the circuit.
Similarly, for command selection,
scan-driver pins 17, 16, 15, 13, 12, 11, 10
and 9 for scan lines KO0 through KO7,
respectively, need to be momentarily
connected to key-sense input pins 21
through 27 and 1 representing sense
Fig. 12: Circuit of RC-5 encoder for selecting 1 of 32 system and 64 commands
Fig. 13: Selection of TV1 or TV2 using shorting
link
Fig. 14: Command switches
used for RTC-interfaced
multiple device control
Table IV
Remote Command Codes
button Command Function (as used)
0-9 0-9 Number keys
10 10+
Sfx 36 20+
Mute 13 delete task
AC 34 Clear the prog. memory
PWR 12 Change the password
Timer 38 Change the time
Search 30 Change the existing tasks
CH+ 32 See the next task
CH- 33 See the previous task
RCL 15 Toggle the LCd backlight
PP 14 Enter a new task
Store 41 Toggle the child lock
volume+ 16 Increase the value
volume 17 decrease the value
Tv/Av 56 Confirmation
ConstruCtion
108 March 2007 electroni cs for you www. e f y Ma g . c o M
Fig. 15: PCB layout of RC5 remote for RTC-interfaced microcontroller for multiple device control
Fig. 16: Component layout for the PCB shown in Fig. 15
lines KI0 through KI7, respectively,
one at a time (for one system). Com-
mand numbers 0 through 63 (deci-
mal) for any specifc system (selected
as described above) can be selected
by pressing respective push-switches
marked 0 through 63 (i.e., command
number + 1).
Once a system is selected and a
command key is momentarily pressed,
14 bits of the code word modulates
a 38kHz carrier generated within IC
SC3010 and the modulated output
is available at pin 7 (labeled as MD-
OUT). The output signal MDOUT
transmits the generated information
modulated by one-twelfth of the os-
cillator frequency with a 50% duty
cycle. This output is used to drive IR
LED1 via transistor T1. A single OSC
input pin 18 is used for connecting
the 455kHz resonator via a 1-kilo-ohm
resistor, while the other end of the
resonator is grounded.
System-mode-select (input pin
2) is to be held low (connected to
ground) when the encoder is used
for combined system operation,
whereas for a single-system selection
pin 2 is to be connected to Vcc. Fig.
12 shows selection of the single-
system mode.
The device will immediately reset
under the following conditions:
1. A key is released during the de-
bounce time.
2. A key is released between two
codes.
3. During matrix scanning:
1. A key is released while one of
the driver outputs is in the low ohmic
state (logic 0).
2. A key is released before that key
has been detected.
3. There is no wired connection in
the C-KO matrix when pin 2 is high.
(Note. Although 36kHz carrier fre-
quency has been mentioned in the RC-
5 format, but for that you have to use
a 432kHz resonator. Since the 432kHz
resonator is not commonly available,
we have used a 455kHz resonator to
get a carrier frequency of 38 kHz as in
the case of the NEC remote.)
ConstruCtion
electroni cs for you March 2007 109 www. e f y Ma g . c o M
Example. Let us design an IR re-
mote for the RTC-interfaced Multiple
Device Control project published in
Sept. 2006 issue of EFY, which requires
a Philips RC5-code compatible remote
controller for programming the RTC
chip DS12887 used in that project.
Command switches used for RTC-
interfaced multiple-device control are
separately shown in Fig. 14 (Note.
Three additional command switches
for functions Volume+ (code 16),
Volume(code 17) and TV/AV (code
56) have been added to enhance its
application for some other projects,
which may be published in EFY in
due course). The actual command No.
(decimal) is the same as the switch/
key number. The frst 22 command
numbers are the same as used by au-
thor as per Table IV of the project. You
can easily correlate command numbers
(decimal) of Table IV to switch num-
bers shown by red dots in Figs. 12 and
14. That makes designing the circuit
really easy.
For system selection, simply short
pin 17 to pin 3 as the author has con-
fgured the project to recognise TV1
system commands only. An additional
provision can be made for selection of
TV2 system as well.
The system-selection arrangement
is shown in Fig. 13, which makes use
of a shorting link to select either TV1
or TV2 system. The identical system-
selection arrangement is also shown
by using switches marked 1 (address
0 for TV1) and 2 (address 1 for TV2),
as per Table I. These two switch dots
are shown in different colour in Fig.
12. (Note that the system address is
equal to the switch No.1.)
The PCB designed for the example
project shows the command code
as well as the function in the screen
overlay.
Caution. IC1 is a surface-mount
device and it is to be mounted on the
track-side itself after proper alignment
of pins. For soldering the surface-
mount IC, strictly follow the instruc-
tions in the box. This caution applies
to the previous PCB of NEC remote
as well.
The PCB for the example remote
is shown in Fig. 15 and its component
layout in Fig. 16. Ready-made PCBs
for both the projects are available with
KitsnSpares.
FEBRUARY 2005 WWW. E F Y MA G . C O M
CONSTRUCTION
CMYK
CMYK
T
hese days most audio systems
come with remote controllers.
However, no such facility is
provided for normal audio amplifiers.
Such audio controllers are not avail-
able even in kit form. This article pre-
sents an infrared (IR) remote-con-
trolled digital audio processor. It is
based on a microcontroller and can be
used with any NEC-compatible full-
function IR remote control.
This audio processor has enhanced
features and can be easily customised
to meet individual requirements as it
is programmable. Its main features are:
1. Full remote control using any
NEC-compatible IR remote control
handset
2. Provision for four stereo input
channels and one stereo output
3. Individual gain control for each
input channel to handle different
sources
4. Bass, midrange, treble, mute and
attenuation control
KULAJIT SARMA 5. 80-step control for volume and
15-step control for bass, midrange and
treble
6. Settings displayed on two 7-seg-
ment light-emitting diode (LED) dis-
plays and eight individual LEDs
7. Stereo VU level indication on 10-
LED bar display
8. Full-function keys on-board for
audio amplifier control
9. All settings stored on the
EEPROM
10. Standby mode for amplifier
power control
Circuit description
Fig. 1 shows the block diagram of the
remote-controlled digital audio proces-
sor. The system comprises Atmels
AT89C51 microcontroller (IC1),
TDA7439 audio processor from SGS-
Thomson (IC4) and I
2
C bus compat-
ible MC24C02 EEPROM (IC5). The
microcontroller chip is programmed to
control all the digital processes of the
system. The audio processor controls
all the audio amplifier functions and
is compatible with
I
2
C bus. All the com-
mands from the re-
mote control are re-
ceived through the IR
sensor. The audio
amplifier can also be
controlled using the
on-board keys.
Microcontroller.
The function of the
microcontroller is to
receive commands
(through port P3.2)
from the remote
handset, program au-
dio controls as per
the commands and
update the EEPROM.
A delay in updating
the EEPROM is de-
REMOTE-CONTROLLED
DIGITAL AUDIO PROCESSOR
PARTS LIST
Semiconductors:
IC1 - AT89C51 microcontroller
IC2, IC3 - CD4543 7-segment decoder/
driver
IC4 - TDA7439 audio processor
IC5 - MC24C02 I
2
C EEPROM
IC6 - KA2281 2-channel level
meter driver
IC7 - TSOP1238 IR receiver
module
IC8 - 7809 9V regulator
IC9 - 7805 5V regulator
IC10 - LM317 variable regulator
T1 - BC558 pnp transistor
T2, T3, T5 - BC547 npn transistor
T4 - BD139 pnp transistor
BR1 - W04M bridge rectifier
D1-D6 - 1N4004 rectifier diode
DIS1, DIS2 - LTS543 7-segment display
DIS3 - 10-LED bargraph display
LED1-LED8 - Red LED
LED9 - Green LED
Resistors (all -watt, 5% carbon):
R1 - 8.2-kilo-ohm
R2-R24,
R40-R49 - 1-kilo-ohm
R25, R28,
R50, R53 - 10-kilo-ohm
R26, R29,
R30, R34 - 2.7-kilo-ohm
R27 - 100-ohm
R31, R35 - 5.6-kilo-ohm
R32, R33 - 4.7-kilo-ohm
R36-R39 - 22-kilo-ohm
R51 - 220-kilo-ohm
R52 - 2.2-kilo-ohm
Capacitors:
C1, C2 - 33pF ceramic disk
C3, C10 - 10F, 16V electrolytic
C4-C6,
C39-C41 - 100nF ceramic disk
C7 - 4.7F, 16V electrolytic
C8, C9 - 2.2F, 16V electrolytic
C11, C20 - 5.6nF polyester
C12, C19 - 18nF polyester
C13, C18 - 22nF polyester
C14, C17 - 100nF polyester
C21-C28 - 0.47F polyester
C29-C32 - 4.7F, 25V electrolytic
C33, C34 - 10F, 25V electrolytic
C35 - 1000F, 25V electrolytic
C36 - 4700F, 25V electrolytic
C37, C38 - 0.33F ceramic disk
C42 - 470F, 25V electrolytic
Miscellaneous:
X1 - 230V AC primary to 12V, 1A
secondary transformer
RL1 - 9V, 160, 2 C/O relay
X
TAL
- 12MHz crystal
S1- S7 - Push-to-on switch
S8 - On/Off switch
Remote - Creatives remote (NEC-
compatible format)
liberately provided because normally
the listener will change the value of a
parameter continuously until he is sat-
isfied.
The 40-pin AT89C51 microcontroller
FEBRUARY 2005 WWW. E F Y MA G . C O M
CONSTRUCTION
CMYK
CMYK
has four 8-bit input/output (I/O) ports.
Port 0 is used for indicating
through LEDs the various functions se-
lected via the remote/on-board keys.
Port 1 drives the 7-segment display
using 7-segment latch/decoder/driver
IC CD4543.
Port 2 is pulled up via resistor net-
work RNW1 and used for manual key
control.
Pins P3.0 and P3.1 of the
microcontroller are used as serial data
(SDA) and serial clock (SCL) lines for
the I
2
C bus for communicating with
the audio processor (TDA7439) and
EEPROM (MC24C02). These two lines
are connected to pull-up resistors,
which are required for I
2
C bus devices.
P3.2 receives the remote commands
through the IR receiver module. Pin
P3.4 is used for flashing LED9 when-
ever a remote command is received or
any key is pressed.
The microcontroller also checks the
functioning of the memory (MC24C02)
and the audio processor (TDA7439). If
it is not communicating with these two
ICs on the I
2
C bus, it flashes the vol-
ume level on the 7-segment displays.
Memory. IC MC24C02 is an I
2
C-bus
compatible 2k-bit EEPROM organised
as 2568-bit that can retain data for
more than ten years. Various param-
eters can be stored in it.
To obviate the loss of latest settings
in the case of power failure, the
microcontroller stores all the audio set-
tings of the user in the EEPROM. The
memory ensures that the
microcontroller will read the last saved
settings from the EEPROM when
power resumes. Using SCL and SDA
lines, the microcontroller can read and
write data for all the parameters.
For more details on I
2
C bus and
memory interface, please refer to the
MC24C02 datasheet. Audio parameters
can be set using the remote control
handset or the on-board keys as per
the details given under the remote
control section.
Audio processor. IC TDA7439 is a
single-chip I
2
C-bus compatible audio
controller that is used to control all
the functions of the audio amplifier.
The output from any (up to four) ste-
reo preamplifier is fed to the audio
processor (TDA7439). The
microcontroller can control volume,
treble, bass, attenuation, gain and other
functions of each channel separately.
All these parameters are programmed
by the microcontroller using SCL and
SDA lines, which it shares with the
memory IC and the audio processor.
Data transmission from the
microcontroller to the audio processor
(IC TDA7439) and the memory
(MC24C02) and vice versa takes place
through the two-wire I
2
C-bus interface
consisting of SDA and SCL, which are
connected to P3.0 (RXD) and P3.1
(TXD) of the microcontroller, respec-
tively. Here, the microcontroller unit
acts as the master and the audio pro-
cessor and the memory act as slave
devices. Any of these three devices can
act as the transmitter or the receiver
under the control of the master.
Some of the conditions to commu-
nicate through the I
2
C bus are:
1. Data validity: The data on the
SDA line must be stable during the
high period of the clock. The high and
FEBRUARY 2005 WWW. E F Y MA G . C O M
CONSTRUCTION
CMYK
CMYK
low states of the data line can change
only when the clock signal on the SCL
line is low.
2. Start and Stop: A start condition
is a high-to-low transition of the SDA
line while SCL is high. The stop con-
dition is a low-to-high transition of the
SDA line while SCL is high.
3. Byte format: Every byte trans-
ferred on the SDA line must contain
eight bits. The most significant bit
(MSB) is transferred first.
4. Acknowledge: Each byte must
be followed by an acknowledgement
bit. The acknowledge clock pulse is
generated by the master. The transmit-
ter releases the SDA line (high) dur-
ing the acknowledge clock pulse. The
receiver must pull down the SDA line
during the acknowledge clock pulse
so that it remains low during the high
period of this clock pulse.
To program any of the parameters,
the following interface protocol is used
for sending the data from the
microcontroller to TDA7439. The in-
terface protocol comprises:
1. A start condition (S)
2. A chip address byte containing
the TDA7439 address (88H) followed
by an acknowledgement bit (ACK)
3. A sub-address byte followed by
an ACK. The first four bits (LSB) of
this byte indicate the function selected
(e.g., input select, bass, treble and vol-
ume). The fifth bit indicates incremen-
tal/non-incremental bus (1/0) and the
sixth, seventh and eighth bits are dont
care bits.
4. A sequence of data followed by
an ACK. The data pertains to the value
for the selected function.
5. A stop condition (P)
In the case of non-incremental bus,
the data bytes correspond only to the
function selected. If the fifth bit is high,
the sub-address is automatically
incremented with each data byte. This
mode is useful for initialising the de-
vice. For actual values of data bytes
for each function, refer to the datasheet
of TDA7439.
Similar protocol is followed for
sending data to/from the
microcontroller to MC24C02 EEPROM
by using its chip address as A0H.
Power supply. Fig. 3 shows the
power supply circuit for the remote-
controlled digital audio processor. The
AC mains is stepped down by trans-
former X1 to deliver a secondary output
of 9V AC at 1A. The transformer output
is rectified by full-wave bridge rectifier
BR1 and filtered by capacitor C42. Regu-
lators IC8 and IC9 provide regulated 5V
and 9V power supplies, respectively.
IC10 acts as the variable power supply
CMYK
FEBRUARY 2005 WWW. E F Y MA G . C O M
CMYK
CONSTRUCTION
regulator. It is set to provide 3V regu-
lated supply by adjusting preset VR1.
Capacitors C39, C40 and C41 bypass
any ripple in the regulated outputs.
This supply is not used in the circuit.
However, the readers can use the same
for powering devices like a Walkman.
As capacitors above 10 F are con-
nected to the outputs of regulator ICs,
diodes D3 through D5 provide protec-
tion to the regulator ICs, respectively,
in case their inputs short to ground.
Relay RL1 is normally energised to
provide mains to the power amplifier.
In standby mode, it is de-energised.
Switch S2 is the on/off switch.
Software
The software was assembled using
Metalinks ASM51 assembler, which is
freely available for download. The
source code has been extensively com-
mented for easier understanding. It
can be divided into the following seg-
ments in the order of listing:
1. Variable and constant definitions
2. Delay routines
3. IR decoding routines
4. Keyboard routines
5. TDA7439 communication
6. MC24C02 communication
7. I
2
C bus routines
8. Display routines
9. IR and key command processing
10. Timer 1 interrupt handler
11. Main program
On reset, the microcontroller ex-
ecutes the main program as follows:
1. Initialise the microcontrollers
registers and random-access memory
(RAM) locations.
2. Read Standby and Mute status
from the EEPROM and initialise
TDA7439 accordingly.
3. Read various audio parameters
from the EEPROM and initialise the
audio processor.
4. Initialise the display and LED
port.
5. Loop infinitely as follows, wait-
ing for events:
Enable the interrupts.
Check the monitor input for AC
power-off. If the power goes off, jump
to the power-off sequence routine.
Else, if a new key is pressed, call
the DO_KEY routine to process the
key. For this, check whether the
NEW_KEY bit is set. This bit is cleared
after the command is processed.
Else, if a new IR command is re-
ceived, call the DO_COM routine to
process the remote command. For this,
check whether the NEW_COM (new IR
command available) bit is set. This bit is
cleared after the command is processed.
Jump to the beginning of the
loop.
FEBRUARY 2005 WWW. E F Y MA G . C O M
CONSTRUCTION
CMYK
CMYK
6. Power-off sequence. Save all the
settings to the EEPROM, and turn off
the display and standby relay.
Since the output of the IR sensor is
connected to pin 12 (INT0) of the
microcontroller, an external interrupt
occurs whenever a code is received.
The algorithm for decoding the IR
stream is completely implemented in
the external interrupt 0 handler rou-
tine. This routine sets NEW_COM
(02H in bit memory) if a new com-
mand is available. The decoded com-
mand byte is stored in Command (lo-
cation 021H in the internal RAM). The
main routine checks for NEW_COM
bit continuously in a loop. Timer 0 is
exclusively used by this routine to de-
termine the pulse timings.
Decoding the IR stream involves
the following steps:
1. Since every code is transmitted
twice, reject the first by introducing a
delay of 85 milliseconds (ms) and start
timer 0. The second transmission is
detected by checking for no-overflow
timer 0. In all other cases, timer 0 will
overflow.
2. For second transmission, check
the timer 0 count to determine the
length of the leader pulse (9 ms). If
the pulse length is between 8.1 ms and
9.7 ms, it will be recognised as valid.
Skip the following 4.5ms silence.
3. To detect the incoming bits,
timer 0 is configured to use the strobe
signal such that the counter runs be-
tween the interval periods of bits. The
value of the counter is then used to
determine whether the incoming bit is
0, 1 or Stop. This is implemented
in the RECEIVE_BIT routine.
4. If the first bit received is Stop,
repeat the last command by setting the
NEW_COM bit.
5. Else, receive the rest seven bits.
Compare the received byte with the
custom code (C_Code). If these dont
match, return error.
6. Receive the next byte and com-
pare with the custom code. If these
dont match, return error.
7. Receive the next byte and store
in Command.
8. Receive the next byte and check
whether it is complement value of
Command. Else, return error.
9. Receive Stop bit.
10. Set NEW_COM and return
from interrupt.
Other parts of the source code are
relatively straightforward and self-ex-
planatory.
Remote control. The micro-control-
ler can accept commands from any IR
remote that uses NEC transmission for-
mat. These remote controllers are readily
available in the market and use PD6121,
PT2221 or a compatible IC. Here, weve
used Creatives remote handset.
All the functions of the system can
be controlled fully using the remote
or the on-board keys. By default, the
display shows the volume setting and
LEDs indicate the channel selected.
LED9 glows momentarily whenever a
command from the remote is received
or any key is pressed.
Function adjustments are detailed
below:
1. Volume: Use Vol+/Vol- key to
increase/decrease the volume. The vol-
ume settings are shown on the two-
digit, 7-segment display. Steps can be
varied between 1 and 80.
2. Mute and Standby: Using Mute
and Standby buttons, you can toggle
the mute and standby status, respec-
tively. If Mute is pressed, the display
will show 00. In Standby mode, the
relay de-energises to switch off the
main amplifier. All the LEDs and dis-
plays, except LED9, turn off to indi-
cate the standby status.
3. Input Select: To select the audio
input source, press Channel key until
the desired channel is selected. The
LED corresponding to the selected chan-
nel turns on and the input gain setting
for that channel is displayed for five
seconds. Thereafter, the volume level
is displayed on the 7-segment display.
4. Input Gain set: Press Gain key.
The LED corresponding to the channel
will start blinking and the gain value is
displayed. Use Vol+/Vol- key to in-
crease/decrease the gain for that chan-
nel. Note that the gain can be varied
from 1 to 15. If you press Gain key
once more, and no key is pressed for
five seconds, it will exit the gain setting
mode and the volume level is displayed.
5. Audi o: Press Audi o Set
(Menu) key to adjust bass, middle,
treble and attenuation one by one.
Each time Audio Set key is pressed,
the LED corresponding to the se-
lected function turns on and the
function value is displayed. Once the
required function is selected, use
Vol+ and Vol- to adjust the setting.
Bass, middle and treble can be var-
ied from 07 to 7. Values 0
through 7 indicate Boost and 00
through 07 indicate Cut. Attenu-
ation can be varied from 0 to 40.
Construction
The circuit can be easily assembled
on any PCB with IC base. Before you
install the microcontroller, memory
and audio processor in their sockets
and solder the IR receiver module,
make sure that the supply voltage is
correct. All parts, except the audio
processor (TDA7439), require 5V DC
supply. The audio processor is pow-
ered by 9V DC.
EFY note. Datasheets of all the rel-
evant ICs, source code, etc have been
included in this months EFY-CD. z
circuit
ideas
100 OctOber 2005 electroni cs for you www. e f y ma g . c O m
CMYK
Fig. 1: Digital dice
Fig. 2: Different faces of dice
Sagar g. Yadav
digital dice
T
he digital dice presented here
acts just like a normal dice. It
has six faces (refer Fig. 2) like
the normal dice and uses four different
logic gate combinations to bring out
the six faces of the dice.
At the heart of the circuit is a 14-
stage ripple-carry binary counter IC
CD4060BC (IC1) with built-in oscil-
lator. The logic section is designed
around CMOS quad 2-input NOR gate
IC CD4001BC (IC2) and quad 2-input
NAND gate IC CD4011BC (IC3). The
display section is formed by a group
of seven LEDs.
The circuit is divided into three sec-
tions: counter, logic and display.
The counter section is built around
binary counter IC CD4060BC (IC1). The
counter frequency (f) is decided by the
in-built oscillator formed by resistor R1
and capacitor C1 as follows:
f=1/2.2R1C1.
Here, the frequency is fxed at around
2056 Hz.
Only the frst three outputs of the
counter (designated as A, B and C,
respectively) have been used in the cir-
cuit. The counter is designed
to reset at the sixth count
(110) as only six counts are
required for operation. This
is done with the help of
diodes D1 and D2 and resis-
tor R3, which are connected
such that they generate an
AND logic.
From the table it can
be noticed that at the sixth
count, the counter outputs
A and B hold logic 1 simul-
taneously for the frst time,
so by ANDing A and B outputs you
can give logic 1 to the reset terminal of
the counter at the sixth count, thereby
resetting the counter.
LED2 and LED5 always glow at
the same count, as do LED1 and LED6,
and LED3 and LED4. Using these three
pairs of LEDs and LED7, four logical
combinations have been made in the
circuit. LED1 and LED6 glow at all
counts, except 0 and 1. Further, it
can be noticed that they glow when A
or B is high, hence a NOR gate whose
output is A+B according to Boolean
algebra will perform the job of operat-
ing these LEDs.
LED3 and LED4 glow at all
counts, except for the first three
counts, i.e., they glow when ei-
ther A, or B and C are high. This
logic function can be obtained by us-
ing an OR gate and an AND gate, but
since we are using only NAND and
NOR gates in the circuit we make use
of two NAND gates and a NOR gate
(with A+BC output) to perform this
function.
LED2 and LED5 glow only at the
frst and ffth counts. In other words,
they glow only when the complement
of B and C outputs goes high. This
function can be obtained by using two
NAND gates such that their output
corresponds to the Boolean expression
BC or B+C according to De Morgans
theorem.
LED7 glows at even counts like
0, 2 and 4. In other words, it glows
when the C output is low. This func-
tion can be achieved easily by inverting
the C output twice using the remain-
circuit
ideas
electroni cs for you OctOber 2005 101 www. e f y ma g . c O m
CMYK
ing two NAND gates. The output will
also be buffered by these two inverter
gates.
The display section comprises sev-
en LEDs. LED1 and LED6 have com-
mon cathodes, as do LED2 and LED5,
and LED3 and LED4. The anodes of all
the LEDs are tied together to the posi-
tive terminal of the battery via resistors
R4 through R10, respectively.
When you place your fnger on the
touch pad, the oscillator starts oscillat-
ing. The counter will start counting at
the rate of 2056 Hz and all the LEDs of
the display section will appear to glow
simultaneously due to the high counter
frequency. This high-frequency count-
ing will make the dice foolproof. When
you remove your fnger from the touch
pad, the counter will stop counting and
the display section will show any one
of the six possible faces with a prob-
ability of 1/6.
The entire circuit can be powered
by a 9V battery as the inbuilt oscillator
of the counter IC will not work prop-
erly below 7V. Use of CMOS ICs means
less power consumption.
The circuit can be constructed on a
general-purpose PCB and housed in-
side a plastic case with the LEDs array
mounted on the top as shown in Fig. 2.
The touch pad can be mounted beside
the array.
Dice Score and LEDs Lit at Different Counts
Count Dice A B C LEDs lit
score
0 1 0 0 0 LED7
1 2 0 0 1 LED2 LED5
2 3 0 1 0 LED1 LED7 LED6
3 4 0 1 1 LED1 LED3 LED4 LED6
4 5 1 0 0 LED1 LED3 LED7 LED4 LED6
5 6 1 0 1 LED1 LED3 LED2 LED5 LED4 LED6
6 1 1 0
circuit
ideas
electroni cs for you March 2005 105 www. e f y Ma g . c o M
CMYK
Y
ou can use this simple and reli-
able security system as a watch-
dog by installing the sensing
loops around your building. You have
to stretch the loop wires two feet above
the ground to sense the unauthorised
entry into your premises.
Wire loops 1, 2 and 4 are connected
to the A, B and C inputs of 7-segment
decoder 4511 (IC1), respectively, while
the D input of IC1 is grounded perma-
nently. The loops are also connected to
a dual 3-input NOR gate and inverter
CD4000 (IC2) to activate the alarm.
Fig. 1 shows the circuit of the digi-
tal security system, while Fig. 2 shows
the proposed wiring diagram for the
loops around the premises. Before us-
ing this security system, make sure that
loops shown in Fig. 2 are connected as
Pherdaus Islam shown in Fig. 1. If you dont want to
use a buzzer, switch it off by opening
switch S2.
The circuit works off a 9V regu-
lated power supply. However, battery
back-up is recommended. A common-
cathode, 7-segment display (LTS543) is
used for displaying whether the loops
are intact or not.
If loop 1 is broken, the display will
show 1. If two or all the three loops
are broken, the display will show the
sum of the respective broken loop
numbers. For example, if loops 1 and
4 are broken, the display will show
5(1+4).
When all the three loops are intact,
the display will show 0. All the three
inputs of gate N1 remain low to give
a high output. This high output is fur-
ther given to gate N2 and, as a result,
its output remains low. This keeps
sImPle dIgItal securIty system
transistor T1 in cut-off position and the
piezobuzzer does not sound.
When any loop is broken, the
output of NOR gate N1 goes low,
while the output of gate N2 goes high.
Transistor T1 conducts and the buzzer
sounds to alert you. You can mute the
buzzer by switching off power to the
circuit through switch S1.
Fig. 1: The digital security system circuit
Fig. 2: The proposed wiring diagram of loops
ConstruCtion
62 July 2007 electroni cs for you www. e f y ma g . c o m
Raj K. GoRKhali
DiGital VoltmeteR
SUNI L KUMAR
A
voltmeter fnds its importance
wherever voltage is to be mea-
sured. Here we present an easy-
to-build and accurate digital voltmeter
that has been designed as a panel meter
and can be used in DC power supplies
panels or where it is necessary to have
an accurate indication of the voltage.
Circuit description
The circuit uses an analogue-to-
digital converter ICL7107 made by
INTERSIL. Fig. 1 shows the pin detail
of IC L7107. This IC incorporates in a
40-pin case all the circuitry necessary
to convert an analogue signal into
digital and can drive a series of four
seven-segment LED displays directly.
which is directly proportional to
the input voltage.
At the end of the preset pe-
riod, the integrator is fed with
an internal reference voltage and
the output of the circuit is gradu-
ally reduced until it reaches the
level of the zero reference volt-
age. This second phase is known
as the negative slope period and
its duration depends on the out-
put of the integrator in the frst
period. As the duration of the
frst operation is fxed and the
length of the second is variable,
it is possible to compare the two
and this way the input voltage is
in fact compared to the internal
reference voltage and the result is
coded and sent to the display.
All this sounds quite simple
and easy but in fact it comprises
a series of complex operations,
which are all made by the
ADC IC with the help of a few
external components that are used to
confgure the circuit for accurate mea-
surement.
Fig. 2 shows the circuit of the
digital voltmeter. The voltage to be
measured is applied across points IN-
L and IN-H of pins 30 and 31 of IC1,
respectively, through circuit resistors
R5, R6, R7 or R8 and preset VR1.
Resistor R2 together with C5 forms
the circuit used to set the frequency of
the oscillator (clock), which is set at 48
kHz approximately. At this clock rate,
there are about three different readings
per second.
Capacitor C4, which is connected
between pins 33 and 34 of IC1, com-
pensates for the error caused by the
internal reference voltage and also
keeps the display steady. Capacitor C2
and resistor R1 together forms the cir-
cuit that does integration of the input
voltage and at the same time prevents
The circuits built into the IC are an
analogue-to-digital converter (ADC),
a comparator, a clock, a decoder and a
seven-segment LED display driver.
The circuit can display any DC volt-
age in the range of -1999 volts to +1999
volts. It operates off 5 volts.
In order to understand the operat-
ing principle of the circuit, it is neces-
sary to explain how the ADC IC works.
An analogue-to-digital converter,
better known as a dual slope converter
or integrating converter, is generally
preferred over other types as it offers
accuracy, simplicity in design and a
relative indifference to noise, which
makes it very reliable.
The operation of the circuit is
described in two stages for better un-
derstanding. During the frst stage, for
a given period the input voltage is inte-
grated, and the output of the integrator
at the end of this period is a voltage
Fig. 1: Pin details of ICL7107
PArts List
Semiconductor:
IC1 - ICL7107 3 digit
analogue-to-digital
converter
IC2 - 7805 +5V regulator
IC3 - 7905 -5V regulator
DIS1-DIS4 - LTS542 CA seven-
segment display
Resistors (all -watt, 5% carbon):
R1 - 470-kilo-ohm
R2, R7 - 100-kilo-ohm
R3 - 22-kilo-ohm
R4 - 220-ohm
R5 - 10-ohm
R6 - 1-kilo-ohm
R8 - 1-mega-ohm
VR1 - 2-kilo-ohm trimpot
VR2 - 1-kilo-ohm trimpot
Capacitors:
C1 - 0.22F ceramic disk
C2 - 0.47F ceramic disk
C3 - 0.01F ceramic disk
C4, C6, C7 - 0.1F ceramic disk
C5 - 100pF ceramic disk
C8 - 220F electrolytic
Miscellaneous:
S1 - Push-to-on switch
S2 - 2-pole, 4-position (each
ganged) rotary switch
BATT.1,
BATT.2 - 9V battery
ConstruCtion
electroni cs for you July 2007 63 www. e f y ma g . c o m
any division of the input voltage mak-
ing the circuit faster and more reliable.
Capacitor C1 forces the instrument to
display zero when there is no voltage
at its input.
Resistor R3 together with reference
control preset VR2 is used to adjust
the instrument during set-up so that it
displays 0 when the input is zero. Re-
Fig. 2: Circuit diagram of digital voltmeter
Fig. 3: A single-side, actual-size PCB layout for digital voltmeter Fig. 4: Component layout for the PCB
sistor R4 controls the current that is al-
lowed to fow through the displays (for
decimal point) so that there is suffcient
brightness without damaging them.
ConstruCtion
64 July 2007 electroni cs for you www. e f y ma g . c o m
The IC, as mentioned earlier, is
capable of driving four common-an-
ode, seven-segment displays. Displays
DIS1 through DIS3 are connected such
that they can display all the numbers
from 0 to 9, while display DIS4 can
display only digit 1 (and - sign when
the voltage is negative).
When TEST switch is pressed, test
pin is pulled high (to V+) and all seg-
ments turn on to show 1888 on the
display. The TEST pin will sink about
15 mA under this condition. In the
lamp test mode, the segments have
a constant DC power supply. Pin 36
(REF HI) is made high through VR2
to adjust the reference voltage and pin
35 (REF LO) is connected to the nega-
tive terminal of the input. Preset VR1
is used to adjust the range of voltage
divisions.
Resistors R5 , R6, R7 and R8 con-
nected to pin 31 are used for range
selection. Switch S2 is two-pole, four-
position (each ganged) rotary switch.
Decimal point is connected to resistor
R4 via rotary switch S2 for different
range selection.
The entire circuit operates off a
dual 5V DC power supply which is
applied to IC1 as follows: pin 1 to +5V,
pin 21 to 0V and pin 26 to -5V. Dual
power supply is derived from two 9V
batteries. Regulators IC2 and IC3 are
used to provide a regulated +5V and
-5V, respectively to the circuit. Capaci-
tors C6 and C7 bypass any ripple from
the regulated supply.
Construction
An actual-size, single-side PCB layout
for the digital voltmeter is shown in
Fig. 3 and its component layout in Fig.
4. Connection points for decimal point
and for range-selection resistor are
provided on the PCB for connecting
rotary switch S2. IC base is used for
IC1. Rotary switch is ftted outside the
PCB. Connections from the PCB to the
rotary switches are made using suitable
lengths of shielded wire.
CIRCUIT
IDEAS
ELECTRONI CS FOR YOU DECEMBER 2007 95 WWW. E F Y MA G . C O M
T.A. BABU
DOOR GUARD
S.C. DWIVEDI
T
hieves often target locked
houses. This door guard cir-
cuit detects any vibration in its
vicinity when somebody tries to break
open the door. It is very simple to
build and can be fitted anywhere in
the vicinity of the door.
The circuit sounds the siren when
someone tries to intrude into your
home or office by knocking, pushing
and hitting the door. Mount the piezo
sensor element on the door and it will
sense the vibration produced by
knocking. The voltage developed by
vibrations in the piezo sensor is fed to
transistors T1 and T2, which fires
MOSFET BS170 and the supply is con-
nected to IC1. The output of IC1 is fed
to the Darlington pair built around
transistors T4 and T5 for sounding the
siren through the loudspeaker.
At the heart of the circuit is the
piezo transducer (PZ1), which is the
sensor element. If anyone attempts to
open the door, the piezo element vi-
brates and the developed voltage
drives transistors T1 and T2 into con-
duction. Now the alarm sounds for 20
seconds, which is taken care of by
MOSFET T3 along with capacitor C1
and resistor R4 wired as a monostable
timer.
Arming (activating) the circuit is
possible with the door key, if switch
S1 is mounted such that its contacts
close when the door is locked.
IC UM3561 (IC1) generates a tone
simulating police siren. Re-
sistor R6 controls its oscil-
lation. Sensitivity of the cir-
cuit depends on the piezo
transducer element. There-
fore it should be mounted
such that it receives vibra-
tions properly. This circuit
does not drain the battery
as the standby current is
zero.
Assemble the circuit on
a small general-purpose
PCB and house it in a suit-
able cabinet. Connect the
piezo element to the circuit
by using a single-core
shielded wire. Fix the piezo
sensor on the front door and your door
guard is ready for use, provided switch
S1 is on.
The circuit works off a 9V battery.
You can also use a stabilised 9V DC
mains adaptor in place of the battery.
c i r c u i t i d e a s
electronics for you April 2003
H
eres the circuit of a multi-switch
input musical doorbell (shown in
Fig.1). The circuit is built around
the popular and less expensive quad
D-latch CD4042B (IC1). When switch S6 is
pushed to on condition, the circuit gets
+9V and the four data inputs (D1 through
D4) of ICI are in low state because these
are tied to ground via resistors R1 through
R4. Polarity input (POL) pin 6 of IC1 is also
Multi-switch doorbell
with indicators
T.K. Hareendran pulled down by resistor R5. Clock input
(pin 5) of the quad D-latch is wired in
normally low mode and hence all the four
outputs (Q0 through Q3) have the same
states as their corresponding data inputs.
As a result, LED1 through LED4 are in off
condition.
There are four switches ftted at four
different doors/gates outside the home
and a monitoring panel (as shown in Fig.
2) in the common room of the home. If any
switch is pressed by a visitor (for example,
Fig. 1: Multi-switch doorbell with indicators
Fig. 2: Suggested panel layout of musical
doorbell
switch S1 at door 1), pins 2 and 4 of IC1
go high.
Simultaneously, pin 3 to IC1 (Q0
output) goes low and LED1 starts glow-
ing to indicate that
switch S1 is pressed
by someone.
Next , out put
pin 13 of the dual
4-input NOR gate
(IC2, here wired as
a single 4-input OR
gate) goes high to
forward bias buzzer-
driver transistor T1
via resistor R10.
The fnal result
is a soft and pleasing
musical bell, which
l ast s unt i l reset
switch S5 is pressed
by the owner. For
this latching arrange-
ment , output pin 13
of IC2 from the NOR
gate is fed back to
the clock input of
IC1.
The circuit costs
around Rs 100.
C I R C U I T I D E A S
ELECTRONICS FOR YOU NOVEMBER 2004
Fig. 2: Receiver circuit
Fig. 3: Pin configurations of
TSOP1738 and UM66
S
.C
. D
W
IV
E
D
I
ELECTRONIC WATCHDOG
H
eres an electronic watchdog for
your house that sounds to inform
you that somebody is at the gate.
TAPAN KUMAR MAHARANA
pillars of the gate such that the IR
beam gets interrupted when someone
is standing at the gate or passing
through it.
The transmitter circuit (see Fig. 1)
is built around timer NE555 (IC1),
which is wired as an astable
multivibrator producing a frequency of
about 38 kHz. The infrared (IR) beam
is transmitted through IR LED1.
The receiver circuit is
shown in Fig. 2. It comprises
IR sensor TSOP1738 (IR RX1),
npn transistor BC548 (T1),
timer NE555 (IC2) and some
resistors and capacitors. IC2 is
wired as a monostable
multivibrator with a time pe-
riod of around 30 seconds. The
melody generator section is
built around melody generator
IC UM66 (IC3), transistor T2
and loudspeaker LS1. Fig. 3
shows pin configurations of IR
sensor TSOP1738 and melody
generator IC UM66.
The power supply for the
Fig. 1: 38kHz IR transmitter circuit
The circuit comprises
a transmitter unit and
a receiver unit, which
are mounted face to
face on the opposite
Fig. 4: Mounting arrangement for transmitter and receiver units
and trigger pin 2 of IC2 remains high.
When anyone interrupts the IR beam
falling on the sensor, its output goes high
to drive transistor T1 into conduction and
pin 2 of IC2 goes low momentarily. As a
result, IC2 gets triggered and its pin 3
goes high to supply 3.3V to melody gen-
erator IC3 at its pin 2, which produces a
sweet melody through the speaker fitted
inside the house. Output pin 3 of IC2
remains high for around 30 seconds.
Fig. 4 shows mounting arrangement
for both the transmitter and receiver units
on the gate pillars. To achieve a high di-
rectivity of the IR beam towards the sen-
sor, use a reflector behind the IR LED.
After both the units have been built,
connect 6V power supply to the receiver
circuit. You should hear a continuous
melody from the speaker. Now connect
6V power to the transmitter also and
orient IR LED1 towards IR receiver. The
transmitter is derived from the receiver
circuit by connecting its points A and B
to the respective points of the receiver
circuit. The receiver is powered by regu-
lated 6V DC. For the purpose, you can
use a 6V battery.
The transmitter and receiver units are
aligned such that the IR beam falls di-
rectly on the IR sensor. As long as IR
beam falls on the sensor, its output re-
mains low, transistor T1 does not conduct
C I R C U I T I D E A S
ELECTRONICS FOR YOU NOVEMBER 2004
melody should stop after about 30 sec-
onds. Now the transmitter and the re-
ceiver units are ready for use.
When somebody enters through the
door, the IR beam is interrupted and the
alarm sounds for 30 seconds. The alarm
keeps sounding as long as one stands
between the transmitter and receiver units.
Using preset VR1, you can set the volume
of the loudspeaker.
This circuit can also be used as a door-
bell or burglar alarm.
KS Project Manual
eFY MaY 2009
ELECTRONIC
BICYCLE LOCK
The electronic bicycle lock described
here is a worthwhile alternative for
bicycle owners who want to make
their bicycles intelligent at reasonable
cost. One of the benefts of building it
yourself is that the
circuit can be used
for virtually any
make of bicycles.
In the circuit,
input jacks J1 and
J2 are two stan-
dard RCA sockets.
A home-made se-
curity loop can be used to link these
two input points. Around 50cm long,
standard 14/36 fexible wire with one
RCA plug per end is enough for the
security loop.
Fig. 1 shows the circuit of the
electronic bicycle lock. It is powered
by a compact 9V battery (6F22).
Key lock switch S1 and smoothing
capacitor C2 are used for connect-
ing the power supply. A connected
loop cannot activate IC1 and therefore
the speaker does not sound. When
the loop is broken, zener diode ZD1
(3.1V) receives operating power sup-
ply through resistor R2 to enable tone
generator UM3561 (IC1). IC1 remains
enabled until power to the circuit is
turned off using switch S1 or the loop
is re-plugged through J1 and J2.
Assemble the circuit on a general-
purpose PCB and house in a small tin-
plate enclosure. Fit the system key lock
switch (S1) on the front side of the enclo-
sure as shown in Fig. 2. Place RCA sock-
ets (J1 and J2) at appropriate positions.
Now, mount the fnished unit in place of
your existing lock (as shown in Fig. 3) by
using suitable clamps and screws.
ParTs LisT
Semiconductors:
IC1 - UM3561
T1 - BD679/677
ZD1 - 5mm Red
Resistors (all -watt, 5% carbon):
R1 - 1K
R2 - 2.2K
R3 - 270K
R4 - 470K
Capacitors:
C1 - 100F, 10V electrolytic
C2 - 470F, 250V electrolytic
Miscellaneous:
LS1 - 8-Ohm, 0.5W speaker
S1 - On/Off switch
Fig. 1: Circuit of electronic bicycle lock
Fig. 2: Lock box
Fig. 3: Lock ftted on the bicycle
electronics for you december 2001
c i r c u i t i d e a s
91
s
.c
. d
w
iv
e
d
i
Qu
iz-type game shows are increas-
ingly becoming popular on tele-
vision these days. In such games, fastest
fnger frst indicators (FFFIs) are used
to test the players reaction time. The
players designated number is displayed
with an audio alarm when the player
presses his entry button.
The circuit presented here determines
as to which of the four contestants frst
pressed the button and locks out the re-
maining three entries. Simultaneously,
an audio alarm and the correct decimal
number display of the corresponding con-
testant are activated.
When a contestant presses his switch,
the corresponding output of latch IC2
(7475) changes its logic state from 1 to 0.
The combinational circuitry comprising
dual 4-input NAND gates of IC3 (7420)
locks out subsequent entries by producing
the appropriate latch-disable signal.
Priority encoder IC4 (74147) encodes
the active-low input condition into the
corresponding binary coded decimal
(BCD) number output. The outputs of IC4
after inversion by inverter gates inside
hex inverter 74LS04 (IC5) are coupled to
BCD-to-7-segment decoder/display driver
IC6 (7447). The output of IC6 drives com-
mon-anode 7-segment LED display (DIS.1,
FND507 or LT543).
The audio alarm generator comprises
clock oscillator IC7 (555), whose output
drives a loudspeaker. The oscillator
frequency can be varied with the help of
preset VR1. Logic 0 state at one of the
outputs of IC2 produces logic 1 input
condition at pin 4 of IC7, thereby enabling
the audio oscillator.
IC7 needs +12V DC supply for suf-
fcient alarm level. The remaining circuit
operates on regulated +5V DC supply,
which is obtained using IC1 (7805).
Once the organiser identifies the
contestant who pressed the switch frst,
he disables the audio alarm and at the
same time forces the digital display to 0
by pressing reset pushbutton S5.
With a slight modifcation, this cir-
cuit can accommodate more than four
contestants.
P. RAjESh BhAT
Fastest Finger
First indicator
c i r c u i t i d e a s
electronics for you february 2002
s
u
n
il
k
u
m
a
r
FM Booster
PradeeP G.
H
ere is a low-cost circuit of an FM
booster that can be used to listen
to programmes from distant FM
stations clearly. The circuit comprises
a common-emitter tuned RF preampli-
fer wired around VHF/UHF transistor
2SC2570. (Only C2570 is annotated on the
transistor body.)
Assemble the circuit on a good-qual-
ity PCB (preferably, glass-epoxy). Adjust
input/output trimmers (VC1/VC2) for
maximum gain.
Input coil L1 consists of four turns of
20SWG enamelled copper wire (slightly
space wound) over 5mm diameter former.
It is tapped at the frst turn from ground
lead side. Coil L2 is similar to L1, but has
only three turns. Pin confguration of tran-
sistor 2SC2570 is shown in the fgure.
T E C H N I D O
Model No:
Freeduino Starter kit
TN -93
The Arduino Starter Kit is a great raw parts re-fill for beginners and weathered professionals alike.
It Includes:
1. Freeduino USB board
2. 1 Amps, 12v SMPS power supply
3. FlyingLeads-20
4. Small geared DC motor
5. Plastic wheel
6. USB cable
7. RGB LED
8. Potentiometer
9. 3mmRED LED
10. 16x2 Alpha number LCD
11. Motor driving Module
12. IR Proximity sensor
13. DTMF decoder
www.technido.com
66
circuit
ideas
electroni cs for you March 2011 131 www. e f y Ma g . c o M
also be used to
detect combusti-
ble gases, espe-
cially methane.
This circuit has
been tested with
LPG gas and was
found to work
satisfactorily.
Wh e n e v e r
there is LPG con-
centration of 1000
ppm (parts per
million) in the area, the OUT pin of
the sensor module goes high. This
signal drives timer IC 555, which is
wired as an astable multivibrator. The
multivibrator basically works as a tone
generator.
Output pin 3 of IC 555 is connected
to LED1 and speaker-driver transistor
SL100 through current-limiting resis-
tors R5 and R4, respectively. LED1
glows and the alarm sounds to alert
the user of gas leakage. The pitch of
the tone can be changed by varying
preset VR1. Use a suitable heat-sink for
transistor SL100.
L
PG gas is supplied in pressur-
ised steel cylinders. As this gas
is heavier than air, when it leaks
from a cylinder it fows along foor
and tends to settle in low spots such
as a basement. This can cause fre or
suffocation if not dealt with.
Here is a circuit that detects the
leakage of LPG gas and alerts the user
through audio-visual indications.
Fig. 1 shows the circuit of the gas
leakage alarm. The circuit operates off
a 9V PP3 battery. Zener diode ZD1 is
used to convert 9V into 5V DC to drive
the gas sensor module.
The SEN-1327 gas sensor mod-
ule from RhydoLABZ is used in this
circuit. Its out-
put goes high
when the gas
level reaches or
exceeds certain
point. A preset
in the module is
used to set the
threshold. Inter-
facing with the
sensor module is
done through a
4-pin SIP head-
er.
Pin details
of the gas sen-
sor module are
shown in Fig. 2. An MQ-6 gas sensor
is used in the gas sensor module. As
per its datasheet, it has high sensitiv-
ity to propane, butane, isobutene,
LPG and natural gas. The sensor can
Sani Theo
GaS LeakaGe aLarm S.C. DW
IVEDI
Fig. 1: Circuit for gas leakage alarm
Fig. 2: Pin details of gas
sensor module
T E C H N I D O
Model No:
Robotic Arm and Gripper Kit
This kit consist of aluminum parts, assemblies , motors, wheels and tracks. Combining all
these parts user can create a pick and place robot with gripper. Unique design of gripper
allows it to hold object as huge as 10cms and as small as 1 cm in width. This kit gives the
machine an additional 2 degrees of freedom. High torque motor at arm joint gives it
Arm & Gripper Kit
TN -34
www.technido.com
machine an additional 2 degrees of freedom. High torque motor at arm joint gives it
ability to lift load of 200grams.
Features:
Lead screw arrangement for gripper
Unique set of shaft couplers
Rubber tracks for extra traction
4 wheel assemble extension for better stability
Powerful gripper
Package Includes:
Powder coated aluminum parts
Set of shaft couplers
Set of rubber tracks
Wheels
100rpm motor-1
3.5 rpm motor-1
34
URDP(NOT Included)
circuit
ideas
100 November 2005 electroni cs for you www. e f y ma g . c o m
CMYK
A
t the heart of this heat-sensi-
tive switch is IC LM35 (IC1),
which is a linear temperature
sensor and linear temperature-to-volt-
age converter circuit.
The converter provides accurately
linear and directly proportional out-
put signal in millivolts over the
temperature range of 0C to 155C. It
develops an output voltage of 10 mV
per degree centigrade change in the
ambient temperature. Therefore the
output voltage varies from 0 mV at
0C to 1V at 100C and any voltage
measurement circuit connected across
the output pins can read the tempera-
ture directly.
The input and ground pins of this
heat-to-voltage converter IC are con-
nected across the regulated power
supply rails and decoupled by R1 and
C1. Its temperature-tracking output
is applied to the non-inverting input
(pin 3) of the comparator built around
IC2. The inverting input (pin 2) of IC2
is connected across the positive sup-
ply rails via a voltage divider network
formed by potmeter VR1.
Since the wiper of potmeter VR1 is
connected to the inverting input of IC2,
the voltage presented to this pin is lin-
early variable. This voltage is used as
the reference level for the comparator
against the output supplied by IC1.
So if the non-inverting input of
IC2 receives a voltage lower than
the set level, its output goes low (ap-
proximately 650 mV). This low level is
applied to the input of the load-relay
driver comprising npn transistors
T1 and T2. The low level presented
at the base of transistor T1 keeps it
non-conductive. Since T2 receives the
forward bias voltage via the emitter
of T1, it is also kept non-conductive.
Hence, relay RL1 is in de-energised
state, keeping mains supply to the load
off as long as the temperature at the
sensor is low.
Conversely, if the non-inverting
input receives a voltage higher than
the set level, its output goes high
(approximately 2200 mV) and the
load is turned on. This happens
when IC1 is at a higher temperature
and its output voltage is also higher
than the set level at the inverting
input of IC2. So the load is turned on
as soon as the ambient temperature
rises above the set level. Capacitor
C3 at this pin helps iron out any
ripple that passes through the posi-
tive supply rail to avoid errors in the
circuit operation.
By adjusting potmeter VR1 and
thereby varying the reference volt-
age level at the inverting input pin
of IC1, the temperature threshold
at which energisation of the relay is
required can be set. As this setting is
linear, the knob of potmeter VR1 can
be provided with a linear dial caliber-
ated in degrees centigrade. Therefore
any temperature level can be selected
and constantly monitored for external
actions like turning on a room heater
in winter or a room cooler in sum-
mer. The circuit can also be used to
activate emergency fre extinguishers,
if positioned at the probable fre ac-
cident site.
The circuit can be modifed to op-
erate any electrical appliance. In that
case, relay RL1 must be a heavy-duty
type with appropriately rated contacts
to match the power demands of the
load to be operated.
M.K. Chandra Mou-
leeswaran and
Miss Kalai Priya
heat-sensitive switCh S. C. DWI VEDI
c i r c u i t i d e a s
electronics for you December 2004
Hit sWitcH
T
his versatile hit switch is the elec-
tronic equivalent of a conventional
switch. It can be used to control
the switching of a variety of electronic
devices.
The circuit of the hit switch uses a
piezoelectric diaphragm (piezobuzzer) as
the hit sensor. A piezoelectric material de-
velops electric polarisation when strained
by an applied stress. The hit sensor makes
use of this property.
When you hit or knock the piezo
element (hit plate) with your fngertip,
a small voltage developed by the piezo
T.A. BABu
Initially, the input of gate N1 is low,
while the input of gate N2 is high. Trigger-
ing the voltage-control switch by hitting
the sensor pulls the input of gate N1 to
high level and causes the bistable to toggle.
The capacitor gets charged via resistor R1
and the circuit changes its state. This latch
continues until the bistable switch gets the
next triggering input.
Every time the hit plate receives a hit,
the voltage-control switch triggers the
bistable circuit. That means every subse-
quent hit at the sensor will toggle the state
of the switch. The red LED (LED1) con-
nected at the output of gate N3 indicates
on/off position
of the switch. Re-
lay RL1 is activated
by the hit switch
to control the con-
nected load.
The circuit works
off 12V DC. It can
be constructed on
any general-purpose
PCB. For the desired
results, proper con-
nections and instal-
lation of the hit sen-
sor are necessary.
Remove the cover of
the piezobuzzer and connect its two leads
to the circuit. Mount the plate such that it
receives the hit properly. The piezoelectric
material on the plate can easily get dam-
aged, so hit the switch gently.
element is amplifed by transistor BC547
(T1). The combination of transistor T1
and the bridge rectifer comprising diodes
D1 through D4 acts as a voltage-control
switch. The inverter gates of IC CD4069
(IC1) together with associated components
form a bistable switch.
IC CD4069 is a CMOS hex inverter. Out
of the six available inverter gates, only
three are used here. IC1 operates at any
voltage between 3V and 15V and offers a
high immunity against noise. The recom-
mended operating temperature range for
this IC is 55C to 125C. This device is
intended for all general-purpose inverter
applications.
ConstruCtion
electroni cs for you November 2010 107 www. e f y ma g . c o m
only a single
data lead and a
ground return.
The i But t on
DS1990A pro-
vides the ad-
ditional 1-wire
protocol capa-
bility that al-
lows the search
ROM command to be interpreted by
the DS1990A.
Circuit description
Fig. 4 shows the circuit of the secure
digital access system using iButton.
The circuit is built around an ATme-
ga16 microcontroller.
The ATmega16 is an 8-bit micro-
controller based on the AVR enhanced
RISC architecture that executes power-
ful instructions in a single clock cycle.
It has 16kB in-system programmable
flash program memory with read-
while-write capabilities, 512 bytes
of EEPROM, 1kB SRAM, 32 general-
purpose input/output (I/O) lines, 32
general-purpose working registers,
three flexible timers/counters with
Chirutkar harshadkumar
Govindrao and dr h.n. Pandya
seCure diGital aCCess
system usinG iButton
Sunil Kumar
A
ccess control forms a vital link
in a security chain. Here we
describe a secure digital ac-
cess system using iButton that allows
only authorised persons to access a
restricted area.
The iButton is used here as a key
to the access control system. Its unique
identifcation (ID) number is used for
authorisation. On detection of an au-
thorised iButton, the system allows ac-
cess. Thereafter, an automated lock key
locks the system again. The system is
permanently halted after fve repeated
false attempts. A service control unit
built around an AVR microcontroller
is interfaced to the iButton with 1-wire
protocol for authentication of user vali-
dation of data.
iButton ds1990a
Here we have used the iButton
DS1990A from Dallas Semiconductor
(MAXIM). Its block diagram is shown
in Fig. 1.
An iButton is a chip housed in a
stainless-steel enclosure (refer Fig. 2).
The electrical interface is reduced to
the absolute minimum, i.e., a single
data line plus a ground reference. The
energy needed for operation is taken
from the data line. The DS1990A serial
number iButton is a rugged data car-
rier that acts as an electronic registra-
tion number for automatic identifca-
tion. It contains a unique ROM code
that is 64-bit long as shown in Fig. 3.
The frst eight bits are a 1-wire family
code. The next 48 bits are a unique
serial number. The last eight bits are a
cyclic redundancy check (CRC) of the
frst 56 bits.
Data is transferred serially via
the 1-wire protocol, which requires
compare modes, internal and external
interrupts, a serial programmable
PArts List
Semiconductors:
IC1 - ATMega16 microcontroller
IC2 - PC817 optocoupler
IC3 - MAX232 RS-232 driver
IC4 - 7806, 6V regulator
IC5 - DS1990A iButton
T1 - BC548 npn transistor
D1-D7 - 1N4007 rectifer diode
LED1 - 5mm LED
Resistors (all -watt, 5% carbon):
R1 - 5-kilo-ohm
R2 - 1-kilo-ohm
R3 - 220-ohm
R4 - 10-kilo-ohm
R5 - 330-ohm
Capacitors:
C1 - 1000F, 25V electrolytic
C2 - 0.1F ceramic disk
C3 - 3.3F, 16V electrolytic
C4-C8 - 1F, 16V electrolytic
Miscellaneous:
X1 - 230V AC primary to 9V,
300mA secondary
transformer
RL1 - 6V, 1C/O relay
PZ1 - Piezobuzzer
S1 - Push-to-on tactile switch
9-pin D-type female
connector
Fig. 1: Block diagram of iButton
Fig. 2: A typical iButton chip
ConstruCtion
108 November 2010 electroni cs for you www. e f y ma g . c o m
USART, a byte-oriented two-wire seri-
al interface, a programmable watchdog
timer with internal oscillator, an SPI
serial port and six software-selectable
power-saving modes.
Piezobuzzer PZ1 is used as an
audible indicator for true, fake, ran-
dom touches and system halt. It is
controlled from port pin PD6 of the mi-
crocontroller with the help of transistor
T1. The iButton socket is connected to
port pin PD2. Pull-up resistor R1 is
used as required from the 1-wire pro-
tocol. Port pin PD4 controls the relay
operation through optocoupler PC817
(IC2). The door locking mechanism,
say, for a slide door, is connected to
the contacts of relay RL1, which closes
after some time automatically.
Whenever someone attempts to
gain access by touching the iButton
(IC5) using his own iButton, the frm-
ware inside the AVR reads its unique
ID and matches with the ID in the
frmware. If the ID matches, port pin
PD4 goes high, the internal LED of
the optocoupler (IC2) glows and relay
RL1 energises for the predefned time.
Simultaneously, the buzzer sounds to
indicate grant of access.
Thereafter, relay RL1 de-energises.
The buzzer gets the PWM signal to
produce sound from port pin PD6 of
the microcontroller. The 1-wire com-
munication is done through interrupt
port pin PD2 (INT0), so the AVR does
not have to poll the pin but respond
when any change in signal is detected
on the interrupt pin. Switch S1 is used
for manual reset.
Port pin PD1 of the microcontroller
is used to interface with the hyper
terminal of the
PC through RS-
232 interface
MAX232 I C
(IC3) for iBut-
ton verifcation
and checking.
The microcon-
troller provides a transmit channel for
serial data transfer. Transmit data pin
(TXD) is specifed at port pin PD1. The
microcontroller is connected to T1 IN
(pin 11) of MAX232. T1 OUT (pin 14)
of IC3 is connected to pin 2 of the COM
port connector. The signals provided
on these pins are TTL-level and must
be boosted and inverted through a
MAX232 converter to comply with the
RS-232 standard.
The MAX232 has two internal
charge pumps that convert +5V into
10V (unloaded) for RS-232 driver op-
eration. The frst converter uses capaci-
tor C6 to double the +5V input to +10V
on capacitor C8 at pin 2. The second
converter uses capacitor C5 to invert
+10V to -10V on capacitor C4 at pin 6.
The power supply for this circuit
is derived from 230V, 50Hz AC mains.
Transformer X1 steps down 230V,
50Hz AC mains to deliver a secondary
output of 9V, 300 mA. The transformer
output is rectifed by a full-wave recti-
fer comprising diodes D1 through D4,
fltered by capacitor C1 and regulated
by IC 7806 (IC4). Capacitor C2 bypass-
es the ripples present in the regulated
supply. LED1 acts as the
power indicator and R5
limits the current through
LED1.
Construction and
testing
An actual-size, single-side
PCB for the secure digital
access system is shown in
Fig. 5 and its component
layout in Fig. 6. Assemble
the circuit on a PCB as it
minimises time and as-
sembly errors. Carefully
assemble the components
and double-check for any
overlooked error. Con-
nect the assembled circuit
to the COM port of the
computer. The iButton
access code and message
is transferred is to the PC
through the COM port
using the Hyper Terminal Fig. 4: Circuit of the secure digital access system using iButton
Fig. 3: 64-bit lasered Rom
ConstruCtion
electroni cs for you November 2010 109 www. e f y ma g . c o m
program. For interfacing of the Hyper
Terminal, refer EFY Oct. 2010 issue.
software
The software for this project is given
at the end of this article. It is written in
Basic language and compiled using
BASCOM-AVR compiler. The source
program is well commented and easy
to understand.
Burn the fnally obtained Intel hex
code fle into the AVRs fash memory
using a suitable programmer. The mi-
crocontroller uses an 8MHz internally
generated clock. To activate, program
fuse bytes as follows:
Fuse low byte = D4
Fuse high byte = 99
The source program is developed
quickly with the help of the BASCOM-
AVR library function. The 1wrest,
1wread and 1wwrite functions are
used for checking the presence of
1-wire device, reading of the unique
ID of iButton and writing to the 1-wire
device, respectively. Sound function
is used for generating the beep sound
from the buzzer. The iButton is con-
1wirereset.bas
$regfle = m16def.dat
$baud = 9600
$crystal = 8000000
$hwstack = 32
default use 32 for the hardware stack
$swstack = 64
default use 10 for the SW stack
$framesize = 20
default use 40 for the frame space
Confg Portd = Output
$lib mcsbyte.lbx
Confg Com1 = 9600 , Synchrone = 0 ,
Parity = None , Stopbits = 1 , Databits
= 8 , Clockpol = 0
Confg 1wire = Portd.2
use this pin
Confg Int0 = Low Level
Dim Ar(8) As Byte , A As Word , I As
Byte , E As Byte , W As Word
Dim Code1(8)as Byte
Dim Flag As Bit
fag for correctness
Code(8 Byte) = {&H01 ,&HDD , &H83 ,
&H07 , &H13 , &H00 , &H00 , &H1E}
Code1(1) = &H01
Code1(2) = &HDD
Code1(3) = &H83
Code1(4) = &H07
Code1(5) = &H13
Code1(6) = &H00
nected to hardware interrupt pin INT0
so that any change on the pin can be
detected and further processing for
1-wire done.
The program execution starts by
initialising the input/output ports, the
interrupt pin and its level of detection.
Global interrupts are enabled and
the interrupt service routine is ready
to be executed when any interrupt
is received. As soon as the normal
program execution is interrupted, an
interrupt is issued and the control of
execution enters the interrupt service
routine, where iButton is given reset
command frst and then the ROM
command to fetch the unique ID
of the iButton. This fetched ID is
compared with the unique ID pro-
grammed in the frmware. If there
is a mismatch between the two IDs,
a fake parameter counter is incre-
mented and the relay connected to
port PD4 de-energises. If the two
IDs match, the relay connected to
port PD4 energises and simultane-
ously the buzzer connected to port
PD6 sounds. If the unique ID is
wrong sequentially fve times, the
system enters the major warning
state where the buzzer sounds con-
tinuously and it can only be stopped
by resetting the system.
EFY note. The source code of
this project has been included in this
months EFY-CD and is also avail-
able on www.efymag.com website.
Dr H.N. Pandya is a reader and head of
Department of Electronics at Saurashtra
University, Rajkot, and Ph.D guide of the co-
author. Chirutkar Harshadkumar Govindrao is a
research scholar in Department of Electronics,
Saurashtra University
Fig. 5: An actual-size, single-side PCB for the secure digital access system using iButton
Fig. 6: Component layout for the PCB
ConstruCtion
110 November 2010 electroni cs for you www. e f y ma g . c o m
Code1(7) = &H00
Code1(8) = &H1E
On Int0 Int0_int
Enable Interrupts
Enable Int0
enable the interrupt
E = 0
fag for number of attempts
W = 65000
Do
Set Portd.4
initially the relay is off
Loop
Int0_int:
Disable Interrupts
Disable Int0
Flag = 0
Wait 1
1wreset
reset the device
Print iButton Access Code:;
If Err = 0 And E <= 6 Then
check DS1990A is present
1wwrite &H33
present, read code
read ROM command
Ar(1) = 1wread(8)
For I = 1 To 8
Print Hex(ar(i));
print output
Next
Print
For I = 1 To 8
If Ar(i) <> Code1(i) Then
Set Portd.4
Flag = 0
access not allowed
For A = 10 To 1000
Sound Portd.6 ,
4 , A
Next
Print Access Code Not
Match:Access Denied;
Print
E = E + 1
Print E;
Print :;
Exit For
Else
Flag = 1
End If
Next
If Flag = 1 Then
E = 0
Print Err;
Reset Portd.4
access allowed
Sound Portd.6 , 10 , 50000
siren on port PD6
Print --Access Allowed;
Print
Wait 2
End If
Else
Set Portd.4
access not allowed
For A = 50 To 500
Sound Portd.6 ,
1 , A
Next
Print Rejected;
Print
If E = 5 Then
5 attempts of correctness
Do
Sound Portd.6 , 4 , W
SOUND pin, duration, pulses
W = W + 1
If W > 1000 Then
W = 10
End If
Loop
End If
End If
End If
Enable Int0
Enable Interrupts
Return

www.electronicsforu.com www.beneftmag.com www.ffymag.com www.linuxforu.com www.efyindia.com www.eb.efyindia.com


CONSTRUCTION
J UNE 2007 WWW. E F Y MA G . C O M
JAYARAMAN KIRUTHI VASAN
MICROCONTROLLER-BASED
INDUSTRIAL TIMER
SUNI L KUMAR
I
ndustrial timers can be con-
structed using discrete compo-
nents including up/down
counters and timers. However, to in-
corporate various facilities like setting
the count, start, stop, reset and dis-
play, these circuits would require too
many ICs and discrete components.
A microcontroller-based industrial
timer can be programmed and used
as a timer, counter
and time totaliser.
Here is a simple de-
sign based on 40-pin
Atmel AT89S52
microcontroller that
performs count-down
operation up to 9999
minutes/second with
four 7-segment dis-
plays showing the ac-
tual time left. The re-
lay energises as you
press the start switch
and remains on till the
countdown reaches
0000. Four tactile,
push-to-on switches
are used to start/stop,
select either minutes
or seconds, and set the
initial value for count-
down operation (us-
ing up and down
keys).
Circuit
description
Fig. 1 shows the cir-
cuit of the
microcontroller-based
industrial timer. The
microcontroller is
Atmel AT89S52 (IC1),
which is a 40-pin de-
is configured for segments of the 7-
segment display. Port 0 is an 8-bit
open-drain bidirectional I/O port. Port
0 is pulled up with 10-kilo-ohm resis-
tor network RNW1. Port pins P0.0
through P0.6 are connected to pins of
segments a through g via resistors
R2 through R8, respectively. Port P0.7
is connected to decimal via resistor R9.
Resistors R2 through R9 are used as
current limiter for various segments of
displays, respectively.
vice with 8 kB of program flash
memory, 256 bytes of RAM, 32 I/O
lines, Watchdog timer, two data point-
ers, three 16-bit timer/counters, a six-
vector two-level interrupt architecture,
a full-duplex serial port, on-chip oscil-
lator and clock circuitry. The power-
down mode saves the RAM contents
but freezes the oscillator, disabling all
other chip functions until the next in-
terrupt or hardware reset is activated.
Port P0 of microcontroller AT89S52
CONSTRUCTION
J UNE 2007 WWW. E F Y MA G . C O M
Port 2 is used to control DIS1
through DIS4. Port 2 is an 8-bit bidi-
rectional I/O port with internal pull-
ups. When port-2 pin is low, the tran-
sistor conducts and provides supply
to the common pin of 7-segment dis-
play. Port pins P2.5 through P2.2 con-
trol DIS1 through DIS4 with the help
of transistors T1 through T4, respec-
tively.
The microcontroller drives the 7-
segment displays in multiplex mode.
This helps in reducing current con-
sumption while maintaining the
brightness of the display. For driving
the displays, timer 2 inside the
microcontroller is used. It enables dis-
play of each digit every two millisec-
onds.
For driving the dis-
plays, the microcontroller
uses port-0 to send the
segment outputs. It se-
lects the corresponding
units, tens, hundreds
and thousands displays
through P2.5, P2.4, P2.3
and P2.2, respectively.
Four pins of port 1 are
used for various switches
like select, up, down and
start/stop. Port 1 is an 8-
bit bidirectional I/O port
with internal pull-ups.
Switches S1 through S4
are connected to pins 5
through 8 of the
microcontroller and used
for select, up, down and
start/stop functions, re-
spectively.
Pin P3.7 controls re-
lay RL1. When pin P3.7
goes high, transistor T5 is
driven into saturation
and relay RL1
energises. Diode D1
serves as a free-wheel-
ing diode. Any appli-
ance can be connected
with contacts of relay
RL1.
Power-on-reset is
achieved by connect-
ing resistor R1 and ca-
pacitor C1 to pin 9 of
the microcontroller.
Other ends of the capacitor and resis-
tor are connected to Vcc and ground,
respectively. Switch S5 is used for
manual reset. The microcontroller is
operated with the clock derived from
a 20MHz crystal oscillator.
Power supply. Fig. 2 shows the cir-
cuit of the power supply. The AC
mains is stepped down by transformer
X1 to deliver a secondary output of
7.5V at 350 mA. The transformer out-
put is rectified by a full-wave bridge
rectifier BR1, filtered by capacitor C5
and regulated by IC2. Capacitor C6 by-
passes any ripple present in the regu-
lated output. Unregulated power sup-
ply is used for relay RL1.
An actual-size, single-side PCB lay-
out for the microcontroller-based in-
dustrial timer (Fig. 1) including power
supply (Fig. 2) is shown in Fig. 3 and
its components layout in Fig.4.
Operation
Switch on the circuit using using ON/
OFF switch S6. The
microcontroller is reset
by power-on-reset and
then timer is in seconds
mode. The select key se-
lects the mode between
seconds and minutes.
This is displayed as 0
for seconds and 1 for
minutes on the
hundreds digit display
(DIS3), respectively.
Up key increments
the time setting in sec-
onds and minutes.
Down key decre-
ments the time setting in
seconds and minutes.
After setting the de-
sired time with the help
of up and down keys,
press start key. This
energises the relay. The
timer counts down for
the set time and once the
display becomes zero,
PARTS LIST
Semiconductor:
IC1 - AT89S52 micrcontroller
IC2 - 7805 5V regulator
T1-T4 - BC557 pnp transistor
T5 - BC547 npn transistor
BR1 - 1A bridge rectifier
D1 - 1N4007 rectifier diode
DIS1-DIS4 - LTS542 common-anode
display
Resistors (all -watt, 5% carbon):
R1, R14-R18 - 8.2-kilo-ohm
R2-R9 - 270-ohm
R10-R13 - 470-ohm
RNW1 - 10-kilo-ohm resistor
network
Capacitors:
C1 - 10F,16V electrolytic
C2, C3 - 33pF ceramic disk
C4, C6 - 0.1F ceramic disk
C5 - 1000F, 25V electrolytic
Miscellaneous:
X1 - 230V AC primary to 6V,
350mA secondary
transformer
X
TAL
- 20MHz crystal
RL1 - 6V, 1C/O relay
S1-S5 - Push-to-on switch
S6 - On/off switch
CONSTRUCTION
J UNE 2007 WWW. E F Y MA G . C O M
the relay de-energises.
The timer will stop be-
fore preset time by press-
ing start key again.
Software
The source program is
written in C language
and compiled with Keil
Microvision 3 IDE. It is
well commented and
easy to understand.
D o w n l o a d
C51V808A.EXE from
www.keil.com/demo/
eval/c51.htm. This file is
a freely available and
self-extracting setup pro-
gram for Keil
Microvision 3 IDE.
Normally, when there
is no interrupt, the
microcontroller executes
while loop in the main
function. Here it scans
the keys and acts according to the key
pressed.
Two interrupts are enabled in the
software, namely, timer 0 and timer 2.
Timer 0 counts milliseconds, which are
then accumulated to seconds or min-
utes according to the user selection.
Timer 2 drives the displays in multi-
plex mode.
For time counting, timer 0 is
initialised by the void
Timer0_init(unsigned char
Timer0h,unsigned char Timer0l) func-
tion. Timer 0 interrupts the
microcontroller every millisecond.
When interrupted by timer 0, the
microcontroller executes the void
isr_t0(void) function wherein it incre-
ments two counter variables, namely,
Timer0Counter and LedCounter.
Timer0Counter is re-
sponsible for counting
the number of millisec-
onds elapsed and incre-
ments the minutes/sec-
onds counter according
to the mode selected
(seconds or minutes
count). Once the set
value is reached, the
timer-0 interrupt is dis-
abled and time counting
stops.
The LED counter
makes the dot LED of the
units digit flash every
second once.
Display-driving pro-
cess is taken care of by
the built-in timer 2. Timer
2 is initialised by the void
Timer2_init(unsigned
char Timer2h,unsigned
char Timer2l) function.
Timer 2 gives an in-
terrupt to the microcontroller to
switch on the common pin of each 7-
segment display for every two milli-
seconds. When an interrupt occurs, the
void isr_t2(void) function is executed
and the microcontroller returns to
while loop in the main function.
EFY note. The software and other
relevant files of this article have been
included in this months EFY-CD.
SOURCE PROGRAM
/*** Include Files ***/
#include <At89x52.h>
/*** RENAMING OF PORTS ****/
#define SegPort P0
#define DigPort P2
/* CODE FOR LIGHTING EACH SEGMENT OF
THE SEVEN SEGMENT LED DISPLAY */
#define seg_a 0xfe
#define seg_b 0xfd
#define seg_c 0xfb
#define seg_d 0xf7
#define seg_e 0xef
#define seg_f 0xdf
#define seg_g 0xbf
#define seg_dot 0x7f
/* SEVEN SEGMENT CODE FOR EACH NUM-
BER FROM 0 TO 9 ,DOT AND SPACE */
#define NUM_0 (seg_a & seg_b & seg_c & seg_d
& seg_e & seg_f)
#define NUM_1 (seg_b & seg_c)
#define NUM_2 (seg_a & seg_b & seg_d & seg_e
& seg_g)
#define NUM_3 (seg_a & seg_b & seg_c & seg_d
& seg_g)
#define NUM_4 (seg_b & seg_c & seg_f & seg_g)
#define NUM_5 (seg_a & seg_c & seg_d & seg_f
& seg_g)
#define NUM_6 (seg_a & seg_c & seg_d & seg_e
& seg_f & seg_g)
#define NUM_7 (seg_a & seg_b & seg_c)
#define NUM_8 (seg_a & seg_b & seg_c & seg_d
& seg_e & seg_f & seg_g)
#define NUM_9 (seg_a & seg_b & seg_c & seg_d
& seg_f & seg_g)
#define NUM_DOT (seg_dot)
#define NUM_SPACE 0Xff;
const unsigned char hex_table[] =
{
NUM_0, NUM_1, NUM_2, NUM_3, NUM_4,
NUM_5,NUM_6,NUM_7,
NUM_8,NUM_9,NUM_DOT
};
/* ADDRESS FOR SELECTING THE COMMON
PIN OF THE DISPLAY FOR EACH DIGIT */
#define UNITS 0xdf
#define TENS 0xef
#define HUNDS 0xf7
#define THS 0xfb
/* RELOAD VALUE FOR TIMER2 FOR INTER-
RUPT DURATION OF 2 MILLISECONDS */
#define TIMER2H_2MS 0xf2
#define TIMER2L_2MS 0xfb
/* RELOAD VALUE FOR TIMER0 FOR INTER-
RUPT DURATION OF 1 MILLISECOND */
#define TIMER0H_1MS 0xf9
#define TIMER0L_1MS 0x7e
/* VECTOR VALUE FOR TIMER INTERRUPT
*/
#define TIMER0VECTOR 1
#define TIMER2VECTOR 5
/* MINUTES AND SECONDS CONSTANTS */
#define SEC 999
#define MIN (60 * SEC)
/* VARIABLES DEFINITION */
unsigned char Units;
unsigned char Tens;
unsigned char Hunds;
unsigned char Ths;
unsigned int Timer0Counter=0;
unsigned char DisplayCounter=0;
unsigned int LedCounter=0;
unsigned char TimeDig;
unsigned int OneSecCount=0;
unsigned int SetSec=0;
unsigned char OneMinCount;
unsigned char key;
unsigned char KeyCount;
unsigned char Mode;
/* FUNCTION PROTOTYPES */
void Timer0_init(unsigned char
Timer0h,unsigned char Timer0l);
CONSTRUCTION
J UNE 2007 WWW. E F Y MA G . C O M
void Timer2_init(unsigned char
Timer2h,unsigned char Timer2l);
void Display(unsigned char Digit);
void IntToSevSeg(unsigned int TimeTemp);
void KeyDebounce(unsigned char dly);
void Keyscan(void);
/* RENAMING PORT PINS FOR EASY USAGE
*/
sbit RELAY = P3^7;
sbit SEL = P1^4;
sbit UP = P1^5;
sbit DN = P1^6;
sbit STRT = P1^7;
/* MAIN FUNCTION */
void main(void)
{
RELAY = 0;
Timer2_init(TIMER2H_2MS,TIMER2L_2MS);
Timer0_init(TIMER0H_1MS,TIMER0L_1MS);
TR0=0;
EA=1;
while(1)
{
if(TR0==0)IntToSevSeg(SetSec);
else if( (TR0==1)&& (Timer0Counter==0) )
IntToSevSeg(OneSecCount);
Keyscan();
switch(key)
{
case 4:
if(SetSec>0)
{
if(TR0==0)
{
OneSecCount
= SetSec;
RELAY = 1;
TR0=1;
}
else
{
TR0=0;
}
}
key=0;
break;
case 3:
SetSec;
if(SetSec>9999)
SetSec=9999;
key=0;
break;
case 2:
SetSec++;
if(SetSec>9999)
SetSec=0;
key=0;
break;
case 1:
Mode++;
if(Mode>1)Mode=0;
Hunds=hex_table[Mode];
Tens = NUM_SPACE;
Units = NUM_SPACE;
key=0;
KeyDebounce(10);
break;
}
}
}
/* TIMER INITIALISATION FUNCTIONS */
void Timer0_init(unsigned char
Timer0h,unsigned char Timer0l)
{
TMOD &= 0xf0;
TMOD |= 0x01;
TH0 = Timer0h;
TL0 = Timer0l;
ET0=1;
TR0=1;
}
void Timer2_init(unsigned char
Timer2h,unsigned char Timer2l)
{
T2CON = 0x04;
T2MOD = 0x00;
TH2 = Timer2h;
RCAP2H=Timer2h;
TL2 = Timer2l;
RCAP2L=Timer2l;
ET2=1;
TR2=1;
}
/* KEYSCAN FUNCTIONS */
void Keyscan(void)
{
while( (SEL==0) || (STRT==0) )
{
KeyDebounce(1);
if(SEL==0)key=1;
else if(STRT==0)key=4;
}
if ((UP==0) || (DN==0) )
{
KeyCount;
if(KeyCount<1)KeyCount=1;
KeyDebounce(KeyCount);
if(UP==0)key=2;
else if(DN==0)key=3;
}
else
KeyCount=10;
}
void KeyDebounce(unsigned char dly)
{
unsigned int z;
while(dly>0)
{
dly;
for(z=0;z<8000;z++);
}
}
/* DISPLAY FUNCTIONS */
void Display(unsigned char DigCount)
{
switch(DigCount)
{
case 0:
DigPort = UNITS;
SegPort = Units;
break;
case 1:
DigPort = TENS;
SegPort = Tens;
break;
case 2:
DigPort = HUNDS;
SegPort = Hunds;
break;
case 3:
DigPort = THS;
SegPort = Ths;
break;
}
}
/* INTEGER VALUE TO SEVEN SEGMENT
CONVERSION FUNCTION */
void IntToSevSeg(unsigned int TimeTemp)
{
TimeDig = TimeTemp/1000;
TimeTemp -=(TimeTemp/1000)*1000;
if(TimeDig==0)
{
Ths=NUM_SPACE;
}
else
{
Ths = hex_table[TimeDig];
}
TimeDig = TimeTemp/100;
TimeTemp -=(TimeTemp/100)*100;
if((Ths==0xff)&&(TimeDig==0))
{
Hunds=NUM_SPACE;
}
else
{
Hunds = hex_table[TimeDig];
}
TimeDig = TimeTemp/10;
TimeTemp -=(TimeTemp/10)*10;
if((Hunds==0xff)&&(TimeDig==0))
{
Tens=NUM_SPACE;
}
else
{
Tens = hex_table[TimeDig];
}
TimeDig = TimeTemp%10;
Units = hex_table[TimeDig];
}
/* Interrupt Routines */
/* Drives LED Displays */
void isr_t2(void) interrupt TIMER2VECTOR
{
DisplayCounter++;//Increments every 50
ms.
if(DisplayCounter>3)DisplayCounter=0;
Display(DisplayCounter);
TF2 = 0;
}
/* Counts Seconds */
void isr_t0(void) interrupt TIMER0VECTOR
{
TH0 = TIMER0H_1MS;
TL0 = TIMER0L_1MS;
TF0=0;
Timer0Counter++;//Counts every 1msec.
LedCounter++;
if(LedCounter<200)
Units= Units & NUM_DOT;
else if( (LedCounter>=200) && (LedCounter
<999) )
Units = Units | 0x80;
else
LedCounter=0;
if(Mode==0)
{
if(Timer0Counter>SEC)
{
Timer0Counter=0;
OneSecCount;
if(OneSecCount==0)
{
//OneSecCount=0;
TR0=0;
RELAY = 0;
}
}
}
else if(Mode==1)
{
if(Timer0Counter>MIN)
{
Timer0Counter=0;
OneSecCount;
if(OneSecCount>MIN)
{
OneSecCount=0;
TR0=0;
RELAY = 0;
}
}
}
}
/****************** END *****************/
78 january 2005 electroni cs for you www. e f y ma g . c o m
circuit
ideas
CMYK
CMYK
T
his infrared object counter can
be installed at the entry gate to
count the total number of people
entering any venue. For example, it can
be used at the railway stations or bus
stands to count the people arriving per
day or week.
The counter uses an infrared trans-
mitter-receiver pair and a simple, low-
cost calculator. It works even in the
presence of normal light. The maximum
detection range is about 10 metres. That
means the transmitter and the receiver
are to be installed (at the opposite pil-
lars of the gate) not more than 10 metres
apart. No focusing lens is required. If an
8-digit calculator is used the counter can
count up to 99,999,999 easily, and if a
10-digit calculator is used the counter
can count up to 9,999,999,999.
Powered by a 9V battery, the trans-
mitter circuit (see Fig. 1) comprises IC
555 (IC1), which is wired as an astable
multivibrator with a centre frequency
RambiR Singh of about 38 kHz, and two infrared
light-emitting diodes (LEDs). The
receiver circuit (see Fig. 2) is powered
by a 5V regulated power supply built
around transformer X1, bridge recti-
fer comprising diodes D1 through D4
and regulator IC2. It uses an infrared
receiver (IR) module (RX1), optocoupler
(IC3) and a simple calculator.
When switch S1 is in on position,
the transmitter circuit activates to
produce a square wave at its output
pin 3. The two infrared LEDs (IR
LED1 and IR LED2) connected at
its output transmit modulated IR
beams at the same frequency (38
kHz). The oscillator frequency can
be adjusted using preset VR1.
In the receiver circuit, IR re-
ceiver module TSOP1738, which
is commonly used in colour tele-
visions for sensing the IR signals
transmitted from the TV remote,
is used as the sensor.
The IR beams transmitted by IR
LED1 and LED2 fall on infrared re-
ceiver module IR RX1 of the receiver
circuit to produce a low output at its
pin 2. This keeps transistor T1 in non-
conduction mode.
Now when anyone enters through
the gate to interrupt the IR beam, the
IR receiver module produces a high
output pulse at its pin 3. As a result,
transistor T1 conducts to activate IC3
and its internal transistor shorts key =
of the calculator to advance the count
infRaRed Object cOunteR
by one.
Both the transmitter and the receiv-
er can be assembled on any general-
purpose PCB. Place the transmitter and
the receiver around one metre apart.
For calibration, press switches S1
and S2 followed by on key of the
calculator. Now press 1 and + keys
sequentially to get 1 on the screen of
the calculator. Then, place a piece of
cardboard between the transmitter and
the receiver to interrupt the IR rays two
times. If the calculator counts 2, the
counter is working properly for that
range. Repeat this procedure for higher
ranges as well. If there is any problem,
adjust VR1.
For installation, switch off the
transmitter, receiver and calculator,
and mount the transmitter and the
receiver on the opposite pillars of the
main entry gate such that they are
properly orientated towards each
other. Mount the calculator where you
can read it easily. Connect pins 4 and 5
of IC3 across = key connections on the
PCB of the calculator.
Now switch on the transmitter
and the receiver by pressing switches
S1 and S2, respectively. Thereafter,
switch on the calculator and press 1
followed by + key of the calculator to
initialise it. Now your counter is ready
to count.
The calculator reads 1 after one
interruption, 2 after second interrup-
tion and so on.
Fig. 1: Transmitter circuit
Fig. 2: Receiver-cum-counter circuit
CI R CU I T I D E A S
ELECTRONICS FOR YOU MARCH 2002
I R REMOTE SWI TCH
S
.C
. D
W
IV
E
D
I
K. S. SANKAR
CI R CU I T I D E A S
I
magine the convenience of selecting
TV channels using your remote and
then pointing the same remote to your
switchboard to switch on/ off the fan or
the tubelight. Here is a simple circuit to
remotely switch on/ off any electrical de-
vice through a relay using the normal TV/
VCR/ VCP/ VCD remote control unit. It
works up to a distance of about 10 metres.
The circuit is built around a 3-pin IR
IC receiver (Siemens SFH-506-38 or equiva-
lent) that can detect 38kHz burst frequency
generated by a TV remote. (This IR re-
ceiver module has been covered earlier in
many projects published in EFY.)
The output pin of IR sensor goes low
when it detects IR light, triggering the
monostable (1-second) built around timer
NE555. The output of the mono toggles
the J-K flip flop, whose Q output drives
the relay through SL100 npn transistor (T1).
LED2, LED3, and LED4 are used to
display the status of each output stage dur-
ing circuit operation. Back-EMF diode D5
is used for protection. Transistor T1 is con-
figured as an open-collector output device
to drive the relay rated at 12V DC.
The circuit draws the power from volt-
age regulator 7805. Capacitor C5 is sol-
dered close to the IR sensors pins to avoid
noise and false
t riggering. Ca-
pacitor C3 and
resistor R3 also
avoid false trig-
ger ing of
m o n o s t a b l e
NE555. The
monostable acts
as a 1-second
hysterisis unit to
restrict the flip-
flop from getting
r e t r i g g e r e d
within one sec-
ond. To activate
any other 12V
logic device, use
the output across
the relay coil ter-
minals.
c i r c u i t i d e a s
electronics for you January 2004
intruder alarm
Praveen Kumar
T
his circuit, ftted to the door of your
house, sounds an alarm if anyone
pushes the door. This way it alarms
you against thieves or intruders. The cir-
cuit (refer Fig. 1) comprises transmitter
and receiver sections. The transmitter is
ftted onto the inside of the doorframe and
the receiver is ftted to the door panel.
The transmitter section comprising a
laser diode is powered by a 9V battery. When
switch S1 in the transmitter section is closed,
the laser diode glows. Closing switch S2
provides power supply to the receiver sec-
tion. Light falling from the laser diode on the
light-dependent resistor (LDR) in the receiver
section provides base current to transistor T1
and it starts conducting. This grounds the
base of transistor T2, so it doesnt conduct
and the alarm remains off.
When somebody pushes the door,
light incident on the LDR is interrupted
s
.c
. d
w
iv
e
d
i
c i r c u i t i d e a s
and transistor T1 stops conducting since
the LDR offers a high resistance in the
absence of light. Transistor T2 receives
base current and starts conducting. The
pulse from the emitter of transistor T2
is connected to the inputs of AND gate
N1 (IC1). The high ouput of AND gate
is connected to a JK fip-fop (IC2) that
works as a latch. As a result, output pin
12 (Q1) of IC2
goes high to
cause conduc-
tion of tran-
sistor T3 and
c ons equent
sounding of
the alarm. The
alarm can be
turned off by
switch S2.
Ar r a n g e
the laser diode
and the LDR
such that when the circuit is on and the
door is closed, light from the laser diode
falls on the LDR to keep the alarm off.
In order to make sure that ambient light
is not incident on the LDR, make the ar-
rangement as shown in Fig. 2.
EFY note. While testing at EFY Lab,
a laser torch in place of the transmitter
was used.
Fig. 2: Transmitter and receiver cabinets with holes for laser LED and
LDR, respectively
Fig. 1: Circuit diagram of intruder alarm
c i r c u i t i d e a s
electronics for you may 2003
S
.C
. D
w
iv
e
D
i
T
his infrared remote control timer can
be used to turn an appliance on/off
for a period of 0.11 second to 110.0
seconds.
The circuit comprises two sections,
namely, the transmitter section and the
receiver section.
Fig. 1 shows the IR transmitter section.
The astable multivibrator NE555 (IC1) is
used to generate a 10kHz modulated IR
signal. The output of IC1 is connected to
the base of pnp transistor T1 via resistor
R2. Two infrared LEDs (IR1 and IR2) are
connected in series between the collector
(via resistor R3) and ground.
When switch S1 is pressed, the IR LEDs
transmit the modulated IR signal of 10-11
kHz. This frequency can be changed with
the help of VR1 potmeter.
In the receiver section shown in Fig. 2,
two photodiodes (IR3 and IR4) receive the
IR signal transmitted by the IR transmitter.
Transistors T2 and T3 amplify the weak
signal. The amplifed signal is fltered by
capacitors C6 and C7. The amplifed and
fltered signal is now fed to the inverting
input pin 2 of op-amp IC2 (IC 741). The
output of IC2 is further connected to trigger
pin 2 of timer NE555 (IC3) that is used as a
monostable multivibrator whose frequency
infrared remote control timer
Dipanjan Bhattacharjee may be varied with the
help of potmeter VR3.
When switch S1
of the transmitter is
pressed, the modu-
lated IR rays are gen-
erated, which are re-
ceived by photodiodes
in the receiver sec-
tion and amplifed by
the amplifer circuit.
The output of op-amp
goes low to trigger
the monostable. Then
high output at pin 3
of IC3 activates the
two-changeover relay
RL via transistor T3
(BC548) for a preset
time.
The on/off time
can be set in the timer
with the help of VR3
and C10. Switch S2 is
used to reset the mo-
nostable. If you want
to turn the appliance
on for a preset time,
connect the appliance
via relay RL(a). On
the other hand, if you
want to turn the ap-
pliance off for
a preset time,
connect t he
appliance via
rel ay RL(b).
The timer can
be reset by
pressing reset
switch S2.
The circuit
works up to 3
metres with-
out using any
focusing lens.
However, you
can increase
the operating
range by us-
ing focusing
lens.
This circuit
costs around
Rs 100.
Fig. 1: IR transmitter section
F
i
g
.

2
:

I
R

r
e
c
e
i
v
e
r

s
e
c
t
i
o
n
c i r c u i t i d e a s
electronics for you november 2002
T
his circuit (Fig. 1), used in conjunc-
tion with a thin piezoelectric plate,
senses the vibration generated on
knocking a surface (such as a door or a
table) to activate the alarm. It uses read-
ily-available, low-cost components and can
also be used to safeguard motor vehicles.
The piezoelectric plate is used as the sen-
sor. It is the same as used in ordinary
piezobuzzers and is easily available in the
market.
The piezoelectric plate can convert
any mechanical vibration into electrical
variation. As it doesnt sense sound from a
distance like a microphone, it avoids false
triggering. The plate can be fxed on a door,
cash box, cupboard, etc using adhesive. A
1-1.5m long, shielded wire is connected
between the sensor plate and the input of the
KnocK alarm
PradeeP G.
S
u
n
il
K
u
m
a
r
circuit. When someone knocks on the
door, the piezoelectric sensor generates
an electrical signal, which is amplifed
by transistors T1 through T3.
The amplifed signal is rectifed
and fltered to produce a low-level
DC voltage, which is further ampli-
fed by the remaining transistors. The
fnal output from the collector of pnp
transistor T6 is applied to reset pin 4
of 555 (IC1) that is wired as an astable
multivibrator. Whenever the collector of
transistor T6 goes high, the astable multivi-
brator activates to sound an alarm through
the speaker. The value of resistor R12 is
chosen between 220 and 680 ohms such
that IC1 remains inactive in the absence of
any perceptible knock.
When the circuit receives an input
signal due to knocking, the alarm gets acti-
vated for about 10 seconds. This is the time
Fig. 1: The circuit of knock alarm
Fig. 2: Proposed installation of knock alarm
that capacitor C5 connected between the
emitter of transistor T4 and ground takes
to discharge after a knock. The time delay
can be changed by changing the value of
capacitor C5. After about 10 seconds, the
alarm is automatically reset.
The circuit operates off a 9V or a 12V
battery eliminator. The proposed installation
of the knock alarm is shown in Fig. 2.
This circuit costs around Rs 75.
circuit
ideas Laptop Security Station
You can easily convert your ordinary docking station into a smart electronic laptop docking station
with antitheft alarm.
The add-on sensor circuit required for this is built around IC CNY70 (IC1) and IC CD4060 (IC2) as
shown in Fig.1. IC CNY70 is an integrated reflectivetype opto-sensor that contains a phototransistor and an
infrared LED. The LED emits infrared light and the transistor works as a receiver. The current flowing through the
phototransistor depends on the intensity of the light detected.
IC CD4060 is a 14-stage ripple-carry binary counter. The counter is reset to zero by a gating positive
voltage at the reset input independent of clock. Power supply to the circuit is derived from AC mains by using
stepdown transformer X1. The transformer output is rectified by a full-wave bridge rectifier comprising diodes D1
through D4 and smoothed by capacitor C1.
When power switch S1 is in on position, the circuit gets power supply and power-on indicator LED1
lights up. At the same time, the mains socket also gets the AC mains supply. This mains socket can be used to
connect the laptop charger and/or a desktop lamp, etc.
Working of the circuit is simple. When the laptop is in the docking station, the phototransistor inside
IC1 receives the IR light from the LED, reflected by the laptop surface. The phototransistor conducts to make
reset pin 12 of IC2 high, so IC2 does not oscillate.

Fig. 1: Circuit for laptop security station with antitheft alarm
When someone lifts up the laptop from the docking station, the phototransistor cuts off and pin 12 of
IC2 goes low. As a result, IC2 starts oscillating. After a few seconds, delay pin 3 of IC2 goes high to drive
transistor T1. The piezobuzzer starts beeping to raise an alert and the LED2 glows to indicate that someone has
stolen the laptop from the dockyard.
The simplicity of the circuit makes it ideal for construction on a small PCB. After completion of wiring,
check the circuit for proper functioning of all the sections and enclose the unit in a suitable ABS case. Mount the
finished unit beneath the docking station using small screws/double-sided glue pads so that the opto-sensor is
exactly at the centre of the docking-station base plate. Refer Fig. 2 for the arrangement.
Fig. 2: Proposed assembly for docking station
If your laptop computer is black in colour, it will reflect far less IR light. You can overcome this
drawback by attaching a white sticker suitably at the bottom of the laptop.Calibrate the circuit before first use.
Set preset VR1 at the centre and place the laptop in the docking station.Now turn VR1 slowly until IC2 goes to
standby (no-oscillation) mode. Then remove the laptop from the docking station, ensure that IC2 is enabled (pin
12 is low) and wait for the alarm sound. Repeat the process and adjust VR1 until you get the correct result. Note
that the LED in the opto-sensor is permanently powered via resistor R2. Similarly, you are free to experiment
with the values of IC2 timing components C5, R3 and R4 for increasing or
decreasing the delay time.
80 J ANUARY 2005 ELECTRONI CS FOR YOU WWW. E F Y MA G . C O M
CIRCUIT
IDEAS
CMYK
S. C. DWI VEDI
L
aser torch-based burglar alarms
normally work in darkness only.
But this long-range photoelectric
alarm can work reliably in daytime also
PRADEEP G.
to warn you against intruders in your
big compounds, etc. The alarm com-
prises laser transmitter and receiver
units, which are to be mounted on the
opposite pillars of the entry gate. When-
ever anyone enters to interrupt the
transmitted laser beam
falling on the receiver, the
buzzer in the receiver cir-
cuit sounds an alarm.
The range of this bur-
glar alarm is around 30
metres, which means you
can place the transmitter
and the receiver up to 30
metres apart. Since the la-
ser torch can transmit
light up to a distance of
500 metres, this range can
be increased by orienting
the phototransistor sensor
properly. To avoid false
triggering by sunlight,
mount the phototransistor
LONG-RANGE BURGLAR ALARM
USING LASER TORCH
sensor such that it doesnt directly face
sunlight.
The transmitter circuit is powered
by 3V DC. The astable multivibrator
built around timer 7555 (IC1) produces
5.25kHz frequency. CMOS version of
timer 7555 is used for low-voltage op-
eration. The body of the laser torch is
connected to the emitter of npn tran-
sistor T1 and the spring-loaded lead
protruding from inside the torch is
connected to the ground.
The receiver circuit is powered by
12V DC. It uses photoDarlington 2N5777
(T2) to sense the laser beam transmitted
from the laser torch. The output beam
signals from photoDarlington are given
to the two-stage amplifier followed by
switching circuit, etc. As long as the
laser beam falls on photoDarlington T2,
relay RL1 remains un-energised and
the buzzer does not sound. Also, LED1
doesnt glow.
When anyone interrupts the laser
beam falling on photoDarlington T2,
npn transistor T6 stops conducting
and npn transistor T7 is driven into
conduction. As a result, LED1 glows
and relay RL1 energises to sound the
buzzer for a few seconds (deter-
mined by the values of resistor R15
and capacitor C10). At the same
time, the large indication load (230V
AC alarm for louder sounds or any
other device for momentary indica-
tion) also gets activated as it is
connected to 230V AC mains via
normally opened (N/O) contact of
relay RL1. z
Fig. 1: Circuit of laser torch based transmitter
Fig. 2: Receiver circuit
CirCuit ideas
83
ElEctronics For You DEcEmbEr '99
PradeeP G.
for the above coils)
L3 7 turns of 24 SWG wire close
wound with 3mm diameter air core.
L4 7 turns of 24 SWG wire-wound
on a ferrite bead (as choke)
Potentiometer Vr1 is used to set the
centre frequency whereas potentiometer
Vr2 is used as power control. For hum-
free operation, operate the transmitter
on a 12V rechargeable battery pack of
10 x 1.2-volt Ni-Cd cells. Transistor T2
must be mounted on a heat sink. do
not switch on the transmitter without
a matching antenna. adjust both trim-
mers (VC1 and VC2) for maximum
transmission power. adjust potenti-
ometer Vr1 to set the centre frequency
near 100 MHz.
This transmitter should only be
used for educational purposes. regular
transmission using such a transmitter
without a licence is illegal in India.
Long-range FM
Transmitter
circuit on a good-quality glass epoxy
board and house the transmitter inside
an aluminium case. Shield the oscillator
stage using an aluminium sheet.
Coil winding details are given be-
low:
L1 4 turns of 20 SWG wire close
wound over 8mm diameter plastic
former.
L2 2 turns of 24 SWG wire near
top end of L1.
(Note: No core (i.e. air core) is used
G
.S
. S
a
G
o
o
S
everal circuits for constructing
FM transmitters have been pub-
lished in eFY. The power output
of most of these circuits were very low
because no power amplifer stages were
incorporated.
The transmitter circuit described
here has an extra RF power amplifer
stage, after the oscillator stage, to raise
the power output to 200-250 milliwatts.
With a good matching 50-ohm ground
plane antenna or multi-element Yagi
antenna, this transmitter can provide
reasonably good signal strength up to a
distance of about 2 kilometres.
The circuit built around transistor
T1 (BF494) is a basic low-power vari-
able-frequency VHF oscillator. a vari-
cap diode circuit is included to change
the frequency of the transmitter and to
provide frequency modulation by audio
signals. The output of the oscillator
is about 50 milliwatts. Transistor T2
(2N3866) forms a VHF-class a power
amplifer. It boosts the oscillator signals
power four to fve times. Thus, 200-250
milliwatts of power is generated at the
collector of transistor T2.
For better results, assemble the
circuit
ideas
102 June 2010 electroni cs for you www. e f y ma g . c o m
T
his hearing aid circuit offers the
advantages of high sensitivity,
low current consumption, low
PradeeP G.
Low-cost HearinG aid
S.C. DW
IVEDI
cost and light weight.
Audio signals are sensed by the
condenser microphone and ampli-
fied by two op-amps built around
741 ICs. The frst IC 741 (IC1) is wired
as a high-gain preamplifier, while
the second IC 741 (IC2) is used as a
low-gain, medium-
power amplifer to
drive the earphone.
A 470-kilo-ohm pre-
set (VR1) is used
to control the gain,
while a 1-kilo-ohm
preset (VR2) is used
as the output vol-
ume controller.
Assembl e the
circuit on a small
general - purpose
PCB and house it
together with a 9V
PP3 battery inside a
cabinet the size of a
cigarette pack.
CirCuit ideas
88
ElEctronics For You octobEr '99
S
everal intercom circuits have ap-
peared in EFY using integrated
circuits. The circuit described here
uses three easily available transistors
only. Even a beginner can easily as-
semble it on a piece of veroboard.
The circuit comprises a 3-stage
resistor-capacitor coupled amplifier.
When ring button S2 is pressed, the
amplifer circuit formed around tran-
sistors T1 and T2
gets converted into
an asymmetrical
astable multivib-ra-
tor generating ring
signals. These ring
signals are ampli-
fed by transistor T3
to drive the speaker
of earpiece.
to be used. Output of one amplifer unit
goes to speaker of the other unit, and
vice versa. For single-battery operation,
join corresponding supply and ground
terminals of both the units together.
The complete circuit, along with
microphone and earpiece etc, can be
housed inside the plastic body of a cell-
phone toy, which is easily available in
the market. Suggested cellphone cabinet
is shown.
Current consumption of
this intercom is 10 to 15 mA
only. Thus a 9-volt PP3 battery
would have a long life, when
used in this circuit.
For making a two-way in-
tercom, two identical units, as
shown in fgure, are required
Low-cost
Transistorised
Intercom
PrAdEEP G.
electronics for you may 2000
c i r c u i t i d e a s
W
hile travelling by a train or bus,
we generally lock our luggage
using a chain-and-lock arrange-
ment. But, still we are under tension,
apprehending that somebody may cut
the chain and steal our luggage. Here is
a simple circuit to alarm you when
somebody tries to cut the chain.
Transistor T1 enables supply to
the sound generator chip when the
base current starts fowing through
it. When the wire (thin enameled
copper wire of 30 to 40 SWG, used
for winding transformers) loop
around the chain is broken by
somebody, the base of transistor T1,
which was earlier tied to positive
rail, gets opened. As a result, tran-
sistor T1 gets forward biased to extend
the positive supply to the alarm circuit.
In idle mode, the power consumption of
the circuit is minimum and thus it can be
used for hundreds of travel hours.
To enable generation of different
DHurjATI SInHA
Luggage Security SyStem
Select 1 Select 2 Sound effect
(Pin6) (Pin1)
X X Police siren
V
DD
X Fire-engine siren
V
SS
X Ambulance siren
- V
DD
Machine-gun sound
Note: X = no connection; - = do not care
alarm sounds, connections to pin 1 and 6
may be made as per the table.
KS Project Manual
eFY aPril 2009
Microcontroller-Based
Moving-Message display
L
ED-based moving-message
displays are becoming popular
for transmitting information to
large groups of people quickly. These
can be used indoors or outdoors. We
can fnd such displays in areas like rail-
way platforms, banks, public offces,
hotels, training institutes, nightclubs
and shops.
Compared to LEDs, liquid-crystal
displays (LCDs) are easy to interface
with a microcontroller for display-
ing information as these have many
built-in functions. But these cant be
observed from a distance and large-
size LCDs are very costly.
LED-based displays can be of two
types: dot-matrix and segmental. If you
implement a moving-message display
with multiplexed dot-matrix LEDs, it
will be very costly for displaying 16
characters or more at a time. Moreover,
programming will require a lot of data
memory or program memory space.
An external RAM may be needed to
complement a microcontroller like
AT89C51.
However, if you use alphanumeric
(16-segment LED) displays for the
above purpose, programming burden
is reduced and also it becomes highly
cost-effective. You can make your
own display panel consisting of 16
alphanumeric characters at a much
lower cost.
The circuit presented here uses 16
common-anode, single-digit, alphanu-
meric displays to show 16 characters
at a time. Moreover, programming has
been done to make the characters move
in a beautiful manner. A message ap-
pears on the panel from the right side,
stays for a few seconds when the frst
character reaches the leftmost place
and then goes out from the left side.
It displays 16 different messages to
depict different occasions, which can
be selected by the user through a DIP
switch.
circuit description
Fig. 1 shows the circuit of the micro-
controller-based moving-message
display. It comprises microcontrol-
ler AT89C51, three-to-eight decoder
74LS138, common anode alphanumeric
displays, regulator 7805 and a few dis-
crete components.
At the heart of the moving-mes-
sage display is Atmel AT89C51 mi-
crocontroller (IC1). It is a low-power,
high-performance, 8-bit microcontrol-
ler with 4 kB of fash programmable
and erasable read-only memory
(PEROM) used as on-chip program
memory, 128 bytes of RAM used as
internal data memory, 32 individually
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
circuitry.
Ports P0 and P2 of the microcon-
troller have been confgured to act
as a common data bus for all the 16
alphanumeric displays whose cor-
responding data pins have been tied
together to make a common 16-bit
data bus. Port-2 provides the higher
byte of data, while port-0 provides
the lower one to light up a character
on the display. Port pins P1.2-P1.4
and P1.5-P1.7 of the microcontroller
have been used as address inputs
for decoder IC3 and IC4 (74LS138) to
enable one of the fourteen alphanu-
meric displays (DIS3 through DIS16)
at a time, respectively. However,
displays DIS1 and DIS2 are enabled
or disabled directly by port pins P1.0
and P1.1. Pins 4 and 5 are grounded
and pin 6 is made high to enable de-
coder 74LS138.
Fig. 2 shows the pin confguration
of the common-anode alphanumeric
display.
All the corresponding data pins
DIS1 through DIS16 of alphanumeric
displays have been tied together,
Parts List
Semiconductors:
IC1 - AT89C51 microcontroller
IC2, IC3 - 74LS138 3-to-8 decoder
IC4 - 7805 5V regulator
T1-T16 - BC558 pnp transistor
D1-D4 - 1N4007 rectifer diode
DIS1-DIS16 - KLA51 common-anode
alphanumeric display
LED1 - 5mm LED
Resistors (all -watt, 5% carbon):
R1-R16 - 2.2-kilo-ohm
R17-R32 - 120-ohm
R33-R37 - 10-kilo-ohm
R38 - 220-ohm
Capacitors:
C1, C2 - 33pF ceramic disk
C3 - 2200F, 25V electrolytic
C4 - 1F, 16V electrolytic
C5 - 10F, 16V electrolytic
C6 - 0.1F ceramic disk
Miscellaneous:
X1 - 220V AC primary to 9V,
500mA secondary
transformer
X
TAL
- 11.0592MHz crystal
S0-S3 - 4-pin DIP switch
S4 - Push-to-on switch
List of Messages
Which can be Selected
S3S2S1S0 Message selected
0 0 0 0 Happy Birthday
0 0 0 1 Happy New Year
0 0 1 0 *Happy Diwali*
0 0 1 1 Merry Christmas
0 1 0 0 *Happy Holi*
0 1 0 1 *Eid Mubarak*
0 1 1 0 Happy Dashehra
0 1 1 1 Happy Wedding
1 0 0 0 Happy Janmashtmi
1 0 0 1 *Happy Rakhi*
1 0 1 0 *Happy Pongal*
1 0 1 1 Happy Mothers Day
1 1 0 0 *Happy Ramjan*
1 1 0 1 *Happy Lohri*
1 1 1 0 *Happy Easter*
1 1 1 1 Welcome to All
KS Project Manual
eFY aPril 2009
F
i
g
.

1
:

C
i
r
c
u
i
t

f
o
r

m
i
c
r
o
c
o
n
t
r
o
l
l
e
r
-
b
a
s
e
d

m
o
v
i
n
g
-
m
e
s
s
a
g
e

d
i
s
p
l
a
y

KS Project Manual
eFY aPril 2009
while the common anode of each
display is separately powered via a
BC558 transistor which switches on
or off as required, through outputs
of 74LS138 ICs and pins P1.0 and
P1.1 of IC1. The higher nibble of
port P3 (P3.4 through P3.7) is used
as a selection bus to select one of
the 16 previously stored messages
using the 4-bit binary value present
on these pins. This value can be
changed through a 4-pin DIP switch
(S0 through S3).
Selection pins P3.4 through P3.7
are pulled high via resistors R36
through R33, respectively. When the
switch connected to a given pin is
open the value is high (1), and when
it is closed the pin is held low and
the value becomes 0. In this way,
by using a 4-bit number you can
select any of the 16 messages shown
in the Table.
Capacitor C5 and resistor R37
form the power-on reset circuit,
while a push-to-connect switch has
been used for manual reset. An
11.0592MHz crystal generates the
basic clock frequency for the micro-
controller. To change the message
being displayed while the circuit is
working, first change the number
present at the selection bus, then
press reset key.
The 220V AC mains is stepped
down by transformer X1 to deliver
the secondary output of 9V, 500 mA.
The output of the transformer is
rectifed by a full-wave bridge recti-
fer comprising diodes D1 through
D4, fltered by capacitor C3 and then
regulated by IC 7805 (IC4). Capacitor
C4 bypasses any ripple present in the
regulated power supply. LED1 acts as
the power-on indicator.
construction
Fig. 3 shows an actual-size, single-
side PCB layout for the microcontrol-
ler-based moving-message display
circuit, except displays DIS1 through
DIS16, transistors T1 through T16
and resistors R17 through R32. Com-
ponent layout for this PCB is shown
in Fig. 4.
Fig. 5 shows the PCB for displays
DIS1 through DIS8, transistors T1
through T8 and resistors R17 through
R24. Component layout for this PCB
is shown in Fig. 6. You need to use an
additional PCB as shown in Fig. 5 for
DIS9 through DIS16, so as to confgure
16 alphanumeric displays. For this
PCB, the corresponding components
will be transistors T9 through T16 and
resistors R25 through R32 in addition
to displays DIS9 through DIS16. Cor-
Fig. 2: Pin confguration of alphanumeric display
Fig. 3: Actual-size, single-side PCB for the microcontroller-based moving-message display circuit,
except alphanumeric display and associated components
Fig. 4: Component layout for the PCB shown in Fig. 3
KS Project Manual
eFY aPril 2009
responding connector are provided to
make a proper connection. Connectors
CON2, CON4 and CON6 of Fig. 3 are
connected to CON2, CON4 and CON6
of Fig. 5, respectively, through external
wires to interface DIS1 through DIS9.
Connectors CON3, CON5 and CON7
of Fig. 3 are connected to CON2, CON4
and CON6 of Fig. 5, respectively,
through external cable to interface DIS9
through DIS16.
software and its working
The source code movmsg.asm is writ-
ten in Assembly language and assem-
bled using cross-compiler. It is well-
commented and easy to understand.
Timer 1 has been used to generate a
delay of around 1 ms for the switching
gap between two consecutive displays.
Thus, each display is enabled for 1 ms
while displaying a message. The length
of this cycle depends upon the length
of the message string. The cycle repeats
after a 0 is encountered at the end of
each message stored in the look-up
table at the end of the program.
Each time, to display a character at
a given display, frst two bytes (16 bits)
of data are sent to Port-2 and Port-0,
then the desired display is enabled by
sending its address to Port-1. Thereaf-
ter, a delay of 1 ms (slightly more than
that) is generated by timer 1. Upon
timer overfow, the entire display panel
is refreshed by passing FFFFH to the
data bus. Then the next character at the
next display is passed in the similar
manner. The cycle frequency is vari-
able (depending upon the length of the
message) but always high enough so
that the message appears continuous
to the human eye.
Timer 0, with its interrupt enabled,
is used to change the starting address
of the message in cyclic manner so
that the characters scroll from left
to right with a proper gap between
each shift. Meanwhile, the interrupt
service sub-routine also checks for the
starting address of DIS16 (right-most
display). As soon as the frst character
reaches DIS16, the message stays for a
longer time so that the entire message
(message length not longer than 16
characters) can be easily read. There-
after, characters again start scrolling
rightwards, so the entire message goes
out and disappears after a while to
reappear from left side.
All the messages are stored in the
form of a look-up table in the program
memory (ROM) itself. When the circuit
is switched on (or reset), the monitor-
ing program frst checks for the binary
number present at the selection bus
and according to that, the ROM ad-
dress of the starting character of the
selected message is loaded into the
data-pointer. Thereafter, on-chip ROM
reading is used to read the entire mes-
sage over there.
Note that each character is rep-
resented in the look-up table of the
source code by two bytes. For exam-
Fig. 5: Actual-size, single-side PCB for alphanumeric display
Fig. 6: Component layout for the PCB shown in Fig. 5
KS Project Manual
eFY aPril 2009
$mod51
DBH equ p2 ; Higher byte of Data
Bus
DBL equ p0 ; Lower byte of Data Bus
ADB equ p1 ; Address Bus
input equ p3 ; message select input

;** codes for decimal digits are given
below:
; (h refers to higher byte, l to
lower one)
zeroh equ 17h
zerol equ 0e8h

oneh equ 0d7h
onel equ 0ffh

twoh equ 23h
twol equ 0ech

threeh equ 2bh
threel equ 0fch

fourh equ 0c3h
fourl equ 0fbh

fveh equ 0bh
fvel equ 0f8h

sixh equ 0bh
sixl equ 0e8h

sevenh equ 0d7h
sevenl equ 0fch

eighth equ 03h
eightl equ 0e8h

nineh equ 03h
ninel equ 0f8h

;** codes for alphabets are given
below:

Ah equ 0c3h
Al equ 0e8h

Bh equ 0bh
Bl equ 0ebh

Ch equ 3fh
Cl equ 0e8h

Dh equ 03h
Dl equ 0efh

Eh equ 2bh
El equ 0e8h

Fh equ 0ebh
movmsg.asm
Fl equ 0e8h

GH equ 1bh
Gl equ 0e8h

Hh equ 0c3h
Hl equ 0ebh

Ih equ 0ffh
Il equ 9fh

Jh equ 17h
Jl equ 0ffh

Kh equ 0ech
Kl equ 0ebh
Lh equ 3fh
Ll equ 0ebh
Mh equ 0d5h
Ml equ 0e3h
Nh equ 0d6h
Nl equ 0e3h
Oh equ 17h
Ol equ 0e8h
Ph equ 0e3h
Pl equ 0e8h
Qh equ 06h
Ql equ 0e8h
Rh equ 0e2h
Rlw equ 0e8h
Sh equ 0bh
Sl equ 0f8h
Th equ 0ffh
Tl equ 9ch
Uh equ 17h
Ul equ 0ebh
Vh equ 0fdh
Vl equ 6bh
Wh equ 17h
Wl equ 0abh
Xh equ 0fch
Xl equ 77h

Yh equ 0e3h
Yl equ 0bbh
Zh equ 3dh
Zl equ 7ch
;** codes for few special characters:
strh equ 0e8h ;for star sign (as-
terisk)
strl equ 17h
plsh equ 0ebh ;for + sign
plsl equ 9fh
mnsh equ 0ebh ;minus sign
mnsl equ 0ffh
_h equ 3fh ;underscore sign
_l equ 0ffh
bsh equ 0ffh ;blank space
bsl equ 0ffh
pieh equ 0eah ;for pie
piel equ 7fh
mueh equ 0e3h ;for micro (mu)
muel equ 0ebh
org 0000h
sjmp main
org 000bh ;timer0 inter-
rupt vector address
clr tr0 ;clear timer0
run bit
mov tl0,#00h
mov th0,#00h ;reload timer0
with initial count
djnz r7,a1
mov r7,#46
cjne r1,#60h,a5 ;check to again
start entering from left-side
sjmp a4
a5: cjne r1,#50h,a2 ;check for display
to stay on reaching display-16
sjmp a3
a2: inc r1
sjmp a1
a3: djnz r6,a1
inc r1
sjmp a1
a4: mov r6,#10
mov r1,#41h
a1: setb tr0 ;set timer0 run
bit
reti ;return from
timer0 ISR and clear tf0
main: mov ie,#00h
setb ea ;set global
interrupt bit
setb et0 ;enable
ple, S is represented by Sh and Sl
separated by a comma. In addition to
the alphabets, Arabic numerals and
a few special characters have been
defned in the program. For instance,
a blank space is represented by bsh,
bsl. Thus, it is very easy to modify
the program.
Suppose you want to display
HOUSE NO 401-H in place of mes-
sage 0. First, open the source code in
the editor. Delete the old string and
write the new string as below:
msg0: db Hh, Hl, Oh, Ol, Uh, Ul, Sh,
Sl, Eh, El, bsh, bsl, Nh, Nl, Oh,
Ol, bsh, bsl, fourh, fourl, zeroh,
zerol, oneh, onel, msh, msl, Hh, Hl, 0
(Please note that the assembler is
case-insensitive. Still, upper and lower
cases have been used for clarity.)
Future enhancements
Many more messages would be
possible if complete Port-3 is used
for message selection. Pins RxD,
TxD, INT0 and INT1 have been
kept free, so that these can be used
for interfacing with the serial port
of the PC. Also, interrupt pins can
be used to display some message
and sound an alarm in the case of
an emergency. For example, a fre
sensor can be connected to INT0 and
a vibration detector to INT1. These
pins can also be used to send signals
to synchronise a similar system that
displays another related message at
the same time, so a 16-character, two-
line display is made possible.
KS Project Manual
eFY aPril 2009
timer0 interrupt
mov tmod,#01h ;timer0 con-
fgured in mode 1
mov tcon,#00h
mov tl0,#00h
mov th0,#00h ;set initial
count to 0000H
mov r7,#46 ;provides gap
between each shift
mov r6,#10 ;

mov r0,#60h
blank: mov @r0,#0ffh ;initialize the
pointed location by null address
dec r0
cjne r0,#2fh,blank
mov r1,#41h ;load address-
pointer with initial address

mov 50h,#0dfh ;address for 16th
Display (rightmost)
mov 4fh,#0bfh ;address for 15th
Display
mov 4eh,#9fh ;address for 14th
Display
mov 4dh,#7fh ;address for 13th
Display
mov 4ch,#5fh ;address for 12th
Display
mov 4bh,#3fh ;address for 11th
Display
mov 4ah,#1fh ;address for 10th
Display
mov 49h,#0fbh ;address for 9th
Display
mov 48h,#0f7h ;address for 8th
Display
mov 47h,#0f3h ;address for 7th
Display
mov 46h,#0efh ;address for 6th
Display
mov 45h,#0ebh ;address for 5th
Display
mov 44h,#0e7h ;address for 4th
Display
mov 43h,#0e3h ;address for 3rd
Display
mov 42h,#0fdh ;address for 2nd
Display
mov 41h,#0feh ;address for 1st
Display (leftmost)
chk: mov a,input ;load accumulator
with value at P3
orl a,#0fh ;mask lower nible
to get selection bus value
cjne a,#0ffh,chk0
mov dptr,#default ;load dptr
with starting address of defalt message
sjmp read ; now start
reading
chk0: cjne a,#0fh,chk1
mov dptr,#msg0 ;load dptr with
starting address of msg0
sjmp read ; now start
reading

chk1: cjne a,#1fh,chk2
mov dptr,#msg1
sjmp read

chk2: cjne a,#2fh,chk3
mov dptr,#msg2
sjmp read

chk3: cjne a,#3fh,chk4
mov dptr,#msg3
sjmp read

chk4: cjne a,#4fh,chk5
mov dptr,#msg4
sjmp read

chk5: cjne a,#5fh,chk6
mov dptr,#msg5
sjmp read

chk6: cjne a,#6fh,chk7
mov dptr,#msg6
sjmp read

chk7: cjne a,#7fh,chk8
mov dptr,#msg7
sjmp read

chk8: cjne a,#8fh,chk9
mov dptr,#msg8
sjmp read

chk9: cjne a,#9fh,chk10
mov dptr,#msg9
sjmp read

chk10: cjne a,#0afh,chk11
mov dptr,#msg10
sjmp read

chk11: cjne a,#0bfh,chk12
mov dptr,#msg11
sjmp read

chk12: cjne a,#0cfh,chk13
mov dptr,#msg12
sjmp read

chk13: cjne a,#0dfh,chk14
mov dptr,#msg13
sjmp read

chk14: mov dptr,#msg14
sjmp read
read: mov r3,dph
mov r2,dpl
setb tr0
rd1: mov r0,01h
rd2: clr a
movc a,@a+dptr
jz down
mov DBH,a
clr a
inc dptr
movc a,@a+dptr
mov DBL,a
mov ADB,@r0
acall timer
dec r0
inc dptr
sjmp rd2
down: mov dph,r3 ;reload dph
mov dpl,r2 ;reload dpl
sjmp rd1
timer: mov tmod,#10h ;set mode 1 for
timer1
mov th1,#0fch ;FC66H will gen-
erate a delay of 1ms with 11.0592MHz
Xtal
mov tl1,#66h
setb tr1
jnb tf1,$ ;wait until timer1
overfows
clr tr1
clr tf1
mov DBH,#0ffh
mov DBL,#0ffh
ret

;** look-up table starts from here:
msg0: db Hh,Hl,Ah,Al,Ph,Pl,Ph,Pl,Yh
,Yl,bsh,bsl,Bh,Bl,Ih,Il,Rh,Rlw,Th,Tl,Hh
,Hl,bsh,bsl,Dh,Dl,Ah,Al,Yh,Yl,0
msg1: db Hh,Hl,Ah,Al,Ph,Pl,Ph,Pl,Y
h,Yl,bsh,bsl,Nh,Nl,Eh,El,Wh,Wl,bsh,bsl,
Yh,Yl,Eh,El,Ah,Al,Rh,Rlw,0
msg2: db strh,strl,bsh,bsl,Hh,Hl,
Ah,Al,Ph,Pl,Ph,Pl,Yh,Yl,bsh,bsl,Dh,Dl,
Ih,Il,Wh,Wl,Ah,Al,Lh,Ll,Ih,Il,bsh,bsl,
strh,strl,0
msg3: db Mh,Ml,Eh,El,Rh,Rlw,Rh,Rlw,
Yh,Yl,bsh,bsl,Ch,Cl,Hh,Hl,Rh,Rlw,Ih,Il,
Sh,Sl,Th,Tl,Mh,Ml,Ah,Al,Sh,Sl,0
msg4: db strh,strl,bsh,bsl,Hh,Hl,Ah
,Al,Ph,Pl,Ph,Pl,Yh,Yl,bsh,bsl,Hh,Hl,Oh,O
l,Lh,Ll,Ih,Il,bsh,bsl,strh,strl,0
msg5: db strh,strl,bsh,bsl,Eh,El,
Ih,Il,Dh,Dl,bsh,bsl,Mh,Ml,Uh,Ul,Bh,Bl,
Ah,Al,Rh,Rlw,Ah,Al,Kh,Kl,bsh,bsl,strh,
strl,0
msg6: db Hh,Hl,Ah,Al,Ph,Pl,Ph,Pl,Y
h,Yl,bsh,bsl,Dh,Dl,Ah,Al,Sh,Sl,Hh,Hl,Eh
,El,Hh,Hl,Rh,Rlw,Ah,Al,0
msg7: db Hh,Hl,Ah,Al,Ph,Pl,Ph,Pl,Y
h,Yl,bsh,bsl,Wh,Wl,Eh,El,Dh,Dl,Dh,Dl,Ih
,Il,Nh,Nl,Gh,Gl,0
msg8: db Hh,Hl,Ah,Al,Ph,Pl,Ph,Pl,Yh
,Yl,bsh,bsl,Jh,Jl,Ah,Al,Nh,Nl,Mh,Ml,Ah,A
l,Sh,Sl,Hh,Hl,Th,Tl,Mh,Ml,Ih,Il,0
msg9: db strh,strl,bsh,bsl,Hh,Hl,
Ah,Al,Ph,Pl,Ph,Pl,Yh,Yl,bsh,bsl,Rh,Rlw
,Ah,Al,Kh,Kl,Hh,Hl,Ih,Il,bsh,bsl,strh,
strl,0
msg10: db strh,strl,bsh,bsl,Hh,Hl,
Ah,Al,Ph,Pl,Ph,Pl,Yh,Yl,bsh,bsl,Ph,Pl,
Oh,Ol,Nh,Nl,Gh,Gl,Ah,Al,Lh,Ll,bsh,bsl,
strh,strl,0
msg11: db Hh,Hl,Ah,Al,Ph,Pl,Ph,Pl,Yh
,Yl,bsh,bsl,Mh,Ml,Oh,Ol,Th,Tl,Hh,Hl,Eh,E
l,Rh,Rlw,Sh,Sl,Dh,Dl,Ah,Al,Yh,Yl,0
msg12: db strh,strl,bsh,bsl,Hh,Hl,
Ah,Al,Ph,Pl,Ph,Pl,Yh,Yl,bsh,bsl,Rh,Rlw
,Ah,Al,Mh,Ml,Jh,Jl,Ah,Al,Nh,Nl,bsh,bsl
,strh,strl,0
msg13: db strh,strl,bsh,bsl,Hh,Hl,
Ah,Al,Ph,Pl,Ph,Pl,Yh,Yl,bsh,bsl,Lh,Ll,
Oh,Ol,Hh,Hl,Rh,Rlw,Ih,Il,bsh,bsl,strh,
strl,0
msg14: db strh,strl,bsh,bsl,Hh,Hl,
Ah,Al,Ph,Pl,Ph,Pl,Yh,Yl,bsh,bsl,Eh,El,
Ah,Al,Sh,Sl,Th,Tl,Eh,El,Rh,Rlw,bsh,bsl
,strh,strl,0
default: db Wh,Wl,Eh,El,Lh,Ll,Ch,Cl,O
h,Ol,Mh,Ml,Eh,El,bsh,bsl,Th,Tl,Oh,Ol,bs
h,bsl,Ah,Al,Lh,Ll,Lh,Ll,0
end

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.

Das könnte Ihnen auch gefallen