Harsh Dethe
Published © CC BY-NC-SA

Simple Weather Station Using ESP8266

Make a simple weather station using an ESP8266. You can also use the ESP32 or Raspberry Pi too.

IntermediateFull instructions provided1 hour1,533
Simple Weather Station Using ESP8266

Things used in this project

Hardware components

NodeMCU ESP8266
×1
LCD
×1
Breadboard (generic)
Breadboard (generic)
×1
Pushbutton
×1
Resistor 220 ohm
Resistor 220 ohm
×1
10k potietiometer
×1

Software apps and online services

Arduino IDE
Arduino IDE
RemoteMe.org cloud
RemoteMe.org cloud

Story

Read more

Schematics

Circuit Diagram

Code

Weather.ino

Arduino
Error opening file.

Code snippet #1

Plain text
#define WIFI_NAME "WiFi Name"
#define WIFI_PASSWORD "WiFi Password"
#define DEVICE_ID 1 
#define DEVICE_NAME "Device Name"
#define TOKEN "Add Token"
#define btn D1  //Declare a button variable for push button

#include<RemoteMe.h>
#include<RemoteMeSocketConnector.h>
#include<ESP8266WiFi.h>
#include<ESP8266WiFiMulti.h>
#include<LiquidCrystal.h> //including library to use LCD

LiquidCrystal lcd(D2, D3, D5, D6, D7, D8); //mapping LCD pins to ESP's pins 

/* Variables to store data from RemoteMe */
int16_t i, i1, i2, temp, pres;
int32_t subs, views;
String hr; //Only needed if you want to display time.

long lastDebounceTime = 0, debounceDelay = 50; //To eliminate button bouncing.

ESP8266WiFiMulti WiFiMulti;
RemoteMe& remoteMe = RemoteMe::getInstance(TOKEN, DEVICE_ID);
void onSubscribersChange(int32_t i) 
{
    subs = i; //Storing subscriber data in variable 'subs' 
}

void onViewsChange(int32_t i) 
{
    views = i; //Storing views in variable 'views'
}

void onWeatherChange(int16_t i1, int16_t i2,String s1,String s2) 
{
    temp = i1; //storing temperature  
    pres = i2; //Storing Pressure 
}

/*New functions to display the stored data*/

void youtube()
{
  //Display YouTube info.
  Serial.printf("Subscribers : %d\n", subs);
  Serial.printf("Views : %d\n", views);
  
  lcd.clear();
  lcd.printf("Subscribers : %d", subs);
  lcd.setCursor(0,1);
  lcd.printf("Views : %d", views);
  lcd.setCursor(0,0);
}

void weather()
{
  //Display weather info.
  Serial.printf("Temparature : %d °C\n", temp);
  Serial.printf("Pressure : %d Pa\n", pres);
  lcd.clear();
  lcd.printf("Temperature : %d", temp);
  lcd.setCursor(0,1);
  lcd.printf("Pressure : %d", pres);
  lcd.setCursor(0,0);
}

void setup() 
{
    Serial.begin(9600);
    lcd.begin(16, 2);
    pinMode(btn, INPUT);
    
    WiFiMulti.addAP(WIFI_NAME, WIFI_PASSWORD);
    while (WiFiMulti.run() != WL_CONNECTED) 
    {
        delay(100);
    }
    remoteMe.getVariables()->observeInteger("Subscribers" ,onSubscribersChange);
    remoteMe.getVariables()->observeInteger("Views" ,onViewsChange);
    remoteMe.getVariables()->observeSmallInteger2Text2("Weather" ,onWeatherChange);
    remoteMe.sendRegisterDeviceMessage(DEVICE_NAME);
    Serial.print("Connected...");
    lcd.print("Connected...");
}

void loop() 
{
  int btn_state = LOW; //button state is initially set LOW 
  static int flag = 0; //flag is set 0
  
     btn_state = digitalRead(btn); //button input is read.

     if((millis() - lastDebounceTime) > debounceDelay) 
     {
       if((btn_state == HIGH) && (flag == 0)) //if button is pressed & flag is 0
       {
         weather(); //show weather data
         flag = 1; //set flag to 1
       }
       else if((btn_state == HIGH) && (flag == 1)) //if button is pressed & flag is 1
       {
         youtube(); //show YouTube info
         flag = 0; //set flag to 0
       }
       lastDebounceTime = millis();
     }
    remoteMe.loop();
}

arduino.ino

Arduino
Error opening file.

Credits

Harsh Dethe
30 projects • 71 followers
Electronics hobbyist, AI Enthusiast. I like to play with technology.
Contact

Comments

Please log in or sign up to comment.