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.
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 -
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 -
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,
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.
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
}
}
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
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- How to connect the interface to implement ADC using 51 development board
- Analog Discovery 2 Review (5) Acquisition System Hardware Analysis
- Embedded USB driver-free device communication method based on WinUSB
- Data Accuracy for Power Management
- Application of Chemical Vapor Deposition in Back-end Process of Integrated Circuit Manufacturing
- Application of Computer Control Technology in Tire Vulcanization System
- Which hero can give me a programming manual for STM32F030XX
- Application skills/Three-phase energy meter SA9904B acquisition system based on MSP430
- GD32 Competition - Motor Control - Hardware Design
- Guo Tianxiang's New Concept 51 MCU C language tutorial. Getting started, improving, and developing