cv
#include <WiFi.h>
#include <ThingSpeak.h>
// Replace with your network credentials
const char* ssid = "YourWiFiSSID";
const char* password = "YourWiFiPassword";
// Replace with your ThingSpeak channel details
const unsigned long channelID = YOUR_CHANNEL_ID;
const char* writeAPIKey = "YourWriteAPIKey";
// Initialize the WiFi client
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(2000);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Set ThingSpeak channel details
ThingSpeak.begin(client);
ThingSpeak.setChannel(channelID);
}
void loop() {
// Read sensor data or prepare the data you want to send
float sensorValue = 23.45;
// Write the data to ThingSpeak
ThingSpeak.writeField(1, sensorValue, writeAPIKey);
// Wait for 20 seconds before sending the next data point
delay(20000);
}
Comments
Post a Comment