01-02-12, 01:53 PM | #1 |
Super Moderator
Join Date: May 2009
Location: Warsaw, Poland
Posts: 961
Thanks: 188
Thanked 110 Times in 86 Posts
|
DIY weather station
My temperature logger project has gotten a little carried away: I added 2 humidity sensors to the initial 4 temperature sensors, then an LCD display, and now I don't have enough pins for the SD card shield anymore It's pretty much a weather station at the moment, and that's not the end of it - the goal is a fully functional thermostat. I started this thread to document the weather station side of the project, the desciption of the thermostat part (once it gets that far) will go into a more relevant thread.
Over the next few posts I'll go over the hareware, share the code and explain how it works. I'll start with the housing for the external sensors and work my way indoors. The housing for the outdoor sensors is made of 6 stacked plastic cottage cheese containers. The 2nd, 3rd and 4th have a hole in the bottom. I used straws cut to 2.5cm as spacers. It's mounted about 120cm (48in) above the ground and 50cm (20in) from the east corner of the house. I plan to add an aluminum foil 'hat' to protect it from the sun's heat and UV. Even better would be a small PV on the top which would power a fan to keep the air moving inside, but I'm not going that far, yet.
__________________
Ecorenovation - the bottomless piggy bank that tries to tame the energy hog. |
01-03-12, 08:22 AM | #2 |
Super Moderator
Join Date: May 2009
Location: Warsaw, Poland
Posts: 961
Thanks: 188
Thanked 110 Times in 86 Posts
|
Sensors
To measure temperature I'm using MCP9700-E/TO sensors. They can use either the 3.3V or 5V supply voltage and they show a 10mV difference per °C.
Code:
float temp; temp = analogRead(0) * 5 / 1024.0; // reading * supply voltage / analog resolution (10-bit = 1024) temp = temp - 0.5; // scaling to 0°C (sensor shows 500mV at 0°C) temp = temp / 0.01; // 10mV/°C CAUTION!! Fooling around with the AREF pin can be dangerous to the Arduino. Please do not do anything you do not understand. I take responsibility only for what I do to my own Arduino. Here is the code for improved resolution: Code:
#define AREF_VOLTAGE 3.3 void setup(void) { analogReference(EXTERNAL); } void loop(void) { float temp; temp = analogRead(0) * AREF_VOLTAGE / 1024.0; temp = temp - 0.5; temp = temp / 0.01; } Once the temperature sensors are installed and operational, they should be calibrated, i.e. their readings should be compared to the actual temperature. A digital or IR thermometer, which is known to be accurate, is helpful. The datasheet for these sensors says each one can be off by up to 2 (or was it 4?) degrees, plus long lengths of wiring may cause a voltage drop. Adding this offset value to each reading should correct it. Getting a HCH-1000 humidity sensor working is more difficult. It is a capacitor, and the charge it can store depends on the humidity of its environment. So, the best way to do this is to totally discharge it, then check how long it takes to charge. This is done with two functions: Code:
void discharge(int CHARGE_PIN, int DISCHARGE_PIN, int VOLTAGE_CHECK_PIN) { // Setting pins into discharge mode pinMode(CHARGE_PIN, INPUT); digitalWrite(CHARGE_PIN, LOW); pinMode(DISCHARGE_PIN, OUTPUT); digitalWrite(DISCHARGE_PIN, LOW); // Wait for capacitor to discharge to 0V while (analogRead(VOLTAGE_CHECK_PIN) > 0); } unsigned long charge(int CHARGE_PIN, int DISCHARGE_PIN, int VOLTAGE_CHECK_PIN) { // Setting pins into charge mode pinMode(DISCHARGE_PIN, INPUT); unsigned long begin_time = micros(); pinMode(CHARGE_PIN, OUTPUT); digitalWrite(CHARGE_PIN, HIGH); // 647 - Wait for capacitor to reach 63,2% of charge voltage // while (analogRead(VOLTAGE_CHECK_PIN) < 647); // 1016 - Wait for capacitor to reach 99,3% of charge voltage while (analogRead(VOLTAGE_CHECK_PIN) < 1016); return micros() - begin_time; // Return charging time } Next, the sensor must be calibrated, i.e. you have to know what the charge time is for both extremes (0% and 100% RH). This can be done by putting the sensor into a plastic bag with a dry or wet towel and recording the max and min charge time (data logging is a must, since it takes a few minutes to stabilize). The reason that calibration is needed (instead of just using the extreme values from the sensor's datasheet) is that the wires that lead to the sensor influence the whole system's capacitance. In my case, the wires connecting the outdoor humidity sensor to the Arduino are about 10-12 meters long. The effect is that just those wires (with the sensor removed) act like a much larger capacitor than the sensor itself. During calibration I "clocked" the open circuit charge time as 22210 microsec, while times with sensor for 0% and 100% RH were 25214 and 27380 resp. On the other hand, the indoor sensor, which is suck in a breadboard right next to the Arduino, had times of: 700 (open), 4302 (0%), 4900 (100%) microseconds. With everything up and working I've noticed that the outdoor humidity readings bounce around, meaning that there is a lot more influencing the charge time than just the humidity that the sensor itself is in. Once the minimum and maximum charge times are known, each reading must be scaled down from that interval to 0-100. There is a handy function which does just that: Code:
humidity = map(hum_charge_time, 0_charge_time, 100_charge_time, 0, 100); I'd like to thank Nettigo for helping me understand how sensors can be used with the Arduino. Nettigo is more than just an internet store with Arduinos and accessories, it has lots of info on how to get those gadgets working and, most importantly, why they work. Thankfully their blog is translated into English, which is very good since some of the stuff doesn't seem to be posted anywhere else. The following pages are the main source of info of what I covered in this post: How to measure temperature with Arduino and MCP9700 Temperature and LCD What analogRead() actually measures? Humidity sensor EDIT: I just realized that since I'm feeding 3.3V to AREF, then the capacitor humidity sensor will only get charged to 3.3V, not 5V. (Actually it will get charged to 5V, ie the HIGH output of a digital pin, but the analog inputs will stop reading above 3.3V.) This effects the time it takes to get to full charge (or whatever percent of full), so it may throw off the precision. On the other hand, if all proportions stay the same, then it should still work, only the charge times will be shorter.
__________________
Ecorenovation - the bottomless piggy bank that tries to tame the energy hog. Last edited by Piwoslaw; 01-12-12 at 08:55 AM.. |
01-03-12, 08:38 AM | #3 |
Administrator
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
|
They do make an arduino mega that has almost 2x as many pins. I don't know how many analog pins you get, but it might be worth looking into.
__________________
Current project - To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. & To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. |
|
|