How to control LED lights using touch sensor and 8051 microcontroller

Publisher:RoboPilotLatest update time:2023-10-26 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In this project we are interfacing touch sensor with 8051 microcontroller AT89S52. If you are new to 8051 microcontrollers then you can start the 8051 by blinking an LED.


What is a capacitive touch sensor?

Capacitive touch works on the electrostatic charges available on our bodies. The screen is already filled with electric fields. When we touch a screen, a closed circuit is formed due to the static charge flowing through our body. Additionally, the software determines the positions and actions to be performed. Capacitive touch screens don't work with gloves because there won't be any conduction between the fingers and the screen.


Touch sensor used in this project

The touch sensor used in this project is a capacitive touch sensor module, and the sensor driver is based on the driver IC TTP223. IC TTP23 operates at a voltage of 2.0V to 5.5V and the current consumption of the touch sensor is very low. Touch sensors based on TTP223 are popular in their market segments due to their low price, low current consumption and easy integration support.

pYYBAGMYRDiAZq4PAAMc3AxFC38466.png

In the image above, both sides of the sensor show where the pinout is clearly visible. It also has a solder jumper that can be used to reconfigure the sensor based on the output. The jumpers are A and B. In the default configuration or in the default state of the solder jumpers, the output changes from low to high when the sensor is touched. However, when the jumpers are set and the sensor is reconfigured, the output changes its state when the touch sensor detects a touch. The sensitivity of the touch sensor can also be configured by changing the capacitance.

The image below shows the different outputs with different jumper settings -

pYYBAGMYRDOAUayDAAAPR-M7xnc945.png

For this project, the sensor will be used in the default configuration available in factory release conditions. In this project, touch sensor will be used to control AC light bulb using AT89S52 microcontroller.

The relay is connected with 8051 microcontroller. The pinout of the relay is as shown in the figure below -

poYBAGMYRDCAKT_4AAI3cZcFHZY948.png

NO is always open, NC is always connected. L1 and L2 are the two terminals of the Relay coil. When no voltage is applied, the relay is closed and POLE is connected to the NC pin. When voltage is applied to the coil terminals, L1 and L2 of the relay are turned on and POLE is connected to NO. Therefore, the connection between POLE and NO can be opened or closed by changing the operating state of the relay.

materials needed

AT89S52 8051 microcontroller

Standard Cube Relay - 5V

11.592 MHz crystal oscillator

33pF capacitor - 2 pcs.

2k resistor-1

4.7k resistor - 1 pc

10uF capacitor

BC549B transistor

TTP223 sensor

1N4007 diode

light bulb with socket

Breadboard

5V power supply, a mobile phone charger can work.

Lots of jumper or berg wires.

AT89S52 programming environment with Programmer Kit and IDE with compiler

Circuit schematic

A schematic diagram of controlling light using a touch sensor and 8051 is shown below,

poYBAGMYRCmARV71AAB9b9iouIM301.png

Transistors are used to turn relays on or off. The touch sensor is connected to AT89S52 microcontroller unit. The circuit was built using a breadboard.

pYYBAGMYRC2ACLKeAAO97-yc2gM804.png

Programming the Atmega AT89S52 Microcontroller

Finally, the complete 8051 code is given. Here we explain several parts of the code. If you are new to 8051 microcontroller then first learn how to program 8051 microcontroller.

The following lines of code are used to integrate relays and touch sensors with 8051 microcontroller. REGX52 is the header file of AT89S52 microcontroller unit. A delay function is also declared.

#include


// RELAY Pin 

sbit RELAY = P1^0; // Pin P1.0 is named RELAY


//Touch sensor pin

sbit Touch = P1^1; // Pin P1.1 is named Touch Sensor


//Function declaration

void delay(char ms);

Touch and relay are initialized to 0. Touching the sensor changes logic 0 to 1. If the statement is true when the touch sensor is activated, the state of the relay changes. However, to detect touches accurately, a debounce delay is used.


// main function

void main(void) 

{


   relay = 0;


     touch = 0; 

   while(1){ 

             if (Touch == 1){ 

                   delay(15); //Debounce delay

                   if (Touch == 1){ 

                         RELAY = !RELAY; //Switch relay pin

                         delay(30);

                   }                       

            }                

     } 

}

Next, write the delay function. The function accepts input in millisecond format and uses two for loops to generate the delay. This delay is less accurate but acceptable and depends mainly on clock cycle timing.


/*Delay related functions*/ 

void delay(char ms){

    integer a, b;

    for (a=0;a<1295;a++){

            For (b=0; b


This touch-controlled light circuit was tested on a breadboard with a low-power bulb connected.


/* Name: touchsensor.c


*Purpose: For use in circuit abstracts. Touch sensor interfaced with 8051 (AT89S52)


*/


#include


//relay pin


Bit relay = P1^0; // Pin P1.0 is named RELAY


//Touch sensor pin


sbit touch = P1^1; // Pin P1.1 is named Touch Sensor


//Function declaration


void delay(charms);


// Main function


void main(void)


{


relay = 0;


touch = 0;


And (1){


if (touch == 1) {


delay(15); //debounce delay


if (touch == 1) {


relay=! Relay; // Switch relay pin


delay(30);


}


}


}


}


/*Delay related functions*/


void delay(charms) {


integer a, b;


for (a=0;a<1295;a++){


For (b=0; b


}


}


Reference address:How to control LED lights using touch sensor and 8051 microcontroller

Previous article:What are the reset methods for 8051 microcontroller?
Next article:How many interrupt sources are there in 8051 microcontroller? There are several interrupt sources in 8051 microcontroller.

Popular Resources
Popular amplifiers
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号