loading

This instructable is for the software of my Weater Station Project. Please read it first to understand all explanations.

Because of the both MCUs the software concept is based on two parts: The ESP8266 runs on Nodemcu and does the Internet connection and thingspeak.com related parts. The Arduino does all the sensor related things. The communication between Arduino and ESP8266 is via serial connection whereby the Arduino uses the SoftwareSerial Library on pins D2 (RX) and D3 (TX).

The configuration is divided into the both units:

  • All wifi and thingspeak.com relevant parameters are stored in the ESP8266 in a config file.
  • All sensor and measuring related parameter are set in the Arduino.

Why? I build up a lot of different units which only differ in the thingspeak.com and wifi parameters. And I build a neat programmer (image) for the ESP01. So I only have to save the new config file to the ESP01 and keep all other things same. And can easily change the thingspeak channel by changing only the ESP01 config.

There's two modes in the Arduino software: standard and low power. The standard version powering the ESP01 once and sends data regularly (short periods) to thingspeak.com. The low power one sends the date also regularly but within longer periods. Between two sendings the ESP01 is powered down. Why using the standard version and not always save power? If you want a more reliable, equidistant time stamp on thingspeak.com reconnection to wifi takes too long and is not equal from one reconnection to the other. And if you don't run the system on battery, power saving is not the most important aspect.

Step 1: The ESP01 Software

If not already done, flash the Nodemcu firmware to the ESP01. For flashing see this other ESP01 project (link).

Extract all file from the the attached archive. To upload and communicate with the ESP01 I use ESPlorer.

  • First, change the Wifi and thingspeak.com parameters in config.lua to yours:
wifiStation = "yourssid"
wifiPW = "yourwifipw"
devName = "name_of_your_device"
thingsSpeakKey = "ts_write_key"
tsChannel = "ts_channel_nb" 
  • Save localServer.lua, tempArduino.lua, wifiConfig.lua and init_real.luaand compile them. After compiling you can delete the *.lua files.
  • Save the config.lua and init.lua to the ESP01. Do not compile these files.
  • Restart the device.
  • Test the connection with ESPlorer: Wait until Wifi settled down and send sendData() via serial to the ESP01. This should do an update of the thingspeak.com channel. If no positive return check your config.

LEDs

The both LEDs show the status of the ESP01:

  • RED on: ESP01 is running, looks for Wifi connection
  • GREEN on: Wifi connected
  • RED blinking: No Wifi connection found. Module uses AP mode:
    • SSID: ESP+ DeviceID
    • PW: DeviceID
    • IP address: 192.168.1.1

If red and green are reversed reverse the LEDs in the header.

Step 2: The Arduino Software

The Arduino is the measuring device. It reads all sensor values and calculates the average over a specific time period (moving or rolling average).It also sets the ESP01 to sleep and wake it up again.

There are few things to setup in the header individually. First the working mode:

// ------------- mode setup ------------------
#define lowPowerMode 1 // lowPower = 1, standard = 0

Second different times:

// ------------- time setup ------------------
#define wifiSendPeriod 300000 // send data every x ms to thingspeak
#define meanPeriod 300000 // calculate the average of the sensor values of the last x ms
#define avAnzDef 60 // number of values within the meanPeriod for averaging

And also the data of your thermistor:

// ------------- thermistor setup ------------------ 
float thermr = 10000; // reference resistance of the thermistor
int beta = 3950; // beta value
float t0 = 298.15; // reference temperature of the thermistor
float pad = 10000; // balance/pad resistor value

That's all!

Step 3: Communication Between ESP8266 and Arduino

Direction:

  • AE: Send command from Arduino to ESP01
  • A←E: Answer from ESP01 to Arduino
  • E→A: Send status from ESP01 to Arduino
  • E←A: Answer from Arduino to ESP01

Send data to thingspeak.com:

A→E:

sendData()

A←E:

D0         // not successful
D1 // successfully send to thingspeak.com

Update values on the ESP01:

A→E:

field01=<value>                     // temperature from thermistor
field02=<value> // temperature from DHT11
field03=<value> // humidity
field04=<value> // illuminance
field05=<value> // resistance of the thermistoir
field06=<value> // temperature from BMP180
field07=<value> // pressure from BMP180

A←E:

no answer

Wifi Status

E→A:

WS1          // Wifi on and connected

Step 4: Stability

To see the stability of the system here's the link to a chart from my thingspeak.com account showing the temperature and the illuminance somewhere in Germany:

https://thingspeak.com/plugins/13247

Actually it shows a one week overview. The system runs since mid of August without a break.

So, if there are any questions ask them in the comments.

And for further instructables follow me.

<p>I managed to get it going and added a motion sensor, Straight up couldn't have got there without your kickstart,</p><p>Probably riddled with errors but here is everything I have, </p><p>Library's I got it going where,</p><p>Adafruit_BMP085_Library</p><p>DHT</p><p>SoftwareSerial</p><p>Wire</p><p>Cheers for posting the project.</p>
<p>Cool project!, i'm 90% the way there I've made the hardware got the esp online with thingspeak but, i've just been spending a while trying to get the library's right and i'm just having a bit of trouble with the Average library namely the running average function, i've tried older versions of the arduino ide and eclipse, including all average.h libraries i could find with still no luck, are you using your own altered library?</p><p>This is the error i'm getting in the Arduino Ide and eclipse using the standard Average library from Majenko.</p><p>tempArduino_low_04.ino: In function 'void setup()':</p><p>tempArduino_low_04:119: error: 'rollingAverage' was not declared in this scope</p><p>tempArduino_low_04.ino: In function 'void loop()':</p><p>tempArduino_low_04:147: error: 'rollingAverage' was not declared in this scope</p><p>'rollingAverage' was not declared in this scope</p><p>Any help would be great, otherwise in any case appreciate the effort you've gone through to post this project to get me this far!</p>
<p>Hello, I ran into the same problem the last time I uploaded it with the newest Arduino IDE. There is a new Average library with a new syntax. I then wrote a new version of the Arduino program. But suddenly I hadn't the time to test it. I will do this in the next days and give you a feedback.</p><p>Thanks for building my project. If it's possible for you, please send me a picture of the final device.</p>
<p>It works !! Excellent instro, I modified your code to take just 1 sensor at the moment, a DS18S20. The wifi perform flawlessly, connecting to the router in less than 4 seconds. Only 1 problem, when router not available, the ESP8266 has a panic fault and repeatedly reboots...otherwise...well done !</p>

About This Instructable

26,744views

156favorites

More by ohneschuh:AVR Programmer Shield Traffic Light without Arduino ESP8266 Weather Station with Arduino – #2 Software 
Add instructable to: