项目创意

自制Arduino全功能气象站

字号+ 作者:duino123.com 来源:未知 2016-04-27 16:22 我要评论( )

本项目的气象站功能包括:大气压力,温度,雨滴,土壤湿度,空气湿度,利用Arduino采集和保存数据,非常适合入门的朋友

PLCLIVE.COM注:

本项目的气象站功能包括:大气压力,温度,雨滴,土壤湿度,空气湿度,利用Arduino采集和保存数据,非常适合入门的朋友,如果条件允许,你还可以将这些数据与互联网连接,通过网页,微信或者手机APP随时查看家里的各项数据,爽的不是一丁点啊。赶快淘宝下单,收货,开干吧!

Step 1: 材料清单


 

- Arduino boards (mine Arduino Uno Rev3)

- DHT11 Humidity and temperature sensor 

- BMP185 Barometer sensor 

- Rain Drop sensor module

- Soil Humidity sensor module 

- Breadboard or Custom ProtoShield (Check it out how to make it >> )

- Jumper Wire

Step 2: 硬件连接


In general, the connections are very simple. Follow the instructions and images above, and you should have no problems.

Connecting Rain Drop Module

  • the VCC pin on Arduino’s 5V output
  • the GND pin to Arduino’s GND and
  • the Analog Data to Arduino's analog pin 0

Connecting Soil Humidity Module

  • the VCC pin on Arduino’s 5V output
  • the GND pin to Arduino’s GND and
  • the Analog Data to Arduino's analog pin 1

Connecting BMP185

  • the VCC pin on Arduino’s 3.3V output
  • the GND pin to Arduino’s GND
  • the SDA (Serial Data Line) pin to Arduino’s analog pin 4 and
  • the SCL (Serial Clock Line) pin to Arduino’s analog pin 5

Connecting DHT11

  • the VCC pin on Arduino’s 5V output
  • the GND pin to Arduino’s GND and
  • the DATA pin to Arduino’s digital pin 4

Step 3: Arduino编程



Below is the Arduino Weather Station code. Include the library from AWS_library.rar, upload the code to your Arduino (Mine Arduino Uno Rev3), and you should have no problems.
AWSTest.ino

/*
Pin Configuration
Rain Drop      A0
Soil Humidity  A1
SDA            A4
SCL            A5
DHT11 Data     D2
*/

int result [5];           //Sensor result array
#include <Wire.h>         //Including wire library
#include <SFE_BMP180.h>   //Including BMP180 library
#define ALTITUDE 3        //Altitude where I live (change this to your altitude)
SFE_BMP180 pressure;      //Creating an object
#include <DHT.h>          //Including DHT11 library
#define DHTPIN 2          //Define DHT11 digital pin
#define DHTTYPE DHT11     //Define DHT TYPE which is DHT11
DHT dht(DHTPIN, DHTTYPE); //Execute DHT11 library

void setup() {
Serial.begin(9600);       //Starting serial communication
Serial.println("Program started");
//Analog setup
pinMode(A0, INPUT);       //Soil
pinMode(A1, INPUT);       //Rain
//BMP180 Setup
if (pressure.begin())     //If initialization was successful, continue
 {Serial.println("BMP180 init success");
 Serial.print("AWS :");
 Serial.print("\t");
 Serial.print("Rain Drop\t");
 Serial.print("Soil Hum\t");
 Serial.print("Pressure \t");
 Serial.print("Air Hum\t");
 Serial.print("\t");
 Serial.println("Temp \t");}
else                       //Else, stop code forever
  {
    Serial.println("BMP180 init fail");
    while (1);
  }
  
//DHT11 setup
dht.begin(); 
}

void loop() {
//analog setup
int A_Rain = analogRead(A0);
int A_Soil = analogRead(A1); 
A_Rain = map(A_Rain, 800, 1023, 100, 0);
A_Soil = map(A_Soil, 400, 1023, 100, 0);
result[0]=A_Soil;
result[1]=A_Rain;
//bmp180 setup
char status;
double T, P, p0; 
status = pressure.startTemperature();
if (status != 0) {
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0) {
    status = pressure.startPressure(3);
      if (status != 0) {
        delay(status);
        status = pressure.getPressure(P, T);
        if (status != 0) {
          p0 = pressure.sealevel(P, ALTITUDE);
          result[2]=p0;
        }}}}
result[3] = dht.readHumidity();
result[4] = dht.readTemperature();
Serial.print("AWS : ");
Serial.print(" \t");
Serial.print(result[0]);
Serial.print(" %\t");
Serial.print("\t");
Serial.print(result[1]);
Serial.print(" %\t");
Serial.print("\t");
Serial.print(result[2]);
Serial.print(" hPa \t");
Serial.print(result[3]);
Serial.print(" %\t");
Serial.print("\t");
Serial.print(result[4]);
Serial.println("C \t");
delay(5000);
}

DHT.h
/* DHT library

MIT license
written by Adafruit Industries
*/
#ifndef DHT_H
#define DHT_H

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif


// Uncomment to enable printing out nice debug messages.
//#define DHT_DEBUG

// Define where debug output will be printed.
#define DEBUG_PRINTER Serial

// Setup debug printing macros.
#ifdef DHT_DEBUG
  #define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
  #define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
  #define DEBUG_PRINT(...) {}
  #define DEBUG_PRINTLN(...) {}
#endif

// Define types of sensors.
#define DHT11 11
#define DHT22 22
#define DHT21 21
#define AM2301 21


class DHT {
  public:
   DHT(uint8_t pin, uint8_t type, uint8_t count=6);
   void begin(void);
   float readTemperature(bool S=false, bool force=false);
   float convertCtoF(float);
   float convertFtoC(float);
   float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
   float readHumidity(bool force=false);
   boolean read(bool force=false);

 private:
  uint8_t data[5];
  uint8_t _pin, _type, _bit, _port;
  uint32_t _lastreadtime, _maxcycles;
  bool _lastresult;

  uint32_t expectPulse(bool level);

};

class InterruptLock {
  public:
   InterruptLock() {
    noInterrupts();
   }
   ~InterruptLock() {
    interrupts();
   }

};

#endif

SFE_BMP180.h
/*
	SFE_BMP180.h
	Bosch BMP180 pressure sensor library for the Arduino microcontroller
	Mike Grusin, SparkFun Electronics

	Uses floating-point equations from the Weather Station Data Logger project
	http://wmrx00.sourceforge.net/
	http://wmrx00.sourceforge.net/Arduino/BMP085-Calcs.pdf

	Forked from BMP085 library by M.Grusin

	version 1.0 2013/09/20 initial version
	Verison 1.1.2 - Updated for Arduino 1.6.4 5/2015
	
	Our example code uses the "beerware" license. You can do anything
	you like with this code. No really, anything. If you find it useful,
	buy me a (root) beer someday.
*/

#ifndef SFE_BMP180_h
#define SFE_BMP180_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

class SFE_BMP180
{
	public:
		SFE_BMP180(); // base type

		char begin();
			// call pressure.begin() to initialize BMP180 before use
			// returns 1 if success, 0 if failure (bad component or I2C bus shorted?)
		
		char startTemperature(void);
			// command BMP180 to start a temperature measurement
			// returns (number of ms to wait) for success, 0 for fail

		char getTemperature(double &T);
			// return temperature measurement from previous startTemperature command
			// places returned value in T variable (deg C)
			// returns 1 for success, 0 for fail

		char startPressure(char oversampling);
			// command BMP180 to start a pressure measurement
			// oversampling: 0 - 3 for oversampling value
			// returns (number of ms to wait) for success, 0 for fail

		char getPressure(double &P, double &T);
			// return absolute pressure measurement from previous startPressure command
			// note: requires previous temperature measurement in variable T
			// places returned value in P variable (mbar)
			// returns 1 for success, 0 for fail

		double sealevel(double P, double A);
			// convert absolute pressure to sea-level pressure (as used in weather data)
			// P: absolute pressure (mbar)
			// A: current altitude (meters)
			// returns sealevel pressure in mbar

		double altitude(double P, double P0);
			// convert absolute pressure to altitude (given baseline pressure; sea-level, runway, etc.)
			// P: absolute pressure (mbar)
			// P0: fixed baseline pressure (mbar)
			// returns signed altitude in meters

		char getError(void);
			// If any library command fails, you can retrieve an extended
			// error code using this command. Errors are from the wire library: 
			// 0 = Success
			// 1 = Data too long to fit in transmit buffer
			// 2 = Received NACK on transmit of address
			// 3 = Received NACK on transmit of data
			// 4 = Other error

	private:
	
		char readInt(char address, int16_t &value);
			// read an signed int (16 bits) from a BMP180 register
			// address: BMP180 register address
			// value: external signed int for returned value (16 bits)
			// returns 1 for success, 0 for fail, with result in value

		char readUInt(char address, uint16_t &value);
			// read an unsigned int (16 bits) from a BMP180 register
			// address: BMP180 register address
			// value: external unsigned int for returned value (16 bits)
			// returns 1 for success, 0 for fail, with result in value

		char readBytes(unsigned char *values, char length);
			// read a number of bytes from a BMP180 register
			// values: array of char with register address in first location [0]
			// length: number of bytes to read back
			// returns 1 for success, 0 for fail, with read bytes in values[] array
			
		char writeBytes(unsigned char *values, char length);
			// write a number of bytes to a BMP180 register (and consecutive subsequent registers)
			// values: array of char with register address in first location [0]
			// length: number of bytes to write
			// returns 1 for success, 0 for fail
			
		int16_t AC1,AC2,AC3,VB1,VB2,MB,MC,MD;
		uint16_t AC4,AC5,AC6; 
		double c5,c6,mc,md,x0,x1,x2,y0,y1,y2,p0,p1,p2;
		char _error;
};

#define BMP180_ADDR 0x77 // 7-bit address

#define	BMP180_REG_CONTROL 0xF4
#define	BMP180_REG_RESULT 0xF6

#define	BMP180_COMMAND_TEMPERATURE 0x2E
#define	BMP180_COMMAND_PRESSURE0 0x34
#define	BMP180_COMMAND_PRESSURE1 0x74
#define	BMP180_COMMAND_PRESSURE2 0xB4
#define	BMP180_COMMAND_PRESSURE3 0xF4

#endif

AWS_test.ino
AWS_library.rar

Step 4: 收工!



After making sure that everything works smoothly, you can take this project into bigger project (Check it Out >> Integrated Weather Station)!

Power through batteries or a plug and you’re good to go!

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

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

请加群:214461008

相关文章
  • 使用Arduino+Processing实现的雷达扫描效果

    使用Arduino+Processing实现的雷达扫描效果

    2016-05-30 17:14

  • 利用电视遥控器控制Arduino

    利用电视遥控器控制Arduino

    2016-05-13 17:27

  • ESP8266 Arduino气象站

    ESP8266 Arduino气象站

    2016-04-28 18:44

  • 简化到不能再简化的Arduino

    简化到不能再简化的Arduino

    2016-04-28 16:50

网友点评
Arduino
热门教程
关注我们
自动化世界