cstram
Published © GPL3+

Simple and easy weather station for indoor and outdoor

It's a simple weather station, that measures, internal and external temperature. It's made out of two components: indoor and outdoor.

BeginnerFull instructions provided1,530
Simple and easy weather station for indoor and outdoor

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×2
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×2
Arduino Nano R3
Arduino Nano R3
×2
433Mhz FS1000A transmitter
×1
433Mhz RXB6 receiver
×1
I2C OLED Display
×1
Push Button normally open
×1

Story

Read more

Schematics

Transmitter

External temperature transmitter

Receiver

Internal Temperature Receiver

Code

Transmitter Arduino code

Arduino
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();
#include <DHT_U.h>

#define DHTPIN 3 
#define DHTTYPE    DHT22
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;

char temp[7];
char umid[7];

void setup() {
  
  // Transmitter is connected to Arduino Pin #10  
  mySwitch.enableTransmit(10);
  dht.begin();
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  dht.humidity().getSensor(&sensor);
  delayMS = sensor.min_delay / 1000;
  
}

void loop() {
  delay(delayMS);
  // Get temperature event and print its value.
  sensors_event_t event;
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println(F("Error reading temperature!"));
  }
  else {
    mySwitch.send(int(event.temperature*10),24);
  }
  delay(delayMS);
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    Serial.println(F("Error reading humidity!"));
  }
  else {
    mySwitch.send(int(event.relative_humidity*10),25);
  }
  
  delay(2000);
}

Receiver Code

Arduino
New Version 04 Feb 2024
/*
  Temperature receiver
  
  Displays temperature and Humidity internal and external 

  Carlo Stramaglia
  04-Feb-2024
  https://www.youtube.com/@CarloStramaglia

*/

#include <RCSwitch.h>
#include <DHT_U.h>
#include <U8glib.h>
#include <OneButton.h>

#define DHTPIN 3 
#define DHTTYPE    DHT22

RCSwitch mySwitch = RCSwitch();

U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);

DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;

OneButton button(A1, true);

int tmp;
int checkavail=0;
int EstInt=0; // If 0 show internal while if 1 show external temperature
char temp[7];
char umid[7];
char tempe[7];
char umide[7];
//float flt = 2.75;

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
  u8g.setColorIndex(1); 

//  button.attachClick(click);
  //attachInterrupt(digitalPinToInterrupt(5), checkTicks, CHANGE);
  button.attachLongPressStop(longPressStop);

  dht.begin();
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  Serial.println(F("------------------------------------"));
  Serial.println(F("Temperature Sensor"));
  Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
  Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
  Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
  Serial.println(F("------------------------------------"));
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  Serial.println(F("Humidity Sensor"));
  Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("%"));
  Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("%"));
  Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("%"));
  Serial.println(F("------------------------------------"));
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 2000;
}

void loop() {
  button.tick();
  if (mySwitch.available()) {
    tmp = mySwitch.getReceivedValue();
    if (mySwitch.getReceivedBitlength() == 24) {
      Serial.print("External Temperature: ");
      checkavail=0; // Reset the value
      dtostrf(float(tmp)/10, 2, 1, tempe);      
      Serial.print("Arriving: ");
      Serial.println(tmp);
      if (tmp < 100 and tmp >= 0)
        tempe[3]=byte(0x20);
        tempe[4]=byte(0x20);
      if (tmp < (-32758+100)) {
        tempe[3]=byte(0x20);
        tmp=(tmp+32768);
        dtostrf(float(tmp)/10, 2, 1, tempe);
        tempe[4] = tempe[3]; // Added 4 Feb 2024
        tempe[3] = tempe[2];
        tempe[2] = tempe[1];
        tempe[1] = tempe[0];
        tempe[0] = '-';  
        tempe[4]=byte(0x20);
      }
      if (tmp < 0 and tmp >= (-32758+100)) {
        tmp=(tmp+32768);
        dtostrf(float(tmp)/10, 2, 1, tempe);
        tempe[4] = tempe[3]; // Added 4 Feb 2024
        tempe[3] = tempe[2];
        tempe[2] = tempe[1];
        tempe[1] = tempe[0];
        tempe[0] = '-';  
        //tempe[4]=byte(0x20);
      }
      //tempe[4]=byte(0xb0);
      tempe[5]='C';
      tempe[6]='\0';
      Serial.println(tempe);
      }
    else {
      Serial.print("External Humidity: ");
      dtostrf(float(tmp)/10, 2, 1, umide);
      Serial.print(umide);
      Serial.println("%");
      umide[4]=' ';
      umide[5]='%';
      umide[6]='\0';
      }
    mySwitch.resetAvailable();
  }
  else {
    checkavail++;
    if (checkavail==100) {
      String notav = "NOT AV";
      strncpy(tempe, notav.c_str(), sizeof(tempe));
      tempe [sizeof(tempe) - 1] = 0;
      strncpy(umide, notav.c_str(), sizeof(umide));
      umide [sizeof(umide) - 1] = 0;
      checkavail=0;
    }
  }
  
  delay(delayMS);
  // Get temperature event and print its value.
  sensors_event_t event;
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println(F("Error reading temperature!"));
  }
  else {
    Serial.print(F("Internal Temperature: "));
    Serial.print(event.temperature);
    Serial.println(F("°C"));
    dtostrf(event.temperature, 2, 1, temp);
    temp[4]=byte(0xb0);
    temp[5]='C';
    temp[6]='\0';
  }
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    Serial.println(F("Error reading humidity!"));
  }
  else {
    Serial.print(F("Internal Humidity: "));
    Serial.print(event.relative_humidity);
    Serial.println(F("%"));
    dtostrf(event.relative_humidity, 2, 1, umid);
    umid[4]=' ';
    umid[5]='%';
    umid[6]='\0';
  }
  if (EstInt==0) {
    u8g.firstPage();  
    do {
      draw("In Temp:", 0, 14);
      draw(temp, 70, 14);
      draw("In Humi:", 0, 32);
      draw(umid, 70, 32);
    } while( u8g.nextPage() );
  }
  else {
    u8g.firstPage();  
    do {
      draw("Ex Temp:", 0, 14);
      draw(tempe, 70, 14);
      draw("Ex Humi:", 0, 32);
      draw(umide, 70, 32);
    } while( u8g.nextPage() );
  }
}

void longPressStop() {
  Serial.println("Button click.");
  u8g.firstPage();  
  do {
    draw("Please Wait...", 0, 23);
    } while( u8g.nextPage() );

  if (EstInt == 0)
    EstInt=1;
  else
    EstInt=0;
} 

void draw(char* parola, int posx, int posy) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( posx, posy, parola);
}

Credits

cstram

cstram

16 projects • 21 followers
Passionate about IT, Electronics and DIY. Strong believer in Raspberry and Arduino devices. Experience in digital television and security.

Comments