Pages: [1]   Go Down
Author Topic: Problems with temperature sensor and mini photocell used together  (Read 619 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello good day everyone. I am building a project where i have 4 outputs going to led's and 4 inputs. The 4 inputs are:

2 Rainsensors - http://www.seeedstudio.com/depot/datasheet/Electronic%20brick%20-%20water%20sensor.pdf

1 light sensor - https://www.sparkfun.com/products/9088

1 temperature sensor - https://www.sparkfun.com/products/10988

These 4 inputs were used as analog inputs. I am having a problem when using both the light sensor and temperature sensor together. Alone they work just fine and are accurate but once they are used together. Nothing works. The leds don't work as they are supposed to and the temperature is way off. I've done some research and some have said that its due to multiplexing and the adc needing time to reach the voltage. Others said maybe the temperature sensor is too high impedence. I tried adding several delays and also analogreads since it was suggested that this was the solution but once i use both sensors simultaneously i get the same result. Nothing works. Any help would be greatly appreciated. Below is my code.

***********************************************************************************************************************************************************************
used for arduino in the automated Cocoa House


/*

Declaring of Variables
*/
int rainsensor1 = A2; //rain sensor1 input
int rainsensor2 = A3; //rain sensor2 input
int lightsensor = A0; //light sensor input
int tempsensor = A11; //temperature sensor input
int closingroof = 22; //Output to close roof
int openingroof = 24; //Output to open roof
int turningbeans = 26; //Output to turn beans
int heater = 28; //Output to turn on heater
int rainsensor1val = 0; //storing the value of rainsensor1
int rainsensor2val = 0; //storing the value of rainsensor2
int lightsensorval = 0; //storing the value of the light sensor
int tempsensorval = 0; //storing the value of the temperature sensor
float voltage = 0; //volate calculated from output of temperature sensor
float temperature = 0; //temperature calculated with voltage converted from temperature sensor



void setup()
{
Serial.begin(9600);
pinMode (rainsensor1,INPUT); //setting rain sensor 1 as an input
pinMode (rainsensor2,INPUT); //setting rainsensor 2 as an input
pinMode (lightsensor,INPUT); //setting the light sensor as an input
pinMode (tempsensor,INPUT); //setting the temperature sensor as an input
pinMode (closingroof,OUTPUT); //setting an output used to close roof
pinMode (openingroof,OUTPUT); //setting an output used to open roof
pinMode (turningbeans,OUTPUT); //setting an output to turn beans for 5 minutes
pinMode (heater, OUTPUT); //setting an output to turn the heater on
}


void loop()
{
rainsensor1val=analogRead(rainsensor1); //storing of rainsensors, light sensor and temperature sensor inputs
rainsensor2val=analogRead(rainsensor2);
analogRead(lightsensor);
delay(10);
lightsensorval=analogRead(lightsensor);
analogRead(tempsensor);
delay(10);
tempsensorval=analogRead(tempsensor);
voltage = tempsensorval * (5000/1024); //calculating volate from input of temperature sensor
temperature = (voltage / 10); //calculating temperature from the voltage calculated

Serial.println("First Rainsensor value = ");
Serial.println(rainsensor1val);
Serial.println("Second Rainsensor value = ");
Serial.println(rainsensor2val); //Output to screen values of sensors
Serial.println("Light Sensor value = ");
Serial.println(lightsensorval);
Serial.println("Temperature in Celcius = ");
Serial.println(temperature);
//delay(3000);

if (rainsensor1val <= 200 || rainsensor2val <= 200 || lightsensorval <= 300)
{
digitalWrite (closingroof,HIGH);
digitalWrite (openingroof,LOW);
digitalWrite (heater,HIGH);
digitalWrite (turningbeans,HIGH); //causes roof to close, heater to come on and turning of beans for 5 minutes if conditions met
}
else if (rainsensor1val > 200 && rainsensor2val > 200 && lightsensorval > 300)
{
digitalWrite (openingroof,HIGH);
digitalWrite (closingroof,LOW);
digitalWrite (heater,LOW); //causes roof to open, heater to come off and turning of beans for 5 minutes if conditions met
digitalWrite (turningbeans,HIGH);

}

}
***********************************************************************************************************************************************************************
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Won't even compile for me:

sketch_aug12a:7: error: 'A11' was not declared in this scope

You probably meant A1.

Code:
tempsensorval=analogRead(tempsensor);
voltage = tempsensorval * (5000/1024); //calculating volate from input of temperature sensor
temperature = (voltage / 10); //calculating temperature from the voltage calculated

Since 5000/1024 == 4 (not 4.88 because you are using integers) your value will be way off.
Try "voltage = (tempsensorval * 5000UL) /1024;"
Note the "UL" on the end of 5000 to make it an unsigned long.  This will prevent an integer overflow since a regular integer can only hold 32767 and 1023*5000 is quite a bit bigger than that.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks alot John.I can use that to get more accurate readings.however I still can't use both the photocell and temp sensor together.thats the main problem.A11 is an Analog input on My arduino.I am using the arduino At MEGA 2560.My main concern is having both the sensors work together.thank you very much for your feedback.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is your LDR (light sensor) connected?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: