#include <WiFi.h>
#include "ThingSpeak.h"
#include "DHT.h"
const char* WIFI_NAME = "Wokwi-GUEST";
const char* WIFI_PASSWORD = "";
const int myChannelNumber = 2502991;
const char* myApiKey = "SJBYA9QG3CKYTGO0";
const char* server = "api.thingspeak.com";
const int trigPin=5;
const int echoPin=7;
long duration;
int distance;
WiFiClient client;
void setup() {
Serial.begin(115200);
pinMode(5,OUTPUT);
pinMode(17,INPUT);
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED){
delay(1000);
Serial.println("Wifi not connected");
}
Serial.println("Wifi connected ! Data Sent");
Serial.println("Local IP: " + String(WiFi.localIP()));
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop() {
int a = analogRead(27);
digitalWrite(trigPin,0);
delayMicroseconds(2);
digitalWrite(trigPin,1);
delayMicroseconds(10);
digitalWrite(trigPin,0);
duration=pulseIn(echoPin,HIGH);
distance=duration*0.034/2;
ThingSpeak.setField(1,a);
ThingSpeak.setField(2,distance);
ThingSpeak.writeFields(myChannelNumber,myApiKey);
Serial.print("Potentio Meter: \t");
Serial.println(a);
Serial.print("Ultra Sonic : \t");
Serial.println(distance);
delay(3000);
}