Hi all,
I'm trying to do some data logging on my greenhouse, but I'm getting some inconsistent values from my analog pins.
Specifically, I have 6 sensors, using all of the UNO's analog pins A0-A5.
I have 2x TMP36 temperature sensors (inside and outside temperature), 2 moisture sensors (nails on wires), a light sensor, and eventually will have a water level indicator for the rain barrel.
All the sensors seemed to work well individually when I tested things separately (and with short leads), but now the numbers seem to vary a lot from one reading to the next, at least for my temperature sensors (I think the others need some fine tuning of expected ranges).
I take a reading every 15 minutes, and store it in an array. I have a bluetooth adapter hooked up, so I can take my laptop to the room nearest the greenhouse and connect wirelessly to the Arduino that way. I can then type in a command and see the data that was stored, and I can get the current values.
To save it from added power drain I thought I would use D12 as my power pin. So D12 is usually low, but just before reading the values I set it high to provide 5V to the two temperature sensors (the other sensors just connect to ground). Come to think of it, I think I'll just keep that set to high to remove that extra unknown
So I'm wondering - do the analog pins need to "settle" at all before I take readings? Right now I set D12 high, wait 1 second, and then read each of the analog pins:
digitalWrite(power_pin, HIGH); delay(1000); int insideTemp = readTemp(inside_temperature_sensor); int outsideTemp = readTemp(outside_temperature_sensor); int moistureLevel1 = readMoistureLevel(moisture_sensor1); int moistureLevel2 = readMoistureLevel(moisture_sensor2); int waterLevel = readWaterLevel(waterlevel_sensor); int sunshineLevel = readSunshine(sunshine_sensor); // prints stuff to BTSerial port here digitalWrite(power_pin, LOW);
The TMP36 sensors are hooked up to 5v, AnalogPin, Gnd (as per the oomlout example).
All of the other sensors are connected just via 2 wires each: ground and analog pin. I'm using the internal pull-up resistors as follows:
pinMode(moisture_sensor1, INPUT); digitalWrite(moisture_sensor1, HIGH); // use pullup resistor
The Arduino is set up in my garage, and uses about 15 feet (5 meters) of CAT-5 cable to connect to the sensors in the greenhouse. CAT-5 has 4 pairs, or 8 wires. I use 1 wire for 5v, 1 for Gnd, and the other 6 are for each of the Analog pins. I soldered a header on the greenhouse end to bring out 6x Gnd connections and 2x 5v connection, so that all sensors can be plugged in that way.
So my questions are:
1. Do I need to do anything special for the analog reads, or is my procedure ok? For example, would it make sense to wait between readings, or take 15 readings per pin and use the average?
2. Does the length of the sensor wires cause a problem?
3. Does sharing the GND over that distance cause an issue?
4. I realize that the waterlevel sensor is not connected, but I have a pullup resistor in place which puts it to a constant 5v, or 1023. This wouldn't affect any other pin readings, would it?
Thanks!
-Nico