Week 11
Input devices.
This week the assignment is to add a sensor to a microcontroller and read it. I wanted to make a capactive touch sensor for this week assignment. I watched many videos that domenstrates the different concepts behind touch sensors. I choose to go with the capacitive touch.
Capacitors store electrical energy in an electrical field. When we charge the capacitor the voltage across its plates increases. The capacitance of the capacitors affects its charge time and also the resistor connected in series with it. When the capacitance increases, the charge/discharge time increses. Adding a resistor in series with the capacitor makes it charge/discharge slowly, so when the resistor increses the charge/discharge time increases.
The concept of the circuit is to charge the capacitor and then turn the source of charge off. The capacitor will discharge through the resistor to the ground. We measure the time it takes the capacitor to discharge. If i touch the plate the capacitance will increase and thus the discharge time will be longer. So i can determine if the plate is touched or not by measuring the time of discharge and compare it to a threshold.
I could of just used a touch plate to make a capacitor but i added a 10pF capacitor with the touch plate for more stability. I use microncontroller pin to charge the capacitor and then configure it as input to measure the time it takes to discharge(to be logic 0 which is around 0.2 volt).
I wasn't sure that the idea will work because the orignal deisgn is based on a switching element to charge the capacitor and the microcontroller to just measure the time it takes to discharge. I wanted to use the same pin to charge and measure. I designed a simple circuit with attiny45, touch sensor, and FTDI cable to communicate with the compuer.
Download the eagle files.
Touchsensor_V1.schDownload the exported images
Touchsensor_V1_traces.pngI wrote a program to do the following:
1- Set the pin as ouput and write high.
2- Wait for the capacitor to charge.
3- Set the pin as input.
4- initialise the counter.
5- Wait for the capacitor to discharge (when the PINx is LOW).
6- Send the value of the counter to computer over serial.
I also wrote a simple python program that reads the serial and print the value recieved.
Download the source code:
Touchsensor_V1.cCompile the code by writing make -f Touchsensor_V1.c.make
Upload the HEX file by writing make -f Touchsensor_V1.c.make program-usbtiny
It worked pretty good. It normally sends 1 but when i touch the plate the number go beyound 1.
This time i'm going to add 4 sensors.
I made the touch pad bigger this time.
Download the eagle files.
Touchsensor_V2.schDownload the exported images
Touchsensor_V2_traces.pngThe program have not changed a lot, i duplicated the same routine for every pin. I also added a part to compare the value against a thershold(i determined the value by testing the sensor using serial) to test if the plate is touched or not and combine the whole 4 sensor values in a buffer and send them over serial.
Download the source code:
Touchsensor_V2.cCompile the code by writing make -f Touchsensor_V2.c.make
Upload the HEX file by writing make -f Touchsensor_V2.c.make program-usbtiny
I modified Neil's python interfacing program and made this simple interface. It simply displays the currently touched plates.
The circuit is super fun and the sensors are very precise and stable. And this version is better because i the touch pads is bigger. You can watch a video of the circuit in action.
Fab Academy - Week 11 - Input devices from Mohamed Kamel on Vimeo.
That's all for week 11 !