Help in HC-SR04 read data.

Hello everyone, i'm a little noob in Arduino dev.
I'm trying to build one machine how use 2 HC-SR04 measure sensors in each of the four Arduino Nano.

// NewPing - Version: Latest 
#include <NewPing.h>

#define SONAR_NUM      2 // Number of sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).

unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
uint8_t currentSensor = 0;          // Keeps track of which sensor is active.

NewPing sonar[SONAR_NUM] = {     // Sensor object array. [Each sensor's trigger pin, echo pin, and max distance to ping.]
  NewPing(4, 5, MAX_DISTANCE), // Sensor 01_Right
  NewPing(7, 8, MAX_DISTANCE), // Sensor 02_Right

void setup() {
  pingTimer[0] = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.
  for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;

void loop() {
  for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
    if (millis() >= pingTimer[i]) {         // Is it this sensor's time to ping?
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
      if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
      currentSensor = i;                          // Sensor being accessed.
      cm[currentSensor] = 0;                      // Make distance zero in case there's no ping echo for this sensor.
      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
  // Other code that *DOESN'T* analyze ping results can go here.

void echoCheck() { // If ping received, set the sensor distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;

void oneSensorCycle() { // Sensor ping cycle complete, do something with the results.
  // The following code would be replaced with your code that does something with the ping results.
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
    Serial.print(" , ");

However, using this library, I can only receive the sensor data as "int".
But I need the values ​​received with the 2 decimal places.
Now = "10 10" // Sensor data 1 and 2
New = "10.11 10.12"

Anyone know how to change this?
Thx for the help =D (3.04 KB)

Two options.

  1. just read the HC-SR04 directly. They're so dead simple to deal with I don't see the use of a library. Get all the decimals you want.
  2. forget about the decimals, it's not that accurate anyway, maximum resolution is about 0.4 cm for that sensor (1/2 wavelength - 7.5 mm at 40 KHz). And to get to that resolution you'd at least have to compensate for temperature.