<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Arduino｜イノの多趣味な記録</title>
	<atom:link href="https://inoguitar.com/archives/category/%E9%9B%BB%E5%AD%90%E5%B7%A5%E4%BD%9C%E3%83%BB%E4%BF%AE%E7%90%86/arduino-%E9%9B%BB%E5%AD%90%E5%B7%A5%E4%BD%9C/feed" rel="self" type="application/rss+xml" />
	<link>https://inoguitar.com</link>
	<description>PC, 音楽, 旅, プログラミング, etc...</description>
	<lastBuildDate>Fri, 13 Jun 2025 12:11:51 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://inoguitar.com/wp-content/uploads/2024/07/cropped-4248ad98773cd546a99d34d11e982871-32x32.png</url>
	<title>Arduino｜イノの多趣味な記録</title>
	<link>https://inoguitar.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【ESP32・DHT22】気温・湿度をHTTP通信で取得する方法</title>
		<link>https://inoguitar.com/archives/2976</link>
		
		<dc:creator><![CDATA[イノ]]></dc:creator>
		<pubDate>Tue, 10 Jun 2025 09:00:39 +0000</pubDate>
				<category><![CDATA[Arduino]]></category>
		<guid isPermaLink="false">https://inoguitar.com/?p=2976</guid>

					<description><![CDATA[ESP32とDHT22を使用して、特定のHTTP（http://～）にアクセスすると、気温や湿度を取得出来るようなものを作ります。 必要なもの 回路 ESP32とDHT22をそれぞれ、V5（VIN）とVCC、D13とS、 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>ESP32とDHT22を使用して、特定のHTTP（http://～）にアクセスすると、気温や湿度を取得出来るようなものを作ります。</p>



<h2 class="wp-block-heading jinr-heading d--bold">必要なもの</h2>



<ul class="wp-block-list jinr-list">
<li>ESP-WROOM-32（<a href="https://amzn.to/4kHzZms">Amaz</a><a href="https://amzn.to/4kHzZms" target="_blank" rel="noreferrer noopener">o</a><a href="https://amzn.to/4kHzZms">n</a>）</li>



<li>DHT22湿度・温度センサー（<a href="https://amzn.to/3ZkG3so" target="_blank" rel="noreferrer noopener">Amazon</a>）</li>



<li>ジャンプワイヤ（<a href="https://amzn.to/4kwmt4J" target="_blank" rel="noreferrer noopener">Amazon</a>）</li>



<li>USB-Cケーブル（<a href="https://amzn.to/45cqczN" target="_blank" rel="noreferrer noopener">Amazon</a>）</li>
</ul>



<h2 class="wp-block-heading jinr-heading d--bold">回路</h2>



<p>ESP32とDHT22をそれぞれ、V5（VIN）とVCC、D13とS、GNDとGNDに接続します。</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1019" height="679" src="https://inoguitar.com/wp-content/uploads/2025/06/3e45ae772c2950e59aa2583ee8510d80.jpg" alt="" class="wp-image-2986" srcset="https://inoguitar.com/wp-content/uploads/2025/06/3e45ae772c2950e59aa2583ee8510d80.jpg 1019w, https://inoguitar.com/wp-content/uploads/2025/06/3e45ae772c2950e59aa2583ee8510d80-300x200.jpg 300w, https://inoguitar.com/wp-content/uploads/2025/06/3e45ae772c2950e59aa2583ee8510d80-768x512.jpg 768w" sizes="(max-width: 1019px) 100vw, 1019px" /></figure>



<h2 class="wp-block-heading jinr-heading d--bold">コード</h2>



<p>&#8220;DHT sensor library by Adafruit&#8221;、&#8221;ESPAsyncWebServer by ESP32Async&#8221;の2つのライブラリをインストールしてください。Arduino IDEのライブラリマネージャーからインストールできます。</p>



<p><span class="jinr-d--text-color d--user-color1 d--bold">追記:Arduino IDE 2.3.3で不具合が生じるようです。Arduino IDE2.3.2にて動作を確認できました。</span><br><span class="jinr-d--text-color d--user-color1 d--bold">ESPAsyncWebServer 3.7.7は動作が不安定でした。現状3.6.0が最も安定します。</span></p>



<p>IPアドレスはHTTP通信の際固定しておいたほうが良いので、固定しています。</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">#include "DHT.h"
#include &lt;WiFi.h&gt;
#include &lt;ESPAsyncWebServer.h&gt;

// WiFi設定
const char* ssid = "xxxxxx";//Wi-FiのSSID
const char* password = "xxxxxx";//Wi-Fiのパスワード

IPAddress ip(192, 168, 10, xxx); // ESP32のIPアドレス
IPAddress gateway(xxx,xx, xx, xxx); // ESP32のゲートウェイ
IPAddress subnet(255, 255, 255, 0); // ESP32のサブネット

AsyncWebServer server(8080);

//temperature、humidityを宣言
float temperature = 0.00;
float humidity = 0.00;

#define DHTPIN 13     // Digital pin connected to the DHT sensor

#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

DHT dht(DHTPIN, DHTTYPE);



void setup() {
  Serial.begin(115200);
    if (!WiFi.config(ip,gateway,subnet)){
      Serial.println("Failed to configure!");
  }
  WiFi.begin(ssid, password);
  // Wi-Fi接続完了
  Serial.println("Connected to WiFi");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
  


    // HTTPサーバーのエンドポイントを設定
  server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
    String temperature_str = String(temperature, 1); // temperatureを文字列に変換
    request-&gt;send(200, "text/plain", temperature_str); // temperatureの値を返す
  });

    // HTTPサーバーのエンドポイントを設定
  server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
    String humidity_str = String(humidity, 1); // humidityを文字列に変換
    request-&gt;send(200, "text/plain", humidity_str); // humidityの値を返す
  });

  // サーバー開始
  server.begin();
  Serial.println(F("DHTxx test!"));

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  float h = dht.readHumidity();

  float t = dht.readTemperature();

  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));

