So i have my weather station everything works fine.
But, i want to make my station this way: when i pressed the button it will show the temperature only
then i will press it again and it will show the humidity only and for last if i press it , it will show the pressure only and if i press it again it will show the temperature again and it will go around again.
If you have same time for my code please add the solution into my code, i would be very glad.
The button is connected to pin 6.
Here is my code:
#include <LiquidCrystal.h> //pripojíme knižnicu pre LCD 16x2
#include <Wire.h> // pripojíme knižnicu pre prepojovacie káble
#include <Adafruit_Sensor.h> // pripojíme knižnicu pre senzory
#include <Adafruit_BMP085_U.h> // pripojíme knižnicu pre senzor BMP180( BMP085 )
#include <cactus_io_SHT31.h> // pripojíme knižnicu pre senzor SHT31
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
cactus_io_SHT31 sht31;
///Prepojenie BMP180 a SHT31 k Arduinu UNO
//Pripojíme SCL na analógový vstup A5
//Pripojíme SDA na analógový vstup A4
//Pripojáme VDA na 3,3 Volta
//Pripojím GND na GND Arduino
const int buttonPin = 6;
const int backLight = 9;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // priradíme vývody
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // zadáme vývody na LCD monitore
void setup()
{
Serial.begin(9600); //Priradíme Serial Monitor
pinMode(backLight,HIGH);
digitalWrite(backLight,HIGH);
lcd.begin(16, 2); // Zapneme obrazovku
lcd.print(" METEOSTANICA ");// Vypíše nám Meteostanica Viktor
lcd.setCursor(0,1);
lcd.print(" Viktor Joba 4F ");
delay(1500); // oneskorenie v ms
lcd.clear(); // vyčistíme obrazovku
if(!bmp.begin())
{
// cyklus na ten prípad ak by bol nijaky problem so senzorom BMP180
lcd.print("NO BMP180 DETECTED!");
while(1);
}
// cyklus na ten prípad ak by bol nijaky problem so senzorom SHT31
if (!sht31.begin()) {
lcd.println("NO SHT31 DETECTED!"); //
while(1) ;
}
}
void loop(){
sensors_event_t event; // vytvoríme nove udalosti
bmp.getEvent(&event);
if (event.pressure) {
float temperature;
bmp.getTemperature(&temperature); // načítame hodnotu teploty zo senzora BMP180
lcd.setCursor(0,0); // nastvíme kurzor na začiatok prvého riadku
lcd.print("T:");
lcd.print(temperature); // vypíše nám teplotu s nepresnosťou +/- 2
lcd.print(char(178)); // znak
lcd.print("C");
lcd.print(" H:");
lcd.print(round(sht31.getHumidity())); // načíta hodnotu vlhkosti zo senzora SHT31 s nepresnostou
lcd.print("%");
lcd.setCursor(0,1); // nastavíme kurzor na začiatok druhého riadku
lcd.print(" P:");
lcd.print(event.pressure); // načítame hodnotu tlaku zo senzora BMP180
lcd.print(" hPa ");
}
else
{
lcd.println("Sensor error"); // Ak nastane niaka chyba
}
delay(250);
}
kopka_meteostania.ino (2.45 KB)