I'm trying to create a circuit that has 3 sensors on it - an LM35 temperature sensor, a photocell for light level measurement and an MQ2 gas sensor shield for pollutants.
I have a circuit that is working, but as soon as I added the photocell, the readings off the LM35 increased by a approx 8 units, or 4deg celcius.
Note that the diagram does not include the gas sensor - I couldn't find one in Fritzing. The addition of the gas sensor does not seem to change the LM35's reading.
My electronics knowledge is practically zero, but I'm guessing it has something to do with the additional load affecting the LM35's output. However, I'm further perplexed as to why the addition of the gas sensor does not have a similar result.
Any help or comments are greatly appreciated.
The circuit :
The code :
long start=0; //the counter used to track milliseconds for uploading every nn seconds
int samplePeriod=4999; //the amount of time in milliseconds between serial writes
long n=0; // number of samples
int officeTemperatureSensorPin =5; //temperature sensor is connected to analog pin 5
float officeTemperatureAvg = 0.00; // the average
int officeLightSensorPin = 4; //temperature sensor is connected to analog pin 4
float officeLightAvg = 0.00; // the average
int airQualityPin=1;
float airQualityAvg = 0.00; // the average
//This is to cater for a faulty circuit - when both temp and gas sensors are connected,
//the temp sensor reads 3-4 degress higher.
int temperatureOffset=3.5;
void setup(){
Serial.begin(9600);
start=millis();
//Wait a bit before accessing the sensor to avoid noise
delay(500);
}
void loop()
{
// increment sample count
n++;
// get samples from all sensors and calculate moving average
officeTemperatureAvg += (analogRead(officeTemperatureSensorPin)-officeTemperatureAvg) / n;
delay(10);
officeLightAvg += (analogRead(officeLightSensorPin) - officeLightAvg) / n;
delay(10);
airQualityAvg += (analogRead(airQualityPin)-airQualityAvg) / n;
delay(10);
//if we've been going longer than the samplePeriod var, write the data to the serial port
if(millis() > start + samplePeriod)
{
//Office Temperature
printToSerial('A',officeTemperatureSensorPin,(officeTemperatureAvg/2.01)+temperatureOffset);
officeTemperatureAvg=0;
//Office Light
printToSerial('A',officeLightSensorPin,officeLightAvg);
officeLightAvg=0;
//Office Air Quality
printToSerial('A',airQualityPin,airQualityAvg);
airQualityAvg=0;
//reset;
n=0;
start=millis();
}
delay(2);
}
void printToSerial(char pinType,int pinNumber,float value){
Serial.print(millis());
Serial.print(":");
Serial.print(pinType);
Serial.print(pinNumber);
Serial.print(":");
Serial.println(value);
}
Try reading the input twice in succession and using the second value. There is only one A/D converter and if you input impedance is too high it can take a little longer to settle when you switch to a new channel.
Grumpy_Mike:
Try reading the input twice in succession and using the second value. There is only one A/D converter and if you input impedance is too high it can take a little longer to settle when you switch to a new channel.
Hi Mike,
Thanks for your response.
I've tried reading twice (even went to three times), but no change I'm afraid.
but I'm guessing it has something to do with the additional load affecting the LM35's output.
No.
Measure the voltages on the analogue inputs and see if you can see the change with a meter.
Write a much simpler sketch that just reads the two channels and prints them out and see if you still have the same problem.
A schematic would be good. What is that blue component close to the temperature sensor.
but I'm guessing it has something to do with the additional load affecting the LM35's output.
No.
Measure the voltages on the analogue inputs and see if you can see the change with a meter.
Write a much simpler sketch that just reads the two channels and prints them out and see if you still have the same problem.
A schematic would be good. What is that blue component close to the temperature sensor.
Hi Mike,
It's worth mentioning at this point (as if you haven't worked it out already), that I have an extremely rudimentary understanding of electronics, but a 25 year Microsoft based (VB6, ASP, C# etc) programming background. I did an electronics course (Basic Certificate of Electronics) about 20 years ago, but most of it's a fading memory.....V=IR is kinda familiar
Re: A schematic (and to MarkT)
My elementary electronic knowledge does not allow me to draw one by hand, let alone in a format I can post here.
I tried the schematic view in Fritzing, but it's not the view I'd expect to see if someone asks for a schematic, but please let me know if you want to see it anyway.
The blue component is a 100nF cap across the power inputs of the LM35, apparently acting as a 'decoupling capacitor'. The idea as far as I can understand is to make the LM35 draw power from this cap when it needs to do it's reading, in an attempt to ensure a more stable voltage at the Vcc leg of the LM35 when the reading is taken. Please feel free to point out any errors in my understanding of this cap - it's all pieced together from reading stuff on the web, along with posts on this forum, so it's quite possible I've got it all wrong
I have run a 'test' version of that sketch that has nothing but 2 readings from 2 components and got the same results as soon as the second component was introduced.
Would you mind telling me 'in dummy's guide format' (as my knowledge level obviously requires) the tests I need to perform to measure the voltages to get the voltages you suggested?
Would you mind telling me 'in dummy's guide format' (as my knowledge level obviously requires) the tests I need to perform to measure the voltages to get the voltages you suggested?
You take a multi meter set to volts.
Put the black wire on the ground.
Then put the red wire on the analogue connection into the arduino from the temperature sensor. Make a note of the reading. Now move the red wire to the light resistor and make a note of the reading.
Finally move the red wire back to the temperature sensor, look at the reading and then remove the analogue input from the light sensor.
Do you see a change in voltage like you see a change in the reading of the voltage from the arduino?