🇵🇱 Czujnik wilgotnośći gleby
Prosty czujnik wilgotności gleby używający mikrokontrolera Arduino UNO.
Użyte elementy
Kod
Ten program jest napisany w języku programowania C++.
Wykorzystane biblioteki
Połączenia
Pin Arduino | Pin wyświetlacza | Pin czujnika |
---|---|---|
GND | GND | GND |
A4 | SDA | ❌ |
A5 | SCL | ❌ |
A0 | ❌ | AOUT |
5V | VCC | ❌ |
3.3V | ❌ | VCC |
Kalibracja
Kod do kalibracji czujnika
Pin danych z czujnika został podpięty do pinu A0
.
void setup() {
Serial.begin(9600);
}
void loop() {
int value;
value = analogRead(A0);
Serial.println(value);
delay(100);
}
Kroki
Na początku zapisz najwyższą wartość, jaką czujnik uzyskuje, gdy jest suchy. Zmień wartość w kodzie (domyślnie 603) na zmierzoną:
const int dryValue = 616; -> const int dryValue = TWOJA_WARTOŚĆ;
Następnie zmierz wartość, jaką czujnik uzyskuje, gdy jest najbardziej mokry. Zmierz wartość na zmierzoną.
const int wetValue = 292; -> const int wetValue = TWOJA_WARTOŚĆ;
Teraz wystarczy załadować kod do Arduino i wszytko powinno działać!
Zasada działania
Czujnik co 100ms sprawdza poziom wilgotności gleby. Następnie ta wartość jest przesyłana do Arduino, gdzie zostaje przetworzona. Na jej podstawie kontroler określa procent wilgotność gleby zgodnie ze zmienną:
percent = 100-((soilCapacityValue-(dryValue-wetValue))*100)/wetValue;
Ta zmienna prezentuje poziom wilgotności w procentach, na podstawie której tworzony jest pasek wilgotności gleby.
Koniec
Jeżeli wykonałeś wszytkie kroki i myślałeś czujnik powinien być gotowy do pracy!
🇬🇧 Soil Moisture Sensor
A simple soil moisture sensor using an Arduino UNO microcontroller.
Components Used
Code
This program is written in the C++ programming language.
Used Libraries
Connections
Arduino Pin | Display Pin | Sensor Pin |
---|---|---|
GND | GND | GND |
A4 | SDA | ❌ |
A5 | SCL | ❌ |
A0 | ❌ | AOUT |
5V | VCC | ❌ |
3.3V | ❌ | VCC |
Calibration
Sensor Calibration Code
The sensor data pin is connected to pin A0
.
void setup() {
Serial.begin(9600);
}
void loop() {
int value;
value = analogRead(A0);
Serial.println(value);
delay(100);
}
Steps
First, record the highest value the sensor obtains when dry. Change the value in the code (default is 603) to the measured value:
const int dryValue = 616; -> const int dryValue = YOUR_VALUE;
Next, measure the value the sensor obtains when wettest. Measure and replace the value in the code:
const int wetValue = 292; -> const int wetValue = YOUR_VALUE;
Now, upload the code to Arduino, and everything should work!
Operating Principle
The sensor checks the soil moisture level every 100ms. The value is then transmitted to Arduino, where it is processed. Based on this value, the controller determines the percentage of soil moisture according to the formula:
percent = 100-((soilCapacityValue-(dryValue-wetValue))*100)/wetValue;
This variable represents the moisture level in percentage, used to create the soil moisture bar.
Conclusion
If you have followed all the steps, the sensor should be ready to work!