/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/74db45f8-ae7a-46c5-8c7c-8d0b7a734312
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudTemperatureSensor temperatura;
CloudRelativeHumidity umidade;
bool led;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include "DHT.h"
#define DHTTYPE DHT22
#define DHTPIN 5
#define LED1_PIN 2
#define LED2_PIN 4
#define POTENTIOMETER_PIN 34
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
dht.begin();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop()
{
ArduinoCloud.update();
// Your code here
// Leitura de temperatura e umidade
float temp = dht.readTemperature();
float umid = dht.readHumidity();
// Atribui os valores das leituras às variáveis do Arduino IoT Clo
temperatura = temp;
umidade = umid;
// Configurações para o potenciômetro
const int potentiometerPin = 34;
int potentiometerValue = 0;
// Leitura do potenciômetro e envio do valor
potentiometerValue = analogRead(potentiometerPin);
Serial.print("Potenciômetro: ");
Serial.println(potentiometerValue);
delay(5000); // Aguarda 5 segundos para a próxima leitura
}
/*
Since Led1 is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLed1Change()
{
// Add your code here to act upon Led change
if(led1 == 1)
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
}
/*
Since Led2 is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLed2Change()
{
// Add your code here to act upon Led change
if(led2 == 1)
{
digitalWrite(4, HIGH);
}
else
{
digitalWrite(4, LOW);
}
}