– Productivity Blocks Documentation (Wiki) – Productivity Blocks (Development Timesaver) – Arduino IDE (Integrated Development Environment) Watch the video below for the operation of the ultrasonic sensor on our Arduino Uno Super Starter Kit. The above Arduino program sketches can be downloaded here. Call up the serial monitor and watch the distance measured in mm displayed. Upload the program to the Arduino UNO R3. Displays the distance on the Serial Monitor Reads the echoPin, returns the sound wave travel time in microsecondsĭistance = duration * 0.343 / 2 // Speed of sound wave divided by 2 (go and back) Sets the trigPin HIGH (ACTIVE) for 10 microseconds Serial.println("Ultrasonic Sensor HC-SR04 Test") // print some text in Serial Monitor Serial.begin(9600) // // Serial Communication is starting with 9600 of baudrate speed PinMode(echoPin, INPUT) // Sets the echoPin as an INPUT PinMode(trigPin, OUTPUT) // Sets the trigPin as an OUTPUT Int distance // variable for the distance measurement Long duration // variable for the duration of sound wave travel #define trigPin 12 //attach pin D12 Arduino to pin Trig of HC-SR04 #define echoPin 11 // attach pin D11 Arduino to pin Echo of HC-SR04 *-( Declare Constants and Pin Numbers )-*/ Sample Program based on the following information (us)ģ – Calculate the distanced based on the formula distance = duration * 0.343 / 2Ĥ – Write the distance to the serial monitor. (microseconds)Ģ – Read the duration of the Echo input in microseconds. The program will do the following in a continuous loop.ġ – Set the Trig output high for 10 us. The serial port will be used to display the measurement taken. We will also set up variables for the duration time (us) of the return from the Echo and the distance measured in millimeters (m). This sketch (program) will define the Echo and Trig pins of our ultrasonic sensor. The Trig (trigger) will be connected to D12 (Output) and the Echo will be connected to D11 (Input). ‘Gnd’ will be black and connected to the GND connection on our Arduino UNO R3. The Vcc connection will be red and connected to our 5VDC supply. Wiring the Ultrasonic Senor to our Arduino UNO The echo pin will output time in us (microseconds) that the sound wave traveled. This sound will travel at the speed of sound to the object and back again. When the trigger pin is set high for 10 us this will send out 8 sonic sound bursts. The timing chart will show us the general method that the HC-SR04 module will work. So we will divide by two for the actual distance. Since the sound waves are traveling to the object, bouncing off of it, and traveling back to the sensor the distance covered is twice that of the actual object. The time of the return sound will determine the distance.ģ43mps (meters per second) = 0.343 mm/us (meters per micro second)ġ Meter = 1000 Millimetres (100 Centimetres) If an object is in the way, the sound will bounce off of it and back to the sensor. The ultrasonic sensor HC-SR04 contains transmitters, receivers, and control circuits all in one unit.Īn ultrasonic sensor will send out a sound and wait for the return of this sound. Ultrasonic Sensor HC-SR04 – How they work Watch the video below of the operation of the ultrasonic sensor with our Arduino Uno Kit. Previous posts in this Arduino Uno Super Starter Kit Series: Let’s get started.Ī full list of posts in this series can be obtained at the following location: We will be wiring the ultrasonic sensor to our Arduino UNO R3 controller on our super starter kit. The modules include ultrasonic transmitters, receivers, and control circuits. Ultrasonic sensor module HC-SR04 provides a 2cm-400cm non-contact measurement function, the accuracy can reach 3mm. We will be sending signals directly to the sensor and interpreting the results without the need for a library. The HC-SR04 is inexpensive and easy to use. The ultrasonic sensor (HC-SR04) is great for all kinds of projects that need distance measurements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |