1
0

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 3 years have passed since last update.

Grove IoT スターターキット for SORACOM で超音波距離計を使う

Last updated at Posted at 2021-08-06

距離が 30cm 以下ならば LED が赤
距離が 30cm から 100cm ならば LED が黃
距離が 100cm 以上ならば LED が青になります。

次のサイトからライブラリーをダウンロードして下さい。
Seeed-Studio / Seeed_Arduino_UltrasonicRanger
Zip ファイル
Seeed_Arduino_UltrasonicRanger-master.zip

ultrasonic_ranger/ultrasonic_ranger.ino
// ---------------------------------------------------------------
/*
	ultrasonic_ranger.ino

					Aug/06/2021
*/
// ---------------------------------------------------------------
#include <WioLTEforArduino.h>
#include <Ultrasonic.h>

#define ULTRASONIC_PIN	(WIOLTE_D38)
#define INTERVAL	(500)

Ultrasonic UltrasonicRanger(ULTRASONIC_PIN);

WioLTE Wio;

// ---------------------------------------------------------------
void setup()
{
	Wio.Init();
}

// ---------------------------------------------------------------
void loop()
{
	long distance;
	distance = UltrasonicRanger.MeasureInCentimeters();
	SerialUSB.print(distance);
	SerialUSB.println("[cm]");

	if (100 <= distance)
		{
		Wio.LedSetRGB(0, 0, 1);
		}
	else if (30 <= distance)
		{
		Wio.LedSetRGB(1, 1, 0);
		}	
	else
		{
		Wio.LedSetRGB(1, 0, 0);
		}
	
	delay(INTERVAL);
}

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

超音波センサーを D38 に接続して下さい。
IMG_20210806_111132.jpg

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?