Hi guys, bit of newby any advice would be greatly appreciated.
Im trying to run multiple LM35 sensors at once to turn on a cooling fan, but if i add one in parallel the temp becomes very inaccurate, if i add a sensor in a different port it then ignores the original. I have bought a heap of lm35 sensors and are hoping to use them in this project. code as follows.
// Declare variables
float tempC;
int tempPin = 0;
int ledPin = 13;
int fan1 = 5;
void setup ()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(fan1, OUTPUT);
}
JimboZA:
I wondered that too, but I wasn't sure if that was OP's final code. But anyway, wawa's code at #3 a couple of hours ago takes care of that issue.
Yes but the OP won't learn if they just get everything fed to them. This is really a very straightforward problem which should have an obvious solution.
Guilty as charged.
There is a lot more to improve though.
An LM35 is a poor performer with simple code like this.
One degree C accuracy/stability at best.
Reading the sensors with 1.1volt Aref enabled, multiple reads, and/or some form of smoothing and calibration is needed to get accuracy and stability <= 0.1 degree C.
Leo..
Putting a 1k resistor between LM35 output and analog in pin + 0.1uF between analog in and GND, I was able to get 0.1 degree resolution and good stability with this sketch, maybe I'm lucky or its a fluke, but it works great. I don't have a second LM35 to try a multi sensor version.
Make sure you understand the difference between "precision" and "resolution" - "0.1 degree resolution and good stability" does not mean it was accurate to 0.1 degree - for that you have to work the calibration issue. Good stability and resolution is a good start, but it needs to be calibrated for what you are asking.
wow, thanks Wawa, ill try that. As far as reading the other sensors i added another pin for each senor and another tempc. Yes i am very much a newbie, and have recently re-kindled my love electronics and cant wait to get a handle on code writing. Thanks all for you inputs.