Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Sketch generated by the Arduino IoT Cloud Thing "Untitled"
- https://create.arduino.cc/cloud/things/af1ef035-f477-44a9-b162-2af28cb1d771
- Arduino IoT Cloud Variables description
- The following variables are automatically generated and updated when changes are made to the Thing
- int gasValue;
- int ldrValue;
- int pirValue;
- 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"
- #define pirPin 39
- #define ldrPin 35
- #define gasPin 34
- #define ledPin 33
- #define buzzerPin 32
- 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(pirPin, INPUT);
- pinMode(ldrPin, INPUT);
- pinMode(gasPin, INPUT);
- pinMode(ledPin, OUTPUT);
- pinMode(buzzerPin, OUTPUT);
- digitalWrite(ledPin, LOW);
- digitalWrite(buzzerPin, LOW);
- // 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
- gasValue = analogRead(gasPin);
- ldrValue = analogRead(ldrPin);
- pirValue = digitalRead(pirPin);
- if (pirValue == 1 || gasValue>3000) {
- digitalWrite(buzzerPin, HIGH);
- delay(1000);
- digitalWrite(buzzerPin, LOW);
- }
- else {
- digitalWrite(buzzerPin, LOW);
- }
- //delay(1000);
- }
- /*
- Since Led is READ_WRITE variable, onLedChange() is
- executed every time a new value is received from IoT Cloud.
- */
- void onLedChange() {
- // Add your code here to act upon Led change
- digitalWrite(ledPin, led);
- }
Add Comment
Please, Sign In to add comment