Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: v1 - Source Code compiled for: Arduino Uno - Source Code created on: 2023-12-05 02:22:08 - Source Code generated by: Pham ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Use hc-sr04 ultrasonic sensor and yf-s401 flow */ /* sensor to make a water pumping system with a relay */ /* connected to the pump when the water volume is */ /* below 20% and stop the pump when the water volume */ /* is over 80% in a 16cm high tank, The flow sensor */ /* will c */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
#include
#include
const int triggerPin = 2; const int echoPin = 3; const int flowSensorPin = 4; const int relayPin = 5; long duration; int distance; int flowRate; float waterVolume; float tankHeight = 16; float tankCapacity = 100; float thresholdLow = tankCapacity * 0.2; float thresholdHigh = tankCapacity * 0.8; LiquidCrystal_I2C lcd(0x27, 20, 4); void setup() { pinMode(triggerPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(flowSensorPin, INPUT); pinMode(relayPin, OUTPUT); lcd.begin(20, 4); lcd.backlight(); lcd.clear(); } void loop() { digitalWrite(triggerPin, LOW); delayMicroseconds(2); digitalWrite(triggerPin, HIGH); delayMicroseconds(10); digitalWrite(triggerPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration * 0.034 / 2; flowRate = pulseIn(flowSensorPin, HIGH); waterVolume = tankHeight * (tankCapacity - distance) / tankCapacity; if (waterVolume < thresholdLow) { digitalWrite(relayPin, HIGH); } else if (waterVolume > thresholdHigh) { digitalWrite(relayPin, LOW); } lcd.setCursor(0, 0); lcd.print("Distance: "); lcd.print(distance); lcd.print(" cm"); lcd.setCursor(0, 1); lcd.print("Flow Rate: "); lcd.print(flowRate); lcd.print(" ml/s"); lcd.setCursor(0, 2); lcd.print("Water Volume: "); lcd.print(waterVolume); lcd.print(" L"); delay(1000); }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)