πŸŒ„ How to make weather station (Arduino project)

The proposed method of manufacturing weather stations for home or cottage. We take the Arduino board and a set of sensors as a basis: temperature, humidity, pressure and a carbon dioxide sensor.
1

The proposed method of manufacturing weather stations for home or cottage. We take the Arduino board and a set of sensors as a basis: temperature, humidity, pressure and a carbon dioxide sensor. The data will be displayed on the LCD display, and power will be supplied from the power supply for the mobile phone or batteries.

We will need:

  • Arduino UNO or another compatible card;
  • temperature and humidity sensor DHT11 or other;
  • pressure sensor BMP085 or more modern BMP180, or another;
  • MQ135 carbon dioxide sensor (optional);
  • LCD display 1602 or other;
  • 10 kΞ© potentiometer;
  • the case for weather station;
  • a piece of foiled fiberglass;
  • screws for fastening components;
  • connecting wires;
  • power supply connector;
  • soldering iron.

Instructions for creating a home weather station on Arduino

Selection of the case for the future weather station

First, you need to find a suitable case. There must fit all the components of the future room weather station. Such enclosures are sold in many electronics stores. Or use any other enclosure that you can find.

Estimate how all components will be placed inside. Cut through the window to secure the LCD display if it is not there. If you place a carbon dioxide sensor inside that is hot enough, place it on the side opposite to other sensors or make it remote. Provide a hole for the power connector.

Components Used

  • The 1602 LCD display uses 6 Arduino + 4 pins for power (backlight and sign synthesizer).
  • DHT11 temperature and humidity sensor connected to any digital pin. To read the values we will use the DHT11 library.
  • The pressure sensor BMP085 is connected via I2C interface to two Arduino pins: SDA – to analog pin A4 and SCL – to analog pin A5. Note that for the power supply the sensor is supplied with a voltage of +3.3 V.
  • The carbon dioxide sensor MQ135 is connected to one of the analog pins.

In principle, to assess the meteorological conditions, it is sufficient to have data on temperature, humidity, and atmospheric pressure, and a carbon dioxide sensor is not necessary.

Using all 3 sensors, we will have 7 digital and 3 analog pins of Arduino, not counting the power supply, of course.

Connection diagram of the weather station components

The scheme of the weather station is shown in the figure. It’s all clear.

Sketch weather station

Let’s write a sketch for Arduino. The code whenever possible is supplied with detailed comments.

#include 
#include  
#include  
#include  

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
dht11 sensorTempHumid; 
MQ135 gasSensor = MQ135(A0); 
#define RZERO 76.63
float rzero;
float ppm;

int del = 5000;
const unsigned char OSS = 0; 

int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
long b5;

float temperature; 
long pressure; 
const float p0 = 101325; 
const float currentAltitude = 179.5; 
const float ePressure = p0 * pow((1 - currentAltitude/44330), 5.255);  
float weatherDiff;

#define DHT11PIN 9 
#define BMP085_ADDRESS 0x77  

void setup() {
  lcd.begin(16, 2); 
  Wire.begin(); 
  bmp085Calibration(); 
}

void loop() {
  int chk = sensorTempHumid.read(DHT11PIN);
  
  switch (chk) {
    case DHTLIB_OK: 
                lcd.clear();
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                lcd.clear();
                lcd.print("Checksum error");
                delay(del); 
                return;
    case DHTLIB_ERROR_TIMEOUT: 
                lcd.clear();
                lcd.print("Time out error"); 
                delay(del);
                return;
    default: 
                lcd.clear();
                lcd.print("Unknown error"); 
                delay(del);
                return;
  }
  
  temperature = bmp085GetTemperature(bmp085ReadUT());
  temperature *= 0.1;
  pressure = bmp085GetPressure(bmp085ReadUP());
  pressure *= 0.01;
  
  weatherDiff = pressure - ePressure;
     
  rzero = gasSensor.getRZero();
  ppm = gasSensor.getPPM();
    
  lcd.setCursor(0, 0); 
  lcd.print(pressure*3/4); 
  lcd.print("mmHg "); 
 
  if(weatherDiff > 250)
    lcd.print("Sun");
  else if ((weatherDiff <= 250) || (weatherDiff >= -250))
    lcd.print("Cloudy");
  else if (weatherDiff > -250)
    lcd.print("Rain");
  
  lcd.setCursor(0, 1); 
  lcd.print(temperature, 1);
  lcd.print("C ");
  
  lcd.print(sensorTempHumid.humidity);
  lcd.print("% ");
  
  lcd.print(ppm);
   
  delay(del);
  lcd.clear();
}

void bmp085Calibration()
{
  ac1 = bmp085ReadInt(0xAA);
  ac2 = bmp085ReadInt(0xAC);
  ac3 = bmp085ReadInt(0xAE);
  ac4 = bmp085ReadInt(0xB0);
  ac5 = bmp085ReadInt(0xB2);
  ac6 = bmp085ReadInt(0xB4);
  b1 = bmp085ReadInt(0xB6);
  b2 = bmp085ReadInt(0xB8);
  mb = bmp085ReadInt(0xBA);
  mc = bmp085ReadInt(0xBC);
  md = bmp085ReadInt(0xBE);
}

short bmp085GetTemperature(unsigned int ut)
{
  long x1, x2;  
  x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
  x2 = ((long)mc << 11)/(x1 + md);
  b5 = x1 + x2;
  return ((b5 + 8)>>4);  
}

long bmp085GetPressure(unsigned long up)
{
  long x1, x2, x3, b3, b6, p;
  unsigned long b4, b7;
  
  b6 = b5 - 4000;
  
  x1 = (b2 * (b6 * b6)>>12)>>11;
  x2 = (ac2 * b6)>>11;
  x3 = x1 + x2;
  b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
  
  x1 = (ac3 * b6)>>13;
  x2 = (b1 * ((b6 * b6)>>12))>>16;
  x3 = ((x1 + x2) + 2)>>2;
  b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
  
  b7 = ((unsigned long)(up - b3) * (50000>>OSS));
  if (b7 < 0x80000000)
    p = (b7<<1)/b4;
  else
    p = (b7/b4)<<1;
    
  x1 = (p>>8) * (p>>8);
  x1 = (x1 * 3038)>>16;
  x2 = (-7357 * p)>>16;
  p += (x1 + x2 + 3791)>>4;
  
  return p;
}

unsigned int bmp085ReadUT()
{
  unsigned int ut;
  
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF4);
  Wire.write(0x2E);
  Wire.endTransmission();  
  delay(5);
  
  ut = bmp085ReadInt(0xF6);
  return ut;
}

unsigned long bmp085ReadUP()
{
  unsigned char msb, lsb, xlsb;
  unsigned long up = 0;
  
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF4);
  Wire.write(0x34 + (OSS<<6));
  Wire.endTransmission();
  
  delay(2 + (3<<OSS));
  
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF6);
  Wire.endTransmission();
  Wire.requestFrom(BMP085_ADDRESS, 3);
  
  while(Wire.available() < 3);
  msb = Wire.read();
  lsb = Wire.read();
  xlsb = Wire.read();
  
  up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
  
  return up;
}

char bmp085Read(unsigned char address)
{
  unsigned char data;
  
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
  
  Wire.requestFrom(BMP085_ADDRESS, 1);
  while(!Wire.available());
    
  return Wire.read();
}

int bmp085ReadInt(unsigned char address)
{
  unsigned char msb, lsb;
  
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
  
  Wire.requestFrom(BMP085_ADDRESS, 2);
  while(Wire.available()<2);
  msb = Wire.read();
  lsb = Wire.read();
  
  return (int) (msb<<8 | lsb);
}

Load this sketch into the memory of the Arduino board controller.

Assembling weather station

We will make a printed circuit board for placing components inside the case – this is the most convenient solution for building and connecting sensors. For the manufacture of PCB at home, I use “laser-iron” technology (we described it in detail in previous articles) and etching with citric acid. We will provide places on the board for jumpers (β€œjumpers”) in order to be able to turn off the sensors. This will be useful if you need to reprogram the microcontroller when there is a desire to modify the program.

With the help of soldering install pressure sensors and gases.

To install the Arduino Nano, it is convenient to use special adapters or sockets with a 2.54 pitch. But in the absence of these parts and because of the space savings inside the case, I will install the Arduino also by soldering.

The thermal sensor will be located at some distance from the board and will be insulated from the inside of the meteorological station using a special insulating gasket.

Provide space for external power supply to our homemade board. I will use a regular 5-volt charger from an old broken router. Plus 5 volts from the charger will be fed to the pin Vin of the Arduino board.

The LCD screen will be screwed directly to the body, to the front. It will be connected with wires with Dupont type quick connectors.

Install the printed circuit board inside the case and fasten it with screws. Connect the LCD screen to the Arduino’s legs according to the diagram.

Carefully close the weather station housing.

Turn on the weather station

Once again, re-checking that everything is connected correctly, we are energizing our weather station. The LCD screen should light up, and after a few seconds, it will display pressure data, a small forecast based on pressure readings, as well as data on temperature, humidity and carbon dioxide concentration.

Findings
We have assembled a home weather station from inexpensive and affordable components. In the process of working on a meteorological station, we became acquainted with the basics of interaction with temperature and humidity sensors, an atmospheric pressure sensor and a carbon dioxide sensor.

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest