This weather station project is still in the making. This is only first part. Upgrades will be uploaded in next one or two months.
Nearly all needed materials for this project can be bought on online store: DFRobot
#include <SD.h> //SD #include <SPI.h> //SD File myFile; //SD int pinCS = 10; //////////// //LCD #include <Wire.h> #include <LiquidCrystal_I2C.h> #define BACKLIGHT_PIN 3 LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); /////////// int sensorPin = A0; //battery voltage pin int sensorValue = 0; /////////////////// int sensorPin_solar = A1; //solar panel voltage pin int sensorValue_solar = 0; //////////////// char databuffer[35]; double temp; void getBuffer() //Get weather status data { int index; for (index = 0;index < 35;index ++) { if(Serial.available()) { databuffer[index] = Serial.read(); if (databuffer[0] != 'c') { index = -1; } } else { index --; } } } int transCharToInt(char *_buffer,int _start,int _stop) //char to int) { int _index; int result = 0; int num = _stop - _start + 1; int _temp[num]; for (_index = _start;_index <= _stop;_index ++) { _temp[_index - _start] = _buffer[_index] - '0'; result = 10*result + _temp[_index - _start]; } return result; } int WindDirection() //Wind Direction { return transCharToInt(databuffer,1,3); } float WindSpeedAverage() //air Speed (1 minute) { temp = 0.44704 * transCharToInt(databuffer,5,7); return temp; } float WindSpeedMax() //Max air speed (5 minutes) { temp = 0.44704 * transCharToInt(databuffer,9,11); return temp; } float Temperature() //Temperature ("C") { temp = (transCharToInt(databuffer,13,15) - 32.00) * 5.00 / 9.00; return temp; } float RainfallOneHour() //Rainfall (1 hour) { temp = transCharToInt(databuffer,17,19) * 25.40 * 0.01; return temp; } float RainfallOneDay() //Rainfall (24 hours) { temp = transCharToInt(databuffer,21,23) * 25.40 * 0.01; return temp; } int Humidity() //Humidity { return transCharToInt(databuffer,25,26); } float BarPressure() //Barometric Pressure { temp = transCharToInt(databuffer,28,32); return temp / 10.00; } void setup() { lcd.begin (20,4); lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.home (); ////////// Serial.begin(9600); //////// pinMode(pinCS, OUTPUT); // SD Card Initialization if (SD.begin()) { Serial.println("SD card is ready to use."); } else { Serial.println("SD card initialization failed"); return; } ////////// } void loop() { ////////////////// sensorValue = analogRead(sensorPin); //Monitoring battery voltage float voltage = sensorValue*(5.0/1023.0); lcd.setCursor(0,3); //0,3 lcd.print("Voltage bat: "); lcd.print(voltage); lcd.print(" V"); ///////////////// sensorValue_solar = analogRead(sensorPin_solar); float voltage_solar = 2*sensorValue_solar*(5.0/1023.0)-0.07; Serial.println(voltage_solar); // lcd.setCursor(0,2); //This is example how to set your LCD commands // lcd.print("Voltage sol: "); // lcd.print(voltage_solar); // lcd.print(" v"); ///////////////////// getBuffer(); //Begin! /////// if(WindDirection()==0){ Serial.print("Wind Direction: "); Serial.print("SW"); Serial.println(" "); } if(WindDirection()==45){ Serial.print("Wind Direction: "); Serial.print(" W"); Serial.println(" "); } if(WindDirection()==90){ Serial.print("Wind Direction: "); Serial.print("NW"); Serial.println(" "); } if(WindDirection()==135){ Serial.print("Wind Direction: "); Serial.print(" N"); Serial.println(" "); } if(WindDirection()==180){ Serial.print("Wind Direction: "); Serial.print("NE"); Serial.println(" "); } if(WindDirection()==225){ Serial.print("Wind Direction: "); Serial.print(" E"); Serial.println(" "); } if(WindDirection()==270){ Serial.print("Wind Direction: "); Serial.print("SE"); Serial.println(" "); } if(WindDirection()==315){ Serial.print("Wind Direction: "); Serial.print(" S"); Serial.println(" "); } // Serial.print("Wind Direction: "); //Serial.print(WindDirection()); // Serial.println(" "); Serial.print("Average Wind Speed (One Minute): "); Serial.print(WindSpeedAverage()); Serial.println("m/s "); Serial.print("Max Wind Speed (Five Minutes): "); Serial.print(WindSpeedMax()); Serial.println("m/s"); // lcd.setCursor(0,0); // lcd.print("Max Speed"); // lcd.print(" "); //lcd.print(WindSpeedMax()); // lcd.print(" "); // lcd.print("m/s"); Serial.print("Rain Fall (One Hour): "); Serial.print(RainfallOneHour()); Serial.println("mm "); Serial.print("Rain Fall (24 Hour): "); Serial.print(RainfallOneDay()); Serial.println("mm"); Serial.print("Temperature: "); Serial.print(Temperature()); Serial.println("C "); // lcd.setCursor(0,2); // lcd.print("Temperature: "); // lcd.print(Temperature()); // lcd.print("C "); Serial.print("Humidity: "); Serial.print(Humidity()); Serial.println("% "); Serial.print("Barometric Pressure: "); Serial.print(BarPressure()); Serial.println("hPa"); Serial.println(""); Serial.println(""); //// myFile = SD.open("test.txt", FILE_WRITE); if (myFile) { if(WindDirection()==0){ myFile.print("Wind Direction: "); myFile.print("SW"); myFile.println(" "); } if(WindDirection()==45){ myFile.print("Wind Direction: "); myFile.print(" W"); myFile.println(" "); } if(WindDirection()==90){ myFile.print("Wind Direction: "); myFile.print("NW"); myFile.println(" "); } if(WindDirection()==135){ myFile.print("Wind Direction: "); myFile.print(" N"); myFile.println(" "); } if(WindDirection()==180){ myFile.print("Wind Direction: "); myFile.print("NE"); myFile.println(" "); } if(WindDirection()==225){ myFile.print("Wind Direction: "); myFile.print(" E"); myFile.println(" "); } if(WindDirection()==270){ myFile.print("Wind Direction: "); myFile.print("SE"); myFile.println(" "); } if(WindDirection()==315){ myFile.print("Wind Direction: "); myFile.print(" S"); myFile.println(" "); } // myFile.print("Wind Direction: "); // myFile.print(WindDirection()); // myFile.println(" "); myFile.print("Average Wind Speed (One Minute): "); myFile.print(WindSpeedAverage()); myFile.println("m/s "); myFile.print("Max Wind Speed (Five Minutes): "); myFile.print(WindSpeedMax()); myFile.println("m/s"); myFile.print("Rain Fall (One Hour): "); myFile.print(RainfallOneHour()); myFile.println("mm "); myFile.print("Rain Fall (24 Hour): "); myFile.print(RainfallOneDay()); myFile.println("mm"); myFile.print("Temperature: "); myFile.print(Temperature()); myFile.println("C "); myFile.print("Humidity: "); myFile.print(Humidity()); myFile.println("% "); myFile.print("Barometric Pressure: "); myFile.print(BarPressure()); myFile.println("hPa"); myFile.println(""); myFile.println(""); myFile.print("Voltage bat: "); myFile.print(voltage); myFile.println(" V"); myFile.print("Voltage sol: "); myFile.print(voltage_solar); myFile.println(" V"); myFile.close(); // close the file } // if the file didn't open, print an error: else { Serial.println("error opening test.txt"); } delay(100); }