3

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:

error

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
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  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
  Serial.print(distanza);
  Serial.println("cm");
  graph.plot(millis(), int(distanza), tokens[0]);  //fase di invio su plot.ly
  delay(20);
}

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

VE7JRO
  • 2,515
  • 19
  • 27
  • 29
em1lio189
  • 31
  • 2

0 Answers0