More than 3 years have passed since last update.
Grove IoT スターターキット for SORACOM で超音波距離計を使う
1
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
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
