Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Hugo Gomes
Published © GPL3+

ESP8266 Solar Weather Station

Get the temperature, humidity and pressure, and display them over the internet; everything is powered by the sun. (ESP8266 version.)

IntermediateFull instructions provided8 hours34,221
ESP8266 Solar Weather Station

Things used in this project

Hardware components

DFRobot Gravity: I2C BME280 Environmental Sensor (Temperature, Humidity, Barometer)
×1
DFRobot 3.7V Polymer Lithium Ion Battery - 1000mAh
×1
DFRobot Solar Lipo Charger (3.7V)
×1
ESP8266
×1
6V 1W Solar Panel
×1
Perfboard
×1
Female Header
×1
Enclosure
×1

Software apps and online services

Cayenne
myDevices Cayenne
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

System Schematic

Components mounting plate

Code

Code_V1.0.ino.ino

Arduino
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// Library
#include "ESP8266WiFi.h"

#define uS_TO_m_FACTOR 60000000   // Conversion factor for micro seconds to minutes
// Time to sleep (in minutes):
const int sleepTimeM = 15;


// WiFi network info.
char ssid[] = "YOUR_SSID";
char wifiPassword[] = "YOUR_WIFI_PASSWORD";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "YOUR_USERNAME";
char password[] = "YOUR_PASSWORD";
char clientID[] = "YOUR_CLIENT_ID";



//Library for BME280 Sensor
#include <DFRobot_BME280.h>

#define SEA_LEVEL_PRESSURE  1013.25f

DFRobot_BME280 bme; //I2C

float temp, pressure, hum, alt; //Variables for the BME280 Sensor

ADC_MODE(ADC_VCC);

void setup() {


  Serial.begin(115200);

  //Connect with Wifi
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);



  //Start I2C
  // I2c default address is 0x77, if the need to change please modify bme.begin(Addr)
  if (!bme.begin()) {
    Serial.println("No sensor device found, check line or address!");
    while (1);
  }

  delay(100);

  Get_Values(); //Get values from the BME280



  //Check Internal Voltage
  float vdd = ESP.getVcc() / 1000.0;
  Serial.println (vdd);


  Cayenne.loop();

  //Send data to Cayenne
  Cayenne.virtualWrite(0, temp); //Send temperature
  Cayenne.virtualWrite(1, pressure); // Send pressure
  Cayenne.virtualWrite(2, hum); // Send humidaty
  Cayenne.virtualWrite(3, vdd); //Send internal voltage

  //Go to sleep
  ESP.deepSleep(sleepTimeM * uS_TO_m_FACTOR, WAKE_RF_DEFAULT); // Sleep for 15 Minutes


}



void Get_Values()
{

  temp = bme.temperatureValue();
  delay(100);

  pressure = bme.pressureValue() / 100.0F;
  hum = bme.humidityValue();
  alt = bme.altitudeValue(SEA_LEVEL_PRESSURE);

  delay(100);

  Serial.println("Collect data");

  Serial.print("Temperature :");
  Serial.print(temp);
  Serial.println(" C");

  Serial.print("Pressure:");
  Serial.print(pressure);
  Serial.println(" hPa");

  Serial.print("Humidity :");
  Serial.print(hum);
  Serial.println(" %");

  Serial.print("Approx. Altitude:");
  Serial.print(alt);
  Serial.println(" m");

  Serial.println("------END------");

  //Place BME280 into sleep mode
  BME280_Sleep();

}


void BME280_Sleep()
{

  //Serial.println("BME280 to Sleep mode");

  Wire.beginTransmission(0x77);
  Wire.write((uint8_t)BME280_REGISTER_CONTROL);
  Wire.write((uint8_t)0b00);
  Wire.endTransmission();
}

//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}


void loop() {


}

Credits

Hugo Gomes
10 projects • 116 followers
http://www.hugogomes.net Youtube Channel - https://goo.gl/fnQLJo

Comments