//temperature、humidityに値を代入
  temperature = t;
  humidity = h;
}</pre></div>



<p>これで、ブラウザなどでhttp://IPアドレス:8080/temperatureにアクセスすると気温、http://IPアドレス:8080/humidityにアクセスすると湿度が返ってきます。尚、文字列データとして返ってくるので、計算に使用する際は注意してください。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="682" src="https://inoguitar.com/wp-content/uploads/2025/06/s-DSCF2653-1024x682.jpg" alt="" class="wp-image-2987" srcset="https://inoguitar.com/wp-content/uploads/2025/06/s-DSCF2653-1024x682.jpg 1024w, https://inoguitar.com/wp-content/uploads/2025/06/s-DSCF2653-300x200.jpg 300w, https://inoguitar.com/wp-content/uploads/2025/06/s-DSCF2653-768x512.jpg 768w, https://inoguitar.com/wp-content/uploads/2025/06/s-DSCF2653.jpg 1280w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>あとはデータベースで収集したり、webに表示したりカスタマイズしてみてください。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>【Arduino】 ESP32で雨をLINEでお知らせしてくれるデバイスの製作</title>
		<link>https://inoguitar.com/archives/281</link>
					<comments>https://inoguitar.com/archives/281#respond</comments>
		
		<dc:creator><![CDATA[イノ]]></dc:creator>
		<pubDate>Sat, 31 Aug 2024 06:03:10 +0000</pubDate>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[電子工作・修理]]></category>
		<category><![CDATA[ESP32]]></category>
		<category><![CDATA[LINE Notify]]></category>
		<category><![CDATA[マイコン]]></category>
		<category><![CDATA[電子工作]]></category>
		<guid isPermaLink="false">https://inoguitar.com/?p=281</guid>

					<description><![CDATA[外で雨が降り始めても、案外気づきづらいものですよね。私も何度かそれで洗濯物を濡らしてしまいました。そこで、今回は雨が降り始めたらLINEでお知らせしてくれるデバイスを製作しました。 2025/1追記 LINE Notif [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>外で雨が降り始めても、案外気づきづらいものですよね。私も何度かそれで洗濯物を濡らしてしまいました。そこで、今回は雨が降り始めたらLINEでお知らせしてくれるデバイスを製作しました。</p>



<p><span class="jinr-d--text-color d--user-color1 d--bold">2025/1追記 LINE Notifyは2025年3月31日にサービス終了します。LINE Messaging APIなど代替サービスをご利用ください。</span></p>



<p><span class="red">完成イメージ↓</span></p>



<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">
<blockquote class="twitter-tweet" data-width="500" data-dnt="true"><p lang="ja" dir="ltr">雨に気付かず洗濯物を濡らしてしまったので、雨が降ったらLINEでお知らせしてくれるようにしました（ESP32使用） <a href="https://t.co/8lmYHmjupn">pic.twitter.com/8lmYHmjupn</a></p>&mdash; イノ (@Ino_guitar_) <a href="https://twitter.com/Ino_guitar_/status/1829720456385134770?ref_src=twsrc%5Etfw">August 31, 2024</a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div></figure>



<p><span class="red"><span class="fz-14px"><span class="fz-16px">いつもの：万が一事故や故障等発生しても、責任は負いかねます。ご了承ください。</span></span></span></p>



<h2 class="wp-block-heading jinr-heading d--bold">必要なもの</h2>



<ul class="wp-block-list jinr-list">
<li>ESP32-WROOM（<a href="https://amzn.to/4efyZ6F" target="_blank" rel="noreferrer noopener">Amazon</a>または<a href="https://akizukidenshi.com/catalog/g/g115673/" target="_blank" rel="noreferrer noopener">秋月電子通商</a>）</li>



<li>雨検知センサー（<a href="https://amzn.to/4cHtniY" target="_blank" rel="noreferrer noopener">Amazon</a>）</li>



<li>ブレッドボード（<a href="https://amzn.to/4g6NHgr" target="_blank" rel="noreferrer noopener">Amazon</a>または<a href="https://akizukidenshi.com/catalog/g/g105294/" target="_blank" rel="noreferrer noopener">秋月電子通商</a>）</li>



<li>ジャンパーワイヤーオス-メス、オス-オス（<a href="https://amzn.to/47g2txx" target="_blank" rel="noreferrer noopener">Amazon</a>）</li>



<li>LINEアカウント</li>
</ul>



<p>実用的に使用する場合はユニバーサル基盤を使用すると思いますが、試作段階ではブレッドボードを使います。</p>



<h2 class="wp-block-heading jinr-heading d--bold">LINE Notifyからトークン発行</h2>



<p>LINE Notifyは、外部WebサービスからLINEメッセージを送信できるようにする、LINE公式のサービスです。</p>



<p>ここでESP32からLINEへメッセージを送信できるようにする、「トークン」と呼ばれるものを発行します。</p>



<p><span class="fz-16px"><span class="fz-22px"><span class="fz-20px"><strong>1.<a href="https://notify-bot.line.me/ja/">LINE Notify</a>にアクセス（スマホ不可）</strong></span></span></span></p>



<p><span class="fz-20px"><strong>2.ログインする</strong></span></p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2baa22c&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2baa22c" class="wp-block-image size-large wp-lightbox-container"><img decoding="async" width="1024" height="561" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify01-1024x561.png" alt="" class="wp-image-283" srcset="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify01-1024x561.png 1024w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify01-300x164.png 300w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify01-768x421.png 768w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify01.png 1070w" sizes="(max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p><strong><span class="fz-20px">3.ログインできたら、ページ右上ユーザーネーム&gt;「マイページ」へ進む</span></strong></p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2baa582&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2baa582" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="399" height="214" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify02.png" alt="" class="wp-image-285" srcset="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify02.png 399w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify02-300x161.png 300w" sizes="auto, (max-width: 399px) 100vw, 399px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p><strong><span class="fz-20px">4.「トークンを発行する」を</span>クリック</strong></p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2baa83f&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2baa83f" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="867" height="344" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify03.png" alt="" class="wp-image-284" srcset="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify03.png 867w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify03-300x119.png 300w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify03-768x305.png 768w" sizes="auto, (max-width: 867px) 100vw, 867px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p><strong><span class="fz-20px">5.トークン名を記入</span></strong></p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2baaafc&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2baaafc" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="782" height="591" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify04.png" alt="" class="wp-image-286" srcset="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify04.png 782w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify04-300x227.png 300w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify04-768x580.png 768w" sizes="auto, (max-width: 782px) 100vw, 782px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>トークン名ではありますが、メッセージに表示されるので、それっぽいものを記入</p>



<p><strong><span class="fz-20px">6.送信するトークルームを選択</span></strong></p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2baadc1&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2baadc1" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="817" height="521" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify05.png" alt="" class="wp-image-287" srcset="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify05.png 817w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify05-300x191.png 300w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify05-768x490.png 768w" sizes="auto, (max-width: 817px) 100vw, 817px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>今回は自分に送信するので、「1:1で～」を選びました。家族LINEとかでも大丈夫です</p>



<p><strong><span class="fz-20px">7.「発行する」をクリック</span></strong></p>



<p><strong><span class="fz-20px">8.発行されたトークンをコピー</span></strong></p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2bab09b&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2bab09b" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="592" height="420" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify06.png" alt="" class="wp-image-288" srcset="https://inoguitar.com/wp-content/uploads/2024/08/LINENotify06.png 592w, https://inoguitar.com/wp-content/uploads/2024/08/LINENotify06-300x213.png 300w" sizes="auto, (max-width: 592px) 100vw, 592px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>以上でLINE側の準備は完了です。</p>



<h2 class="wp-block-heading jinr-heading d--bold">回路</h2>



<p>回路は下図のとおりです。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2bab384&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2bab384" class="wp-block-image size-large wp-lightbox-container"><img loading="lazy" decoding="async" width="1024" height="534" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/ESP32rain_kairo-1024x534.png" alt="" class="wp-image-294" srcset="https://inoguitar.com/wp-content/uploads/2024/08/ESP32rain_kairo-1024x534.png 1024w, https://inoguitar.com/wp-content/uploads/2024/08/ESP32rain_kairo-300x157.png 300w, https://inoguitar.com/wp-content/uploads/2024/08/ESP32rain_kairo-768x401.png 768w, https://inoguitar.com/wp-content/uploads/2024/08/ESP32rain_kairo.png 1104w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>ESP32の5番ピンに雨検知センサーのデジタル出力を差しています。</p>



<p>雨検知センサーの感度は、センサーを接続している長方形のパーツの可変抵抗で調節します。緑のランプがギリギリ2つ点灯しない場所に調整します。（最後にやっても良い）</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2bab63c&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2bab63c" class="wp-block-image size-large wp-lightbox-container"><img loading="lazy" decoding="async" width="1024" height="768" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/IMG20240831145038-1024x768.jpg" alt="" class="wp-image-297" srcset="https://inoguitar.com/wp-content/uploads/2024/08/IMG20240831145038-1024x768.jpg 1024w, https://inoguitar.com/wp-content/uploads/2024/08/IMG20240831145038-300x225.jpg 300w, https://inoguitar.com/wp-content/uploads/2024/08/IMG20240831145038-768x576.jpg 768w, https://inoguitar.com/wp-content/uploads/2024/08/IMG20240831145038-1536x1152.jpg 1536w, https://inoguitar.com/wp-content/uploads/2024/08/IMG20240831145038-2048x1536.jpg 2048w, https://inoguitar.com/wp-content/uploads/2024/08/IMG20240831145038.jpg 1920w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h2 class="wp-block-heading jinr-heading d--bold">ソースコード</h2>



<p>Arduino IDEを使用します。私と同じものを使用した場合、ボードは「ESP32 Dev Module」です。</p>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2bab8ee&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2bab8ee" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="268" height="108" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/ArduinoIDE.png" alt="" class="wp-image-298"/><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>ソースコードは以下の通りです。Wi-FiのSSID、パスワードは各自設定してください。<br>LINE Notifyで発行したトークンは、10行目に記入してください。</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">#include &lt;WiFi.h&gt;
#include &lt;WiFiClientSecure.h&gt;

// WiFi設定
const char* ssid     = "xxxxxxxx"; //接続するWi-FiのSSID
const char* password = "xxxxxxxx";  //接続するWi-Fiのパスワード
 
// LINE Notify設定
const char* host = "notify-api.line.me";
const char* token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";//トークン
const char* message = "洗濯物は大丈夫ですか？";//追加のメッセージ

int flag;

void setup() {

  // ポート設定
  pinMode( 5, INPUT );      // センサからのデジタル入力 

  // シリアルモニタ設定
  Serial.begin( 9600 );

  flag = 0;

  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  // WiFi接続
  WiFi.begin(ssid, password);
  // WiFiの接続状態を確認
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

// line通知
void send_line() {

  // HTTPSへアクセスするためのライブラリ
  WiFiClientSecure client;

  // サーバー証明書の検証を行わずに接続
  client.setInsecure();
  
  Serial.println("Try");
  
  //LineのAPIサーバにSSL接続（ポート443:https）
  if (!client.connect(host, 443)) {
    Serial.println("Connection failed");
    return;
  }
  Serial.println("Connected");

  // リクエスト送信
  String query = String("message=") + String(message);
  String request = String("") +
               "POST /api/notify HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Authorization: Bearer " + token + "\r\n" +
               "Content-Length: " + String(query.length()) +  "\r\n" + 
               "Content-Type: application/x-www-form-urlencoded\r\n\r\n" +
                query + "\r\n";
  client.print(request);
 
  // 受信完了まで待機 
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      break;
    }
  }
  
  String line = client.readStringUntil('\n');
  Serial.println(line);
}
 
void loop() {
  
  // 感雨確認
  if(digitalRead(5) == LOW &amp;&amp; flag == 0){    // 感雨あり
    flag = 1;
    send_line(); // Lineにリクエストを送信する
    Serial.println(flug);
  } else if(digitalRead(5) == HIGH){
    flag = 0;
  }
  
  delay(1000); //誤作動しないよう調整

}</pre></div>



<p>一応void loopのところだけ解説します。</p>



<p>簡単に言うと、雨検知 → LINE送信 をやっています。ただ、これだけだと、雨が降っている間、永遠に通知を送り続けます。なので、雨を検知したときに<strong>flag = 0</strong>だったものを <strong>flag = 1</strong>にします。LINE送信の動作に入る条件として 87行 <strong>if(digitalRead(5)) == LOW &amp;&amp; flag == 0)</strong> と書いているように、このflagが1の時は、送信の条件に入りません。そして、雨を検知しなくなったら、91行 <strong>else if</strong>に入り、<strong>flag = 0</strong>になります。これでリセットになるわけです。<br>もっとスマートなやり方があるかもしれませんが、とりあえずこれで対処しました。</p>



<p>95行目 <strong>delay(1000)</strong>は、センサーのノイズ等で一回切れちゃう事があるので長めにしています。今回は1000msec(=1秒)ですが、10秒とか30秒でも良いと思います。</p>



<h2 class="wp-block-heading jinr-heading d--bold">検証</h2>



<p>センサーに霧吹きを掛けてみたところ、ちゃんと通知が届きました。</p>



<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">
<blockquote class="twitter-tweet" data-width="500" data-dnt="true"><p lang="ja" dir="ltr">雨に気付かず洗濯物を濡らしてしまったので、雨が降ったらLINEでお知らせしてくれるようにしました（ESP32使用） <a href="https://t.co/8lmYHmjupn">pic.twitter.com/8lmYHmjupn</a></p>&mdash; イノ (@Ino_guitar_) <a href="https://twitter.com/Ino_guitar_/status/1829720456385134770?ref_src=twsrc%5Etfw">August 31, 2024</a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div></figure>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69df4d2babc59&quot;}" data-wp-interactive="core/image" data-wp-key="69df4d2babc59" class="wp-block-image size-large wp-lightbox-container"><img loading="lazy" decoding="async" width="1024" height="768" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://inoguitar.com/wp-content/uploads/2024/08/IMG_0016-1024x768.jpg" alt="" class="wp-image-295" srcset="https://inoguitar.com/wp-content/uploads/2024/08/IMG_0016-1024x768.jpg 1024w, https://inoguitar.com/wp-content/uploads/2024/08/IMG_0016-300x225.jpg 300w, https://inoguitar.com/wp-content/uploads/2024/08/IMG_0016-768x576.jpg 768w, https://inoguitar.com/wp-content/uploads/2024/08/IMG_0016-1536x1152.jpg 1536w, https://inoguitar.com/wp-content/uploads/2024/08/IMG_0016-2048x1536.jpg 2048w, https://inoguitar.com/wp-content/uploads/2024/08/IMG_0016-scaled.jpg 1920w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<p>今回はこんなところです。気になったところは、雨検知センサーの銅の部分が剥げやすいところです。実用する場合は他の製品で代用したいところですが、今のところ良さそうなものが見つかっていません。そのうち反応しなくなりそうな気がしますが、取り合えず壊れるまではこのままでやってみます。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://inoguitar.com/archives/281/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
