Project tutorial
Display Current Weather with Arduino and Python!

Display Current Weather with Arduino and Python! © GPL3+

Instead of having to look up weather online, why not just look at your Arduino? Well with this project now you can by using an LCD and LED!

  • 7,969 views
  • 4 comments
  • 19 respects

Components and supplies

Necessary tools and machines

3drag
3D Printer (generic)

Apps and online services

About this project

For this project we will mainly be using the pyserial library and the pyowm API. In order to use the code we must first type in pip install pyserial and pip install pyowm into your shell/ command prompt. Next up you must get a key to use the open weather map API, but don't worry! The API is free if you're using it occasionally. Go to their website at: https://home.openweathermap.org/users/sign_up and enter in your information. After that, insert your API key that is listed on your home dashboard into the python code where it says: "Your API key here". Also, insert your serial port on line 5 in the python code. The program will loop through every 20 minutes, as you can only pull data once every 10 minutes with the free account. 

Now you are ready to enjoy a full weather experience.

Code

The Python SidePython
Just copy and paste
import pyowm
import time
import serial
#setting up serial communication
ser = serial.Serial('<your Arduino serial port>', 9600)
#creating pyowm object
owm = pyowm.OWM(API_key='Your API key here')
#get address
print "Enter your street address with your state and city."
location = raw_input()
#indefinitely loop through and update
while True:
    observation = owm.weather_at_place(location)
    w = observation.get_weather()
    print(w)
    print w.get_status()
    ser.write("stat*" + str(w.get_status()) + "#")      
    ser.write("wind*" + str(w.get_wind()))               
    print w.get_wind()  
    time.sleep(5)
    ser.write("hum*" + str(w.get_humidity()))
    print w.get_humidity()
    time.sleep(5)        
    ser.write("temp*" + str(w.get_temperature('celsius').get('temp')))      
    print w.get_temperature('celcius').get('temp')
    #wait 20 minutes
    time.sleep(1200)
The Arduino SideC/C++
Just copy and paste again into the Arduino IDE
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String str = "";
String data2 = "";
float data;
int red = 0;
int green = 0;
int blue = 0;
int redPin = A1;
int greenPin = A3;
int bluePin = A2;
void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Current Weather:");
  Serial.begin(9600);
  lcd.setCursor(0,1);
}

void loop() {
  if (Serial.available()>0){
    Serial.println("ready");
    str = Serial.readStringUntil('*');
    Serial.println(str);
    if (str =="wind"){
      Serial.println("ok");
      data = Serial.parseFloat();
      lcd.print("Wind: ");
      lcd.print(data);
      lcd.print("kmph");
      delay(6000);
    }
    if (str=="hum"){
      Serial.println("got it");
      data = Serial.parseFloat();
      lcd.print("Humidity: ");
      lcd.print(data);
      lcd.print("%");
      delay(6000);
    }
    if (str=="temp"){
      Serial.println("ok");
      data = Serial.parseFloat();
      lcd.print("Temp: ");
      lcd.print(data);
      lcd.print(" C");
      delay(6000);
    }
    if (str=="stat"){
      data2 = Serial.readStringUntil('#');
      Serial.println(data2);
      if (data2=="Rain"){
        analogWrite(redPin, 0);
        analogWrite(greenPin, 0);
        analogWrite(bluePin, 255);
      }
      else if(data2=="clouds" || "Clouds"){
        analogWrite(redPin, 163);
        analogWrite(greenPin, 163);
        analogWrite(bluePin, 194);
      }
      else if(data2=="sun" || "Sun"){
        analogWrite(redPin, 255);
        analogWrite(greenPin, 255);
        analogWrite(bluePin, 0);
      }
    }
  lcd.clear();
  lcd.setCursor(0,0);
    str = "";
    data = 0;
    lcd.print("Current Weather:");
    lcd.setCursor(0,1);
    }
    
}

Custom parts and enclosures

LCD Enclosure
Just print it out then hot-glue the lcd inside.

Schematics

The Weather chematic
Just attach as-is
Thumbnail20160422 16374 1mual6z

Comments

Similar projects you might like

Temperature sensor

Project tutorial by Grant

  • 12,304 views
  • 6 comments
  • 30 respects

DHT11 Humidity + Temperature Sensor with 16x2 LCD display

Project showcase by onatto22

  • 9,054 views
  • 1 comment
  • 17 respects

$10 Portable Arduino Weather Station (AWS)

Project tutorial by Prajjwal Nag

  • 31,648 views
  • 6 comments
  • 59 respects

AWS - Arduino Weather Station

Project tutorial by GilettaStefano

  • 19,313 views
  • 13 comments
  • 63 respects

Weather Station v.1.0

Project showcase by derapados

  • 10,388 views
  • 3 comments
  • 36 respects

Wireless weather station (Arduino + ESP8266 + Thingspeak)

Project tutorial by Alin-Constantin Paun

  • 8,864 views
  • 2 comments
  • 11 respects
Add projectSign up / Login