buonasera a tutti, mi chiamo Edoardo. Sto facendo un progetto utilizzando un arduino nano MKR wifi 1010, ma ho delle difficoltà nella scrittura del codice. L'utilizzo che dovrei farne è quello di pilotare un relè impostando dal cloud un valore minimo e massimo di temperatura, al di sotto del quale si accende il relè e al di sopra si spegne. Il tutto riportando i valori di temperatura e umidità sull'interfaccia iot.
Sono riuscito a riportare i valori di temperatura e umidità sull'interfaccia, ma non so come procedere coi il relè impostando la temperatura tramite app.
Se qualcuno fosse così gentile da aiutarmi allego l codice scritto fin ora qui
// DHT sensor library - Version: Latest
#include <DHT.h>
#include <DHT_U.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/f9424271-7976-4fd8-a42d-bab210bfad05
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float tEMPmax;
float tEMPmin;
float vHUM;
float vTEMP;
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"
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define rele 8
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);
// 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();
pinMode(rele, OUTPUT);
digitalWrite(rele, HIGH);
dht.begin();
}
void loop() {
ArduinoCloud.update();
// Your code here
delay(2000);
vTEMP = dht.readTemperature();
vHUM = dht.readHumidity();
delay(500);
}
void onTEMPmaxChange() {
delay(500);
float hu = dht.readHumidity();
float te = dht.readTemperature ();
if (isnan(hu)||isnan(te)){
Serial.println("Errore nella lettura del sensore!");
return;
}
if (te>= onTEMPmaxChange) {
digitalWrite(rele,HIGH);
}
else
}
void onTEMPminChange() {
float hu = dht.readHumidity();
float te = dht.readTemperature ();
if (isnan(hu)||isnan(te)){
Serial.println("Errore nella lettura del sensore!");
return;
}
if (te<= TEMPmin){
digitalWrite(rele,LOW);
}
prima di tutto ti segnalo che, nella sezione in lingua Inglese, si può scrivere SOLO in Inglese ... quindi, per favore, la prossima volta presta più attenzione in quale sezione metti i tuoi post; questa volta esso è stato spostato, da un moderatore della sezione di lingua Inglese, nella sezione di lingua Italiana ... la prossima volta potrebbe venire direttamente eliminato, dopo di che ...
... essendo il tuo primo post, nel rispetto del regolamento della sezione Italiana del forum (… punto 13, primo capoverso), ti chiedo cortesemente di presentartiIN QUESTO THREAD (spiegando bene quali conoscenze hai di elettronica e di programmazione ... possibilmente evitando di scrivere solo una riga di saluto) e di leggere con molta attenzione tutto il succitato REGOLAMENTO ... Grazie.
Guglielmo
P.S.: Ti ricordo che, purtroppo, fino a quando non sarà fatta la presentazione nell’apposito thread, nel rispetto del suddetto regolamento nessuno ti risponderà (eventuali risposte verrebbero cancellate), quindi ti consiglio di farla al più presto.
Sono riuscito a ricevere i valori di temperatura e umidità sull'IoT, ma non so come far funzionare il relè tramite un valore ti temperatura minimo, dove si accenderà, e uno massimo al raggiungimento del quale si deve spegnere, entrambi impostati dall'IoT
// DHT sensor library - Version: Latest
#include <DHT.h>
#include <DHT_U.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/f9424271-7976-4fd8-a42d-bab210bfad05
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float tEMPmax;
float tEMPmin;
float vHUM;
float vTEMP;
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"
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define rele 8
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);
// 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();
pinMode(rele, OUTPUT);
digitalWrite(rele, HIGH);
dht.begin();
}
void loop() {
ArduinoCloud.update();
// Your code here
delay(2000);
vTEMP = dht.readTemperature();
vHUM = dht.readHumidity();
delay(500);
}
void onTEMPmaxChange() {
float te = dht.readTemperature ();
int TEMPmax = TEMPmax.read();
if(te>=TEMPmax) {
digitalWrite(rele, HIGH);
}
}
void onTEMPminChange() {
float te = dht.readTemperature ();
float TEMPmax = TEMPmax.read();
if(te<=TEMPmin) {
digitalWrite(rele, LOW);
}
}
mi da come errore la riga in cui dico che TEMPmax è uguale a leggi TEMPmax, ma non ho capito come scriverla
ho provato anche questo sketch dove non mi da errori, ma cambiando i valori dal cloud non succede niente, quindi penso che non vada scritto in questo modo
Allora ... DEVI mette qui il contenuto del file thingProperties.h che hai generato on-line ... senza vedere qullo NON ti possiamo aiutare, inutile che continui a mettere il tuo codice se non conosciamo il contenuto di quel file ...
ciao, rispondo solo ora perché non avevo la scheda arduino per provare lo sketch, comunque mi dice 'TEMPmax' was not declared in this scope, stesso problema che ho avuto fin ora
ok, risolto vuole che la t di TEMPmax e TEMPmin sia minuscola, ora sul monitor vedo il valore impostato dall'iot e quello di temperatura, mentre sul cloud vedo i valori di temperatura e umidità. Provo a scrivere lo sketch per utilizzare il relè
// DHT sensor library - Version: Latest
#include <DHT.h>
#include <DHT_U.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/f9424271-7976-4fd8-a42d-bab210bfad05
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float tEMPmax;
float tEMPmin;
float vHUM;
float vTEMP;
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"
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define rele 8
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);
// 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();
pinMode(rele, OUTPUT);
digitalWrite(rele, HIGH);
dht.begin();
}
void loop() {
ArduinoCloud.update();
// Your code here
delay(2000);
vTEMP = dht.readTemperature();
vHUM = dht.readHumidity();
delay(500);
float te = dht.readTemperature ();
if(te>=tEMPmax) {
digitalWrite(rele, HIGH);
}
else if(te<=tEMPmin) {
digitalWrite(rele, LOW);
}
}
void onTEMPmaxChange() {
}
void onTEMPminChange() {
}
lo sketch funziona, ho solo il problema che arduino riesce ad accendere il led del relè, ma non a farlo scattare, penso sia un problema che posso risolvere solo attaccando l'alimentazione in modo esterno, visto che con il mio arduino uno senza wifi, ha sempre funzionato, aggiungendo anche più cose. Che qualcuno sappia si può alimentare arduino nano (che ha solo la porta per il cavo usb) con 6/7 volt?
avrei una domanda, arduino nano wifi può essere alimentato anche con 6/8 volt o solo con il voltaggio di una comune presa usb? perchè volevo renderlo indipendente, ma a meno che non metto un powerbank o cose simili non posso, mentre se può essere alimentato anche a es 6 volt allora posso usare l'alimentatore che utilizzo per il mio arduino uno normale
Vin: This pin can be used to power the board with a regulated 5V source. If the power is fed through this pin, the USB power source is disconnected. This is the only way you can supply 5v (range is 5V to maximum 6V) to the board not using USB. This pin is an INPUT.