项目创意

ESP8266 Arduino气象站

字号+ 作者:duino123.com 来源:未知 2016-04-28 18:44 我要评论( )

气象站的示例其实已经有了,但是这个的硬件非常精致,甚至连照片都拍的那么认真,看了让人赏心悦目,不得不佩服作者的认真细致!学习吧!

PLCLIVE.COM注:
气象站的示例其实已经有了,但是这个的硬件非常精致,甚至连照片都拍的那么认真,看了让人赏心悦目,不得不佩服作者的认真细致!学习吧!

第一部分:硬件篇




Background

I read about the ESP8266 first in March this year and I didn't know what to do with. And now I'm really fascinated how easy the connection of an Arduino to the Internet can be. Like others I set up a weather station on a breadboard first and sent data to thingspeak.com. This ends up in a highly condensed stripboard layout and the needed software package.

Why stripboarding and not etching a PCB?

There are a lot of good PCB layouts around. But I want to build something that everybody can do easily at home. A soldering stick, stripboards and parts are easy to get. But etching a PCB is often a hurdle. So, my challenge was to make the design on a stripboard within the size and functionality of a etched PCB.

What are the functionalities?

  • measure temperature, humidity, pressure and illuminance (brightness)!
  • send all data to thingspeak
  • ESP8266 can be turned on and off by Arduino for energy saving
  • additional digital IOs
  • Runs on 5 to 12 V
  • and a lot more

Why ESP8266 and Arduino?

Every one of them have its advantages. The Arduino is perfect for dealing with sensors. And the ESP8266 is perfect for the Internet connection. And I can turn off the Internet for energy saving ;).

And the best:

The weather functionalities are only one aspect. You can measure nearly everything with this board because you have the following sensor pinouts of the Arduino:

  • 2x analog
  • 6x digital
  • I2C for WIRE connections
  • 1x reset
  • 1x button

Step 1: Let's build: Parts







To build this weather station you need some parts:

  • 1x stripboard 20x15 vertical
  • 1x ESP01
  • 1x Arduino Mini Clone (this layout Arduino Mini, I chose the clone version because the position of A4 and A5 is more stripboard friendly compared to the official one)
  • 1x DHT11 or DHT22
  • 1x BMP180 shield (the one with 4 pins)
  • 1x my temperature and illuminance sensor shield (link)
  • Capacitors:
    • 3x 100 µF (*)
  • Z-diode
    • 1x 3.3 V
  • Resistor:
    • 1x 10 kΩ
    • 1x 360 Ω
    • 1x 150 Ω (for red LED)
  • AMS 1117
    • 1x 3.3 V
    • 1x 5 V (*)
  • LEDs:
    • 1x red
    • 1x green
    • or a bi-color one
  • Headers:
    • 1x 12x1 female
    • 1x 6x1 female
    • 2x 5x1 female
    • 5x 4x1 female
    • 1x 3x1 female
    • 1x 2x1 female
    • 3x 3x1 male (*)
    • 1x 4x1 male
    • 1x 4x1 male 90°
    • 1x 3x1 male 90°

To (*): If you only want a 5V version you can reduce these parts by one.
 

Step 2: Cutting the PCB







First cut the stripes of the stripboard at the position shown in the drawing. To make this easier use the bottom view image. At the end count your cuts to be sure that you will not have wrong connections.

Step 3: Adding the Headers







Next step is soldering the headers to the board. Take care on the header in the lower right corner. You also have to solder the wire on the left side in the same hole.

Step 4: Wiring





Add all wires to the PCB. The colors are not important. They are only a orientation for me. On the top right corner there is a double usage of one hole. So you have to solder in the resistor in this step, too.

Step 5: Add some Parts ...






Because the two AMS1117 are surface mounted parts you have to prepare them for through hole mounting. For this solder each to one 3x1 male header. After that you can easily place them together with all resistors, capacitors and the Z-diode on the PCB.

The LEDs are connected to the male header like seen in the image. The resistor is for the green leg.

Step 6: Full Setup with Labels



So, here you are. All parts are on the PCB. To check if everything works well and not to get short circuits or over voltages do the following tests first (use a multimeter):

  1. Measure the resistance between (1) and (3). Should be around 1 kΩ (not less!).
  2. Measure the resistance from (1) to all ground (GND, G) pins. Except (13)-G all should be 0 Ω.
  3. Connect a 9V battery to pin (1) (GND,-) and pin (3) (+).
  4. Measure 5 V voltages on pins (2), (8)-5, (9)-5, (10)-5, (12) and (14)-5.
  5. Measure 3.3 V voltages on pin (15).

If the board passed all five tests it's ready to put the components on.

Step 7: You need some Software



Yes, hardware is one part the software is the other. To explain and publish the software I will create an other instructable. Only few words to the concept:

The ESP8266 runs on Nodemcu and does the Internet connection. 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.

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.

So, follow me for the further instructables.

If you want to write your own software here are the relevant pins for the Arduino:

  • D2 Softserial TX
  • D3 Softserial RX
  • D4 DHT11 data
  • D11 SW0
  • D12 Connected to ESP8266 CH_PD: HIGH = On, LOW = Off
  • A0 LDR
  • A3 Thermistor


第二部分:软件篇



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

Because of the both MCUs the software concept is based on two parts: TheESP8266 runs on Nodemcu and does the Internet connection andthingspeak.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.comand 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.luatempArduino.luawifiConfig.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 sendsendData() 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

如需更详细资料,如有好资源分享,请加入QQ交流群:214461008

欢迎阅读,欢迎转载,不用注明出处!本站只提供入门和进阶资料,做您学习的小伙伴!

老司机也欢迎光临指导!有好内容请加群:214461008 不要看声明了,看内容吧!

相关文章
  • 利用电视遥控器控制Arduino

    利用电视遥控器控制Arduino

    2016-05-13 17:27

  • 简化到不能再简化的Arduino

    简化到不能再简化的Arduino

    2016-04-28 16:50

  • 10块钱成本自制Arduino淘宝商家别怪我

    10块钱成本自制Arduino淘宝商家别怪我

    2016-04-28 16:24

  • DIY Arduino第二弹

    DIY Arduino第二弹

    2016-04-28 14:28

网友点评
Arduino