Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Solar-Powered ESP8266 NodeMCU Weather Station with Multiple DS18B20 Sensors and Turbidity Monitoring

View and Edit Project In Cirkit DesignerImage of Solar-Powered ESP8266 NodeMCU Weather Station with Multiple DS18B20 Sensors and Turbidity Monitoring

Circuit Documentation

Summary

This circuit is designed to monitor environmental parameters, specifically temperature and turbidity, and send the data to a cloud service (ThingSpeak). It is powered by a solar panel and includes a charge controller to manage the charging of a Li-ion battery. The core of the circuit is an ESP8266 NodeMCU microcontroller, which reads data from multiple DS18B20 temperature sensors and a turbidity sensor, then transmits the data over WiFi.

Component List

Solar Panel

Do solara (Charge Controller)

XL6009 Voltage Regulator

18650 Li-ion Battery

ESP8266 NodeMCU

Module DS18B20

DS18B20 1-Wire Temperature Sensor Probe Cable

Sonda Sensor Turbidez / Turbidity Sensor

Turbidity Module

Wiring Details

Solar Panel

Do solara (Charge Controller)

XL6009 Voltage Regulator

ESP8266 NodeMCU

Module DS18B20

Sonda Sensor Turbidez / Turbidity Sensor

Documented Code

The following code is written for the ESP8266 NodeMCU microcontroller. It initializes the temperature sensors and WiFi connection, reads temperature data from the sensors, and sends the data to ThingSpeak.

/*
 * Ing.Misael Condado Fomperosa
 * Universidad Tecnologica de Matamoros
 * PROYECTO BIOVIDA HUMEDALES UT MATAMOROS
 */

// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>

String apiKey = "2CPV52I3FAFOHK8O"; // Enter your Write API key from ThingSpeak

const char *ssid = "INFINITUM010D_2.4"; // Replace with your wifi ssid and WPA2 key
const char *pass = "JrxgMmuYt6";
const char* server = "api.thingspeak.com";
// Data wire is connected to GPIOD2
#define ONE_WIRE_BUS D1

// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

WiFiClient client;

void setup()
{
  Serial.begin(115200);
  delay(10);

  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

}

// DeviceAddress of the temperature sensors
DeviceAddress sensor1 = { 0x28, 0xFF, 0x77, 0x62, 0x40, 0x17, 0x4, 0x31 };
// ... (other sensor addresses)

void loop(void){
  // Request temperatures
  sensors.requestTemperatures();
  // Read temperatures in Celsius and Fahrenheit
  float tempC = sensors.getTempCByIndex(0);
  // ... (reading other sensors)

  // Check if reading was successful
  if ((tempC == -127.00) || (tempF == -196))
  {
    Serial.println("Failed to read from sensor!");
    delay(1000);
  }
  else
  {
    // Print temperatures
    Serial.print("Temperature in Celsius campo # 1: ");
    Serial.println(tempC);
    // ... (printing other sensor readings)

    // Send data to ThingSpeak
    if (client.connect(server,80))
    {
      String postStr = apiKey;
      postStr +="&field1=";
      postStr += String(tempC); //tempC
      // ... (adding other fields)
      postStr += "\r\n\r\n";

      client.print("POST /update HTTP/1.1\n");
      client.print("Host: api.thingspeak.com\n");
      client.print("Connection: close\n");
      client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
      client.print("Content-Type: application/x-www-form-urlencoded\n");
      client.print("Content-Length: ");
      client.print(postStr.length());
      client.print("\n\n");
      client.print(postStr);
      Serial.println("Sent data to Thingspeak");
    }
    client.stop();
    Serial.println("Delay of 15 Sec");
    // thingspeak needs minimum 15 sec delay between updates
    delay(15000);
  }
}

This code is responsible for initializing the sensors and WiFi module, reading temperature data, and sending it to the ThingSpeak server. It includes error handling for failed sensor readings and ensures that data is sent at intervals that comply with ThingSpeak's update policy.