weather station

Hello all!

I guess many off have all ready build your own weather station, and now it is my turn.

I did start to put together a sketch, taking a little from here and there.

I am using an UNO board for my prototyping, but I will use a NANO board later.

Reading a DHT11 #define DHTPIN 6

Serial.print: temp C, F is working, Relative Humidity Working, dew point C, F working

So the first problem:

Serial.print("C ");

Serial.print(heatIndex(tF,h));

Serial.println("F ");

// working

But I can not figure out to Serial.print in Celsius, on the same line

Second problem:

Print to the LCD display, using:

#include <LiquidCrystal.h>

LiquidCryatal lcd(12, 11, 5, 4, 3, 2);

But I can not get it to work, trying different methods, without any success.

Those are the first thing I like to get it to work, on one UNO/nano board, DHT11 sensor and a LCD.

Later I like to have wind-speed and direction, barometric pressure, using BMP085 sensor.

And them will come reading CO, CO2 using the MQ sensors. Finally , solar radiation (what sensor to use I do not know),

and lightning detection using a AS3935 module.

But first ting first :smiley:

Can someone kindly help me figure out some of those thing, first the DHT11 sensor Seriel.print and LCD print.

Will be much appreciated.

Will be much appreciated,

Thank You.

Joe in the Phills

Here is my sketch:

#include <DHT.h>

#include <LiquidCrystal.h>

// what pin DHT11 is connected to.

#define DHTPIN 6

// initialize the library with the numbers of the interface pins

//LiquidCrystal lcd(5, 4, 23, 22, 21, 20);

LiquidCryatal lcd(12, 11, 5, 4, 3, 2);

// Uncomment for the type we’re using

#define DHTTYPE DHT11 // DHT 11

//#define DHTTYPE DHT22 // DHT 22 (AM2302)

//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V

// Connect pin 2 of the sensor to whatever your DHTPIN is

// Connect pin 4 (on the right) of the sensor to GROUND

// Connect a 10K resistor from

// pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

float tF;

float dP;

float dPF;

void setup() {

Serial.begin(9600);

Serial.println(“Serial reading DHT11 Sensor using Digital pin 6”);

// Serial.println(“by Joe Fox”);

dht.begin();

}

void loop() {

// Reading temperature or humidity takes about 250 milliseconds!

// Sensor readings may also be up to 2 seconds ‘old’

// its a very slow sensor

float h = dht.readHumidity();

float t = dht.readTemperature();

// check if returns are valid, if they are NaN (not a number) then something went wrong!

if (isnan(t) || isnan(h)) {

Serial.println(“Failed to read from DHT”);

} else {

Serial.print("Relative Humidity: ");

Serial.print(h);

Serial.print(“%\t”);

Serial.print("Temperature: ");

Serial.print(t);

Serial.print("C ");

tF=((t*9)/5)+32;

Serial.print(tF);

Serial.print("F ");

Serial.print(" \t");

Serial.print("Dew Point: ");

Serial.print(dewPointFast(t, h));

Serial.print("C ");

dP=(dewPointFast(t, h));

dPF=((dP*9)/5)+32;

Serial.print(dPF);

Serial.print(“F”);

Serial.print(" \t");

Serial.print("Heat Index: ");

// Serial.print{“heatIndex”); // print serial Heat Index C

Serial.print("C ");

Serial.print(heatIndex(tF,h));

Serial.println("F ");

///////////////////////// do not work

{

lcd.setCursor(0, 0);

lcd.print(“Temp”);

}

////////////////////////

}

}

// delta max = 0.6544 wrt dewPoint()

// 6.9 x faster than dewPoint()

// reference: http://en.wikipedia.org/wiki/Dew_point

double dewPointFast(double celsius, double humidity)

{

double a = 17.271;

double b = 237.7;

double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);

double Td = (b * temp) / (a - temp);

return Td;

}

double heatIndex(double tempF, double humidity)

