ItKindaWorks Forum

A forum for everything that Kinda Works YouTube.com/ItKindaWorks

You are not logged in.

Announcement

Welcome to the ItKindaWorks Forum

#1 2018-02-28 21:27:45

Sparky056
Member
Registered: 2018-02-28
Posts: 12

Home based weather station

For the last month I've working on a home weather station that I will put outside (shielded from the weather).  Using an Adafruit Huzzah ESP8266, DHT22 and BMP280 sensors.  Also have from Adafruit, wind meter (anemometer) #1733.
I have all the sensors working fine but I have trouble with the wind meter.  The max voltage output is 2.0vdc, but the ESP8266 has only one analog input and its max voltage input is 1vdc.
I'm also trying to set up OTA to this board but I'm missing something.
I'm posting this data to thingspeak.  If interested its at channel 525900, in Southwest Missouri

Offline

#2 2018-02-28 21:44:31

cromer
Administrator
From: internet land
Registered: 2017-12-26
Posts: 89
Website

Re: Home based weather station

Oh cool that sounds like a really fun project (and something that I've been meaning to do for a while!)

You could always just use a voltage divider for the wind meter. If you take 2 resistors and put them in series from the output of your sensor to gnd you can read the voltage at the point where those two resistors come together as your input. You can use the calculator here to determine the values of the two resistors. For your situation two equal resistors would make the output voltage drop by half making your 2v output into 1v that you can use on the ESP analog pin.

What are you having trouble with for OTA?


Creator of ItKindaWorks

Offline

#3 2018-03-01 00:20:38

Sparky056
Member
Registered: 2018-02-28
Posts: 12

Re: Home based weather station

the basic ota sketch will not complile

Offline

#4 2018-03-01 00:53:34

Sparky056
Member
Registered: 2018-02-28
Posts: 12

Re: Home based weather station

I just put two resistors is series, so now im reading 1vdc, however my wind meter is not moving.
Please look at the code.  I had this in a sketch on an Uno and the voltage and wind speed looked good, but now its running on my Huzzah ESP8266 and Im getting 30 mph wind and 1vdc (wind meter is not moving)
This is also the sketch that OTA is not working  (commented out for now) and I have removed my network info and API key.


#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "DHT.h"
#include <Adafruit_BMP280.h>
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
#include <ArduinoOTA.h>
#include <ESP8266mDNS.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>

// Helps with connecting to internet
#include <WiFiManager.h>

// HOSTNAME for OTA update
#define HOSTNAME "ESP8266-OTA-"

// ***** OTA set-up *****
//#include "ESPHelper.h"
//
//netInfo homeNet = {  .mqttHost = "YOUR MQTT-IP",     //can be blank if not using MQTT
//          .mqttUser = "YOUR MQTT USERNAME",   //can be blank
//          .mqttPass = "YOUR MQTT PASSWORD",   //can be blank
//          .mqttPort = 1883,         //default port for MQTT is 1883 - only chance if needed.
//          .ssid = "**********",
//          .pass = "xxxxxxxxxx"};
//
//ESPHelper myESP(&homeNet);


char ssid[] = "**********";    //  your network SSID (name)
char pass[] = "xxxxxxxxxx";   // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
WiFiClient client;
unsigned long myChannelNumber = 425900;
const char * myWriteAPIKey = "************";
const char* server = "api.thingspeak.com";
const int postingInterval = 20 * 1000; // post data every 20 seconds

#define DHTPIN 14
#define DHTTYPE DHT22   // DHT 22
DHT dht(DHTPIN, DHTTYPE);

// ***** add BMP280 *****
Adafruit_BMP280 bme; // I2C
float mA;
//  ********** WIND START **********
double x = 0;
double y = 0;
//int sensorValue = analogRead(A0);
//#define VOLTAGE_MAX 1.0
//#define VOLTAGE_MAXCOUNTS 1023.0
//float voltage = sensorValue * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
const int sensorPin = A0; //Defines the pin that the anemometer output is connected to
int sensorValue = 0; //Variable stores the value direct from the analog pin
float sensorVoltage = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed = 0; // Wind speed in meters per second (m/s)
float voltageConversionConstant = .004882814; //This constant maps the value provided from the analog read function, which ranges from 0 to 1023, to actual voltage, which ranges from 0V to 5V
int sensorDelay = 2000; //Delay between sensor readings, measured in milliseconds (ms)
float voltageMin = .4; // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage
float voltageMax = 2.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage
// ********** wind end **********

float tF;
float dP;
float dPF;
float hiF;
float wS;
float Pa;

void setup()
{
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  // ***** OTA start setup
//  Serial.println("Starting Up, Please Wait...");
//
//  myESP.OTA_enable();
//  myESP.OTA_setPassword("4999");
//  myESP.OTA_setHostnameWithVersion("SET OTA HOSTNAME"); // or is this the name?
//  myESP.addSubscription("/shed"); // change name to your project name
//  myESP.setMQTTCallback(callback);
//  myESP.begin();
//  Serial.println("Initialization Finished.");
  // ***** OTA end

  ThingSpeak.begin(client);
    Serial.println(F("BMP280 test"));
 
    if (!bme.begin()) {
      Serial.println("Could not find a valid BMP280 sensor, check wiring!");
      while (1);
    }
}

void loop() {
//  myESP.loop();  //run the OTA loop() method as often as possible - this keeps the network services running
 
  long rssi = WiFi.RSSI();

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

// ***** Run BMP280 *****
Serial.print("Temperature = ");
    Serial.print((bme.readTemperature()*9/5+32));
    Serial.println(" *F");

    Serial.print("Pressure = ");
    Serial.print(bme.readPressure()/3389.39);
    Serial.println(" inHG");
    Pa=(bme.readPressure()/3389.39);

    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");
    //my altitude
    mA=(bme.readAltitude(1013.25))/0.3034;
    Serial.print(mA);
    Serial.println(" Ft.");
    Serial.println();
// ***** End BMP280 *****

// ***** Start DHT22 *****   
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");

    Serial.print("Temperature: ");
    // Serial.print(t);
    // Serial.print(" *C ");
    tF = ((t * 9) / 5) + 32;
    Serial.print(tF);
    Serial.print(" *F ");
    Serial.print(" \t");

    Serial.print("Dew Point: ");
    // Serial.print(dewPointFast(t, h));
    // Serial.print(" *C ");
    dP = (dewPointFast(t, h));
    dPF = ((dP * 9) / 5) + 32;
    Serial.print(dPF);
    Serial.print(" *F");
    Serial.print(" \t");

    Serial.print("Heat Index: ");
    Serial.print(heatIndex(tF, h));
    hiF = (tF, h);
    Serial.println(" *F");
  }

  // ********** WIND **********
  sensorValue = analogRead(sensorPin); //Get a value between 0 and 1023 from the analog pin connected to the anemometer
  sensorVoltage = sensorValue * voltageConversionConstant; //Convert sensor value to actual voltage
  if (sensorVoltage <= voltageMin) {
    windSpeed = 0; //Convert voltage value to wind speed using range of max and min voltages and wind speed for the anemometer. Check if voltage is below minimum value. If so, set wind speed to zero.
  } else {
    windSpeed = ((sensorVoltage - voltageMin) * windSpeedMax / (voltageMax - voltageMin) * 2.23694); //For voltages above minimum value, use the linear relationship to calculate wind speed in MPH.

    //Max wind speed calculation below

    x = windSpeed; if (x >= y) {
      y = x;
    } else
      y = y;
  }
  int sensorValue = analogRead(A0);
  float outvoltage = sensorValue * (5.0 / 1023.0);
  Serial.print("outvoltage = ");
  Serial.print(outvoltage);
  Serial.println("V");
  int Level = 6 * outvoltage; //The level of wind speed is proportional to the output voltage.
  Serial.print("Wind Speed ");
  Serial.println(windSpeed);
  wS = (windSpeed);
  delay(1000);
  //  ********** WIND **********

  ThingSpeak.setField(1, tF);   // temp in F
  ThingSpeak.setField(2, h);    //  humidity %
  ThingSpeak.setField(3, hiF);  // heat index in F
  ThingSpeak.setField(4, dPF);  // dew point in F
  ThingSpeak.setField(5, Pa);    // pressure
  ThingSpeak.setField(6, outvoltage);   // my altitude
  ThingSpeak.setField(7, wS);   // wind speed
  ThingSpeak.setField(8, rssi);
  ThingSpeak.writeFields(425900, myWriteAPIKey);
  //  delay(20000);
//  yield(); // OTA
}
  //void callback(char* topic, uint8_t* payload, unsigned int length) {
  //  //put mqtt callback code here
  //}
// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity * 0.01);
  double Td = (b * temp) / (a - temp);
  return Td;
}

double heatIndex(double tempF, double humidity)
{
  double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248, c5 = -6.838e-3, c6 = -5.482e-2, c7 = 1.228e-3, c8 = 8.528e-4, c9 = -1.99e-6  ;
  double T = tempF;
  double R = humidity;

  double A = (( c5 * T) + c2) * T + c1;
  double B = ((c7 * T) + c4) * T + c3;
  double C = ((c9 * T) + c8) * T + c6;

  double rv = (C * R + B) * R + A;
  return rv;
}

Offline

#5 2018-03-23 03:28:24

cromer
Administrator
From: internet land
Registered: 2017-12-26
Posts: 89
Website

Re: Home based weather station

It sounds like the circuit for the wind sensor might not be wired up correctly if you are getting 1v when the sensor is not moving. Can you send me a link to the sensor so I may get a better idea of what you're using?

As for the OTA program not compiling, can you give me the error that you get when compiling it along with the Arduino version and ESPHelper version that you are using?


Creator of ItKindaWorks

Offline

Board footer

Powered by FluxBB