Reading LM35 with RaspberryPi using amplified RC timer

images-1Inarguably Raspberry Pi has single-handedly brought sci-fi dreams to an ordinary engineer’s desk. If they can send satellites to space using RPi (Astro Pi)then your home automation is cutting butter with hot butcher-knife. RPi simply is over qualified for the job, least to say..


Don’t be deceived by the looks , that is a dynamite of a computing device. Once you own it you become an instant fan of this piece of hardware

Back on the ground, though there must have been a reason why they  have provided 26 digital GPIO (General purpose input output) pins on it and none for analog measurement. It would be naive to dismiss this as a shortcoming and insipidly use RPi only for blinking some LEDs. Often makers with limited budget would build RC timer with discrete components at hand, before moving onto MPC3008 or even better a 16 bit ADC channel. I had a prejudice towards available ICs and always thought of getting the job done earlier rather than having to build  RC timer all by myself.

But believe me there is no fun in letting the IC do that job for you. All you need is a resistor,capacitor, multimeter and you are all set for the circus.

I’m in no way downplaying the role of ICs; what a MPC3008 can do certainly is exclusive. As a tinkerer (if you may call me that ) I just loved fooling around with the “bare basic” components, building my own logic. Armed with only a multi-meter and hand-rolled python code , I realized pure happiness in this world is free , well almost 🙂

“LM35” what about it ? :
Is a humble resistive temperature sensor sending out meek voltage-signals corresponding to temperature in the surrounding. It has a 10mV/oC gain, for simpletons- room temp (25oC) it should send a signal of 250mV and that’s how your system knows how warm is it.

But then was LM35 really built for RPi?
RPi is from another generation.The lowest HIGH signal for any of the GPIO  pins is 1.34V and from numerous documentation we have- that all the pins are 3.3V tolerant pins on the upper side with no pin supplying /sinking more than 16mA (rpistackexchange)  Well , that means LM35 can keep sending signals to RPi , and RPi pays no heed. So even if you were to charge the capacitor with that LM35 voltage signal, RPi cannot read that.

IL358N to the rescue:
Op-Amps are those handy components that can step up the signal voltage against a preset amplification factor. If we can direct the signal from charged capacitor before it feeds the RPi GPIO  we can actually measure the voltage from LM35

With amplification comes limited range :
Op-Amps by theory can step up the voltage to any ceiling. If one wants to save your RPi from giving out that “magic smoke” one better not allow any more than 3.1V as the HIGH signal. So while you can amplify the signal you cannot expect RPi to work at all the levels.

Just to put things in tabular perspective..

Temp (oC) From LM35 (Volts) Op-Amp Amplification RPi GPIO-IN (Volts)
25 0.250 5.36 1.34
30 0.30 5.36 1.6
61.5 0.61 5.36 3.3

You can notice how I can now deal with any voltage between 25oC and 61.5oC with good amount of accuracy but any less than the “floor” would be unnoticed and any greater than “ceiling” is dangerous for RPi

The circuit I used:


Code I rolled up is based on the understanding of RC timings from here : RC timing

Feel free to drop me questions on the circuit and the code anytime.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

Up ↑

%d bloggers like this: