This shows you the differences between two versions of the page.
pm:prj2025:avaduva:adina.zugravescu [2025/05/29 15:40] adina.zugravescu [Software Design] |
pm:prj2025:avaduva:adina.zugravescu [2025/05/29 18:03] (current) adina.zugravescu [Download] |
||
---|---|---|---|
Line 91: | Line 91: | ||
**Funcții implementate:** | **Funcții implementate:** | ||
* setup(): configurarea pinilor, inițializarea LCD și Serial Monitor | * setup(): configurarea pinilor, inițializarea LCD și Serial Monitor | ||
+ | <code> | ||
+ | pinMode(FAN_PIN, OUTPUT); // Set FAN_PIN as an output pin for controlling the fan | ||
+ | pinMode(SENSOR_PIN, INPUT); // Set SENSOR_PIN as an input for reading sensor data | ||
+ | analogWrite(FAN_PIN, 0); // (PWM 0%) | ||
+ | | ||
+ | lcd.init(); | ||
+ | lcd.backlight(); | ||
+ | lcd.setCursor(5, 0); | ||
+ | lcd.print("Ready"); // Display "Ready" on the LCD initially | ||
+ | | ||
+ | // Start serial monitor for debugging | ||
+ | Serial.begin(9600); | ||
+ | </code> | ||
* loop(): verifică senzorul, declanșează ciclul de uscare și gestionează afișajul | * loop(): verifică senzorul, declanșează ciclul de uscare și gestionează afișajul | ||
+ | <code> | ||
+ | // Update every 1 second to monitor the status | ||
+ | if (millis() - lastUpdateTime >= updateInterval) { | ||
+ | lastUpdateTime = millis(); | ||
+ | |||
+ | // If not currently drying and a hand is detected | ||
+ | if (!drying && isHandDetected()) { | ||
+ | drying = true; | ||
+ | startTime = millis(); | ||
+ | analogWrite(FAN_PIN, 200); // Start the fan immediately at 200 PWM | ||
+ | fanState = 1; // Update fan state to "on" | ||
+ | lcd.clear(); | ||
+ | lcd.setCursor(1, 0); | ||
+ | lcd.print("Drying started"); | ||
+ | Serial.println("Hand detected"); | ||
+ | } | ||
+ | |||
+ | if (drying) { | ||
+ | unsigned long elapsed = millis() - startTime; | ||
+ | unsigned long remaining = (dryingDuration - elapsed) / 1000; | ||
+ | |||
+ | lcd.setCursor(4, 1); | ||
+ | lcd.print("Time: "); | ||
+ | lcd.print(remaining); | ||
+ | lcd.print("s "); | ||
+ | |||
+ | // Handle gradual PWM ramp-down in the last 8 seconds | ||
+ | handlePWMSpeedControl(); | ||
+ | |||
+ | // Check if the drying duration has expired | ||
+ | if (elapsed >= dryingDuration) { | ||
+ | // Automatically reset drying process when the time expires | ||
+ | fanState = 0; | ||
+ | resetDryingProcess(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
* isHandDetected(): verifică dacă senzorul IR detectează o mână (semnal LOW) | * isHandDetected(): verifică dacă senzorul IR detectează o mână (semnal LOW) | ||
- | * handlePWMSpeedControl(elapsed): reduce progresiv viteza ventilatorului în ultimele 8 secunde | + | <code> |
+ | int sensorValue = digitalRead(SENSOR_PIN); // Read the digital value from the sensor | ||
+ | if (sensorValue == LOW) { // If the sensor detects a hand | ||
+ | return true; | ||
+ | } | ||
+ | return false; | ||
+ | </code> | ||
+ | * handlePWMSpeedControl(): reduce progresiv viteza ventilatorului în ultimele 8 secunde | ||
+ | <code> | ||
+ | unsigned long elapsedTime = millis() - startTime; | ||
+ | |||
+ | if (elapsedTime >= 52000) { // After 52 seconds, start ramp-down | ||
+ | int pwmValue = 0; | ||
+ | |||
+ | // Ramp down the PWM speed to 150, 100, 50 over the last 8 seconds | ||
+ | if (elapsedTime <= dryingDuration - 7000) { | ||
+ | pwmValue = 150; | ||
+ | } else if (elapsedTime <= dryingDuration - 4000) { | ||
+ | pwmValue = 100; | ||
+ | } else if (elapsedTime <= dryingDuration - 1000) { | ||
+ | pwmValue = 50; | ||
+ | } | ||
+ | |||
+ | pwmValue = constrain(pwmValue, 0, 200); | ||
+ | |||
+ | // Only print PWM value if it's different from the previous one | ||
+ | static int lastPWMValue = -1; | ||
+ | if (pwmValue != lastPWMValue) { | ||
+ | analogWrite(FAN_PIN, pwmValue); | ||
+ | Serial.print("Fan PWM: "); | ||
+ | Serial.println(pwmValue); | ||
+ | lastPWMValue = pwmValue; // Update the last PWM value | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
* resetDryingProcess(): oprește ventilatorul, afișează „Done!” și revine la starea „Ready” | * resetDryingProcess(): oprește ventilatorul, afișează „Done!” și revine la starea „Ready” | ||
+ | <code> | ||
+ | analogWrite(FAN_PIN, 0); // Stop the fan | ||
+ | Serial.print("Fan state: "); | ||
+ | Serial.println(fanState); | ||
+ | lcd.clear(); | ||
+ | lcd.setCursor(5, 0); | ||
+ | lcd.print("Done!"); | ||
+ | delay(2000); | ||
+ | | ||
+ | lcd.clear(); | ||
+ | lcd.setCursor(5, 0); | ||
+ | lcd.print("Ready"); | ||
+ | drying = false; | ||
+ | </code> | ||
**Validare funcționalități:** | **Validare funcționalități:** | ||
Line 125: | Line 224: | ||
Proiectul m-a ajutat să înțeleg mai bine integrarea componentelor hardware cu logica software într-un sistem automat. A fost o experiență practică utilă, care mi-a consolidat noțiunile studiate în cadrul laboratoarelor de PM. | Proiectul m-a ajutat să înțeleg mai bine integrarea componentelor hardware cu logica software într-un sistem automat. A fost o experiență practică utilă, care mi-a consolidat noțiunile studiate în cadrul laboratoarelor de PM. | ||
===== Download ===== | ===== Download ===== | ||
- | {{:pm:prj2025:avaduva: automatic_dryer.zip}} | + | {{:pm:prj2025:avaduva: dryer.zip}} |