#define IO_USERNAME "Ua21abg"
#define IO_KEY "aio_JCWo58iGcFcBy0Uvc1PCi6b5H9uS"
#include <WiFi.h>
#define LED_PIN 13
#include "AdafruitIO_WiFi.h" // note the spelling WiFi not wifi
// AdafruitIO_WiFi controls connecting to the WiFi accesspoint
AdafruitIO_WiFi io(Ua21abg,aio_JCWo58iGcFcBy0Uvc1PCi6b5H9uS,Wokwi-GUEST);
// This will control whether the LED is on or off from your dashboard toggle
// Ensure your feed name matches exactly what you have on Adafruit IO.
AdafruitIO_Feed *toggle = io.feed("enter your toggle feed name");
void setup() {
Serial.begin(9600);
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
}{
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
// -- adafruitio feed -- //
toggle->get();
}
void loop() {
// io.run(); is required for all sketches, always put it at the top of your loop()
// it keeps the client connected to io.adafruit.com, and processes any incoming data.
io.run();
Serial.print("received <- ");
if(toggle->data->toPinLevel() == HIGH) {
Serial.println("HIGH");
} else {
Serial.println("LOW");
}
digitalWrite(LED_PIN, toggle->data->toPinLevel());
// as free IO account limits 30 readings per minute, include a delay and
// so just make sure you don't run it for a long time
delay(5000);
}