EcoRenovator  

Go Back   EcoRenovator > Improvements > Appliances & Gadgets
Advanced Search
 


Blog 60+ Home Energy Saving Tips Recent Posts


Reply
 
Thread Tools Display Modes
Old 01-02-12, 01:53 PM   #1
Piwoslaw
Super Moderator
 
Piwoslaw's Avatar
 
Join Date: May 2009
Location: Warsaw, Poland
Posts: 961
Thanks: 188
Thanked 110 Times in 86 Posts
Default 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.

Attached Thumbnails
Click image for larger version

Name:	ws1.jpg
Views:	850
Size:	42.6 KB
ID:	1980   Click image for larger version

Name:	ws3.jpg
Views:	1687
Size:	41.3 KB
ID:	1981   Click image for larger version

Name:	ws4.jpg
Views:	1213
Size:	83.1 KB
ID:	1982   Click image for larger version

Name:	ws5.jpg
Views:	850
Size:	46.5 KB
ID:	1983  
__________________
Ecorenovation - the bottomless piggy bank that tries to tame the energy hog.
Piwoslaw is offline   Reply With Quote
Old 01-03-12, 08:22 AM   #2
Piwoslaw
Super Moderator
 
Piwoslaw's Avatar
 
Join Date: May 2009
Location: Warsaw, Poland
Posts: 961
Thanks: 188
Thanked 110 Times in 86 Posts
Default 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
Since the maximum voltage that will read on the analog pin is equal to the 5V supply voltage (in theory, at least - see below), then the best resolution we can get is 5/1024 = 4.88mV per analog "step", which translates to 0.5°C. Not bad, but it could be better. From the sensor's specs we can see that it measures temps between -40 and +125°C, so the maximum voltage we should see on the analog pin is 500mV+125*10mV = 1.75V. If we could tell the Arduino use its whole 10-bit scale up to a lower voltage, then we should get better resolution. Thankfully, this is possible - that's what the AREF pin is for. Supplying 3.3V to the AREF gives 0.3°C resolution.

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;
}
Even better resolution is possible: Setting AREF to the Arduino's internal 1.1V voltage will give 0.1°C resolution, but at the cost of limiting the maximum temperature to about 60°C. No problem for most uses, but since one of the things I'm monitoring is the temperature of the water exiting the boiler then I decided to stay with 3.3V. The Arduino Mega has two internal voltages - 1.1V and 2.56V, see the analogReference page for more info.

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
}
The sensor has one leg grounded, while the other is connected to analog VOLTAGE_CHECK_PIN. That same pin is also connected to two digital pins through resistors (CHARGE_PIN with 10M Ohm and DISCHARGE_PIN with 220 Ohm). The first function sets both digital pins to LOW and waits for the voltage in the sensor to bleed down to 0. The second function sets CHARGE_PIN to HIGH and starts counting microseconds. Once the capacitor is charged to a certain percent, that charge time is returned (see this link for a much better explanation).

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);
To get better readings from the sensors (temperature and humidity) I take 5 consequent readings, reject the max and min, and average the remaining three. This seems to work well enough, though taking 7 or 9 samples may be better. The temperature reads are pretty stable with this, but the indoor humidity jumps around a little (15%-35%). The outdoor humidity is all over the place, though, showing anything between -60% and 180% within only 1-2 minutes. Averaging hourly readings over 24 hours finally sets the outdoor reading to about 65%, which is close to what it should be.

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..
Piwoslaw is offline   Reply With Quote
Old 01-03-12, 08:38 AM   #3
Daox
Administrator
 
Daox's Avatar
 
Join Date: Aug 2008
Location: Germantown, WI
Posts: 5,525
Thanks: 1,162
Thanked 374 Times in 305 Posts
Default

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.
Daox is offline   Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Ad Management by RedTyger
Inactive Reminders By Icora Web Design