Created
August 6, 2021 08:45
-
-
Save ecehan-civril/232bae934da09f774342f27c7c87c19c to your computer and use it in GitHub Desktop.
Arduino IoT Cloud Led Kontrol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "arduino_secrets.h" | |
/* | |
Sketch generated by the Arduino IoT Cloud Thing "Untitled" | |
https://create.arduino.cc/cloud/things/95af331e-a4ee-4612-9086-f4e9309455f5 | |
Arduino IoT Cloud Variables description | |
The following variables are automatically generated and updated when changes are made to the Thing | |
CloudLight led; | |
CloudTemperatureSensor temperature; | |
CloudRelativeHumidity humidity; | |
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 "DHT.h" | |
#include "thingProperties.h" | |
#define DHTPIN 15 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
void setup() { | |
// Initialize serial and wait for port to open: | |
Serial.begin(9600); | |
pinMode(2, OUTPUT); | |
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found | |
delay(1500); | |
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(); | |
DHT_SENSOR_READ(); | |
// Your code here | |
} | |
void onLedChange() { | |
if (led == 1) | |
{ | |
digitalWrite(2, HIGH); | |
} | |
else | |
{ | |
digitalWrite(2, LOW); | |
} | |
// Do something | |
} | |
void DHT_SENSOR_READ() | |
{ | |
float h = dht.readHumidity(); | |
float t = dht.readTemperature(); | |
temperature = t; | |
humidity = h; | |
Serial.print("Temperature - "); Serial.println(t); | |
Serial.print("Humidity - "); Serial.println(h); | |
delay(1000); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment