3D Printed IoT Weather Station Prototype in the Wild

December 26, 2016 | ProgressTH 

Recently, we've been working on a 3D printed, WiFi connected (Internet of Things or IoT) weather station for local farms. We have planned to make three V.1 stations; one for our rooftop garden, and two for farms outside of the city.


We've finally deployed the first V.1 station on the rooftop. We'll work out any issues that arise with this one (including issues transmitting data through the concrete roof), and modify the other two in this series. Finishing the first station required a few extra steps since our last update here.

First, we needed to modify the NodeMCU Arduino code to put the system to sleep for 10 minutes in between transmitting data. This extended the 9V 1600mA sealed lead-acid battery's life from 4-5 hours per full charge to 41 hours.

Then we needed to design and 3D print a bracket assembly to hold the solar panel in place atop the station's mast.

The Arudino code is at the end of the article. We've uploaded the 3D design files for the solar panel bracket to Thingiverse and included the SketchUp 2015 file so people can modify the design to fit the panels they have. 



Above is the read out of the rooftop station. It updates every 10 minutes, day and night. See the Arduino code after the break.  


//http://www.instructables.com/id/Send-sensor-data-DHT11-BMP180-to-ThingSpeak-with-a/
// Edited by Arvin Febriyan ( FARM HACK Dec 2016)
// Use Node MCU to send humidity, temperature and light data. Ver 1. More work to be done to make humidity data and light data more usable.

/*
 *  [ADDED CODE from here: https://blog.squix.org/2015/07/esp8266-long-term-data-logger-rip-after.html] This sketch sends data via HTTP GET requests to thingspeak service every 10 minutes
 *  You have to set your wifi credentials and your thingspeak key.
 */

#include <ESP8266WiFi.h>
extern "C" {
  #include "user_interface.h"
}
#include "DHT.h"

#define DHTPIN 2 //D4 on nodemcu
#define DHTTYPE  DHT11    // what pin we're connected to


DHT dht(DHTPIN, DHTTYPE, 2);

const char* ssid     = "Your WiFi Network Name Including the Parentheses";
const char* password = "Your Password Including the Parentheses";
const char* host = "api.thingspeak.com";
const char* writeAPIKey = "Your Thingspeak Write API Key Including the Parentheses"; //Change to your Thingspeak WRITE API key  

void turnOff(int pin) {
  pinMode(pin, OUTPUT);
  digitalWrite(pin, 1);
}

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

  // disable all output to save power
  turnOff(0);
  turnOff(2);
  turnOff(4);
  turnOff(5);
  turnOff(12);
  turnOff(13);
  turnOff(14);
  turnOff(15);

  dht.begin();
  delay(10);
  

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

int value = 0;

void loop() {
  delay(5000);
  ++value;

  // read the humidity and temperature input from DHT11:
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  // read the input on analog pin 0 (Light Sensor):
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);

  if (isnan(humidity) || isnan(temperature)) {
    delay(1000); //gives better DHT11 performance
    return;
  }

  // make TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    return;
  }

  String url = "/update?key=";
  url += writeAPIKey;
  url += "&field1=";
  url += String(temperature);
  url += "&field2=";
  url += String(humidity);
  url += "&field3=";
  url += String(voltage);
  url += "\r\n";

  // Request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(60000); //Thingspeak will reject your data if you send it too often.

  Serial.print("humidity");
  Serial.print(humidity);

  Serial.println("temperature");
  Serial.print(temperature);

  Serial.println("voltage");
  Serial.print(voltage);
  
  
  Serial.println();
  Serial.println("closing connection. going to sleep...");
  delay(1000);
  // go to deepsleep for 10 minutes
  system_deep_sleep_set_option(0);
  system_deep_sleep(10 * 60 * 1000000);
}