1

このリンクのようにArduinoと2つの超音波hc-sr04を使用して速度検出「デバイス」を作成したい. LDRではなく超音波で作りたい。

そのリンクから。このように、レーザーとldrがどのように機能するか

抵抗はプルダウン抵抗として使用し、センサーを配線してケースに入れ、周囲の光を検出しないようにしました。いずれの場合も、周囲光がセンサーに影響を与えずにレーザービームがセンサーを照らすことができるように、穴が開けられました。動作原理は簡単です。通過する物体がレーザー ビームを「カット」します。これは、LDR センサーがこの光強度の急激な低下を検出することを意味します。最初に、センサーがトリガーされたと見なされるしきい値を定義しました。値が最初のセンサーのしきい値を下回ると、Arduino は 2 番目のセンサーがトリガーされるのを待ちます。この待機時間中に、2 つのイベント間の経過時間をカウントします。2 番目のビームが中断されると、タイマーが停止し、単純な計算になります。2 つのセンサー間の距離は既知であり、

Arduinoコードの下:

/* 
by Claudiu Cristian 
*/ 

unsigned long time1; 
int photocellPin_1 = 0; // 1st sensor is connected to a0 
int photocellReading_1; // the analog reading from the analog port 
int photocellPin_2 = 1; // 2nd sensor is connected to a1 
int photocellReading_2; // the analog reading from the analog port 
int threshold = 700; //value below sensors are trigerd 
float Speed; // declaration of Speed variable 
float timing; 
unsigned long int calcTimeout = 0; // initialisation of timeout variable 

void setup(void) { 
// We'll send debugging information via the Serial monitor 
Serial.begin(9600); 
} 

void loop(void) { 
photocellReading_1 = analogRead(photocellPin_1); //read out values for sensor 1 
photocellReading_2 = analogRead(photocellPin_2); //read out values for sensor 2 
// if reading of first sensor is smaller than threshold starts time count and moves to             calculation function 
if (photocellReading_1 < threshold) { 
time1 = millis(); 
startCalculation(); 
} 
} 

// calculation function 
void startCalculation() { 
calcTimeout = millis(); // asign time to timeout variable 
//we wait for trigger of sensor 2 to start calculation - otherwise timeout 
while (!(photocellReading_2 < threshold)) { 
photocellReading_2 = analogRead(photocellPin_2); 
if (millis() - calcTimeout > 5000) return; 
} 
timing = ((float) millis() - (float) time1) / 1000.0; //computes time in seconds 
Speed = 0.115 / timing; //speed in m/s given a separation distance of 11.5 cm 
delay(100); 
Serial.print(Speed); 
Serial.print("\n"); 
} 

超音波 HC-SR04 センサーでコードを実装する方法は? コーディングは私にとって問題です。うまくいけば、誰かが私を助けることができます...... :(私の下手な英語を許してください!

4

1 に答える 1

1

インターネット上にはすでに多くの例があるので、コピーしたいだけなら google arduino sr04

sr04 には vin、gnd、trigger、echo の 4 つのピンがあります。vin とグラウンドを +5 と GND に接続します トリガーをデジタル出力ピンに接続します エコーをデジタル入力ピンに接続します

2 マイクロ秒 (us) の間ローになり、次に 10 マイクロ秒の間ハイになり、再びローになることによってトリガーします。次に、エコー ピンからの pulseIn で結果を取得します。

詳細については、データシートをお読みください

于 2014-06-11T16:47:47.223 に答える