#include<WiFi.h>
#include<ThingSpeak.h>
char ssid[]="wokwi-GUEST";
char pass []="";
WiFiClient client;
unsigned long mychannelnumber =2446520;
const char * mywriteAPIkey ="K5I74KUZM2A4SQON ";
const int trig = 4;
const int echo = 2;
long duration;
long distance;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
WiFi .mode(WIFI_STA);
ThingSpeak.begin (client );
}
void loop() {
//put your main code here,to run repeatedly :
//this speeds up the simulation
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
//Serial .printIn (duration );
distance = (duration * 0.034/2) + 1;
Serial.println("Distance " + String (distance));
delay (1000);
}