Sunday, October 26, 2008

Standalone temperature logger with Arduino


As I mentioned in the previous post, I am in the process of insulating the attic. Of course, that couldn't go without some sort of measurement to check the effect of said insulation. Therefore, I decided to check the temperature delta from the inside of the attic to the outside before applying the stuff, and after.
So yesterday I finally decided to connect an LM35 to an arduino board, and get it to log the temperatures. Of course, I needed 2 LM35 connected to it. Luckily, I had 2 around, from Joao (sorry for the lack of the tilde), and one of them was even already on a long lead, this from my initial attempts at reading temperature with the computer - Joao then built a parallel port temperature sensor interface.
I built the circuit in the figure using the arduino. The diode is to enable the setup to read negative temperatures, which was not yet necessary, but will be soon.
Since I didn't want to have a computer running all the time just for that I made the arduino store the values into the EPROM. There are 512 bytes in the EPROM, so, for 2 sensors I could have 256 measurements. I decided to get a measurement every 30 minutes, which would allow the setup to run for about 5 days before running out of place in the memory.
To read the contents of the EPROM, I had initially thought of having a switch which would indicate the mode to run in - log or report - , but went for the easier solution of dumping all the contents of the EPROM upon starting the arduino.

So, yesterday I placed the thing in the attic, tried to get the long sensor outside, didn't quite managed, but it was pretty close to be out in the cold.

This morning I couldn't resist: went to get it, downloaded the data and plotted it in Excel. I get a constant 2 degrees difference between the inside and the outside, which I think is very small, might explain why the house gets cold so quickly.

Here is the arduino code. It is not clean nor pretty, but seams to do the job:





/*
* temperature logger
*
* reads and logs 2 temperature sensors to the EPROM
*

*/
#include

int refPin = 1; // select the input pin for the potentiometer
int potPin = 2; // select the input pin for the potentiometer
int potPin2 = 3; // select the input pin for the potentiometer
int val = 0; // variable to store the value coming from the sensor
int ref;
int out;
int val2 = 0; // variable to store the value coming from the sensor
int out2;

int avout, avin;
int addr = 0;
int index = 0;
int outtemps[10];
int intemps[10];

int ledPin = 13; // LED connected to digital pin 13
int value = LOW; // previous value of the LED
long previousMillis = 0; // will store last time LED was updated
long logpreviousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
long loginterval = 1800000; // interval at which to log (milliseconds)

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(9600);

Serial.println("ready to dump! data every 30 minutes");
Serial.println("address \t out \t in");

for (int in = 0; in<256; in++)
{

value = EEPROM.read(in*2);

Serial.print(in);
Serial.print("\t");
Serial.print(value, DEC);
Serial.print("\t");
value = EEPROM.read(in*2 + 1);
Serial.print(value, DEC);
Serial.println();

}


}

void loop() {
ref = analogRead(refPin); // read the value from the sensor
val = analogRead(potPin); // read the value from the sensor
val = val - ref;
out=val*500/1023;
val2 = analogRead(potPin2); // read the value from the sensor
val2 = val2 - ref;
out2=val2*500/1023;

outtemps[index] = out;
intemps[index] = out2;
index++;
if (index == 10)
{
index = 0;
}

delay(100);

// check to see if it's time to blink the LED; that is, is the difference
// between the current time and last time we blinked the LED bigger than
// the interval at which we want to blink the LED.
if (millis() - previousMillis > interval) {
previousMillis = millis(); // remember the last time we blinked the LED

// if the LED is off turn it on and vice-versa.
if (value == LOW)
value = HIGH;
else
value = LOW;

digitalWrite(ledPin, value);
}

//log the temperatures to the eprom
if (millis() - logpreviousMillis > loginterval) {
logpreviousMillis = millis(); // remember the last time we blinked the LED

avout = 0;
avin = 0;
for (int aa = 0; aa<10 ; aa++)
{
avout += outtemps[aa];
avin += intemps[aa];
}
avout = avout/10;
avin = avin/10;


EEPROM.write(addr*2, avout);
EEPROM.write(addr*2+1, avin);
addr = addr + 1;
if (addr == 256)
addr = 0;

Serial.print(avout);
Serial.print(" - ");
Serial.println(avin);

// if the LED is off turn it on and vice-versa.
if (value == LOW)
value = HIGH;
else
value = LOW;

digitalWrite(ledPin, value);
}


}

Friday, October 24, 2008



Just got my yearly report from the utilities company, and once again managed to get some money back by saving energy! In the last 2 years I have reduced my energy consumption by about half! From almost 3500KWh in 2006 to a bit more than 1500KWh this year, and from almost 4000m3 of gas in 2006 to less than 2000m3 this year! You can see the graphics provided by the company that compare my consumption with that of the neighbors.

In terms of gas I am now at the same level as the neighbors, but most neighbors have smaller houses that I do...so I hope that that explains it...anyway, I am currently in the process of properly insulation the attic. More of that soon! Also in the plan is to acquire a new, more efficient boiler. I would like to get the consumption below the 1000m3/year.

In terms of electricity I don't really know what to do further to save electricity...

In the plans for this season is also to finally reuse rain water to flush the toilets. This year we spent about 90 liters of water per person per day. I would like to reduce that!

Monday, October 6, 2008

Hello again!

The door bell project is working in full swing! although not many people seem to ring it...next project: detect bangs from people using the door knock.

On another note, I got my wife a small tablet (wacom bamboo) and it is really nice! to celebrate, I decided to make a handmade schematic of my circuit to read the electricity meter. So here it is on the right. On the bottom is the LDR which has a value of about 20K ohm when in the dark and goes down to 200 or less in bright light. So I get the little LDR, which is about 3mm in diameter right in front of the blinking led on my new digital electric meter and every time it blinks the input of the arduino goes down, signaling one watthour having been consumed. The Arduino then communicates that to the computer which dumps the time into a database, from which I can then generate graphics and check consumption.
On the next post, and to try to improve my tablet skills, I'll describe the circuit used to read the gas meter.

Furthermore, I just got a new Arduino today, the Diecimila, ordered by Joao, so I'll try to get the thermometer and other environment variables going.