#include <ThingSpeak.h>
#include "WiFi.h"
//Replace your wifi credentials here
const char* ssid = "Wokwi-GUEST";//Replace with your Wifi Name
const char* password = "";// Replace with your wifi Password
//change your channel number here
unsigned long channel =2320748;//Replace with your own ThingSpeak Account Channle ID
//1,2 and 3 are channel fields. You don't need to change if you are following this tutorial. However, you can modify it according to your application
unsigned int led1 = 1;
unsigned int led2 = 2;
unsigned int led3 = 3;
const int LedR = 12 ;
const int LedG = 14 ;
const int LedW = 27 ;
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(100);
pinMode(LedR, OUTPUT);
pinMode(LedG, OUTPUT);
pinMode(LedW, OUTPUT);
digitalWrite(LedR, 0);
digitalWrite(LedG, 0);
digitalWrite(LedW, 0);
// We start by connecting to a WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connexion au WiFi en cours...");
}
Serial.println("Connecté au WiFi");
ThingSpeak.begin(client);
}
void loop() {
//get the last data of the fields
int led_1 = ThingSpeak.readFloatField(channel, led1);
int led_2 = ThingSpeak.readFloatField(channel, led2);
int led_3 = ThingSpeak.readFloatField(channel, led3);
if(led_1 == 1){
digitalWrite(LedR, 1);
Serial.println("LED RED is On..!");
}
else if(led_1 == 0){
digitalWrite(LedR, 0);
Serial.println("LED RED is Off..!");
}
if(led_2 == 1){
digitalWrite(LedG, 1);
Serial.println("LED GREEN is On..!");
}
else if(led_2 == 0){
digitalWrite(LedG, 0);
Serial.println("LED GREEN is Off..!");
}
if(led_3 == 1){
digitalWrite(LedW, 1);
Serial.println("LED WHITE is On..!");
}
else if(led_3 == 0){
digitalWrite(LedW, 0);
Serial.println("LED WHITE is Off..!");
}
}