I'm using an Arduino Uno, 1.0.5 r2 version of the IDE with and ultrasonic HC-SR04 sensor for measuring a tank water level. I want to send the data obtained over internet using the official arduino GSM shield sending them on the plot.ly servers with their API using a GPRS connection. When I'm doing all the tasks I get inaccurate values as these:


When I use the only ping sensor without the GSM shield all works well getting good data. The same using a potentiometer + GSM shield + plot.ly.

The function I use for getting the distance is:

long distCalc() {
  long durata, distanza;
  digitalWrite(TRIG_PIN, LOW);  // TRIG_PIN = pin 12
  digitalWrite(TRIG_PIN, HIGH);
  digitalWrite(TRIG_PIN, LOW);
  durata = pulseIn(ECHO_PIN, HIGH);  //ECHO_PIN = pin 11
  distanza = durata / 29.1 / 2 ;
  return distanza;    // in uscita la distanza in [cm]

and the one for posting the data on plot.ly servers is (loop function):

void loop() {
  long distanza;
  distanza = distCalc();  //fase di calcolo distanza
  graph.plot(millis(), int(distanza), tokens[0]);  //fase di invio su plot.ly

Could it be a software serial interrupt that hangs the pulseIn measurement? How could I avoid this?

  • Hi @em1lio189, could be an issue with delay / delayMicroseconds. You may try to put another delay between distCalc() and Serial.print(). On a separate note, how are you going to install this setup in the tank? Water-proofing, etc. I am also working on a similar project and planning to use Bluetooth / Wifi for transmitting data. This is a personal project not commercial for my home. – Vivek Jain Jul 6 '15 at 11:08
  • hi @theghostofc, I tried with the delay with no results. I think that the measure is noisy because the softwareserial library uses interrupts. I solved powering off the gsm shield, making the measure, starting it again and sending data in the main loop. – em1lio189 Jul 7 '15 at 9:52
  • That's great that you got it working, even though with a hack :) – Vivek Jain Jul 7 '15 at 15:08
  • 1
    Could you please let me know how you are going to place the hardware (in the tank or outside). In my case it is placed outside under the Sun, with no power outlets nearby. Main concern that I have is to make the setup weather-proof. Any suggestions? – Vivek Jain Jul 7 '15 at 15:10

Your Answer

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

Browse other questions tagged or ask your own question.