Soil Moisture sensor with Arduino in Tinkercad | how to use soil moisture sensor in Tinkercad Circuit diagram: Arduino Sketch: // C++ code // int moisture_data = 0; void setup() { pinMode(A0, INPUT); Serial.begin(9600); pinMode(12, OUTPUT); pinMode(6, OUTPUT); } void loop() { moisture_data = analogRead(A0); Serial.println(moisture_data); if (moisture_data < 21) { digitalWrite(12, HIGH); digitalWrite(6, HIGH); } else { digitalWrite(12, LOW); digitalWrite(6, LOW); } delay(10); // Delay a little bit to improve simulation performance }
Soil moisture sensor with Arduino IoT cloud | IOT Smart Plant Monitoring System
Arduino code:
#include "arduino_secrets.h"
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/d96be7c3-073d-4272-836b-3f69ceedd1a6
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int sm_sensor;
bool esp32_relay1;
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"
int relay1=4;
int soil_sensor=34;
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(relay1,OUTPUT);
// 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
sm_sensor=analogRead(soil_sensor);
delay(500);
if(sm_sensor>1200)
//modify this value based on soil moisture sensor reading
{
digitalWrite(relay1,LOW);
}
else
{
digitalWrite(relay1,);
}
}
/*
Since Esp32Relay1 is READ_WRITE variable, onEsp32Relay1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onEsp32Relay1Change() {
// Add your code here to act upon Esp32Relay1 change
if(esp32_relay1)
{
digitalWrite(relay1,HIGH);
}
else
{
digitalWrite(relay1,LOW);
}
}
For complete video tutorial
How do you calibrate the formula??
ReplyDeletefor tmp36 to get the exact temperature in Celsius
Delete