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 - Mini Photocell - SEN-09088 - SparkFun Electronics
1 temperature sensor - Temperature Sensor - TMP36 - SEN-10988 - SparkFun Electronics
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);
}
}