{

double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248, c5= -6.838e-3, c6=-5.482e-2, c7=1.228e-3, c8=8.528e-4, c9=-1.99e-6 ;

double T = tempF;

double R = humidity;

double A = (( c5 * T) + c2) * T + c1;

double B = ((c7 * T) + c4) * T + c3;

double C = ((c9 * T) + c8) * T + c6;

double rv = (C * R + B) * R + A;

return rv;

}

Serial.print("C ");
Serial.print(heatIndex(tF,h));
Serial.println("F ");

The “ln” tells it to print on a new line.

#include <LiquidCrystal.h>
LiquidCryatal lcd(12, 11, 5, 4, 3, 2);

This is just the initialization code. Are the LCD pins connected to these pins? What LCD? If you are sure of the connections, take everything out of the code but for the LCD and see if you can get it to work by itself. If it does, then something is conflicting.

You have 2 problems ; getting the temperature in C out to the serial monitor and then getting something/anything to display on some LCD ?

  1. Which code are you using ? This is clearly wrong.
//So the first problem:
Serial.print("C ");
Serial.print(heatIndex(tF,h));
Serial.println("F ");

The above doesn’t send the temp to the serial port. This looks OK.

Serial.println("Failed to read from DHT");
} else {
  Serial.print("Relative Humidity: ");
  Serial.print(h);
  Serial.print("%\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print("C ");
  tF=((t*9)/5)+32;
  Serial.print(tF);
  Serial.print("F ");
  Serial.print(" \t");
}
  1. I don’t see an lcd.begin() in your setup().

http://arduino.cc/en/Reference/LiquidCrystalBegin

http://arduino.cc/en/Tutorial/LiquidCrystalCursor

Hello and thanks for some hints.

This is my first attempt to do some programming, like ever!

I did the following changes:

Remove all the seriel.print stuff, as I do not need it.

Trying to do lcd.print, and actually some of it do work :slight_smile:

But still humidex giving me headache

OK how will I write this in the sketch, looks like this:

Humidex is calculated as air temperature + h

where:

h = (0.5555)*(e – 10.0);

e = 6.11 * exp(5417.7530 * ((1/273.16) – (1/dewpoint)))

And the Wind Chill

From Arduino Wind Chill Machine

Twc=35.74+0.6215Tf-35.75MPH^0.16 +0.4275Tf*MPH^0.16

Does this make some sense to any of you …

This is how my sketch looks like now:


include <DHT.h>

#include <LiquidCrystal.h>

#include <Wire.h>

#include <Adafruit_BMP085.h>

#include <SPI.h>

#include <util.h>

#include <math.h>

#include <RTClib.h>

// what pin DHT11 is connected to.

#define DHTPIN 6

//

// #define LIGHT_SENSOR_PIN 1

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Uncomment for the type we’re using

#define DHTTYPE DHT11 // DHT 11

//#define DHTTYPE DHT22 // DHT 22 (AM2302)

//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V

// Connect pin 2 of the sensor to the pin we’r using, 6

// Connect pin 4 (on the right) of the sensor to gnd

// Connect a 10K resistor from

// pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

float tF;

float tK;

float dP;

float dPF;

void setup() {

Serial.begin(9600);

lcd.begin(16,2);

lcd.clear();

dht.begin();

}

void loop() {

delay(1500);

float h = dht.readHumidity();

float t = dht.readTemperature();

// check if returns are valid, if they are NaN (not a number) then something went wrong!

if (isnan(t) || isnan(h)) {

Serial.println(“Failed to read from DHT”);

} else

{

lcd.print(" ");

lcd.setCursor(0,0);

lcd.print("Temp:C ");

lcd.setCursor(7,0);

lcd.print(t,0); // (t,1) one decimai

lcd.setCursor(9,0);

lcd.print((char)223);

tF=((t*9)/5)+32; // Formula Celcius to Fahrenheit

Serial.print(tF);

Serial.print("F ");

Serial.print(" \t");

lcd.setCursor(11,0);

lcd.print(“F”);

lcd.setCursor(13,0);

lcd.print(tF,0);

lcd.setCursor(15,0);

lcd.print((char)223);

lcd.setCursor(0,1);

lcd.print(“RH:”);

lcd.setCursor(4,1);

lcd.print(h,0);

lcd.setCursor(6,1);

lcd.print(“%”);

// Formula Celsius to Kelvin

// celsius + 273.15 = Kelvin

tK=(t+273.15); // Calculat Celcius to Kelvin

lcd.setCursor(8,1);

lcd.print(“K:”);

lcd.setCursor(11,1);

lcd.print(tK,0);

lcd.setCursor(14,1);

lcd.print((char)223);

delay(10000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print(“DewPoint:”);

lcd.setCursor(10,0);

lcd.print(dewPointFast(t, h));

lcd.setCursor(15,0);

lcd.print((char)223);

//Dex point and humidex calculator

//Humidex = (air temperature) + h

// h = (0.5555)*(e - 10.0);

// e = 6.11 * exp(5417.7530 * ((1/273.16) - (1/dewpoint)))

// Now the code based on DH11 humidity sensor and the BMP085

// temperature sensor. The key value pair are output to

// the serial port where a java program parses and submits

// them to a Mango M2M datalogger running on the local machine.

lcd.setCursor(0,1);

lcd.print(“Humidex :”);

lcd.setCursor(11,1);

delay(10000);

lcd.clear();

// Dew Point Fast

dP=(dewPointFast(t, h));

dPF=((dP*9)/5)+32;

}

}

// delta max = 0.6544 wrt dewPoint()

// 6.9 x faster than dewPoint()

// reference: http://en.wikipedia.org/wiki/Dew_point

double dewPointFast(double celsius, double humidity)

{

double a = 17.271;

double b = 237.7;

double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);

double Td = (b * temp) / (a - temp);

return Td;

}

double heatIndex(double tempF, double humidity)

{

double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248, c5= -6.838e-3, c6=-5.482e-2, c7=1.228e-3, c8=8.528e-4, c9=-1.99e-6 ;

double T = tempF;

double R = humidity;

double A = (( c5 * T) + c2) * T + c1;

double B = ((c7 * T) + c4) * T + c3;

double C = ((c9 * T) + c8) * T + c6;

double rv = (C * R + B) * R + A;

return rv;

}

vixten:
But still humidex giving me headache

What variable stores the “Humidex” ? Where in the above is it declared and what type is it ? Where is it computed ? Be sure all the components of that calculation are also declared and available and of the proper type. Be careful about the order of calculations. Also where in the below code is that variable sent to the LCD ?

lcd.setCursor(0,1);
lcd.print("Humidex :");
lcd.setCursor(11,1);

All the above will do is display Humidex: on the LCD, no reading to go with it. You need something like …

lcd.setCursor(0,1);
lcd.print("Humidex :");
lcd.print(H_variable);        //H_variable is the variable name w/the humidex calculation results
lcd.setCursor(11,1);

And please use the code tags so as to preserve the indentation.

(click on to enlarge)

Mee_n_Mac

Here is what I have but I do not know how to type it in my, and where

//Dex point and humidex calculator

//Humidex = (air temperature) + h

// h = (0.5555)*(e - 10.0);

// e = 6.11 * exp(5417.7530 * ((1/273.16) - (1/dewpoint)))

// Now the code based on DH11 humidity sensor and the BMP085

// temperature sensor. The key value pair are output to

// the serial port where a java program parses and submits

// them to a Mango M2M datalogger running on the local machine

I do not know how and where to declared it :frowning:

and this from another sketch:

double h = temp + 0.5555 * ( 6.11 * exp ( calculateHumidexEValue(DewPoint)) - 10);

lcd.setCursor(x,x);

lcd.print("Humidex = ");

lcd.println(h);

I trying to find a working Humidex reading, but non of what I am finding,

I can not get the calculation to work.

Do I get it correct:

I have to declare it first, early in the sketch, yes?

make the calculation (do not know how and where in my sketch)

print in on the LCD, lcd.setCursor(x, x); lcd.print(h);

And what yet did I miss?

Joe

From another post …

Not knowing what, if any, background you have let me recommend that you should read the following pages to “learn how to swim”. While jumping into the deep end, as you have here, is often touted as a quick way to learn, more often you end up just gasping for air before giving up and drowning.

http://arduino.cc/en/Tutorial/Foundations

Read the pages on the basics of a sketch (gack, I loathe that term). Then the pages on digital pins, variables and functions.

http://arduino.cc/en/Tutorial/HomePage

Look at the 1’st pages on Basics and then those under Control structures for - if and for loops.

If you can grok the above then you should be able to look at, and decipher how, most sketches work. Look at the sketches in the lessons on this page.

http://arduino.cc/en/Tutorial/Links

Above all else bookmark this page and have it open when reading or writing a sketch.

http://arduino.cc/en/Reference/HomePage

It’s your Rosetta Stone.

Do I get it correct:

I have to declare it first, early in the sketch, yes?

make the calculation (do not know how and where in my sketch)

print in on the LCD, lcd.setCursor(x, x); lcd.print(h);

Yup, that's the basic idea. Read the above links. Let's look at this snippet of code.
double h = temp + 0.5555 * ( 6.11 * exp ( calculateHumidexEValue(DewPoint)) - 10);
lcd.setCursor(x,x);
lcd.print("Humidex = ");
lcd.println(h);

It declares a variable h as a type double. In Arduino speak (if you look at the data types page) it probably would also be a floating. That tells the compiler to set aside enough memory locations to store the results of the calculation. In that calculation there are other variables used, temp and DewPoint, that must have been declared and set/calulated earlier in the code. There’s also a function, calculateHumidexEValue(), that uses the variable DewPoint as an input and returns some result. I didn’t see that function in your code.

If you put your code into the Arduino editor and ask it to "AutoFormat (under Tools menu) and then use the code tags, I’ll have a fuller look at your code. Also under the Files menu, click on Preferences and make sure the “Show verbose output during compilation” is checked. Then Verify your code and look at the error messages. Posting those also helps.

Hello all!

Thank you a again Mee_n_Mac for useful information,

and I have a working sketch, I did include a BMP180 for outside temperature and atmospheric pressure.

But the Heat Index in Celsius does not seems to be correct,

lcd.print(heatIndex(tF,h)); in fahrenheit looks correct and give me about 83 deg.

Calculating back to Celsius like this:

lcd.print(heatIndex(tF-32*100/180,h));

LCD give me 73 C, witch is about 50 C to much (should be about 28 C)

Where do my calculation go wrong?

my sketch, and as always any suggestions to improve the code is most welcome :slight_smile:

#include <DHT.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <SFE_BMP180.h>
// #include <SPI.h>
// #include <util.h>
// #include <math.h>
// #include <RTClib.h>

// pin no, DHT11 is connected to.
#define DHTPIN 6 // Digital pin 6 on Arduino UNO

SFE_BMP180 pressure;
#define ALTITUDE 60.0 // Altitude of Santol in in meters

// initialize the library with the numbers of the 
// interface pins to the LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

float tF;
float tK;
float dP;
float dPF;

void setup() {
  Serial.begin(9600);
  /////////////////////////////////////////
  // if (pressure.begin())
  //    Serial.println("BMP180 init success");
  //  else
  //  {
  // Oops, something went wrong, this is usually a connection problem,
  // see the comments at the top of this sketch for the proper connections.

  //    Serial.println("BMP180 init fail (disconnected?)\n\n");
  //    while(1); // Pause forever.
  //  }
  //////////////////////////////////////////

  lcd.begin(16,2);
  lcd.clear();
  dht.begin();

  if (pressure.begin());

}

void loop() {

  char status;
  double T,P,p0,a;

  delay(3000);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float hi = dht.readTemperature();

  // check if returns are valid, 
  // if they are NaN (not a number) then something went wrong
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } 
  else

  {

    lcd.setCursor(0,0);
    lcd.print("Reading DHT11");
    lcd.setCursor(0,1);
    lcd.print("OutsideTmp RH");

    delay(3000);
    lcd.clear();

    lcd.clear(); 
    lcd.print(" ");
    lcd.setCursor(0,0);
    lcd.print("Temp:C ");
    lcd.setCursor(7,0);
    lcd.print(t,0); // (t,1) one decimai
    lcd.setCursor(9,0);
    lcd.print((char)223);

    // Celcius to Fahrenheit
    tF=((t*9)/5)+32;
    Serial.print(tF);
    Serial.print("F ");
    Serial.print(" \t");

    lcd.setCursor(11,0);
    lcd.print("F");
    lcd.setCursor(13,0);
    lcd.print(tF,0);
    lcd.setCursor(15,0);
    lcd.print((char)223);

    lcd.setCursor(0,1);
    lcd.print("RH:");
    lcd.setCursor(4,1);
    lcd.print(h,0);
    lcd.setCursor(6,1);
    lcd.print("%");

    // celsius + 273.15 = Kelvin
    tK=(t+273.15); // Calculat Celcius to Kelvin
    lcd.setCursor(8,1);
    lcd.print("K:");
    lcd.setCursor(11,1);
    lcd.print(tK,0);
    lcd.setCursor(14,1);
    lcd.print((char)223);

    delay(10000);
    lcd.clear();

    lcd.setCursor(0,0);
    lcd.print("Dew Point:");
    lcd.setCursor(0,1);
    lcd.print(dewPointFast(t, h));
    lcd.setCursor(5,1);
    lcd.print((char)223);
    lcd.setCursor(6,1);
    lcd.print("C");
    lcd.setCursor(8,1);
    lcd.print(dewPointFast(tF, h));
    lcd.setCursor(13,1);
    lcd.print((char)223);
    lcd.setCursor(14,1);
    lcd.print("F");

    delay(10000);
    lcd.clear();

    // Heat Index, Dex point, humidex calculation
    // Humidex = (air temperature) + h
    // h = (0.5555)*(e - 10.0);
    // e = 6.11 * exp(5417.7530 * ((1/273.16) - (1/dewpoint)))

    lcd.setCursor(0,0);
    lcd.print("Heat Index:");
    lcd.setCursor(0,1);
    lcd.print(heatIndex(tF-32*100/180,h)); // do not work in Celsius
    lcd.setCursor(5,1);
    lcd.print((char)223);
    lcd.setCursor(6,1);
    lcd.print("C");
    lcd.setCursor(8,1);
    lcd.print(heatIndex(tF,h));
    lcd.setCursor(13,1);
    lcd.print((char)223);
    lcd.setCursor(14,1);
    lcd.print("F");

    delay(10000);
    lcd.clear();

    lcd.setCursor(0,0);
    lcd.print("Reading BPM180");
    lcd.setCursor(0,1);
    lcd.print("InsideTemp ATM");

    delay(3000);
    lcd.clear();

    lcd.setCursor(0,0);
    lcd.print("Altitude");
    lcd.setCursor(9,0);
    lcd.print(ALTITUDE,0);
    lcd.setCursor(11,0);
    lcd.print("m ASL");
    lcd.setCursor(0,1);
    lcd.print(ALTITUDE*3.28084,0);
    lcd.setCursor(5,1);
    lcd.print("feets ASL");
    delay(3000);

    status = pressure.startTemperature();
    if (status != 0)
    {
      delay(status);
      status = pressure.getTemperature(T);
      if (status != 0)
      {

        // Print outside temperatur from BMP180
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Tmperature:");
        lcd.setCursor(0,1);
        lcd.print(T,2);
        lcd.setCursor(5,1);
        lcd.print((char)223);
        lcd.setCursor(6,1);
        lcd.print("C");
        lcd.setCursor(8,1);
        lcd.print((9.0/5.0)*T+32.0,2);
        lcd.setCursor(13,1);
        lcd.print((char)223);
        lcd.setCursor(14,1);
        lcd.print("F");

        delay(10000);
        lcd.clear();

        // Start pressure reading from BMP180
        status = pressure.startPressure(3);
        if (status != 0)
        {
          // Wait for the measurement to complete:
          delay(status);

          status = pressure.getPressure(P,T);
          if (status != 0)
          {
            // Print out pressure messurment
            lcd.setCursor(0,0);
            lcd.print("abs pressure ATM ");
            lcd.setCursor(0,1);
            lcd.print(P,2);
            lcd.setCursor(7,1);
            lcd.print(" mb");

            delay(10000);
            lcd.clear();

            lcd.setCursor(0,0);
            lcd.print("abs pressure ATM ");
            lcd.setCursor(0,1);
            lcd.print(P*0.0295333727,2);
            lcd.setCursor(5,1);
            lcd.print(" inHg");

            delay(10000);
            lcd.clear();

            p0 = pressure.sealevel(P,ALTITUDE);
            lcd.setCursor(0,0);
            lcd.print("sea-level SPL");
            lcd.setCursor(0,1);
            lcd.print(p0,2);
            lcd.setCursor(7,1);
            lcd.print(" mb");

            delay(10000);
            lcd.clear();

            lcd.setCursor(0,0);
            lcd.print("sea-level SPL");
            lcd.setCursor(0,1);
            lcd.print(p0*0.0295333727,2);
            lcd.setCursor(7,1);
            lcd.println("inHg     ");

            delay(10000);
            lcd.clear();

          }
          else Serial.println("error retrieving pressure measurement\n");
        }
        else Serial.println("error starting pressure measurement\n");
      }
      else Serial.println("error retrieving temperature measurement\n");
    }
    else Serial.println("error starting temperature measurement\n");

    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Weather Station");
    lcd.setCursor(0,1);
    lcd.print("by Joe Fox 2014");
    delay(1000);

    // Dew Point Fast
    dP=(dewPointFast(t, h));
    dPF=((dP*9)/5)+32;

  }
}

// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
  double Td = (b * temp) / (a - temp);
  return Td;
}

double heatIndex(double tempF, double humidity)
{
  double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248, c5= -6.838e-3, c6=-5.482e-2, c7=1.228e-3, c8=8.528e-4, c9=-1.99e-6 ;
  double T = tempF;
  double R = humidity;

  double A = (( c5 * T) + c2) * T + c1;
  double B = ((c7 * T) + c4) * T + c3;
  double C = ((c9 * T) + c8) * T + c6;

  double rv = (C * R + B) * R + A;
  return rv;
}

Look at the formula ;

tF-32*100/180

The order of operations is mult and divide first then to addition or subtraction. What I think is happening is the code is multiplying 32 by 100 and then dividing by 180. That result is then subtracted from whatever the temp in Fahrenheit is. And since those numbers aren’t explicitly float point types, you may get some rounding/truncation errors as well.

So try ;

(tF-32.0)*100.0/180.0

Hello,

I think I nailed it, after playing with this formula, and came up with this:

lcd.print(heatIndex((tF-32.00)*(100.00/180.00), 2));

Looks like it is calculating correct.

INTERMEZZO

On my arduino UNO card I now have:

digital 7, 8, 9 and 10

analog 0, 2, 3

and digital 0 → Rx, 1 <-Tx

Any suggestion what I can use them for?

What is next?

I am going to have a separate UNO (or nano) card for wind speed, direction and wind chill.

Joe in the Phils