Your EasyEDA usage duration is brief. In order to avoid advertising information, this action is not supported at present. Please extend your EasyEDA usage duration and try again.
# TinyTouchLight - Dimmable USB Night Light with Capacitive Touch Control
TinyTouchLight is a dimmable USB night light with capacitive touch control based on the ATtiny13A. It plugs into any USB charger or power bank.
- Project Video (YouTube): https://youtu.be/TYuayp2b2vI
- Firmware (Github): https://github.com/wagiminator/ATtiny13-TinyTouchLight
![TinyTouchLight_pic3.jpg](https://raw.githubusercontent.com/wagiminator/ATtiny13-TinyTouchLight/main/documentation/TinyTouchLight_pic3.jpg)
# Capacitive Touch Button
## Introduction
This implementation of a touch-sensitive button (touchkey) is based on the charge sharing approach similar to [Atmel's QTouchADC](http://ww1.microchip.com/downloads/en/Appnotes/doc8497.pdf) and [Tim's TinyTouchLib](https://github.com/cpldcpu/TinyTouchLib). It works without external components, only a resistor for noise reduction is used, which can also be dispensed with. The touchkey itself is a small copper area on the PCB (sense electrode), which is covered with solder mask. This sense electrode is connected to a single ADC-capable pin of the ATtiny via the resistor.
## Basic Principle
The touch sense pin (here PB4) is connected through series resistor RS to the sensor electrode capacitance, represented by Cx. The switch SW represents a finger touching the key. The capacitance introduced by the finger is represented as Ct. When the key is touched, Ct is switched into the circuit forming a parallel capacitor with Cx, changing the effective sensor capacitance to Cx + Ct.
![TinyTouchLight_principle.png](https://raw.githubusercontent.com/wagiminator/ATtiny13-TinyTouchLight/main/documentation/TinyTouchLight_principle.png)
It should be noted that Cx and Ct are not physical capacitors. Cx is the effective capacitance of the sense electrode and Cx + Ct is the effective capacitance of the human finger touching the sensor.
## Component Selection
The series resistor RS is nominally 1kΩ, but it may be increased to higher values to improve the noise immunity of the circuit. The value of RS should be increased in steps to find the lowest value that provides adequate noise immunity. Resistance values of up to 100kΩ have proven to be useful in extremely noisy environments. For this application a 47kΩ resistor was chosen.
The value of Cx should be close to that of the ADC’s internal sample-and-hold capacitor CS/H (~14pF). For best performance it is recommended that Cx+t should not be greater than ~60pF. If the sensor electrode is designed as a copper surface on the PCB, then it should be roughly as large as the contact surface of a finger (8-15 mm in diameter if the touchkey sensor is round, or with a 8-15 mm side if the touchkey sensor is square). There shouldn't be any traces on the other side of the PCB. The back side can have a ground plane, but this should not be a solid fill.
## Sensor Acquisition
The acquisition method works by sharing charge between the ADC’s internal sample-and-hold capacitor (CS/H) and the sense electrode capacitance (Cx). When the sensor is touched the effective capacitance of the sensor electrode increases and becomes Cx + Ct. This affects the amount of charge shared between the capacitors. When pre-charging Cx and sharing with CS/H, charge transferred to CS/H increases on touch and ADC input voltage increases. When pre-charging CS/H and sharing with Cx, charge remaining on CS/H decreases on touch and ADC input voltage decreases. But the resulting signal from the averaged ADC values increases on touch. If the difference between signal and reference is greater than the user-determined threshold (delta), a touch is reported.
The charge sharing is carried out in the following sequence:
1. Precharge touchkey LOW and S/H cap HIGH.
2. Connect touchkey and S/H cap in parallel. Read the voltage via the ADC.
3. Precharge touchkey HIGH and S/H cap LOW.
4. Connect touchkey and S/H cap in parallel. Read the voltage via the ADC.
5. Calculate the voltage difference and compare it with the user-determined threshold.
### Step 1: Precharge touchkey LOW and S/H cap HIGH.
By setting the touch sense pin (PB4) to OUTPUT LOW, the touchkey is discharged. By setting the ADC muxer to a spare pin (here PB3) and setting this pin to OUTPUT HIGH, the internal S/H capacitor is charged.
![TinyTouchLight_step1.png](https://raw.githubusercontent.com/wagiminator/ATtiny13-TinyTouchLight/main/documentation/TinyTouchLight_step1.png)
```c
ADMUX = TC_SHC_ADC; // connect spare pin to S/H cap
PORTB |= (1
Forked project will be set private in personal workspace. Do you continue?
Clone
Project
The Pro editor is about to be opened to save as. Do you want to continue?
private message
Send message to wagiminator
Delete
Comment
Are you sure to delete the comment?
Report
ATtiny13 TinyTouchLight
Dimmable USB Night Light with Capacitive Touch Control based on ATtiny13A
Announcer: Stefan Wagner
Creation time: 2021-09-05 10:09:06
Published time:
2022-02-03 21:43:27
*
Report type:
Please select report type
*
Report reason:
Please fill in the reason for your report and the content is 2-1000
words
*
Upload image:
+
Upload image
*
Email address:
Please fill in your email address
Report
*
Report type:
Please select report type
*
Report reason:
Please fill in the reason for your report and the content is 2-1000
words
*
Upload image:
+
Upload image
*
Email address:
Please fill in your email address
Report
Submitted successfully! The review result can be viewed in the personal
center, review notification.
Kind tips
Your EasyEDA usage duration is brief. In order to avoid advertising information, this action is
not supported at present. Please extend your EasyEDA usage duration and try again.
Share
Project
Copy
Copy
Scan the QR code and open it on the mobile terminal