This shows you the differences between two versions of the page.
|
pm:prj2025:vstoica:radu.silvestru [2025/05/26 20:18] radu.silvestru |
pm:prj2025:vstoica:radu.silvestru [2025/05/26 20:29] (current) radu.silvestru [Software] |
||
|---|---|---|---|
| Line 42: | Line 42: | ||
| ===== Software ===== | ===== Software ===== | ||
| - | == Librarii folosite == | + | |
| - | ``` | + | |
| + | ^ Librarie ^ Scop ^ | ||
| + | | Wire.h | Comunicare I2C (pentru LCD)| | ||
| + | | LiquidCrystal_I2C.h| Afișare pe LCD 1602 cu interfață I2C| | ||
| + | |OneWire.h |Protocol OneWire pentru senzorul de temperatură DS18B20| | ||
| + | |DallasTemperature.h| Citirea temperaturii de la senzorul DS18B20| | ||
| + | |||
| + | <code cpp> | ||
| #include <Wire.h> | #include <Wire.h> | ||
| #include <LiquidCrystal_I2C.h> | #include <LiquidCrystal_I2C.h> | ||
| #include <OneWire.h> | #include <OneWire.h> | ||
| #include <DallasTemperature.h> | #include <DallasTemperature.h> | ||
| - | ``` | ||
| - | == I2C LCD Setup == | ||
| - | ``` | ||
| LiquidCrystal_I2C lcd(0x27, 16, 2); | LiquidCrystal_I2C lcd(0x27, 16, 2); | ||
| - | ``` | ||
| - | == EC Sensor Pins and Constants == | ||
| - | ` | ||
| #define EC_IN1 7 | #define EC_IN1 7 | ||
| #define EC_IN2 6 | #define EC_IN2 6 | ||
| #define EC_ANALOG A0 | #define EC_ANALOG A0 | ||
| #define EC_REF_RESISTOR 1000.0 | #define EC_REF_RESISTOR 1000.0 | ||
| - | ` | ||
| - | == Turbidity Sensor == | ||
| - | ``` | ||
| #define TURBIDITY_PIN A1 | #define TURBIDITY_PIN A1 | ||
| - | ``` | ||
| - | == DS18B20 Setup == | + | #define TEMP_DATA_PIN 2 |
| - | ``` | + | |
| OneWire oneWire(TEMP_DATA_PIN); | OneWire oneWire(TEMP_DATA_PIN); | ||
| DallasTemperature tempSensor(&oneWire); | DallasTemperature tempSensor(&oneWire); | ||
| - | ``` | ||
| - | == EC Calibration Constants == | + | const float EC_VOLT_LOW = 0.20; |
| - | ``` | + | const float EC_VOLT_HIGH = 1.12; |
| - | const float EC_VOLT_LOW = 0.20; // Voltage in distilled water | + | |
| - | const float EC_VOLT_HIGH = 1.12; // Voltage in 1413 uS/cm solution | + | |
| const float EC_LOW_UScm = 0.0; | const float EC_LOW_UScm = 0.0; | ||
| const float EC_HIGH_UScm = 1413.0; | const float EC_HIGH_UScm = 1413.0; | ||
| Line 83: | Line 76: | ||
| const float EC_SLOPE = (EC_HIGH_UScm - EC_LOW_UScm) / (EC_VOLT_HIGH - EC_VOLT_LOW); | const float EC_SLOPE = (EC_HIGH_UScm - EC_LOW_UScm) / (EC_VOLT_HIGH - EC_VOLT_LOW); | ||
| const float EC_OFFSET = EC_VOLT_LOW; | const float EC_OFFSET = EC_VOLT_LOW; | ||
| - | ``` | + | |
| - | ``` | + | void setup() { |
| - | void setup() | + | |
| - | ``` | + | |
| - | == Pin Setup == | + | |
| - | ``` | + | |
| pinMode(EC_IN1, OUTPUT); | pinMode(EC_IN1, OUTPUT); | ||
| pinMode(EC_IN2, OUTPUT); | pinMode(EC_IN2, OUTPUT); | ||
| - | ``` | ||
| - | |||
| - | == Serial & Sensors == | ||
| - | ``` | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| tempSensor.begin(); | tempSensor.begin(); | ||
| - | ``` | ||
| - | |||
| - | == LCD Init (manual style) == | ||
| Wire.begin(); | Wire.begin(); | ||
| lcd.begin(16, 2); | lcd.begin(16, 2); | ||
| Line 107: | Line 89: | ||
| delay(2000); | delay(2000); | ||
| lcd.clear(); | lcd.clear(); | ||
| - | ``` | + | } |
| void loop() { | void loop() { | ||
| - | // === EC Sensor Measurement (manually alternating) === | ||
| digitalWrite(EC_IN1, HIGH); | digitalWrite(EC_IN1, HIGH); | ||
| digitalWrite(EC_IN2, LOW); | digitalWrite(EC_IN2, LOW); | ||
| - | delayMicroseconds(5000); // ~5 ms | + | delayMicroseconds(5000); |
| int adc1 = analogRead(EC_ANALOG); | int adc1 = analogRead(EC_ANALOG); | ||
| digitalWrite(EC_IN1, LOW); | digitalWrite(EC_IN1, LOW); | ||
| digitalWrite(EC_IN2, HIGH); | digitalWrite(EC_IN2, HIGH); | ||
| - | delayMicroseconds(5000); // ~5 ms | + | delayMicroseconds(5000); |
| int adc2 = analogRead(EC_ANALOG); | int adc2 = analogRead(EC_ANALOG); | ||
| float voltage_avg = ((adc1 + adc2) / 2.0) * (5.0 / 1023.0); | float voltage_avg = ((adc1 + adc2) / 2.0) * (5.0 / 1023.0); | ||
| float current_mA = voltage_avg / EC_REF_RESISTOR * 1000.0; | float current_mA = voltage_avg / EC_REF_RESISTOR * 1000.0; | ||
| - | |||
| - | // Apply calibration to get conductivity | ||
| float ec_uScm = EC_SLOPE * (voltage_avg - EC_OFFSET); | float ec_uScm = EC_SLOPE * (voltage_avg - EC_OFFSET); | ||
| if (ec_uScm < 0) ec_uScm = 0; | if (ec_uScm < 0) ec_uScm = 0; | ||
| - | // === Turbidity Sensor === | ||
| int turb_raw = analogRead(TURBIDITY_PIN); | int turb_raw = analogRead(TURBIDITY_PIN); | ||
| float turb_voltage = turb_raw * (5.0 / 1023.0); | float turb_voltage = turb_raw * (5.0 / 1023.0); | ||
| - | // === Temperature Sensor === | ||
| tempSensor.requestTemperatures(); | tempSensor.requestTemperatures(); | ||
| float tempC = tempSensor.getTempCByIndex(0); | float tempC = tempSensor.getTempCByIndex(0); | ||
| - | // === Serial Monitor Output === | ||
| Serial.println("==== WATER QUALITY ===="); | Serial.println("==== WATER QUALITY ===="); | ||
| Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C"); | Serial.print("Temperature: "); Serial.print(tempC); Serial.println(" C"); | ||
| Serial.print("EC: "); Serial.print(ec_uScm); Serial.println(" uS/cm"); | Serial.print("EC: "); Serial.print(ec_uScm); Serial.println(" uS/cm"); | ||
| Serial.print("Turbidity Voltage: "); Serial.print(turb_voltage, 2); Serial.println(" V"); | Serial.print("Turbidity Voltage: "); Serial.print(turb_voltage, 2); Serial.println(" V"); | ||
| - | Serial.println("========================\n"); | + | Serial.println("========================"); |
| - | // === LCD Display Output === | ||
| lcd.setCursor(0, 0); | lcd.setCursor(0, 0); | ||
| lcd.print("T:"); lcd.print(tempC, 1); lcd.print("C "); | lcd.print("T:"); lcd.print(tempC, 1); lcd.print("C "); | ||
| Line 154: | Line 128: | ||
| delay(1500); | delay(1500); | ||
| } | } | ||
| - | ``` | + | </code> |