My error code is 'ping_cm' was not declared in this scope
The highlighted piece of code is this "if (ping_cm > 7) {"
I have included my code below
The idea is that when item gets within a curtain range of the ultrasonic sensor it will send a signal and turn on a led and no matter what, When i try to compile it I get that error code. Please help
I am using 2 arduino wifis and i know that the sensor is wired correctly
This is the sender code.
Thank you
#include <WiFiNINA.h>
#include <NewPing.h>
#define SONAR_NUM 1 // Number of sensors.
#define MAX_DISTANCE 30 // Maximum distance (in cm) to ping.
NewPing sonar[SONAR_NUM] = { // Sensor object array.
NewPing(3, 2, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
};
char ssid[] = "Netcomm 3240";
char pass[] = "Ninazoyope";
int status = WL_IDLE_STATUS;
char server[] = "10.0.1.16";
WiFiClient client;
void setup() {
Serial.begin(9600);
Serial.begin(115200);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
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("cm");
Serial.print("=");
Serial.print(sonar[i].ping_cm());
Serial.print("cm ");
}
Serial.println();
if (ping_cm > 7) {
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /red HTTP/1.0");
client.println();
}
} else
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /green HTTP/1.0");
client.println();
}
} else {
Serial.println("problem");
}
// ---- TO HERE
if (client.connected()) {
client.stop();
}
its just 1 sensor that im using and a few weeks ago (with some code that i lost) i made it so that only using ping_cm it would trigger something...
I am trying to figure out if one sensor detects something that is over 7 cm
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.