1
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

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

前回に続き、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);
        }
    }
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
1
Help us understand the problem. What are the problem?