Page 109 - KEC Khaitan C8.2 Flipbook
P. 109

long duration = pulseIn(ECHO, HIGH);

                   int distance = duration * 0.034 / 2;
                   Serial.print(“Distance: “);

                   Serial.print(distance);

                   Serial.println(“ cm”);

                   delay(500);
                 }
                     Steps to Upload the Code:

                 Step  1    Open Arduino IDE.

                 Step  2    Copy and paste the above code.

                 Step  3    Connect the Arduino Uno to your computer via USB.

                 Step  4    Click Upload and open the Serial Monitor to view distance measurements.


                 Introduction to Piezo Buzzer For Feedback
                 What Is a Piezo Buzzer?

                 A piezo buzzer is a small speaker that generates sound using piezoelectric vibrations.

                                                        Applications:

                                                        o   Alarm systems
                                                        o   Notifications in electronic devices

                                                        o   Reverse parking assistance






                  Connecting the Piezo Buzzer to Arduino

                                                                                     Wiring Guide:
                                                                                      Piezo Buzzer

                                                                                      Pin            Arduino Pin
                                                                                      + (Positive)   Pin 8
                                                                                      - (Negative)   GND

















                                                                                     Fundamentals of Sensors & Data  107
   104   105   106   107   108   109   110   111   112   113   114