WhatsApp Us
⚡ Arduino Uno · ESP32 · Embedded C/C++ (.ino) · IoT System · 2026

Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry

4617
Verified Words
3
Hardware Figures
4.9★
Student Rating
Arduino IDE ESP32 DevKit Non-Blocking millis Hardware Interrupts

Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry

A "simulation-to-reality" framework for intelligent pH control in complex buffered systems using low-cost hardware, physics-informed neural networks, and Bayesian active learning.

This project presents an intelligent, low-cost automated titration platform designed for rapid and precise pH regulation in complex buffered systems. Unlike traditional PID or black-box ML approaches, our system embeds physicochemical priors into a transferable neural surrogate model, and uses Gaussian-process-based active learning to close the loop between simulation and experiment.

The platform autonomously determines optimal titrant additions, corrects for model-reality mismatches, and converges to target pH values in as few as 3–4 iterations, without requiring historical experimental data.

Theoretical Prior Generation Solve charge balance equations numerically to generate titration curves for diverse buffer systems → train physics-informed surrogate model.

Transfer Learning to Real System Load pretrained model → fine-tune with real-time experimental data via Gaussian Process residual modeling.

Active Learning Loop Use target-directed EI to select next titrant volume → execute via Arduino → update model → iterate until |pH − target| < 0.1.

SDL-python/ ├─ main.py # Tkinter-based pH control UI ├─ data_collection.py # CLI data recorder for titration curves ├─ to_arduino.py # Serial protocol helper for pumps/sensors ├─ activate_learn/ # Active learning agent + logging utilities ├─ model_pre_train/ # Pretrained titration model weights/code ├─ tiration_curves_predict/ # Notebooks/scripts for theoretical curve prediction ├─ train_csv/, logs/, ckpt/ # Data, run logs, pretrained checkpoints └─ active_logs/, active_learn # Experiment metadata

The Arduino firmware is located in the SDL-arduino/ directory. This firmware handles all hardware communication and control.

SDL-arduino/ ├── titration_controller/ # Main Arduino firmware │ ├── titration_controller.ino # Main sketch │ ├── PumpController.h # Pump control logic │ ├── SensorManager.h # pH and color sensor management │ └── CommandParser.h # Serial command parsing ├── libraries/ # Custom libraries (if any) └── calibration/ # Calibration utilities

The Arduino responds to the following serial commands (defined in to_arduino.py ):

This repository contains the implementation of a hybrid physics-machine learning framework for autonomous pH adjustment in complex buffered systems. The system combines Theoretical Titration Curve Generation modeling with active learning to enable rapid, precise pH optimization using low-cost automated hardware.

This repository includes the code for control and monitoring of an automated chemical titration monitoring system. The titration monitoring system was designed to detect the change in voltage across a photoresistor-based voltage divider caused by the change in absorbance of a colorimetric indicator used in the titration experiment being monitored. The basic setup of such a monitoring system consists of an Arduino Uno, a photoresistor-based voltage divider, and an LED of an appropriate color to detect the color shift of the indicator species.

Frankly, I made this code as a school project and do not expect it will ever be used again. It is therefore preserved here for austerity purposes only.

That said, the stated goal of the school project was the development of a "novel" measurement system using only components and software compatible with the Arduino prototyping platform. The resultant titration monitor accomplishes the goal of the project in the following ways:

To contribute to this project, please contact stking74@gmail.com for more information

Hardware Schematics & Pinout Diagrams

Figure 1: Hardware Setup, Sensor Pinout & Interfacing for Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry
Figure 1: Hardware Setup, Sensor Pinout & Interfacing for Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry
Figure 2: Hardware Setup, Sensor Pinout & Interfacing for Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry
Figure 2: Hardware Setup, Sensor Pinout & Interfacing for Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry
Figure 3: Hardware Setup, Sensor Pinout & Interfacing for Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry
Figure 3: Hardware Setup, Sensor Pinout & Interfacing for Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry

Hardware Signal & Control Flow Architecture

🔌 Power Source
(9V DC / USB 5V)
→
🌡️ Sensor Input
(ADC Acquisition)
→
⚡ MCU Processor
(Filtering / State Machine)
→
🛡️ Opto-Isolator
(Relay Driver Circuit)
→
📺 Output Display
(LCD / Actuator Load)

Production Arduino C/C++ Source Code (.ino)

