如何建立一个简易的气象站

电子说

1.2w人已加入

描述

第1步:获取所有部分

你需要,

1个Arduino板,我使用的是pro mini

1 dht传感器我使用了dht 22

1个10k电阻器

1个带有匹配板的SD卡或micro SD卡

3英尺线上

3线电缆(您将使用它将您的dht传感器连接到arduino)

焊接材料

第2步:连线。

连接所有导线,如图所示。

dht sensor Pro mini,Uno& mega。将传感器的引脚1(左侧)连接到+ 5V

注意:如果使用具有3.3V逻辑的电路板,如Arduino Due连接引脚1至3.3V而不是5V

将传感器的引脚2连接到您的DHT引脚

将传感器的引脚4(右侧)连接到GROUND

将一个10k电阻从vcc连接到数据pin

对于大型MISO-50 MOSI-51 SCK-52 SS/CS 53

对于uno& pro mini MISO-50 MOSI-51 SCK-52 SS/CS-53。

步骤3:编程Arduino。

// Created by A Homeschoolers Workbench

// 12/1/2016

#include “DHT.h”

#include

File myFile;

int pinCS = 10; // Pin 53 on Arduino mega 10 on pro mini and uno, this is the SS pin

// For the uno and pro mini connect sck-13 miso-12 mosi-11 cs/ss-10

// For mega connect sck-52 miso-50 mosi-51 cs/ss-53

#define DHTPIN 2 // what digital pin we‘re connected to

// Uncomment whatever type you’re using!

//#define DHTTYPE DHT11 // DHT 11

#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 I am using the 22

//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V

// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1

// to 3.3V instead of 5V!

// Connect pin 2 of the sensor to whatever your DHTPIN is

// Connect pin 4 (on the right) of the sensor to GROUND

// Connect a 10k resistor from vcc to data pin

// Initialize DHT sensor.

DHT dht(DHTPIN, DHTTYPE);

void setup() {

Serial.begin(9600); // Start the serial

pinMode(pinCS, OUTPUT);

// SD Card Initialization

if (SD.begin())

{

Serial.println(“SD card is ready to use.”);

} else

{

Serial.println(“SD card initialization failed”);

return;

}

dht.begin();

}

void loop() {

// Wait a 60 seconds between measurements.

delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!

float h = dht.readHumidity();

// Read temperature as Fahrenheit (isFahrenheit = true)

float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again)。

if (isnan(h)||isnan(f)) {

return;

}

// Create/Open file

myFile = SD.open(“TH.txt”, FILE_WRITE);

// if the file opened okay, write to it

if (myFile) {

Serial.println(“Writing to file.。.”);

// Write to file

myFile.print(h); // print Humidity

myFile.print(“,”); // place a divider

myFile.println(f); // print the temp and start a new line

myFile.close(); // close the file

Serial.println(“Done.”);

} //if the file didn‘t open, print an error:

else {

Serial.println(“error opening TH.txt”);

}

}

步骤4:安装它。

传感器放置在您想要测量温度和湿度的任何地方,您必须确保arduino保持干燥。

当您将SD卡放入其主板时,您必须重置arduino,否则它将不会记录数据。

步骤5:如何导出数据

打开SD卡,然后打开TH,选择全部,复制

然后打开excel(Linux中的Libre calc)然后粘贴,并用逗号分隔。然后把它变成一个图表。

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分