hc-sr04_nano_oled_bb.png (310430Bytes)
disp4_ultra.c (1320Bytes)
Hi Everyone,
I have been finding that I get erratic distance measurements on my tests with the HC-SR04 sensors. I put together a circuit with 128x64 OLED SSD1306 I2C display (Really like that module, by the way) connected on a breadboard to Arduino Nano v3.
The idea behind the circuit is:
Use the NewPing library to generate a distance measurement in centimeters.
Print the distance value to the screen, and keep on repeating.
As the sensor is moved around (8V lipo battery connected to Vin and Ground) you can see the distance updated on the tiny screen.
So, the circuit and arduino sketch works reasonably well. I was very happy on my first run, that I was lining up a ruler next to the sensor, and getting a matching distance value being displayed (from approx 40cm down to approx 1cm, with best values in the range 35cm to 2cm). However I noticed: "But this isn't producing any numbers for greater than 50cm" Why's that?
I made little tweaks and changes to my sketch, such as adding/removing the max_distance restriction to the library call. I thought, suppose it could be "this" sensor, and as I have about 4 of these, I decide to turn off, swap sensor, and check the new sensor's measurements. Sensor 2 and 3 gave garbage - fairly random numbers returned from 0-190cm (with no effect from the actual distance to the wall). Pretty unhappy about that - It takes about 25 days for new deliveries from Hong Kong/China. The last HC-SR04 sensor gave decent values again, but only from ~ 1cm to 50cm, like the first one I tested.
All the tests have been done with I2C ports connected to OLED, and GPIO 7 and 8 connected to Echo and Ping on the sensor. The Arduino is 5 Volt model, ATmega328.
Have any of you experienced similar problems? Any idea what I can do to improve performance - Either the garbage sensors or the sensors which aren't giving a decent range. Would it be better if I switched to GPIO 2 and 3 (which are commonly used in examples)? Any of your new sensors not working from first use? Maybe use another library or custom code?
Looking forward to what your comments will uncover.
========
Some more comments about this:
I have just tried out the 1602 LCD module for displaying the distance given by the Ultrasonic sensor. This is behaving much better than the 128x64 OLED display, and isn't interfering with the displayed distance data. Please see the attached code sample. I've been getting decent measurements from approx 3cm to 300cm.
On the OLED display I did get an improvement in the results, by doing the following: The OLED is supposed to support 3.3V - 5V, so I decided to connect it to 3.3V on the Arduino, rather than 5V (which the Ultrasonic distance sensor is using). I also used 10k pull-up resistors on the SDA and SCL lines, and 1 microF capacitor across 3.3V and GND. I have observed some improvement in the distance measurement results being displayed, but still not perfect. I suspect the I2C bus is affecting the accurate timing required by the Ultrasonic Trigger/Echo pulse measurement.