Help... 2 sensor ultrasonic with new ping

sorry if my english is bad
please help me to solve my project
i use 2 sensor ultrasonic with newping.h
if i use:

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <NewPing.h>

NewPing ultrasonic (5,4);

char ssid = “vivo1612”;
char wifiPassword = “99999999”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “0f3d2bb0-fe1b-11e9-84bb-8f71124cfdfb”;
char password = “4f7d89bc3da5581de2a04b1f9750da8430591389”;
char clientID = “0aefc090-0153-11eb-a67f-15e30d90bbf4”;
unsigned long lastMillis = 0;

#define TRIGGER 5
#define ECHO 4
#define VIRTUAL_CHANNEL 1
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT(0)
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}
CAYENNE_OUT(1)
{

int US1 = ultrasonic.ping_cm();
Serial.print(“Hasil Sensor 1 :”);
Serial.print(US1);
Serial.println(“cm”);
delay(100);
Cayenne.virtualWrite(1, US1, “prox”, “cm”);
}

its totally work…
but if i use:
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <NewPing.h>

NewPing ultrasonic (5,4);
NewPing ultrasonic2 (6,7);

// WiFi network info.
char ssid = “vivo1612”;
char wifiPassword = “99999999”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “0f3d2bb0-fe1b-11e9-84bb-8f71124cfdfb”;
char password = “4f7d89bc3da5581de2a04b1f9750da8430591389”;
char clientID = “0aefc090-0153-11eb-a67f-15e30d90bbf4”;
unsigned long lastMillis = 0;

#define TRIGGER 5
#define ECHO 4
#define VIRTUAL_CHANNEL 1
#define TRIGGER2 6
#define ECHO2 7
#define VIRTUAL_CHANNEL 2
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT(0)
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}
CAYENNE_OUT(1)
{

int US1 = ultrasonic.ping_cm();
Serial.print(“Hasil Sensor 1 :”);
Serial.print(US1);
Serial.println(“cm”);
delay(100);
Cayenne.virtualWrite(1, US1, “prox”, “cm”);
}
CAYENNE_OUT(2)
{

int US2 = ultrasonic2.ping_cm();
Serial.print(“Hasil Sensor 2 :”);
Serial.print(US2);
Serial.println(“cm”);
delay(100);
Cayenne.virtualWrite(2, US2, “prox”, “cm”);
}
itsn’t work
please help me to solve

can you share a link of the library you are using.

How to check? Going to library? Or what? Sorry i am newbie, can you give me examples?

anyways, i got it. i hope it is the same you are using. I found this example.

// Example NewPing library sketch that pings 3 sensors 20 times a second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define SONAR_NUM 3      // Number of sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.

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

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() { 
  for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through each sensor and display results.
    delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
    Serial.print(i);
    Serial.print("=");
    Serial.print(sonar[i].ping_cm());
    Serial.print("cm ");
  }
  Serial.println();
 }

Convert the above code for 2 sensors and see if you get reading from them, then we can move to cayenne code.

excuse me sir, if i want to show the values of the single sensor? How the code? Cause your code just show 1 value on my ARDUINO IDE

Every single sensor

what do you mean? the above code is to read n number of sensors. Can you share the code you have to read two sensors?

sorry, I mean that code will show me the value of each sensor?

did you try?

its done and show each value of the sensor, with uno board withoout esp moodule, so how to show the value to cayenne?

are you using Arduino UNO and esp8266? or an esp8266 dev board? the very first code you shared is for the esp8266 dev board. If that the case you can add the cayenne code from it into the code that works for reading both sensor data.

actually I have school tasks, using wemos d1 r2 and wemos d1 r1 for comparing features and part of my task is connecting 2 sensor hcsr 04 to cayenne

for wemos combine Cayenne-MQTT-Arduino/ESP8266.ino at master · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub with the sensor code

okay thanks its work