This shows you the differences between two versions of the page.
|
pm:prj2024:ddosaru:matei.calugaru [2024/05/23 10:54] matei.calugaru [Software Design] |
pm:prj2024:ddosaru:matei.calugaru [2024/05/25 12:37] (current) matei.calugaru [Software Design] |
||
|---|---|---|---|
| Line 30: | Line 30: | ||
| 1 Breadboard | 1 Breadboard | ||
| 1 Furtun cu diametru interior de 6mm | 1 Furtun cu diametru interior de 6mm | ||
| - | 2 x Suport Baterii + 8 Baterii AA | + | 1 Suport Baterii + 4 Baterii AA |
| - | {{:pm:prj2024:ddosaru:schema_electricav3.png?600|}} | + | 1 Incarcator 5V + cablu alimentare Arduino |
| + | {{:pm:prj2024:ddosaru:schema_electrica_final.png?600|}} | ||
| {{:pm:prj2024:ddosaru:cabluri.jpg?600|}} | {{:pm:prj2024:ddosaru:cabluri.jpg?600|}} | ||
| </note> | </note> | ||
| Line 42: | Line 43: | ||
| * mediu de dezvoltare: Arduino IDE | * mediu de dezvoltare: Arduino IDE | ||
| * librării: LiquidCrystal_I2C.h, Wire.h | * librării: LiquidCrystal_I2C.h, Wire.h | ||
| + | Functii: | ||
| + | - Ordered List ItemSetup() - Setez pinii pentru releu si initializez eranul LCD | ||
| + | - Ordered List ItemcreateFixedLengthString() - Creeaza mesajul afisat pe LCD, acesta este pad-uit pentru a nu aparea flickering la ecran | ||
| + | - updateLCD() - face update la ecran daca acesta intra in modul manual | ||
| + | - readSensorAndUpdateLCD() -citeste informatia data de senzor si face update la ecran cu noua informatie despre umiditatea solului | ||
| + | - loop() - sunt apelate functiile de mai sus, senzorul cieste informatii despre umiditate la 3 secunde (aceasta unitate poate fi marita), in acelasi timp, prin intermwdiul aplicatiei pompa de apa poate fi actionata manual sau trecuta la loc in modul automat | ||
| + | Laburi folosite: | ||
| + | - Lab1 USART- interfata seriala | ||
| + | - Lab3 PWM - control pompa | ||
| + | - Lab6 I2C - conectare ecran LCD | ||
| </note> | </note> | ||
| + | <file irrigation.cpp> | ||
| + | #include <Wire.h> | ||
| + | #include <LiquidCrystal_I2C.h> | ||
| + | |||
| + | int moist = A0; | ||
| + | char data = 0; | ||
| + | char prevData = 0; | ||
| + | const int RELAY_PIN = 3; | ||
| + | LiquidCrystal_I2C lcd(0x27, 16, 2); | ||
| + | |||
| + | String previousStatus = ""; // To store the previous status | ||
| + | unsigned long previousMillis = 0; // To store the last time the sensor was read | ||
| + | const long interval = 3000; // Interval for reading the sensor (3 seconds) | ||
| + | bool manualMode = false; // To track whether we are in manual mode | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(9600); | ||
| + | |||
| + | pinMode(LED_BUILTIN, OUTPUT); | ||
| + | digitalWrite(LED_BUILTIN, LOW); | ||
| + | |||
| + | lcd.init(); // initialize the lcd | ||
| + | lcd.backlight(); | ||
| + | |||
| + | pinMode(RELAY_PIN, OUTPUT); | ||
| + | } | ||
| + | |||
| + | // Function to create a string of fixed length | ||
| + | String createFixedLengthString(String message, int length) { | ||
| + | int messageLength = message.length(); | ||
| + | while (messageLength < length) { | ||
| + | message += " "; // Add a space to pad the message | ||
| + | messageLength++; | ||
| + | } | ||
| + | return message; | ||
| + | } | ||
| + | |||
| + | void updateLCD(String status) { | ||
| + | // Pad the status message to the width of the LCD | ||
| + | status = createFixedLengthString(status, 16); //16 char for the LCD | ||
| + | |||
| + | lcd.clear(); | ||
| + | lcd.setCursor(0, 0); | ||
| + | lcd.print("Moist Type: "); | ||
| + | lcd.setCursor(0, 1); | ||
| + | lcd.print(status); | ||
| + | } | ||
| + | |||
| + | void readSensorAndUpdateLCD() { | ||
| + | int moist_val = analogRead(moist); | ||
| + | String status; | ||
| + | |||
| + | if ((moist_val >= 600) && (moist_val <= 1200)) { | ||
| + | status = "Dry"; | ||
| + | digitalWrite(RELAY_PIN, HIGH); | ||
| + | } else if ((moist_val >= 370) && (moist_val < 600)) { | ||
| + | status = "Humid"; | ||
| + | digitalWrite(RELAY_PIN, LOW); | ||
| + | } else if (moist_val <= 370) { | ||
| + | status = "Wet"; | ||
| + | digitalWrite(RELAY_PIN, LOW); | ||
| + | } | ||
| + | |||
| + | // Only update the LCD and print to Serial if the status has changed | ||
| + | if (status != previousStatus) { | ||
| + | Serial.println(status + " Soil"); | ||
| + | updateLCD(status); | ||
| + | previousStatus = status; // Update the previous status | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | unsigned long currentMillis = millis(); | ||
| + | |||
| + | // Check if it's time to read the sensor | ||
| + | if (currentMillis - previousMillis >= interval && !manualMode) { | ||
| + | previousMillis = currentMillis; | ||
| + | readSensorAndUpdateLCD(); | ||
| + | } | ||
| + | |||
| + | // Check for manual control commands | ||
| + | if (Serial.available() > 0) { | ||
| + | data = Serial.read(); | ||
| + | if (data != prevData) { | ||
| + | if (data == '1') { | ||
| + | manualMode = true; // Enable manual mode | ||
| + | digitalWrite(RELAY_PIN, HIGH); | ||
| + | updateLCD("Manual On"); | ||
| + | } else if (data == '0') { | ||
| + | manualMode = true; // Enable manual mode | ||
| + | digitalWrite(RELAY_PIN, LOW); | ||
| + | updateLCD("Manual Off"); | ||
| + | } else if (data == 'a') { | ||
| + | manualMode = false; // Return to automatic mode | ||
| + | readSensorAndUpdateLCD(); // Immediately read sensor and update LCD | ||
| + | } | ||
| + | prevData = data; // Update the previous data | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </file> | ||
| + | <note tip> | ||
| + | * Pentru a testa functionalitatea bluetooth, am facut o aplicatie simplista in MIT App Inventor | ||
| + | {{:pm:prj2024:ddosaru:bluetooth_app.png?600|}} | ||
| + | </note> | ||
| ===== Rezultate Obţinute ===== | ===== Rezultate Obţinute ===== | ||
| <note tip> | <note tip> | ||
| - | Care au fost rezultatele obţinute în urma realizării proiectului vostru. | + | * Atasez, mai jos forma finala a proiectului |
| + | {{:pm:prj2024:ddosaru:poza_final.jpg?600|}} | ||
| + | * Link proiect functional - [[https://youtube.com/shorts/2xoEmipJkVY]] | ||
| + | * Link valori pentru calibrare sensor [[https://www.instructables.com/Soil-Moisture-Measurement-With-Arduino/]] | ||
| </note> | </note> | ||
| ===== Concluzii ===== | ===== Concluzii ===== | ||
| + | * Chiar daca este un proiect simplist, este un bun punct de plecare si obisnuire cu produse hardware. Mai jos vreau sa subliniez cateva lucruri de care m-am lovit si care pot fi evitate usor daca cineva doreste sa se apuce de acest proiect. | ||
| + | |||
| + | - Foloseste o cutie mai mare pentru componente!!!!! | ||
| + | - Incearca sa pozitionezi releul cat mai departe de ecran, undele electromagnetice pot afisa valori garbage pe LCD | ||
| + | - Foloseste un cablu mai lung pentru pompa de apa submersibila | ||
| + | - Cumpara cabluri de mai multe marimi (better cable management) | ||
| ===== Download ===== | ===== Download ===== | ||
| <note warning> | <note warning> | ||
| - | O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului: surse, scheme, etc. Un fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-). | + | {{:pm:prj2024:ddosaru:irrigation_bl.zip|}} |
| - | + | ||
| - | Fişierele se încarcă pe wiki folosind facilitatea *Add Images or other files. Namespace-ul în care se încarcă fişierele este de tipul **:pm:prj20??:c?* sau *:pm:prj20??:c?:nume_student* (dacă este cazul). *Exemplu:* Dumitru Alin, 331CC -> *:pm:prj2022:cc:dumitru_alin*. | + | |
| </note> | </note> | ||
| Line 64: | Line 188: | ||
| <note tip> | <note tip> | ||
| - | 16.05.2024 - Procurarea tuturor elementelor hardware si testarea lor | + | * 16.05.2024 - Procurarea tuturor elementelor hardware si testarea lor |
| + | * 23.05.2024 - Finalizarea si testarea soft-ului | ||
| + | * 24.05.2024 - Finisarea produsului, includerea intr-o carcasa | ||
| </note> | </note> | ||
| Line 70: | Line 196: | ||
| <note> | <note> | ||
| - | Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe *Resurse Software* şi *Resurse Hardware*. | + | |
| + | * [[https://www.youtube.com/watch?v=CvqHkXeXN3M&t=339s]] - conectare LCD | ||
| + | * [[https://www.youtube.com/watch?v=uT8-HPMS1cU]] - conectare HC 05 | ||
| + | * [[https://www.robotique.tech/robotics/control-a-water-pump-by-arduino/]] - conectare pompa de apa | ||
| + | * [[https://www.youtube.com/watch?v=xrchcjYsV1I&t=230s]] - conectare senzor umiditate sol | ||
| + | * [[https://appinventor.mit.edu/]] - site pentru aplicatie | ||
| + | * [[https://www.thingiverse.com/thing:6070873/files]] -link carcasa 3d | ||
| </note> | </note> | ||
| <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | ||