I've found that while "duration1" and "duration2" exchange their order(which means duration2 runs first, then duration1 runs.), the result becomes that distance1 shows 0 but distance2 shows correct value. The situation is that on the Serial Monitor, "distance1" shows correct value however "distance2" is always 0. My code is shown below: int trigPin=12 // this pin work as the output of the two trig pin of the two sensorįloat duration1, distance1, duration2, distance2 ÄigitalWrite(trigPin, LOW) //trig:10 microsecond TTL pulse While a try to display two measured value from each sensor, one of them work fine but the other displays value 0. I especially like the dian(iterations) function - the occasional spurious data can be rejected that way.I've got a problem while I try to use Arduino uno to drive two HC-SR04 ultrasonic sensor. It wasn't available when I originally built Clusterbot, but looks like it is really good. I would use the New Ping library for the HC-SR04.Bottom level for drivetrain and batteries, top level for electronics. I would make a two-layer round platform out of a light plywood.The 6V motors have a lower current draw, and operate at a voltage that is in the "sweet spot" for the TB6612FNG motor driver. I would use the 6V motors here instead of the 3V Mabuchi motors.There are a few things I would do differently if I were building Clusterbot now: Adding to much to a system at once makes it more difficult to troubleshoot the entire system when things don't go as planned. I've found it's important to keep a system as simple as possible when adding a new component. I kept the test code really simple - either turn left or go forward. He continued to spin on his axis until I gave him a way out, which he took at the first opportunity. The test run was a success! I especially liked how well Clusterbot performed when completely surrounded. Also adding an LED and a Speaker for fun. Now we are going to add the HC-SR04 to Clusterbot. You should see the distance the ultrasonic sensor is measuring, updated 10 times per second. Once the code is uploaded, you can open the serial monitor on the Arduino IDE on your computer. Daftar Isi (show) Pengertian Sensor Ultrasonik HC-SR04 Sensor ultrasonik HC-SR04 adalah suatu sensor yang fungsinya mengubah besaran fisis bunyi menjadi besaran listrik maupun sebaliknya. Serial.print(ultrasonic.Ranging(INC)) /* INC for inches, CM for centimeters */ Serial.begin(9600) /*begin serial port comm at 9600 bps */ Ultrasonic ultrasonic(12,13) /*create instance of ultrasonic and define pins*/ Now upload the following code to the Arduino: #include /*include user installed library*/ Digital pin 13 of Arduino to ECHO of HC-SR04.Digital pin 12 of Arduino to TRIG of HC-SR04.Make the following connections on your Arduino and HC-SR04: Output will be to the serial monitor in the Arduino IDE. Here's a simple bit of Arduino code to test the HC-SR04 sensor. You may also find this info from useful: how to add libaries to the Arduino IDE. The library I used is available for download here: HC-SR04 Arduino Library. Using the HC-SR04 sensor is pretty simple once you install the required library to the Arduino IDE. If maximum distance is important, the PING has a published range of 300cm. Talking to a few others on Google+, 100cm seems to be the typical range. I've been able to achieve consistent and accurate results out to 100 cm (about 3.5 feet). The published range of the HC-SR04 is 450cm. The only complaint I have is the maximum range. I've never used the PING sensor, but I've used several of the HC-SR04's. The HC-SR04 sensors are about $3 shipped on eBay. On the HC-SR04, the trigger and echo pins are separate. In the case of the Parallax PING, the trigger and return pulse share the same pin. The sensor measures the amount of time it takes for the 40KHz signal to come back, then outputs a variable-width pulse proportional to the time measured. These sensors emit a 40KHz pulse when an input is provided to the trigger pin. Functionally, the HC-SR04 is roughly the same as the Parallax PING sensor. I decided to go with the HC-SR04 Ultrasonic sensor. This article is available in PDF format for easy printing
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |