Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long duration[2];
- float distance[2];
- int ECHO_PIN[2] = {4, 15};
- int TRIGGER_PIN = 5;
- void setup() {
- Serial.begin (9600);
- pinMode(TRIGGER_PIN, OUTPUT);
- pinMode(ECHO_PIN[0], INPUT);
- pinMode(ECHO_PIN[1], INPUT);
- }
- void loop() {
- digitalWrite(TRIGGER_PIN, LOW); // Added this line
- delayMicroseconds(2); // Added this line
- digitalWrite(TRIGGER_PIN, HIGH);
- delayMicroseconds(10); // Added this line
- digitalWrite(TRIGGER_PIN, LOW);
- for (int x = 0; x < 2; x++) {
- duration[x] = pulseIn(ECHO_PIN[x], HIGH);
- distance[x] = (duration[x] / 2) / 29.1;
- }
- Serial.print("SRF Module_1 = ");
- Serial.print(distance[0]);
- Serial.print(" cm\n");
- Serial.print("SRF Module_2 = ");
- Serial.print(distance[1]);
- Serial.print(" cm\n");
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement