Skip to main content

Soil Moisture sensor with Arduino in Tinkercad | how to use soil moisture sensor in Tinkercad

  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 }

Interfacing of ultrasonic sensor with an Arduino using Tinkercad.



 Interfacing of ultrasonic sensor with an Arduino using Tinkercad


In this Project, we will make an alert alarm using the HC-SR04 ultrasonic sensor. The ultrasonic sensor used in this is utilized as a distance sensor, it will give us the distance at which the obstacle is. Using this distance value, we can turn on or off the buzzer and also, we can flash the LED light.

Circuit Diagram:

The hardware a part of this project is extremely easy to place together. First of all, make the connections for the ultrasonic sensor with the Arduino. The connections for the ultrasonic sensor with the Arduino given below:



connection:

  • Connect VCC on the ultrasonic sensor to the 5V pin on the Arduino.
  • Connect the Trig pin on the ultrasonic sensor to pin 4 on the Arduino.
  • Connect the Echo pin on the ultrasonic sensor to pin 5on the Arduino.
  • Connect the GND on the ultrasonic sensor to GND on the Arduino.

 After making the connection with ultrasonic sensor, make the connections for the buzzer, LED light and the Arduino. Connect the positive pin of the buzzer with pin 2 on the Arduino and Positive pin of the LED to the pin no 3 of an Arduino, buzzer’s negative pin with the GND pin on the Arduino also connect GND pin of LED connect to the GND pin of an Arduino.


How does this project work?

The ultrasonic sensor generates  an ultrasonic sound wave from the trigger which reflects back after hitting the obstacle in front of the sensor  and it is received by the an echo of the ultrasonic sensor. The echo will gives us the distance traveled in microseconds. To send an ultrasonic sound  wave from the trigger of the sensor, we have to set the trigger high for 10us. This will send 8 cycle sonic burst at 40 kHz which will strike the obstacle and is then received back by an echo.

Now we have the time in microseconds but we have  to calculate the distance. So, for that we can use the below equation:

S = v * t

We know the value of t that is time and we know that the speed of a sound in air is 340m/s.

We need to convert the speed of sound into cm/us to calculate the distance.

The speed of sound in cm/us is 0.034cm/us. Now the equation will become.

S = (0.034 * t)

We need divide this equation by 2 because we only need  the distance it takes to strike the obstacle and not the distance it takes to strike the object and come back. So, the final equation will become:

S = (0.035 * t)/2 

We can get the distance value using an equation above and after that, we will set a value which will help us make the buzzer on and off.


Specifications:

The specifications of the ultrasonic distance sensor HC-SR04 are below:

Minimum measuring range

2 cm

Maximum measuring range

400 cm or 4 meter

Operating Voltage

5V

Operating Current

15mA

Working Frequency

40 KHz

Trigger Input signal

10us pulse

Measuring angle

15 degree


Code Explanation (Block Based):

First of all, we declare variable named distance, to store the distance value of an ultrasonic sensor To declare the variable see the below picture.


After declaring the variable we set that variable to following:

Now we want to print the distance value on the screen for that we will use the serial monitor, we will assign the distance variable to the serial monitor:

The trigger pin and echo for the ultrasonic sensor connected to an Arduino pin 4 and echo pin to pin 3 on the Arduino. We have initialized these pins in the code. Then we initialized the buzzer pin and LED pins.

Now we will use the main conditional statement of the program that is ‘if’ block 


In if block we will use the condition for that we need the comparison operator here we have used the less than “<” comparison operator.

Condition is given that if the distance is less than 30 cm then pin 3 will high and low with time interval of 0.5 sec. it acts like LED flasher. Same way we can add the pin 2 as high for buzzer to produce the sound.

Arduino Sketch:

int distance = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)

{

  pinMode(triggerPin, OUTPUT);  // Clear the trigger

  digitalWrite(triggerPin, LOW);

  delayMicroseconds(2);

  // Sets the trigger pin to HIGH state for 10 microseconds

  digitalWrite(triggerPin, HIGH);

  delayMicroseconds(10);

  digitalWrite(triggerPin, LOW);

  pinMode(echoPin, INPUT);

  // Reads the echo pin, and returns the sound wave travel time in microseconds

  return pulseIn(echoPin, HIGH);

}

 

void setup()

{

  Serial.begin(9600);

 

  pinMode(3, OUTPUT);

  pinMode(2, OUTPUT);

}

void loop()

{

  distance = 0.01723 * readUltrasonicDistance(4, 5);

  Serial.println(distance);

  if (distance < 30) {

    digitalWrite(3, HIGH);

    delay(500); // Wait for 500 millisecond(s)

    digitalWrite(3, LOW);

    delay(500); // Wait for 500 millisecond(s)

    digitalWrite(2, HIGH);

  }

}


Watch Working Video:


Like share and comment :

                                                     Our FaceBook Page                                                           







For Any queries please contact:

impulseTech101@gmail.com


Comments

Popular posts from this blog

Water level monitoring system using IoT | IoT based water level using Nodemcu ESP8266 & ESP32

Water level monitoring system using IoT | IoT based water level using Nodemcu ESP8266 & ESP32 Hello Everyone! I have come up with new tutorial Water level monitoring system using IoT | IoT based water level using Nodemcu ESP8266 & ESP32 For Code & Circuit Diragram: In this video what you will learn about? 1. How to configure the new Blynk IoT Platform. 2. How to setup web dashboard 3. How to create template in blynk iot 4. How to interface ultrasonic sensor with node mcu esp8266. 5. How to read ultrasonic sensor with esp8266 1.You can Watch Playlist on New Blynk IoT Platfom New Blynk IoT platform with esp32 | how to setup automation in Blynk IoT app https://youtu.be/O2HZuu4KtIc 2.How to create events in blynk IoT platform | events in new Blynk IoT platform 🔥🔥 https://youtu.be/X5zVaGk8QV0 3.IoT Based smart garden monitoring system | Smart plant monitoring using Blynk IoT https://youtu.be/GTdxD5vQwy0 4.Water level monitoring system using IoT | IoT based

Soil Moisture sensor with Arduino in Tinkercad | how to use soil moisture sensor in Tinkercad

  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 }

DS18B20 Temperature sensor with new Blynk IOT Platform | DS18B20 with Esp32 & Blynk IoT Cloud

DS18B20 Temperature sensor with new Blynk IOT Platform | DS18B20 with Esp32 & Blynk IoT Cloud   Hello Everyone! I have come up with new tutorial based on the all new Blynk IoT platform. which is DS18B20 Temperature sensor with new Blynk IOT Platform | DS18B20 with Esp32 & Blynk IoT Cloud #iot #blynk In this video what you will learn about? 1. How to configure the new Blynk IoT Platform. 2. How to interface DS18B20 sensor with esp32 4. How to configure mobile blynk IoT platform 5. How to setup Automation in Blynk IoT 1.You can Watch Playlist on New Blynk IoT Platfom New Blynk IoT platform with esp32 | how to setup automation in Blynk IoT app | #iot #blynk #esp32 https://youtu.be/O2HZuu4KtIc 2.How to create events in blynk IoT platform | events in new Blynk IoT platform 🔥🔥 #blynk #esp32 #iot https://youtu.be/X5zVaGk8QV0 3.IoT Based smart garden monitoring system | Smart plant monitoring using Blynk IoT #iot #blynk #esp32 https://youtu.be/GTdxD5vQwy0 4.Water