Getting Started with Arduino Cloud Trigger
It's not preferred to continuously monitor the value from an IoT Device but rather get precise alerts whenever particular condition gets awake.
We will see how to add Trigger in Arduino Cloud.
We will see how to add Trigger in Arduino Cloud.
Hardware Setup:
1. MQ4 (Gas Sensor)
2. ESP32:
Connections:
- VCC Pin of Gas Sensor -> 3V3 Pin of ESP32
- GND Pin of Gas Sensor -> GND pin of ESP32
- A0 Pin of Gas Sensor -> 34 Pin of ESP32
(NOTE: ESP32 may vary in Models make sure to install specific Drivers if needed)
Generally there are 2 variables supported in Arduino Cloud for Trigger.
1. Boolean Variable
2. String Variable
Here we are going to see Email alerts based on Boolean Variable Condition.
If you are new to Arduino Cloud please watch this video.
If you are familiar to setup and create dashboard you can move further.
Step 1: Go to Triggers and click -> create trigger
Step 2: Add Trigger Name and click -> Rename
Step 3: Click -> Done (We will come back to this page again)
Step 4: Go to -> Things.
- Click -> Add Variable
- Name it -> gasValue
- Declaration -> (select) int
- Click -> Add Variable
- This will read Gas Value from sensor and display on Arduino Cloud Dashboard to get live value of Gas.
- Similarly we have to create Boolean variable for Trigger (as shown in figure below).
- Click -> Add Variable
- Name it -> isGasFound
- Declaration -> (select) bool
- Variable Permission -> (select) Read Only
- If you want to know in details please refer: https://docs.arduino.cc/arduino-cloud/cloud-interface/variables
- However please comment below regarding any queries, I would be happy to reply.
Step 5: (Read Only)
- You will notice there are 2 variables in comments generated automatically.
- int gasValue and bool isGasFound.
- They are same as we created earlier.
- NOTE: Please do not change anything here.
Step 6: (Writing Code logic)
- There are 2 Functions created by Arduino Cloud by Default.
- void setup() and void loop().
- Do not delete or change it.
Write this in void setup()
- pinMode(34, INPUT);
- isGasFound = false
- We have connected Gas Sensor analog pin to -> ESP32's pin 34.
- As we are reading value it should be as INPUT.
- isGasFound was automatically created so we will keep its value as false, saying that at initial gas leakage is not occurring.
.png)
Step 7: (Main Logic)
Write this in void loop()
- isGasFound = false
- int gasData = analogRead(34);
- gasValue = gasData;
- if (gasData > 1000){ isGasFound = true; }
- Line 1: again we have at initial kept isGasFound as false to saying there is no Leakage of Gas.
- Line 2: we created new variable which will take gas data from sensor.
- Line 3: We pass the gasData variable (which reads gas data) to gasValue (as gasValue will display it on Dashboard)
- Line 4: (MOST IMP)
- If the value of gas is > 1000 then isGasFound is true.
- Which means gas is leaked.
- NOTE: Just for demo I have used 1000 value you may change it as per requirement.
- If value is < 1000 then gas is not leaked and isGasFound will remain false so no email would be sent.
Step 8: Return to Trigger page:
- Click -> Link Variable.
- You will see list of Things (device) you created.
- Click on Thing name for this project (here I named it as Gas Detect Trigger).
- You will find isGasFound variable here click on it
- Finally click on -> Link Variable
Step 9: (Add Email)
- Click -> Email.
- Add Subject and Message of choice.
- Click -> Done
- NOTE: Here you would see Email as well as Push Notification option but we will use Email here.
Step 10: (Enable Trigger)
- Enable the state of Trigger you created.
- Success now you would start receiving Email as Gas is found.
Final Output:
Blog by: Aadi
Comments
Post a Comment