LoginSignup
1
1

More than 5 years have passed since last update.

NefryでGrove IR Distance Interrupter (赤外線距離センサ)を触るメモ

Posted at

前回に続き、NefryでGroveの赤外線距離センサを使ってみます。

Grove - IR Distance Interrupter

スペックはこんな感じです。 Nefryだと3.3V対応しているセンサを使えるのでこのセンサーは問題なく使えます。

Parameter   Value
Operating voltage(V)    3.3 or 5 Volts
Operating current(mA)   Maximum: 20 mA
Effective detectable distance   7.5–40 cm
Reflective photosensor  datasheet
Output operational amplifiers   datasheet
Weight  2.5 g(for the module), 8.5 g(for all single package)

近くにものがあるとライトがつく人感センサっぽいものを作る

Arduinoのサンプルプログラムに毛が生えたくらいですが以下がプログラムになります。

#include <Nefry.h>

void setup()  {
  Nefry.println("Grove IR Distance Interrupter !");
  Nefry.setLed(0,0,0);
  pinMode(12,INPUT); //D4ポート -> 12
}

void loop()  {
    while(1)  {
        Nefry.ndelay(500);
        if(digitalRead(12)==LOW)  {
            Nefry.println("Somebody is here.");
            Nefry.setLed(255,255,255);
        }
        else  {
            Nefry.println("Nobody.");
            Nefry.setLed(0,0,0);
        }
    }
}
1
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
1
1