Insert a regular ring to you piece Ultrasonic Sensors // defines pins numbers const int trigPin = 9; const int echoPin = 10; const int buzzer = 11; const int left_trigPin = 6; const int left_echoPin = 7; const int right_trigPin = 2; const int right_echoPin = 3; const int center_trigPin = 4; const int center_echoPin = 5; // defines variables long duration; int distance; int safetyDistance; void setup() { pinMode(left_trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(left_echoPin, INPUT); // Sets the echoPin as an Input pinMode(right_trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(right_echoPin, INPUT); // Sets the echoPin as an Input pinMode(center_trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(center_echoPin, INPUT); // Sets the echoPin as an Input pinMode(buzzer, OUTPUT); Serial.begin(9600); // Starts the serial communication } void loop(){ left(); right(); center(); } void left(){ delay(500);// reading will be taken after ....miliseconds Serial.println("\n"); int duration, distance; digitalWrite (left_trigPin, HIGH); delayMicroseconds (10); digitalWrite (left_trigPin, LOW); duration = pulseIn (left_echoPin, HIGH); distance = (duration/2) / 29.1; //distance= duration*0.034/2; if (distance < 30) { // Change the number for long or short distances. Serial.print("Left Distance"); Serial.print(distance);} safetyDistance = distance; if (safetyDistance <= 5){ digitalWrite(buzzer, HIGH); } else{ digitalWrite(buzzer, LOW); } } void right(){ delay(500);// reading will be taken after ....miliseconds Serial.println("\n"); int duration, distance; digitalWrite (right_trigPin, HIGH); delayMicroseconds (10); digitalWrite (right_trigPin, LOW); duration = pulseIn (right_echoPin, HIGH); distance = (duration/2) / 29.1; if (distance <30) { // Change the number for long or short distances. Serial.print("Right Distance"); Serial.print(distance); safetyDistance = distance; if (safetyDistance <= 5){ digitalWrite(buzzer, HIGH); } else{ digitalWrite(buzzer, LOW); } } } void center(){ delay(500);// reading will be taken after ....miliseconds Serial.println("\n"); int duration, distance; digitalWrite (center_trigPin, HIGH); delayMicroseconds (10); digitalWrite (center_trigPin, LOW); duration = pulseIn (center_echoPin, HIGH); distance = (duration/2) / 29.1; if (distance <30) { // Change the number for long or short distances. Serial.print("Center Distance"); Serial.print(distance); } safetyDistance = distance; if (safetyDistance <= 5){ digitalWrite(buzzer, HIGH); } else{ digitalWrite(buzzer, LOW); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Insert a regular ring to you piece Ultrasonic Sensors

// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;

const int left_trigPin = 6;
const int left_echoPin = 7;

const int right_trigPin = 2;
const int right_echoPin = 3;

const int center_trigPin = 4;
const int center_echoPin = 5;
// defines variables
long duration;
int distance;
int safetyDistance;


void setup() {
pinMode(left_trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(left_echoPin, INPUT); // Sets the echoPin as an Input

pinMode(right_trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(right_echoPin, INPUT); // Sets the echoPin as an Input

pinMode(center_trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(center_echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);

Serial.begin(9600); // Starts the serial communication
}

void loop(){

        left();

        right();

        center();
}


void left(){
  delay(500);// reading will be taken after ....miliseconds

  Serial.println("\n");

  int duration, distance;

    digitalWrite (left_trigPin, HIGH);

    delayMicroseconds (10);

    digitalWrite (left_trigPin, LOW);

    duration = pulseIn (left_echoPin, HIGH);

    distance = (duration/2) / 29.1;

    //distance= duration*0.034/2;  

    if (distance < 30) {  // Change the number for long or short distances.    

    Serial.print("Left Distance");

    Serial.print(distance);}    
safetyDistance = distance;
if (safetyDistance <= 5){
  digitalWrite(buzzer, HIGH);
  
}
else{
  digitalWrite(buzzer, LOW);
 
}
}

void right(){

   delay(500);// reading will be taken after ....miliseconds

   Serial.println("\n");

   int duration, distance;

    digitalWrite (right_trigPin, HIGH);

    delayMicroseconds (10);

    digitalWrite (right_trigPin, LOW);

    duration = pulseIn (right_echoPin, HIGH);

    distance = (duration/2) / 29.1; 

    if (distance <30) {  // Change the number for long or short distances.

    Serial.print("Right Distance");

    Serial.print(distance);

safetyDistance = distance;
if (safetyDistance <= 5){
  digitalWrite(buzzer, HIGH);
  
}
else{
  digitalWrite(buzzer, LOW);
}
    }
}


void center(){

   delay(500);// reading will be taken after ....miliseconds

   Serial.println("\n");

   int duration, distance;

    digitalWrite (center_trigPin, HIGH);

    delayMicroseconds (10);

    digitalWrite (center_trigPin, LOW);

    duration = pulseIn (center_echoPin, HIGH);

    distance = (duration/2) / 29.1; 

    if (distance <30) {  // Change the number for long or short distances.

    Serial.print("Center Distance");

    Serial.print(distance);
    }
    safetyDistance = distance;
if (safetyDistance <= 5){
  digitalWrite(buzzer, HIGH);
  
}
else{
  digitalWrite(buzzer, LOW);
 
}

}

Expert Solution
steps

Step by step

Solved in 6 steps

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education