4
2

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

視覚障害者向け帽子:赤外線測距センサで障害物までの距離を振動の強弱で伝える帽子の開発

Last updated at Posted at 2019-02-17

#概要
赤外線測距センサで障害物までの距離を振動の強弱で伝える帽子を作りました。
概要.JPG

#使用したもの
obniz
距離センサ(HC-SR04)
振動モータ

以下、補助的なもの
・モバイルバッテリー
・ダイソー帽子(黒)

#作り方
作り方1.JPG
作り方2.JPG

#コード

CapDis2Vib.js
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    <script src="https://unpkg.com/obniz@latest/obniz.js" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/iothome/index.js"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/ai/index.js"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/airobot/index.js"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/ui/index.js"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/ai/opencv3.4/opencv.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.5"> </script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@0.2.2"> </script>
</head>
<body>
Program running...
<div id="OBNIZ_OUTPUT"></div><br/>

<script>
(async function(){
  var obniz, distSens, dcmotor;
  
  obniz = new Obniz('★Your ID is HERE★');
  await obniz.connectWait();
  obniz.display.clear();
  obniz.display.print('CapDisVib')
  dcmotor = obniz.wired("DCMotor",{"forward":10, "back":11});
  dcmotor.power(52);
  dcmotor.move(true);
  await obniz.wait(2000);
  dcmotor.stop();

  
  const hcsr04 = obniz.wired("HC-SR04", {gnd:0, echo:1, trigger:2, vcc:3});
while(true) {
  let avg = 0;
  let count = 0;
  for (let i=0; i<3; i++) { // measure three time. and calculate average
    const val = await hcsr04.measureWait();
    if (val) {
      count++;
      avg += val;
    }
  }
  if (count > 1) {
    avg /= count;
  }
  console.log(Math.round(avg/10) + " cm");
  obniz.display.clear();
  obniz.display.print(Math.round(avg/10) + " cm")
  
    if (avg <= 2000) {
      console.log(2000/avg*20);
      dcmotor.power((2000/avg*20));
      dcmotor.move(true);
        obniz.display.print("In Range")
      await obniz.wait(1000);

    } else {
      dcmotor.stop();
    }  
   
  await obniz.wait(100);
}
  
  
})();
</script>
</body>
</html>

#2019/2/18 追加

超音波は温度により進む速度が違います
デフォルトで15度で計算していますが、変更して正しい値にすることでより精度の高い結果が欲しい>場合はtempから調整します。

との事なので、より正確な距離を求められるように温度センサーを追加して、室温をセットできるようにしました。

温度センサー追加.JPG

##コード

CapDis2VibWithTEMP.js
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    <script src="https://unpkg.com/obniz@latest/obniz.js" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/iothome/index.js"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/ai/index.js"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/airobot/index.js"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/ui/index.js"></script>
    <script src="https://unpkg.com/obniz-parts-kits@0.11.2/ai/opencv3.4/opencv.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.5"> </script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@0.2.2"> </script>
</head>
<body>
Program running...
<div id="OBNIZ_OUTPUT"></div><br/>

<script>
(async function(){
  var obniz, distSens, dcmotor;
  
  /*https://obniz.io/sdk/parts/HC-SR04/README.md?iframe=false*/
  
  
  obniz = new Obniz('XXXXXXXXX');
  await obniz.connectWait();
  obniz.display.clear();
  obniz.display.print('CapDisVib')
  dcmotor = obniz.wired("DCMotor",{"forward":10, "back":11});
  dcmotor.power(30);
  dcmotor.move(true);
  await obniz.wait(1000);
  dcmotor.stop();

  /*温度計 789で接続(Onchangeでは取得出来ている)*/
  var tempsens = obniz.wired("LM35DZ",  { gnd:7 , output:8, vcc:9});
  var temp = await tempsens.getWait();
   console.log(temp + " CEL");
  
  /*距離センサ*/
  const hcsr04 = obniz.wired("HC-SR04", {gnd:0, echo:1, trigger:2, vcc:3});
  /*hcsr04.temp = 23; 温度を23度で設定。距離精度に影響*/
  hcsr04.temp = temp;
  
while(true) {
  let avg = 0;
  let count = 0;
  for (let i=0; i<3; i++) { // measure three time. and calculate average
    const val = await hcsr04.measureWait();
    if (val) {
      count++;
      avg += val;
    }
  }
  if (count > 1) {
    avg /= count;
  }
  console.log(Math.round(avg/10) + " cm");
  obniz.display.clear();
  obniz.display.print(Math.round(avg/10) + " cm")

  
    if (avg <= 3000 && avg >= 500) {
      console.log(Math.round(3000/avg*20+10));
      dcmotor.power((3000/avg*20+10));
      dcmotor.move(true);
        obniz.display.print("In Range")
      await obniz.wait(500);
      dcmotor.stop();
    } else {
      dcmotor.stop();
    }  
   
  await obniz.wait(100);
}
  
  
})();
</script>
</body>
</html>

#参考ページ

4
2
1

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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?