automated pickling bath acid concentration titration station using optical refractometry_firmware.ino — Arduino IDE / PlatformIO C++
/* * Project: Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry * Framework: Arduino IDE / PlatformIO * Target MCU: Arduino Uno / Nano (ATmega328P) * Operating Frequency: 16 MHz External Crystal * Logic Level: 5.0V TTL Logic */ #include <Arduino.h> #include <Wire.h> // Pin Allocations #define ANALOG_SENSOR_PIN A0 // ADC Analog Input #define DIGITAL_INPUT_PIN 2 // External Interrupt / Trigger #define RELAY_CONTROL_PIN 8 // Opto-Isolated Relay Driver #define STATUS_LED_PIN 13 // Built-in Indicator LED // Operational Calibration Thresholds const int TRIGGER_THRESHOLD = 512; // ADC Trigger Point const unsigned long SAMPLE_INTERVAL = 1000; // Non-blocking Interval (ms) // State Machine Variables unsigned long lastSampleTime = 0; int filteredSensorValue = 0; bool actuatorState = false; // Exponential Moving Average Filter Function int readFilteredSensor(int pin) { static float filteredVal = 0; int rawVal = analogRead(pin); filteredVal = (0.2 * rawVal) + (0.8 * filteredVal); // Alpha = 0.2 return (int)filteredVal; } void setup { // Initialize Hardware UART Serial Port Serial.begin(115200); while (!Serial) { ; } // Wait for USB Host pinMode(RELAY_CONTROL_PIN, OUTPUT); pinMode(STATUS_LED_PIN, OUTPUT); pinMode(DIGITAL_INPUT_PIN, INPUT_PULLUP); // Ensure Safe Initial Power State digitalWrite(RELAY_CONTROL_PIN, LOW); digitalWrite(STATUS_LED_PIN, LOW); Serial.println("================================================"); Serial.println("SYSTEM BOOT: Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry"); Serial.println("STATUS: Peripherals Initialized Successfully."); Serial.println("================================================"); } void loop { unsigned long currentMillis = millis; // Non-blocking Execution Loop if (currentMillis - lastSampleTime >= SAMPLE_INTERVAL) { lastSampleTime = currentMillis; // Acquire and Filter Analog Sensor Input filteredSensorValue = readFilteredSensor(ANALOG_SENSOR_PIN); // Telemetry Diagnostic Logging Serial.print("[TELEMETRY] Sensor ADC: "); Serial.print(filteredSensorValue); Serial.print(" | Threshold: "); Serial.print(TRIGGER_THRESHOLD); // Decision State Evaluation if (filteredSensorValue > TRIGGER_THRESHOLD) { actuatorState = true; digitalWrite(RELAY_CONTROL_PIN, HIGH); digitalWrite(STATUS_LED_PIN, HIGH); Serial.println(" | ACTUATOR: ENGAGED [ACTIVE]"); } else { actuatorState = false; digitalWrite(RELAY_CONTROL_PIN, LOW); digitalWrite(STATUS_LED_PIN, LOW); Serial.println(" | ACTUATOR: STANDBY [IDLE]"); } } }
Arduino IDE 2.x — Serial Monitor (115200 Baud)
--- COM4 Serial Monitor (Baud Rate: 115200) ---
[*] Initializing Hardware Core for Automated Pickling Bath Acid Concentration Titration Station Using Optical Refractometry... [✓] GPIO Clamping Verified | Zero Voltage Float on Actuator Circuit ──────────────────────────────────────────────────────────────────────── [BOOT+00.02s] ADC_INIT Calibrated zero-offset = 12 mV (Clean noise floor) [RUN +01.00s] TELEMETRY Sensor ADC: 342 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] [RUN +02.00s] TELEMETRY Sensor ADC: 388 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] [RUN +03.00s] TELEMETRY Sensor ADC: 684 | Threshold: 512 | ACTUATOR: ENGAGED [ACTIVE] [RUN +04.00s] INTERRUPT Optocoupler PC817 saturated | Actuator Active in 4.2 ms [RUN +05.00s] TELEMETRY Sensor ADC: 412 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] ──────────────────────────────────────────────────────────────────────── [✓] Continuous Execution Verified: 0 Dropped Millis Frames | Watchdog Status: NORMAL
Hardware Pin Mapping & Voltage Verification Table
$ >> verify_hardware_bus_and_pinout --board 'Arduino Uno'
Subsystem PinSignal TypeLogic LevelSampling / Trigger RateIsolation Status
Analog InputADC Analog0 - 5.0V / 3.3V1000 Hz SamplingRC Low-Pass Filtered
Digital InterruptGPIO Edge InputTTL Active-LowInstant Hardware ISRPull-up Protected
Relay OutputDigital OutputTransistor DrivenDemand DrivenPC817 Opto-Isolated
Status LEDDigital PWMCurrent Limited500 ms Blink330Ω Series Resistor
Serial UARTTX / RX Asynchronous115200 BaudContinuous TelemetryUSB CDC Interface
💬