BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

NewPing library

esp8266

#1

Hi, I’m making a project with esp8266 nodemcu, but when I upload the code Arduino throws this warning:
WARNING: library NewPing claims to run on (avr, arm) architecture(s) and may be incompatible with your current board which runs on (esp8266) architecture(s).

I looked for NewPing library compatible with esp8266, but didnt find anything. Any advice?


#2

forget NewPing lib, it is useless!
let us show your sketch


#3

Here it is. What can I use instead of NewPing?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <NewPing.h>

 
    #define SONAR_NUM 1                                         
    #define PI 3.1415926535897932384626433832795
    
    //** CHANGE TO SUIT TANK DIMENSIONS
    const int MAX_DISTANCE = 15;                       
    const int Diameter = 4;		                            	       
    const int Depth = 13;			                            
    

    const unsigned int Period = 2000;    
    
    //** SENSOR PINS
  
    const int TrigPin = 5;          //     GPIO5,  D1 
    const int EchoPin = 4;          //     GPIO4,  D2
   
    const int Area = PI * ((Diameter / 2) * (Diameter / 2));	        
   
    
    // Global variables
    int Liters,Distance,DepthWater;
    
    // Set password to "" for open networks.
    char ssid[] = "IFBA-wifi";		                                            
    char pass[] = "******";			                                          
   char auth[] = "***************";                                      

    BlynkTimer timer;                                                                  

    NewPing sonar[SONAR_NUM] = {		                               
	    NewPing(TrigPin, EchoPin, MAX_DISTANCE)	       
	   
    };

void sendSensorReadings()
{
//***********Readings Tank 1
    Distance = sonar[0].ping_cm();                                     
    if (Distance >= Depth || Distance == 0 )  Distance =Depth;                   
	DepthWater = Depth - Distance;							       
	Liters = (Area * DepthWater) / 1000;	                       
   

//***********SEND INFO TO BLYNK
    Blynk.virtualWrite(V1, DepthWater);                                
    Blynk.virtualWrite(V2, Liters);                                            
    Blynk.virtualWrite(V3, Liters / 10);                                    
                                                                                              
    delay(50);
  
    digitalWrite(13, HIGH);              
    delay(50);
    digitalWrite(13, LOW);

//************************* can be commented out, test use only
    Serial.println();
    Serial.println();
    Serial.println("Tank Distance: " + String(Distancia));   
    Serial.println("Tank DepthWater: " + String(DepthWater)); 
    Serial.println("Tank Liters: " + String(Liters));               

    
//***********************************************   
 
}

void setup() {
   
    pinMode(13, OUTPUT); //LED D7
    
	timer.setInterval(Period, sendSensorReadings);	
	delay(10);
  
//**    can be commented out, test only
    Serial.begin(115200);										         
    Serial.println();
    Serial.println("Connecting to " + String(ssid));      
//**	
    Blynk.begin(auth, ssid, pass);
	delay(20);
    
//**    can be commented out, test only
	Serial.println(WiFi.localIP());								    
	Serial.println("WiFi connected");

}

void loop() {
   
	Blynk.run();
	timer.run();
    
}

#4

delete newping

this is the code to get distance from sensor

  digitalWrite(TRIGGER, LOW);
  delayMicroseconds(2);

  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10);

  digitalWrite(TRIGGER, LOW);
  duration = pulseIn(ECHO, HIGH);

  distance = ((duration / 2) / 29.1) * 10;

#5

And here is an example i made for the Ultrasonic sensor… As I already posted in your other topic.