This shows you the differences between two versions of the page.
pm:prj2024:vstoica:rardu_marian.leanca [2024/05/04 01:22] radu_marian.leanca [Descriere generală] |
pm:prj2024:vstoica:rardu_marian.leanca [2024/05/27 17:18] (current) radu_marian.leanca [Download] |
||
---|---|---|---|
Line 41: | Line 41: | ||
* Card SD | * Card SD | ||
* KINGSTATE - KDMG36008-10B - Speaker, Micro, Dynamic, 1.5 W, 8 ohm, 104 dB, 570 Hz to 5 kHz | * KINGSTATE - KDMG36008-10B - Speaker, Micro, Dynamic, 1.5 W, 8 ohm, 104 dB, 570 Hz to 5 kHz | ||
+ | * rezistență 1kΩ 220Ω și 4k7Ω | ||
+ | * MOSFET IRF510 | ||
+ | * protoboard | ||
+ | |||
+ | ==== Diagramă Hardware ==== | ||
+ | {{:pm:prj2024:vstoica:hardware_schematics.png?500|}} | ||
+ | |||
+ | === Conexiuni === | ||
+ | |||
+ | **Modul WiFi** | ||
+ | * modul -> arduino | ||
+ | * VCC -> 3.3V - tensiunea de operare a modulului | ||
+ | * GND -> GND | ||
+ | * TX -> D2 - va fi folosit ca SoftwareSerial | ||
+ | * RX -> D3 - va fi folosit ca SoftwareSerial | ||
+ | * CH_PD -> 3.3V - pentru a activa modulul | ||
+ | * RST -> 3.3V - nu va fi nevoie de reset | ||
+ | |||
+ | **HC-SR04** | ||
+ | * senzor -> arduino | ||
+ | * VCC -> 5V | ||
+ | * GND -> GND | ||
+ | * Trig -> D8 | ||
+ | * Echo -> D9 | ||
+ | |||
+ | **Senzor nivel apă** | ||
+ | * senzor -> arduino | ||
+ | * VCC -> D7 - pentru a putea porni senzorul periodic | ||
+ | * GND -> GND | ||
+ | * SIG -> A5 | ||
+ | |||
+ | **Senzor calitate sol** | ||
+ | * senzor -> arduino | ||
+ | * VCC -> D6 - pentru a porni senzorul periodic | ||
+ | * GND -> GND | ||
+ | * SIG -> A0 | ||
+ | |||
+ | **DFPlayer** | ||
+ | * modul -> arduino | ||
+ | * VCC -> 5V | ||
+ | * GND -> GND | ||
+ | * RX -> D11 - va fi folosit ca SoftwareSerial | ||
+ | * TX -> rezistență 1kΩ -> D10 - pentru a limita spike-urile de curent | ||
+ | |||
+ | * modul -> speaker | ||
+ | * SPK1 -> pin2 | ||
+ | * SPK2 -> pin1 | ||
+ | |||
+ | **Pompă submersibilă** | ||
+ | * pompă -> arduino | ||
+ | * pin2 -> 5V | ||
+ | |||
+ | * pompă -> tranzistor | ||
+ | * pin1 -> emitor BC547 | ||
+ | |||
+ | * tranzistor -> arduino | ||
+ | * bază BC547 -> rezistență 4k7Ω -> D13 - pentru a comanda pompa | ||
+ | * colector BC547 -> GND | ||
+ | |||
+ | {{:pm:prj2024:vstoica:electronics_sswp.jpg?300|}} | ||
+ | {{:pm:prj2024:vstoica:senzor_speaker_sswp.jpeg?300|}} | ||
+ | |||
+ | Atașez și câteva poze din slicer: | ||
+ | Ghiveciul exterior:\\ | ||
+ | {{:pm:prj2024:vstoica:outer_pot_sswp.png?300|}} | ||
+ | \\ | ||
+ | Ghiveciul interior:\\ | ||
+ | {{:pm:prj2024:vstoica:inner_1_sswp.png?200|}} {{:pm:prj2024:vstoica:inner_2_sswp.png?200|}} | ||
+ | \\ | ||
+ | Baza:\\ | ||
+ | {{:pm:prj2024:vstoica:base_sswp.png?300|}} | ||
+ | |||
===== Software Design ===== | ===== Software Design ===== | ||
+ | Mediul de dezvoltare: Arduino IDE | ||
- | <note tip> | + | Biblioteci folosite: DFRobotDFPlayerMini.h, SoftwareSerial.h |
- | Descrierea codului aplicaţiei (firmware): | + | |
- | * mediu de dezvoltare (if any) (e.g. AVR Studio, CodeVisionAVR) | + | |
- | * librării şi surse 3rd-party (e.g. Procyon AVRlib) | + | |
- | * algoritmi şi structuri pe care plănuiţi să le implementaţi | + | |
- | * (etapa 3) surse şi funcţii implementate | + | |
- | </note> | + | |
- | ===== Rezultate Obţinute ===== | + | * DFRobotDFPlayerMini.h a fost folosită pentru utilizarea modului MP3 Player |
+ | * SoftwareSerial.h a fost folosită pentru a putea comunica cu modulul MP3 Player | ||
- | <note tip> | + | Acesta este codul rezultat: |
- | Care au fost rezultatele obţinute în urma realizării proiectului vostru. | + | <code> |
- | </note> | + | #include <SoftwareSerial.h> |
+ | #include <DFRobotDFPlayerMini.h> | ||
- | ===== Concluzii ===== | + | // Define pin numbers for sensors and pump |
+ | const int trigPin = 8; | ||
+ | const int echoPin = 9; | ||
+ | const int waterSensorPin = A5; | ||
+ | const int waterSensorPower = 7; | ||
+ | const int soilMoisturePin = A0; | ||
+ | const int soilMoisturePower = 6; | ||
+ | const int pumpPin = 3; // PWM pin | ||
+ | const int trackMax = 4; | ||
- | ===== Download ===== | + | // Define variables for sensor readings |
+ | long duration; | ||
+ | int distance; | ||
+ | int waterLevel; | ||
+ | int soilMoistureLevel; | ||
+ | int trackNo = 1; | ||
- | <note warning> | + | // Define timing variables |
- | 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ă ;-). | + | unsigned long previousMillisWater = 0; |
+ | unsigned long previousMillisSoil = 0; | ||
+ | const long intervalWater = 10000; // Interval for water level sensor (10 seconds) | ||
+ | const long intervalSoil = 15000; // Interval for soil moisture sensor (15 seconds) | ||
- | 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:prj2009:cc:dumitru_alin**. | + | int df_RX = 11; |
- | </note> | + | int df_TX = 10; |
- | ===== Jurnal ===== | + | // Initialize DFPlayer Mini |
+ | SoftwareSerial dfSerial(df_TX, df_RX); // RX, TX for DFPlayer Mini | ||
+ | DFRobotDFPlayerMini myDFPlayer; | ||
- | <note tip> | + | void setup() { |
- | Puteți avea și o secțiune de jurnal în care să poată urmări asistentul de proiect progresul proiectului. | + | // Set up the serial monitor |
- | </note> | + | Serial.begin(9600); |
- | ===== Bibliografie/Resurse ===== | + | // Set up the software serial for DFPlayer Mini |
+ | dfSerial.begin(9600); | ||
- | <note> | + | // Initialize DFPlayer Mini |
- | Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe **Resurse Software** şi **Resurse Hardware**. | + | if (!myDFPlayer.begin(dfSerial)) { |
- | </note> | + | Serial.println(F("Unable to begin:")); |
+ | Serial.println(F("1. Please recheck the connection!")); | ||
+ | Serial.println(F("2. Please insert the SD card!")); | ||
+ | while (true); | ||
+ | } | ||
+ | Serial.println(F("DFPlayer Mini online.")); | ||
+ | myDFPlayer.volume(30); // Set volume value (0~30). | ||
- | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | + | // Set pin modes using direct register manipulation |
+ | DDRB |= (1 << DDB1); // pumpPin (PB1/Pin 9) | ||
+ | DDRD |= (1 << DDD7); // waterSensorPower (PD7/Pin 7) | ||
+ | DDRD |= (1 << DDD6); // soilMoisturePower (PD6/Pin 6) | ||
+ | DDRB |= (1 << DDB0); // trigPin (PB0/Pin 8) | ||
+ | DDRB &= ~(1 << DDB1); // echoPin (PB1/Pin 9) | ||
+ | analogWrite(pumpPin, 0); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // Measure distance | ||
+ | measureDistance(); | ||
+ | |||
+ | // Timed sensor readings | ||
+ | unsigned long currentMillis = millis(); | ||
+ | |||
+ | if (currentMillis - previousMillisWater >= intervalWater) { | ||
+ | previousMillisWater = currentMillis; | ||
+ | measureWaterLevel(); | ||
+ | Serial.print("Water level: "); | ||
+ | Serial.println(waterLevel); | ||
+ | } | ||
+ | |||
+ | if (currentMillis - previousMillisSoil >= intervalSoil) { | ||
+ | previousMillisSoil = currentMillis; | ||
+ | measureSoilMoisture(); | ||
+ | Serial.print("Soil moisture: "); | ||
+ | Serial.println(soilMoistureLevel); | ||
+ | if (soilMoistureLevel <= 600) { | ||
+ | analogWrite(pumpPin, 255); | ||
+ | Serial.println("Pump on with PWM"); | ||
+ | delay(5000); | ||
+ | } | ||
+ | analogWrite(pumpPin, 0); | ||
+ | Serial.println("Pump off"); | ||
+ | } | ||
+ | |||
+ | Serial.print("Distance: "); | ||
+ | Serial.print(distance); | ||
+ | Serial.println(" cm"); | ||
+ | |||
+ | if (waterLevel < 500 && distance < 10) { | ||
+ | if (trackNo > trackMax) { | ||
+ | trackNo = 1; | ||
+ | } | ||
+ | myDFPlayer.play(trackNo); | ||
+ | delay(5000); | ||
+ | myDFPlayer.stop(); | ||
+ | trackNo++; | ||
+ | } | ||
+ | |||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | void measureDistance() { | ||
+ | // Clear the trigPin | ||
+ | PORTB &= ~(1 << PORTB0); | ||
+ | delayMicroseconds(2); | ||
+ | |||
+ | // Set the trigPin high for 10 microseconds | ||
+ | PORTB |= (1 << PORTB0); | ||
+ | delayMicroseconds(10); | ||
+ | PORTB &= ~(1 << PORTB0); | ||
+ | |||
+ | // Read the echoPin and calculate the duration of the pulse | ||
+ | duration = pulseIn(echoPin, HIGH); | ||
+ | |||
+ | // Calculate the distance in cm | ||
+ | distance = duration * 0.034 / 2; | ||
+ | } | ||
+ | |||
+ | void measureWaterLevel() { | ||
+ | // Power on the water level sensor | ||
+ | PORTD |= (1 << PORTD7); | ||
+ | delay(10); | ||
+ | |||
+ | waterLevel = analogRead(waterSensorPin); | ||
+ | |||
+ | // Power off the water level sensor | ||
+ | PORTD &= ~(1 << PORTD7); | ||
+ | } | ||
+ | |||
+ | void measureSoilMoisture() { | ||
+ | // Power on the soil moisture sensor | ||
+ | PORTD |= (1 << PORTD6); | ||
+ | delay(10); | ||
+ | |||
+ | soilMoistureLevel = analogRead(soilMoisturePin); | ||
+ | |||
+ | // Power off the soil moisture sensor | ||
+ | PORTD &= ~(1 << PORTD6); | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | ===== Rezultate Obţinute ===== | ||
+ | {{:pm:prj2024:vstoica:final_planta.jpg?300|}}\\ | ||
+ | Proiectul acoperă aproape tot ce mi-am propus, totul fiind funcțional mai puțin modulul WiFi, care s-a defectat cu o zi înainte de PM Fair și din păcate nu am găsit altul (fiind și duminică)m(. Am dat un mic fail și cu una din piesele printate 3D, dar am ciopârțit o cutie și am rezolvat.\\ | ||
+ | Am reușit însă să creez un prototip funcțional și care cu siguranță te face să râzi. | ||
+ | Proiectul funcționează în felul următor: | ||
+ | * la o perioadă de timp se citește senzorul de sol, iar dacă umiditatea este sub un threshold stabilit empiric se pornește pompa pentru 5 secunde, interval, de asemenea, stabilit empiric | ||
+ | * tot la o perioadă de timp se citește și senzorul de nivel de apă, iar dacă nivelul este foarte scăzut și senzorul de proximitate simte o persoană aproape de ghiveci, se pornește un sunet amuzant, astfel reamintindu-i omului să umple rezervorul de apă | ||
+ | ===== Concluzii ===== | ||
+ | Per total, a fost un proiect foarte fun. Mi-ar fi plăcut să pot duce la bun sfârșit și integrarea cu WiFi (aveam niște planuri mari), dar ca și în viață, nu totul e posibil (nu până în PM Fair cel puținLOL). | ||
+ | \\ | ||
+ | Simt că am învățat multe de pe urma acestui proiect și că am descpoerit un nou hobby.\\ | ||
+ | |||
+ | ===== Download ===== | ||
+ | |||
+ | {{:pm:prj2024:vstoica:sswp_reg.zip|}} | ||
+ | ===== Bibliografie/Resurse ===== | ||
+ | * Resurse Hardware: | ||
+ | * [[https://www.thingiverse.com/thing:3537287|fișiere 3D]] | ||
+ | * Resurse Software: | ||
+ | * [[https://projecthub.arduino.cc/Isaac100/getting-started-with-the-hc-sr04-ultrasonic-sensor-7cabe1|Senzor ultrasunet]] | ||
+ | * [[https://www.instructables.com/How-to-use-a-Water-Level-Sensor-Arduino-Tutorial/|Senzor nivel apă]] | ||
+ | * [[https://www.dfrobot.com/product-599.html|Senzor sol]] | ||
+ | * [[https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299|DFPlayer Mini]] |