EX.
NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
3.A INTERFACING CAPACITIVE TOUCH SENSOR
[Link]
To understand and implement the capacitive touch sensor using the programming
and with the help of the 8051- development kit.
[Link]
Capacitive touch works on the electrostatic charge that is available on our
body. The screen is already charged with electric field. When we touch the screen
a close circuit forms due to electrostatic charge that flows through our body.
Further, software decides the location and the action to be performed. Capacitive
touch screen won’t work with hand gloves because there won’t be any conduction
between the finger and the screen.
3.TTP223B SENSOR:
The TTP223B is a Digital touchpad detector IC that offers 1 touch key. The
touching detection IC is designed for replacing traditional direct button keys with
diverse pad sizes. This device uses your body as part of the circuit.
When you touch the sensor pad, the capacitance of the circuit is changed
and is detected. That detected change in capacitance results in the output
changing states When a finger touches the corresponding position, the module
output high, if not touched for 12 seconds, switch to low-power mode.
Figure 1: Touch sensor
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
SPECIFICATION:
Operating voltage 2.0V~5.5V
f Operating current at VDD=3V, no-load, SLRFTB=1, At low power mode
typical 1.5uA, maximum 3.0uA and At fast mode typical 3.5uA, maximum
7.0Ua
Operating current at VDD=3V, no-load, SLRFTB=0, At low power mode
typical 2.0uA, maximum 4.0uA and At fast mode typical 6.5uA, maximum
13.0uA
The response time max about 60mS at fast mode, 220mS at low power
mode at VDD=3V
Provides Fast mode and Low Power mode selection by pad option(LPMB
pin)
Operating Temperature:-20 ~ +70 ℃
TOUCH SENSOR PIN OUTS
This is three pin sensor. You provide power, ground, and monitor the
output.
Figure 2: Touch sensor pin outs
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
SIG – Output (If it detects touch, this will be HIGH otherwise LOW)
VCC – 2v to 5.5v
GND – Ground
CODE:
#include<reg51.h>
#define lcd P3
sbit TOUCH=P1^0;
sbit rs=P2^0; //register select
sbit rw=P2^1; //RW
sbit en=P2^2; //enable
void lcd_init();
void cmd(unsigned char);
void dat(unsigned char);
void delay();
void lcd_string(char *s);
void main()
lcd_init();
lcd_string(" EmbeTronicX ");
while(1) {
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
if(TOUCH) {
cmd(0xc0);
lcd_string("Touch Detected");
delay();
} else {
cmd(0xc0);
lcd_string(" ");
void lcd_init()
cmd(0x38);
cmd(0x0e);
cmd(0x06);
cmd(0x01);
cmd(0x80);
void cmd(unsigned char a)
{
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
lcd=a;
rs=0;
rw=0;
en=1;
delay();
en=0;
void dat(unsigned char b)
lcd=b;
rs=1;
rw=0;
en=1;
delay();
en=0;
void lcd_string(char *s)
while(*s) {
dat(*s++);
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
void delay()
unsigned int i;
for(i=0;i<20000;i++);
OUTPUT:
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
3.B INTERFACING DC MOTOR
[Link]:
To understand and implement DC motor in the 8051-development kit with
the help of programming.
[Link]:
The main purpose of DC interfacing with 8051 microcontroller is for
controlling the speed of the motor. The DC motor is an electrical machine with a
rotating part termed as a rotor which has to be controlled. For example, consider
the DC motor whose speed or direction of rotation of DC motor can be controlled
using programming techniques which can be achieved by interfacing with 8051
microcontroller. So, in this article let us discuss about interfacing DC motor with
8051 microcontrollers.
Figure 3 Interfacing DC Motor with 8051 Microcontroller
L293D MOTOR DRIVER:
Interfacing 8051 with DC motor requires a motor driver. There are various
types of driver ICs among which L293D is typically used for interfacing DC
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
motor with 8051. L293 is an IC with 16 pins which are represented in the figure
below.
Figure 4 Motor Driver IC L293D used for Interfacing DC motor with 8051
This L293 IC is having ratings of 600mA per channel and DC supply voltage
in the range of 4.5V to 36V. These ICs can be protected from inductive spikes by
connecting higher speed clamp diodes internally. This 16 pin L293D IC can be used
for controlling the direction of two DC motors. The IC L293D works based on the
H-bridge concept. The voltage can be made to flow in either direction using this
circuit (H-bridge) such that by changing the voltage direction the motor direction
can be changed.
H-BRIDGE CIRCUIT
The name “H-Bridge” comes from the shape of the switching circuit, which
controls the motion of the motor. It is also known as “Full Bridge”. This circuit
has four switching elements. We can make H-bridges with the help of transistors,
MOSFETs, etc. It will be cheap but they will increase the size of the design and
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
the circuit board, which is mostly not preferable, so we can use a small 16-pin IC
for this purpose.
Working of H-bridge Circuit
As we can see in the figure, there are four switching elements named:
High side left
High side right
Low side right
Low side left
Figure 5 H bridge circuit
When these switches are turned on in pairs, the motor changes its direction
accordingly. If we switch on “High side left” and “Low side right”, then the
motor will rotate in a forward direction as current from the power supply flows
through the motor coil and goes to ground through the switch on the low side
(right). This is shown in the figure below.
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
Figure 6 current flow in H bridge
Similarly, when we switch on the low side (left) and the high side (right),
the current flows in the opposite direction and the motor rotates in the opposite
direction. This is the basic working of H-Bridge. We can also make a small truth
table according to the switching of H-Bridge explained above.
Table 1: Working of H-bridge circuit
Interfacing the DC motor with the AT89S52 microcontroller and control
the DC motor speed by using the Speed Increment Switch and Speed Decrement
Switch connected to the Microcontroller port and direction by using Direction
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
Switch. The L293D motor driver IC used to control the DC motor movement in
both directions. It has an in-built H-bridge motor drive.
As shown in the above figure we have connected two toggle switches on
the P1.0 and P1.1 pin of the AT89S52 microcontroller to change the speed
of the DC motor by 10%.
One toggle switch at pin P1.2 controls the motor's rotating direction.
P1.6 and P1.7 pins are used as output direction control pins. It provides
control to motor1 input pins of the L293D motor driver which rotate the
motor clockwise and anticlockwise by changing their terminal polarity.
And Speed of the DC Motor is varied through PWM Out pin P2.0.
Here we are using the timer of AT89S52 to generate PWM.
CODE:
#include <reg52.h>
#include <intrins.h>
/* Define value to be loaded in timer for PWM period of 20 milli second */
#define PWM_Period 0xB7FE
sbit PWM_Out_Pin = P2^0; /* PWM Out Pin for speed control */
sbit Speed_Inc = P1^0; /* Speed Increment switch pin */
sbit Speed_Dec = P1^1; /* Speed Decrement switch pin */
sbit Change_Dir = P1^2; /* Rotation direction change switch pin */
sbit M1_Pin1 = P1^6; /* Motor Pin 1 */
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
sbit M1_Pin2 = P1^7; /* Motor Pin 2 */
unsigned int ON_Period, OFF_Period, DutyCycle, Speed;
/* Function to provide delay of 1ms at 11.0592 MHz */
void delay(unsigned int count)
int i,j;
for(i=0; i<count; i++)
for(j=0; j<112; j++);
void Timer_init()
TMOD = 0x01; /* Timer0 mode1 */
TH0 = (PWM_Period >> 8);/* 20ms timer value */
TL0 = PWM_Period;
TR0 = 1; /* Start timer0 */
/* Timer0 interrupt service routine (ISR) */
void Timer0_ISR() interrupt 1
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
PWM_Out_Pin = !PWM_Out_Pin;
if(PWM_Out_Pin)
TH0 = (ON_Period >> 8);
TL0 = ON_Period;
else
TH0 = (OFF_Period >> 8);
TL0 = OFF_Period;
/* Calculate ON & OFF period from PWM period & duty cycle */
void Set_DutyCycle_To(float duty_cycle)
float period = 65535 - PWM_Period;
ON_Period = ((period/100.0) * duty_cycle);
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
OFF_Period = (period - ON_Period);
ON_Period = 65535 - ON_Period;
OFF_Period = 65535 - OFF_Period;
/* Initially Motor Speed & Duty cycle is zero and in either direction */
void Motor_Init()
Speed = 0;
M1_Pin1 = 1;
M1_Pin2 = 0;
Set_DutyCycle_To(Speed);
int main()
EA = 1; /* Enable global interrupt */
ET0 = 1; /* Enable timer0 interrupt */
Timer_init();
Motor_Init();
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
while(1)
/* Increment Duty cycle i.e. speed by 10% for Speed_Inc Switch */
if(Speed_Inc == 1)
if(Speed < 100)
Speed += 10;
Set_DutyCycle_To(Speed);
while(Speed_Inc == 1);
delay(200);
/* Decrement Duty cycle i.e. speed by 10% for Speed_Dec Switch */
if(Speed_Dec == 1)
if(Speed > 0)
Speed -= 10;
Set_DutyCycle_To(Speed);
while(Speed_Dec == 1);
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
delay(200);
/* Change rotation direction for Change_Dir Switch */
if(Change_Dir == 1)
M1_Pin1 = !M1_Pin1;
M1_Pin2 = !M1_Pin2;
while(Change_Dir == 1);
delay(200);
} } }
OUTPUT:
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
3.c INTERFACING STEPPER MOTOR
[Link]:
To understand and implement stepper motor in the 8051-development kit
with the help of programming.
[Link]:
Stepper motors are used to translate electrical pulses into mechanical
movements. In some disk drives, dot matrix printers, and some other different
places the stepper motors are used. The main advantage of using the stepper motor
is the position control. Stepper motors generally have a permanent magnet shaft
(rotor), and it is surrounded by a stator.
[Link]:
Step Angle − The step angle is the angle in which the rotor moves when
one pulse is applied as an input of the stator. This parameter is used to
determine the positioning of a stepper motor.
Steps per Revolution − This is the number of step angles required for a
complete revolution. So the formula is 360° /Step Angle.
Steps per Second − This parameter is used to measure a number of steps
covered in each second.
RPM − The RPM is the Revolution Per Minute. It measures the frequency
of rotation. By this parameter, we can measure the number of rotations in
one minute.
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
The relation between RPM, steps per revolution, and steps per second is
like below:
Steps per Second = rpm x steps per revolution / 60
[Link] STEPPER MOTOR
Weare using Port P0 of 8051 for connecting the stepper motor. Here
ULN2003 is used. This is basically a high voltage, high current Darlington
transistor array. Each ULN2003 has seven NPN Darlington pairs. It can provide
high voltage output with common cathode clamp diodes for switching inductive
loads.
Figure 8 ULN2003 driver
ULN2003 IC consists of 7 pairs of Darlington transistors, each pair can withstand
500mA and 50V. There are 4 transistors in this module. This module has 4 LEDs
to show the activity of 4 motor control pins.
MODES IN STEPPER MOTOR:
The Unipolar stepper motor works in three modes.
[Link] Drive Mode − In this mode, one coil is energized at a time. So all
four coils are energized one after another. This mode produces less torque than
full step drive mode.
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
The following table is showing the sequence of input states in different windings.
[Link] Drive Mode − In this mode, two coils are energized at the same
time. This mode produces more torque. Here the power consumption is also high.
The following table is showing the sequence of input states in different windings.
[Link] Drive Mode − In this mode, one and two coils are energized
alternately. At first, one coil is energized then two coils are energized. This is
basically a combination of wave and full drive mode. It increases the angular
rotation of the motor
The following table is showing the sequence of input states in different windings .
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
CIRCUIT DESCRIPTION:
In the circuit, Port P2 is defined as output port to provide the input sequence
for the stepper motor. Four transistors are used as switches to drive the motor.
The motor leads are not directly interfaced with the microcontroller pins because
stepper motor requires 60mA current while has the maximum current rating of
50mA. So the transistors switches are used to transfer signals from the
microcontroller to the stepper wires.
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
The sequence of signals mentioned in the tables above rotates the motor in
clockwise direction. Reversing these input sequences would rotate the motor in
counter clockwise direction.
CODE:
#include<reg51.h>
sfr stepper=0xA0;
void delay(unsigned int count)
int i;
for(i=0;i<count;i++);
void main()
while(1)
stepper=0x01;
delay(350);
stepper=0x02;
delay(350);
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
stepper=0x04;
delay(350);
stepper=0x08;
delay(350);
/**** Half Drive Stepping ****/
#include<reg51.h>
sfr stepper=0xA0;
void delay(unsigned int count)
int i;
for(i=0;i<count;i++);
void main()
while(1)
{
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
stepper=0x01;
delay(300);
stepper=0x03;
delay(300);
stepper=0x02;
delay(300);
stepper=0x06;
delay(300);
stepper=0x04;
delay(300);
stepper=0x0C;
delay(300);
stepper=0x08;
delay(300);
stepper=0x09;
delay(300);
}
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
OUTPUT:
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
3.D INTERFACING LDM35 AND LDR
[Link]
To understand and implement LM35 and LDR in the 8051-development
kit with the help of programming.
[Link]:
LM35 is a precession Integrated circuit Temperature sensor, whose output
voltage varies, based on the temperature around it. It is a small and cheap IC
which can be used to measure temperature anywhere between -55°C to 150°C. It
can easily be interfaced with any Microcontroller that has ADC function or any
development platform like Arduino.
Figure 9 LM35
An LDR or light dependent resistor is also known as photo resistor,
photocell, photoconductor. It is a one type of resistor whose resistance varies
depending on the amount of light falling on its surface. When the light falls on
the resistor, then the resistance changes. These resistors are often used in many
circuits where it is required to sense the presence of light. These resistors have a
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
variety of functions and resistance. For instance, when the LDR is in darkness,
then it can be used to turn ON a light or to turn OFF a light when it is in the light.
A typical light dependent resistor has a resistance in the darkness of 1MOhm, and
in the brightness a resistance of a couple of Kohm
Figure 10 LDR
ADC0804:
To make this LM35 we will read the temperature sensor value on ADC0804
and will convert the surrounding temperature to voltage. It further converts the
voltage to Celsius, and prints the temperature on the LCD screen.
ADC0804 is an IC(integrated circuit) which converts the inputanalog
voltage to its equivalent digital output. It is a standalone analog to digital
converter. This analog to digital converter which provide more flexibility,
consumes less power, provides output in multiple formats and are smaller
in size. ADC0804 we need to interfaced with microcontrollers as we do not have
in built in analog to digital converter with Microcontroller AT89S52.
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
Figure 11 ADC0804
How to use ADC0804 analog to digital converter:
Make Cs (chip select) low(0) to activate the adc0804.
Make WR (write) pin low (0).
Make WR (write) pin high (1) after some delay small delay. This low to high
impulse at WR pin starts your conversion.
Now check the INTR (interrupt) pin if it is high (1) conversion is running if it is
low (0) the conversion is over.
Make RD=low (0) and after some time high (1). This will bring the converted
value to the 8 data output pins of ADC 0804.
ADC0804 Pin Configuration
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
CODE:
#include < reg51.h>
#include "lcd.h"
#include "delay.h"
#include"stdutils.h"
#include< stdio.h>
sbit READ_ADC=P3^0; //Read(RD) pin of ADC0804
sbit WRITE_ADC=P3^1; //Write(WR) pin of ADC0804
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
sbit INTR_ADC=P3^2; //Interrupt(INTR) pin of ADC0804
unsigned char ADC_VALUE;
char Tempr[] = " 00.0 C"; //set Temp display format in Celsius
int C;
/* main program */
void main()
{
P1=0xFF; //make Port 1 as input port
INTR_ADC=1; //make INTR pin as input
READ_ADC=1; //set RD pin HIGH
WRITE_ADC=1; //set WR pin LOW
LCD_Init();
lcd_DisplayString(" MICRODIGISOFT ");
lcd_Line_posnY();
lcd_DisplayString("LM35 - ADC0804 ");
delay_ms(1000);
lcd_Clear();
while(1)
{
WRITE_ADC=0; //send LOW to HIGH pulse on WR pin
delay_ms(1);
WRITE_ADC=1;
while(INTR_ADC==1); //wait for End of Conversion
READ_ADC=0; //make RD = 0 to read the data from ADC0804
ADC_VALUE=P1; //copy ADC data
// convert_display(ADC_VALUE); //function call to convert ADC data into
temperature and display it on 16*2 lcd display
C = ADC_VALUE*1.95; // // Read analog voltage and convert it to degree
Celsius
if (C > 99)
Tempr[0] = 1 + 48; // Put 1 (of hundred)
else
Tempr[0] = ' '; // Put space
Tempr[1] = (C / 10) % 10 + 48;
Tempr[2] = C % 10 + 48;
Tempr[5] = 223; // Put degree symbol ( 째 )
lcd_DisplayString("TEMPERATURE");
lcd_Line_posnY();
lcd_DisplayString(Tempr);
[Link] INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
delay_ms(10); //interval between every cycles
READ_ADC=1; //make RD = 1 for the next cycle
delay_ms(1000); //interval between every cycles
lcd_Clear();
}
}
OUTPUT:
CONCLUSION:
` Thus the interfacing of sensors and actuators such as capacitive touch
sensor, DC motor, Stepper motor, LM35 and LDR using 8051 development kit
and output is observed.