GR-COTTON DISTANCE SENSOR

Pocket

前回GR-COTTONリモコンに照度センサを付けました。
人感センサの特性で動かないと検出しないため、じっとしていると居ないことになって、電灯が消されてしまいます。パソコンの前に座っていることを検出するセンサを追加しました。
シャープ測距モジュール GP2Y0A21YK
http://akizukidenshi.com/catalog/g/gI-02551/
このセンサの検出範囲は、測距範囲:10~80cmなので座っている位置が50cm程度に調整しました。距離がこれ以上あった場合は、不在と判断しています。距離が50cm以下の時は、人感センサが未検出でも電灯を消さないようにしました。

プログラムの説明をします。
まず、距離センサを入力するアナログピンを定義します。今回はA2ピンを使用しました。
const int distancePin = A2;
距離に対応した値を保持する変数を定義します。
int distanceValue = 0;

loop()関数で距離センサの値を読み込みます。
distanceValue = analogRead(distancePin);

値が大きいほど距離が近いので、50cm程度に相当する距離以上では、消灯しない仕組みにしました。
if(distanceValue > 150)
{
no_cnt = 0;
}

100msec毎に繰り返します。
delay(100);

とりあえず、電灯自動点灯消灯システムは完成です。
サンプルプログラムは以下にあります。
https://github.com/jendo1969/GR-COTTON/blob/master/Distance_Sensor/Distance_Sensor.ino

 

I attached an illuminance sensor to the last GR – COTTON remote control.
Because it does not detect unless it moves with the characteristics of the human sensor, if it is still, it will not live and the light will be turned off. We added a sensor to detect sitting in front of the personal computer.
Sharp distance measuring module GP2Y0A21YK
http://akizukidenshi.com/catalog/g/gI-02551/
The detection range of this sensor was adjusted to about 50 cm because the range finding range: 10 to 80 cm. If there are more distances, we judge absence. When the distance is 50 cm or less, we made sure that the lights are not extinguished even if the human sensor is not detected.

I will explain the program.
First, define the analog pin to input the distance sensor. This time I used the A2 pin.

const int distancePin = A2;
Define a variable that holds the value corresponding to the distance.
int distanceValue = 0;

Read the distance sensor value with the loop() function.
distanceValue = analogRead(distancePin);

As the value is larger, the distance is closer, so we set up a mechanism that does not go off if it is over a distance equivalent to about 50 cm.
if(distanceValue > 150)
{
no_cnt = 0;
}

Repeat every 100 msec.
delay(100);

Tomorrow, the lighting automatic lighting system is completed.
The sample program is below.

https://github.com/jendo1969/GR-COTTON/blob/master/Distance_Sensor/Distance_Sensor.ino

我將照度傳感器連接到最後一個GR – COTTON遙控器。
因為除非它隨著人體感應器的特性而移動,否則它不會檢測到它,如果它仍然存在,它將無法生存並且燈光將被關閉。 我們添加了一個傳感器來檢測坐在個人電腦前。
夏普測距模塊GP2Y0A21YK
http://akizukidenshi.com/catalog/g/gI-02551/
該傳感器的檢測範圍被調整到約50厘米,因為測距範圍:10到80厘米。 如果有更多的距離,我們判斷缺席。 當距離為50厘米或更小時,即使沒有檢測到人體感應器,我們也確保不要關燈。

我會解釋這個程序。
首先,定義模擬引腳輸入距離傳感器。 這次我使用了A2引腳。

const int distancePin = A2;
定義一個保存與距離相對應的值的變量。
int distanceValue = 0;

用loop()函數讀取距離傳感器值。
distanceValue = analogRead(distancePin);

由於數值越大,距離越近,所以我們建立了一個機制,如果它的距離相當於大約50厘米,它就不會熄滅。
if(distanceValue > 150)
{
no_cnt = 0;
}

每100毫秒重複一次。
delay(100);

明天,照明自動照明系統完成。
示例程序如下。

https://github.com/jendo1969/GR-COTTON/blob/master/Distance_Sensor/Distance_Sensor.ino

 

Post Tagged with ,

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください