忍者ブログ
[288]  [287]  [286]  [285]  [284]  [283]  [282]  [281]  [280]  [279]  [278
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

・RaspberryPiに続いてArduinoでまったく同じセンターで距離測定
 トリガーをD8
 エコーをD9に接続
 スイッチサイエンスのHPを参照にソース
 
 pulseIn関数が使えるのでラズパイよりはずっとスマート
 ピンがHIGHになるのを待ち、時間計測を開始する。
 その後、ピンがLOWになるのを待ち、時間計測を終了する
 結果はマイクロ秒
 
int Trig = 8;
int Echo = 9;
int Duration;
float Distance;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(Trig,OUTPUT);
  pinMode(Echo,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(Trig,LOW);
  delayMicroseconds(1);
  digitalWrite(Trig,HIGH);
  delayMicroseconds(11);
  digitalWrite(Trig,LOW);
  Duration = pulseIn(Echo,HIGH);
  if (Duration>0) {
    Distance = Duration/2;
    Distance = Distance*340*100/1000000;  
    Serial.print(Distance);
    Serial.println(" cm");
  }
  delay(500);
 
}

raspberypiでは不安定だったがこちらは安定稼働

・シャープの距離センサーはもっと簡単
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
  int val;
  val=analogRead(0);
  Serial.println(val);
  delay(500);
}

後は、電圧と距離補正を組み込めば完成

この測距方法だが、三角測量の原理だそうで、赤外線LEDからの反射を
PSD(光位置検出素子)で見ているので、反射光に左右されない
ようです。


拍手

PR
カレンダー
03 2025/04 05
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
フリーエリア
最新CM
[03/10 DORA]
最新TB
プロフィール
HN:
dorabu
性別:
非公開
バーコード
ブログ内検索
P R
Copyright © ドラブーのアンドロイドとIoTなブログ All rights reserved. / Template by 四季. / Material by てんせん.

忍者ブログ [PR]