Como usar o Arduino IOT cloud
- Eduardo Brennand Paranhos
- 21 de set. de 2024
- 2 min de leitura
O Arduino IOT cloud é uma ferramenta que vem sendo utilizada cada vez mais pela comunidade maker, tendo em vista o quão fácil e rápido é o seu uso. Neste post, iremos ver como utilizar essa ferramenta tanto para enviar quanto para receber dados.
Essa ferramenta é compatível com qualquer placa programável na linguagem do arduino que apresente WiFi embutido(isso inclui ESP32, ESP8266, Arduino nano 33 IOT, Arduino MKR WiFi, entre outros). Neste post, usarei o Arduino nano 33 IOT, mas saiba que há várias outras placas compatíveis com o sistema
Segue o circuito utilizado no projeto:

Agora, vá para https://app.arduino.cc/ e configure sua placa conforme as instruções apresentadas no site. Após isso, vá em things, crie um novo projeto e adicione as variáveis a seguir:


Segue o código:
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/4945a91f-c97a-4ecb-b705-3bc9242e8be3
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int ldr;
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"
const int LED = 12;
const int LDR = A0;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(LDR, INPUT);
pinMode(LED, OUTPUT);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// 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() {
ldr = analogRead(LDR); // define o thing ldr
ArduinoCloud.update();
// Your code here
}
/*
Since Led is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedChange() {
digitalWrite(LED, led); // liga ou desliga o led de acordo com o estado do botão
}
/*
Since LDR is READ_WRITE variable, onLDRChange() is
executed every time a new value is received from IoT Cloud.
*/
/*
Since Ldr is READ_WRITE variable, onLdrChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLdrChange() {
// Add your code here to act upon Ldr change
} // o código acaba aqui
Agora, vamos criar o painel. Vá em dashboards e copie o painel a seguir(não se esqueça de ligar as variáveis a cada elemento do painel):

O resultado deverá ser esse:
Comments