I'm trying to send the reading distance of an HC-SR04 sensor to an Android app, using Bluetooth. I succesfully managed to send values from many other sensor to the app, but when it comes to sending the HC-SR04 reding, a strange behaviour happens. To send the reading over BT I use a simple Serial.printl(value) command, which also display the reading on the PC serial monitor. The strange thing is this: if the bluetooth module is disconnected, the readings are correct, but as soon as I connect the Bluetooth module on the breadboard (a JY-MCU), the reading start to get apparently random, even I watch at them on the PC monitor, and not from the app. I still haven't figured out if this problem is hardware or software related.

I also tried to disconnect all the other sensors and components from the circuit, using a vary basic sketch, but the result is the same: as soon as I insert the Bluetooth module ( even if the data is not sent to the Android app), I start getting random distance values. Here is the sketch:

int trig = 10;
int echo = 7;
void setup(){ 
void loop(){
 long distance = getUltrasonicAltitude();
long getUltrasonicAltitude(){
  long duration, cm;
  digitalWrite(trig, LOW);
  digitalWrite(trig, HIGH);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo,HIGH);
  cm = duration/29/2;
  return cm;

I tried using the newPing library, and even using interrupts instead of the pulseIn function to get the time between the pulses, but the result was always the same: everything was ok but only without the bluetooth module...

Do you know a way, or have a suggestion, to fix this annoying issue that has been bugging me for two days? It may be an hardware or a software issue, so I'm really open to hear any kind of possible solutions.


I finally found the reason of the issue! Using a voltmeter I found out that the problem basically is that the bluetooth module absorbs too much current every time the Serial.println function in called, and this causes the voltage to oscillate up and down, between 3.8 and 4.3 volt. It seems that the ultrasonic range sensor doesn't like that. Is there any way to fix this problem without using an other external power supply? Maybe a capacitor can smooth the voltage drops?

migrated from electronics.stackexchange.com May 2 '15 at 17:42

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 1
    I have faced a similar issue with HC-SR04 and a LED 7-seg display. Adding a decoupling cap, near the HC-SR04 voltage pins, fixed the issue (actually I had added 2 caps: one 10uF, one 100nF). – jfpoilpret May 3 '15 at 7:19

In all the blutooth interfacing projects I have done, I have used.


Try it out, hope it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy