Postlab3 02
Postlab3 02
1.AIM
To understand and implement the capacitive touch sensor using the programming and with the
help of the 8051- development kit.
2.INTRODUCTION
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.
51
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
SPECIFICATION:
This is three pin sensor. You provide power, ground, and monitor the output.
SIG – Output (If it detects touch, this will be HIGH otherwise LOW)
VCC – 2v to 5.5v
GND – Ground
52
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
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) {
if(TOUCH) {
cmd(0xc0);
lcd_string("Touch Detected");
delay();
} else {
cmd(0xc0);
lcd_string(" ");
53
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
}
void lcd_init()
{
cmd(0x38);
cmd(0x0e);
cmd(0x06);
cmd(0x01);
cmd(0x80);
}
void cmd(unsigned char a)
{
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)
54
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
while(*s) {
dat(*s++);
}
}
void delay()
{
unsigned int i;
for(i=0;i<20000;i++);
}
OUTPUT:
55
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
1.AIM:
To understand and implement DC motor in the 8051-development kit with the help of
programming.
2.INTRODUCTION:
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.
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 motor with 8051. L293 is
an IC with 16 pins which are represented in the figure below.
56
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
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 the circuit board, which is mostly not
preferable, so we can use a small 16-pin IC for this purpose.
As we can see in the figure, there are four switching elements named:
57
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
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.
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
58
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
basic working of H-Bridge. We can also make a small truth table according to the
switching of H-Bridge explained above.
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
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>
59
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
int i,j;
void Timer_init()
TL0 = PWM_Period;
60
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
PWM_Out_Pin = !PWM_Out_Pin;
if(PWM_Out_Pin)
TL0 = ON_Period;
else
TL0 = OFF_Period;
/* Calculate ON & OFF period from PWM period & duty cycle */
61
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
/* 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()
Timer_init();
Motor_Init();
while(1)
if(Speed_Inc == 1)
Speed += 10;
Set_DutyCycle_To(Speed);
while(Speed_Inc == 1);
delay(200);
62
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
if(Speed_Dec == 1)
if(Speed > 0)
Speed -= 10;
Set_DutyCycle_To(Speed);
while(Speed_Dec == 1);
delay(200);
if(Change_Dir == 1)
M1_Pin1 = !M1_Pin1;
M1_Pin2 = !M1_Pin2;
while(Change_Dir == 1);
delay(200);
} } }
63
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
OUTPUT:
64
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
1.AIM:
2.INTRODUCTION:
3.PARAMETERS:
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.
The relation between RPM, steps per revolution, and steps per second is
like below:
Steps per Second = rpm x steps per revolution / 60
65
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
The following table is showing the sequence of input states in different windings.
66
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
2.Full 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.
3.Half 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 .
67
EX.NO:3 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.
68
EX.NO:3 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;
int i;
for(i=0;i<count;i++);
void main()
while(1)
stepper=0x01;
delay(350);
stepper=0x02;
delay(350);
69
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
stepper=0x04;
delay(350);
stepper=0x08;
delay(350);
#include<reg51.h>
sfr stepper=0xA0;
int i;
for(i=0;i<count;i++);
void main()
while(1)
70
EX.NO:3 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);
71
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
OUTPUT:
72
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
1.AIM
To understand and implement LM35 and LDR in the 8051-development kit with the
help of programming.
2.INTRODUCTION:
Figure 9 LM35
73
EX.NO:3 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.
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.
74
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
Figure 11 ADC0804
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.
75
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
CODE:
76
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
/* 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);
77
EX.NO:3 INTERFACING SENSORS AND ACTUATORS USING 8051 DEVELOPMENT
13.09.23 KIT
}
}
OUTPUT:
CONCLUSION:
78