I found out that I can use a capacitor in order to get the data from an analog sensor in a digital manner(Connecting the analog sensor to the GPIO of a Raspberry Pi).

I have a 1μF polarised capacitor. Is it suitable? How should I connect it in order to work?

The sensor I'm talking about is the below push sensor.

Is it ok to connect GND to GND, VCC to 3.3V Power and the capacitor with the positive branch to OUT and with negative to the GPIO pin?

Here is the datasheet of the sensor: http://www.robofun.ro/docs/2010-10-26-DataSheet-FSR400-Layout2.pdf

Thank you!

enter image description here

  • 1
    \$\begingroup\$ You need to tell us a lot more about the sensor and the signal it produces before this question can be answered. \$\endgroup\$
    – Dave Tweed
    Feb 23, 2016 at 13:30
  • \$\begingroup\$ Looks interesting.I may give you a vote if you give more information about your setup(because there isn't enough). \$\endgroup\$ Feb 23, 2016 at 13:38
  • \$\begingroup\$ This site is good for showing the basics of various circuits, including basic capacitor circuits falstad.com/circuit \$\endgroup\$
    – Cameron
    Feb 23, 2016 at 13:40
  • \$\begingroup\$ THis is the datasheet robofun.ro/docs/2010-10-26-DataSheet-FSR400-Layout2.pdf \$\endgroup\$
    – yonutix
    Feb 25, 2016 at 7:40
  • \$\begingroup\$ Did you know there is a circuit tool, you could draw a circuit. \$\endgroup\$
    – Voltage Spike
    Feb 25, 2016 at 7:56

3 Answers 3


Use two GPIO pins, alternate between input and output mode


Discharge the capacitor

Charge one known resistor

Discharge capacitor

Charge the UNKNOWN resistor (the sensor)


Use GPIO as input mode to detect the charge up reaching theshold (about mid point voltage)

This technique allow simple low cost MCU without build in ADC to read analogue sensor (variable resistance depending on sensed quality), including temperature (thermistor), humidity, light (CdS), force, etc.

Good absolute accuracy if the known resistor is high accuracy. Tolerance of capacitor is cancel out.

Widely used in consumer electronics device. Have excellent resolution, can be up to 16 to 20 bits or so. Typical conversion time in range of 100ms. Faster conversion can be traded with smaller resolution. Can use MCU hardware timer.

Raspberry Pi (vs Arduino) has no build in ADC and this technique is often used.

One pin version, lower absolute accuracy as affected by capacitor tolerance. http://www.raspberrypi-spy.co.uk/2012/08/reading-analogue-sensors-with-one-gpio-pin/

Also, three pin version, use one pin for sensing (input mode) and quick discharge (output), for quicker conversion time.

  • \$\begingroup\$ It is the most detailed answer until now, however a scheme and the validation of other users wouldn't hurt \$\endgroup\$
    – yonutix
    Mar 2, 2016 at 13:20
  • \$\begingroup\$ For decades, this technique is widely used in temperature and humidity display, mass manufactured in many millions. \$\endgroup\$
    – EEd
    Mar 2, 2016 at 13:26

This is a force sensing resistor. You can make a capacitor-based analog to digital converter using timing differences. Essentially you will have two R-C circuits using a known value precision resistor and your sensor and the same capacitor.

Since capacitance can vary over time and temperature, you will use the precision resistor to cancel out this variation. I don't have time to draw a diagram, but the premise is that one end of each resistance is connected to an output pin, the junction of the other end of the resistances and the capacitor is on an input pin, and the other leg of the capacitor is grounded.

Now, discharge the capacitor and then begin to charge it through the known, fixed resistor. Time how long it takes until you read HIGH at the capacitor input. Discharge it again, and this time charge it through the sensor resistance and time how long it takes to read a HIGH. The ratio of the times is the ratio of the resistances.

There are improvements that can be made, but this is a basic single-slope A/D converter method.


  • \$\begingroup\$ Like this? dropbox.com/s/m1ygb0oxz03r4pn/Drawing.png?dl=0 \$\endgroup\$
    – yonutix
    Feb 29, 2016 at 11:36
  • \$\begingroup\$ No. You can do it the way Srdjan suggests and it will probably work just fine. Many computer joysticks used to work that way. The method I suggested is just more precise. Anyway, one capacitor leg and one of each resistor leg and an input pin form a node. The other resistor ends go to output pins and the other capacitor end is grounded. \$\endgroup\$
    – lyndon
    Mar 2, 2016 at 1:39

It can be done. Just put the capacitor instead of the 10k resistor in the picture. Make sure to connect negative wire of the cap to ground. The way it works is simple. Push sensor is just a resistor, and its resistance drops when you push it. If the resistance iz high (1 Megaohm) it will take about 1 second to charge the cap to around 2V (Raspberry Pi high input voltage). Datasheet said that the resistance of a sensor is 10 Megaohm unpressed, that means 10s, more like never. But, it chould drop like crazy if I read it correctly. In software switch pin that you are using to output low, discharge the cap. Than switch it to input ant start mesuring the time it takes to go high. All that said, I would recommend first mesuring the resistance of the sensor vith a multimeter, if you have one. Use smaller cap if the resistance is still in Megaohms when you press it. How much pecision do you want out of it anyway?

  • \$\begingroup\$ 5-10% noise would be nice \$\endgroup\$
    – yonutix
    Feb 29, 2016 at 11:59
  • \$\begingroup\$ I recomend using a multimeter to measure the resistance of the sensor with no preassure, max weight/preassure you want to use and with a few weights in between. Knowing the range of values you want to get to the Pi would help us help you. If you can't find one you can go to the store that sells them and use one for a few min. I'm curious about what are building with that sensor. \$\endgroup\$ Mar 2, 2016 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.