#include <WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <ThingSpeak.h>
WiFiClient client;
unsigned long myChannelNumber = 6;
const char * myWriteAPIKey = "PKAPXBB9MCAZOP6Y";
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
const int oneWireBus = 4;
// Configure uma instância oneWire para se comunicar com qualquer dispositivo One-Wire
OneWire oneWire(oneWireBus);
// Passe nossa referência oneWire para o sensor de temperatura Dallas
DallasTemperature sensors(&oneWire);
int number = 0;
void setup() {
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
Serial.begin(115200);
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Conectando…");
LCD.setCursor(0, 1);
LCD.print("WiFi ");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println("Conectado!");
}
void loop() {
delay(250);
int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
// change the value
number++;
if(number > 99){
number = 0;
}
delay(15000); // Wait 15 seconds to update the channel again
}