user1828460
Published

Weather station

A weather station that shows time, pressure, temperature, and humidity. Made on an Arduino Nano board.

IntermediateShowcase (no instructions)155
Weather station

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Alphanumeric LCD, 20 x 4
Alphanumeric LCD, 20 x 4
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
TinyShield Real-Time Clock
TinyCircuits TinyShield Real-Time Clock
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Gravity BMP388 Barometric Pressure Sensors
DFRobot Gravity BMP388 Barometric Pressure Sensors
×1
LED, RGB
LED, RGB
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

Untitled file

C/C++
#include <stdio.h>
#include <DS1302.h>
#include "DHT.h"
#include <Wire.h> 
#include <Adafruit_BMP085.h>
#include <LiquidCrystal_I2C.h>

#define DHTPIN 2     // what pin we're connected to
// DHT sensor type
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 20, 4);
Adafruit_BMP085 bmp;
 

const int kCePin   = 5;  // Chip Enable
const int kIoPin   = 6;  // Input/Output
const int kSclkPin = 7;  // Serial Clock

int redPin = 11;
int greenPin = 13;
int bluePin = 12;

// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);

String dayAsString(const Time::Day day) {
  switch (day) {
    case Time::kSunday: return "Sunday";
    case Time::kMonday: return "Monday";
    case Time::kTuesday: return "Tuesday";
    case Time::kWednesday: return "Wednesday";
    case Time::kThursday: return "Thursday";
    case Time::kFriday: return "Friday";
    case Time::kSaturday: return "Saturday";
  }
  return "(unknown day)";
}

void printTime() {
  // Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
           day.c_str(),
           t.yr, t.mon, t.date,
           t.hr, t.min, t.sec);





  // Print the formatted string to serial so we can see the time.
  Serial.println(buf);
  float h = dht.readHumidity();

  lcd.setCursor(0, 0); 
  lcd.print(h); 
  lcd.setCursor(0, 1); 
  lcd.print(t.hr);
}



void setup() {
  Serial.begin(9600);  
  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP085 sensor, check wiring!");
    while (1) {}
  }

  dht.begin();
  lcd.begin();
  lcd.clear(); 
  show_logo();
  delay(5000); 
  
  pinMode(9,OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  
  // Initialize a new chip by turning off write protection and clearing the
  // clock halt flag. These methods needn't always be called. See the DS1302
  // datasheet for details.
  rtc.writeProtect(false);
  rtc.halt(false);

  // Make a new time object to set the date and time.
  // Sunday, March 29, 2021 at 10:30:50.
  //Time t(2021, 03, 29, 10, 30, 50, Time::kSunday);

  // Set the time and date on the chip.
  //rtc.time(t);
}

// Loop and print the time every second.
void loop() {

  // Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
           day.c_str(),
           t.yr, t.mon, t.date,
           t.hr, t.min, t.sec);
    
  int h = dht.readHumidity();
  int temp = dht.readTemperature();
  
  if((t.hr >= 06) and (t.hr < 23)){  //if the time is greater than or equal to 6 a.m. and less than 23 p.m., the screen will work

  lcd.display(); //turn on
  lcd.backlight(); //turn on backlight
  
  lcd.setCursor(0, 0); 
  lcd.print("Humidity:    "); 
  lcd.print(h);
  lcd.print("%");
  
  lcd.setCursor(0, 1);
  lcd.print("Temperature: "); 
  lcd.print(temp);
  lcd.print("c");
  
  lcd.setCursor(0, 3); 
  lcd.print("Time: ");
  if(t.hr < 10) lcd.print("0");
  lcd.print(t.hr);
  lcd.print(":");
  if(t.min < 10) lcd.print("0");
  lcd.print(t.min);
  lcd.print(":");
  if(t.sec < 10) lcd.print("0");
  lcd.print(t.sec);

  float p = bmp.readPressure()/133.3;
  lcd.setCursor(0, 2);           //Place the cursor on the 0th character of the 2nd line
  lcd.print("Pressure: ");                //Displaying the text
  lcd.print(p,0);                //Displaying the pressure value
  lcd.print("mm");
  

}

  else{
  lcd.clear();
  lcd.noDisplay();
  lcd.noBacklight(); 
  }

  
int led_r=0, led_g=0, led_b=0;

//change the color of the LED from the temperature
  
if ((temp >= 0) and (temp < 5) and (t.hr >= 06) and (t.hr < 22)){   
    led_r = 1;
    led_g = 1;
    led_b = 255;
  }

if ((temp >= 5) and (temp < 10) and (t.hr >= 06) and (t.hr < 22)){   
    led_r = 1;
    led_g = 50;
    led_b = 255;
  }
  
if ((temp >= 10) and (temp < 15) and (t.hr >= 06) and (t.hr < 22)){   
    led_r = 1;
    led_g = 200;
    led_b = 200;
  }

if ((temp >= 15) and (temp < 20) and (t.hr >= 06) and (t.hr < 22)){   
    led_r = 1;
    led_g = 250;
    led_b = 200;
  }
  
if ((temp >= 20) and (temp < 25) and (t.hr >= 06) and (t.hr < 22)){   
    led_r = 10;
    led_g = 200;
    led_b = 1;
  }

if ((temp >= 25) and (temp < 30) and (t.hr >= 06) and (t.hr < 22)){   
    led_r = 150;
    led_g = 150;
    led_b = 1;
  }


if ((temp >= 30) and (temp < 35) and (t.hr >= 06) and (t.hr < 22)){   
    led_r = 255;
    led_g = 255;
    led_b = 1;
  }

if ((temp >= 35) and (temp < 40) and (t.hr >= 06) and (t.hr < 22)){   
    led_r = 255;
    led_g = 1;
    led_b = 1;
  }

  analogWrite(redPin, led_r);
  analogWrite(greenPin, led_g);
  analogWrite(bluePin, led_b);
  delay(1000);
}

void show_logo() {
  lcd.setCursor(7, 1);
  lcd.print("Meteo");
  lcd.setCursor(6, 2);
  lcd.print("Station");



}

Credits

user1828460

user1828460

1 project • 0 followers

Comments

Add projectSign up / Login