0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ESP8266 + DS18B20(1wire温度センサ)でAmbientにデータを送る

Posted at

温度データをネット経由で取得するために絞ったコード

気温や土の温度を計測・記録したい

Aruduino & Wifi : ESP8266

https://www.switch-science.com/catalog/2620/
以前買って手元にあったもの
ポート出力電流上限は12mA(だったような。要確認)

温度センサ : DS16B20+

<選定時要望>
・センサ部を防水にして土中温度を測りたいため、TO-92パッケージみたいな足のついたものを利用したい
・高くないこと
・省エネ
 I2Cでは適当なデバイスみつからず。値段高め、防水しにくい形状
 アナログ:ESP8266はADCが1チャンネルのみ(0から1V)
 1チャンネルのみなのでとりあえず選定から外す
  参考:LM60(2.7V~10Vで駆動)仕様は向いているのだけど
   出力1V超は92℃超なので気温や土温度の際はADC閾値は気にしない
   25℃時電流ドレイン最大110μA 0.11mA
   LM60仕様
 DS16B20+
  Active current MAX 1.5mA
  Standby current MAX 1000nA
  一つのポートに複数接続可
  今回は昔秋月で買ったもの利用(購入時値札300円、2019/3/5時点320円)
  Amazonで10個1000円以下。防水加工済みコード付きも1個200円台

DS16B20+利用のためのArduinoライブラリ(OneWire用、DS16B20+用)
https://github.com/PaulStoffregen/OneWire
https://github.com/milesburton/Arduino-Temperature-Control-Library

DS16B20+接続
DQとVdd間を4.7kΩ抵抗でつなぐ
Vddは5.0Vでも3.3Vでも

IoT croud : Ambient

以前トラ技でみたときにアカウントを作っていた
公式に日本語サンプル解説があって助かる
https://ambidata.io/

ソース


# include <OneWire.h>  //1wire
# include <DallasTemperature.h>  //DS18B20
# include <Ambient.h>

//-----------------------------------------------
const char* ssid = "  --- wifi ssid ---  ";
const char* password = "  --- wifi password ---  ";
unsigned int channelID =   --- Ambient channel id ---  ;
const char* writeKey = "  --- Ambient writekey ---  ";
float temp01;

//-----------------------------------------------

//WiFi
WiFiClient client;

//OneWire&DS18B20
# define ONE_WIRE_BUS 2 //Portは任意。今回は2番
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

//Ambient
Ambient ambient;

//-----------------------------------------------

void setup() {

  WiFi.begin(ssid, password);
  ambient.begin(channelID, writeKey, &client);

  sensors.begin();

}

//-----------------------------------------------

void loop() {
  sensors.requestTemperatures();
  temp01 = sensors.getTempCByIndex(0);

  ambient.set(1,temp01);
  ambient.send();

  delay(30000);  //30秒間隔
}

次の課題<優先度>

<高>センサを複数接続
<高>ESP8266単体で書き込み、駆動
<高>スリープモード利用
<低>1wireと、アナログ・I2Cとの併用
(特に温度湿度センサはI2Cの方が選びやすそう)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?