Arduino “having11” Guy
Published © GPL3+

Display Current Weather with Arduino and Python!

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!

IntermediateFull instructions provided2 hours10,306
Display Current Weather with Arduino and Python!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
RGB LED
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Python OWM API

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

LCD Enclosure

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

Schematics

The Weather chematic

Just attach as-is

Code

The Python Side

Python
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 Side

C/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);
    }
    
}

Credits

Arduino “having11” Guy

Arduino “having11” Guy

89 projects • 615 followers
19 year-old IoT and embedded systems enthusiast. Also an interned at Hackster.io and love working on projects and sharing knowledge.

Comments