Community project

Automatic Water Filtration System

Photo of Automatic Water Filtration System
Generated with AI

Jeric Ustan

Published November 27, 2026

This automatic water filtration system monitors water quality and flow while controlling a motorized filter mechanism via Arduino. The build combines turbidity and flow sensors with a 6-axis IMU to track filter tilt angle, enabling automated cleaning cycles when sediment levels rise or flow rate drops. The system uses a 12V gearmotor with logic-level MOSFET control and a reversing driver to manage filter position, with safety interlocks and timed operation modes.

This guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions for integrating all five sensors with the Arduino Uno, configuring the motor control circuits, and uploading the provided firmware. Builders will learn sensor calibration, PWM motor control, I2C communication with the IMU, and how to commission the system safely before running filtration experiments.

Wiring diagram

Loading diagram…

Gather all the parts

QtyComponent
1

DFRobot SEN0189 analog turbidity sensor

5V, analog 0–4.5V. Set switch to A. Keep probe top and adapter dry.

1

DFRobot SEN0189 analog turbidity sensor

5V, analog 0–4.5V. Set switch to A. Keep probe top and adapter dry.

1

DFRobot SEN0189 analog turbidity sensor

5V, analog 0–4.5V. Set switch to A. Keep probe top and adapter dry.

1

DFRobot SEN0550 flow sensor

Green OUT, red VCC, black GND; 150 pulses/L; specified range 0.5–20 L/min. Calibrate with collection vessel.

1

DFRobot SEN0142 Fermion MPU-6050 6 DOF Sensor Breakout

DFRobot SEN0142 MPU-6050 breakout with 3-5 V board input, I2C interface, onboard I2C pull-ups, and i2cdevlib Arduino example coverage.

1

12V Barrel-Jack Adapter

12 V / 2 A wall adapter with a 5.5 mm / 2.1 mm barrel jack. Used to power motor drivers, LED strips, or boards that need a higher rail.

1

U.S. Solid 1/4 inch nylon 12V DC normally closed direct-acting valve

Choose 12V DC, 5W, 1/4 inch nylon NBR normally closed zero-pressure variant from https://ussolid.com/products/u-s-solid-electric-solenoid-valve-1-4-12v-dc-solenoid-valve-plastic-nylon-body-normally-closed-nbr-seal-html . Not potable. Two interchangeable coil leads assigned PLUS and MINUS.

1

IRLZ44N Logic-Level N-Channel MOSFET

Logic-level N-channel MOSFET commonly used as a low-side switch for DC loads from 3.3V or 5V microcontroller GPIO. Use a gate resistor, a gate pulldown, and a flyback diode for inductive loads.

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

1N4007 Diode

General-purpose silicon rectifier diode in DO-204AL (DO-41) axial through-hole package. Rated 1A average forward current and 1000V peak reverse voltage (VRRM). Forward voltage drop ~0.7V at typical load (up to 1.1V at full 1A). Used here in series with LM7805 Vout for reverse polarity protection: anode to LM7805 output, cathode to 5V rail, resulting in ~4.3V on the output rail. Not suitable for high-frequency switching (reverse recovery ~2µs–30µs); intended for DC or 50/60Hz rectification only.

1

U.S. Solid 1/4 inch nylon 12V DC normally closed direct-acting valve

Choose 12V DC, 5W, 1/4 inch nylon NBR normally closed zero-pressure variant from https://ussolid.com/products/u-s-solid-electric-solenoid-valve-1-4-12v-dc-solenoid-valve-plastic-nylon-body-normally-closed-nbr-seal-html . Not potable. Two interchangeable coil leads assigned PLUS and MINUS.

1

IRLZ44N Logic-Level N-Channel MOSFET

Logic-level N-channel MOSFET commonly used as a low-side switch for DC loads from 3.3V or 5V microcontroller GPIO. Use a gate resistor, a gate pulldown, and a flyback diode for inductive loads.

1

Resistor

220 Ω

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

1N4007 Diode

General-purpose silicon rectifier diode in DO-204AL (DO-41) axial through-hole package. Rated 1A average forward current and 1000V peak reverse voltage (VRRM). Forward voltage drop ~0.7V at typical load (up to 1.1V at full 1A). Used here in series with LM7805 Vout for reverse polarity protection: anode to LM7805 output, cathode to 5V rail, resulting in ~4.3V on the output rail. Not suitable for high-frequency switching (reverse recovery ~2µs–30µs); intended for DC or 50/60Hz rectification only.

1

StepperOnline F4D60-12GN-18S/4GN20K 12V 90 RPM gearmotor

12V brushed DC gearmotor with 20:1 spur gearbox; maker specifies rated speed 90 RPM, rated torque 5.15 Nm and output power 60W. Not constant-speed control. Maximum/startup/stall current and shaft dimensions not verified; motor leads remain disconnected and firmware locked off pending driver, supply, fuse and coupling verification. Source: https://www.omc-stepperonline.com/brushed-12v-60w-5-15nm-729-30oz-in-90rpm-w-20-1-spur-gearbox-dc-gear-motor-f4d60-12gn-18s-4gn20k

1

12V linear actuator — tilt (planning only)

User-listed 12V DC linear actuator. Stroke proposed 200 mm; actual stroke, force (600/700 N under discussion), lead layout and maximum current unverified. Visual placeholder only: leave disconnected. Requires rated reversing controller, fused supply and safe travel limits before use. M1/M2 represent conceptual motor leads, not verified terminal labels or wire colours.

1

USB-C 5V Adapter

USB-C wall adapter delivering regulated 5 V to the board's USB or VBUS rail. Default wired power source for desktop / stationary projects.

1

DFRobot DRI0042 15A reversing driver (5V-compatible controls)

Maker https://wiki.dfrobot.com/dri0042/ specifies control HIGH 2.0–5.5V, LOW 0–0.8V; compatible with UNO 5V logic. Motor input 12–36V; 12A continuous without heatsink. OUT1/OUT2 intentionally disconnected pending actuator verification. 5VO is output only and unused.

1

Mean Well GST120A12-R7B enclosed 12V 8.5A adapter — provisional

Separate tilt supply; 12V 8.5A, 102W. Factory enclosed adapter with 4-pin DIN output. Use a factory matching rated breakout lead with labelled positive/negative; do not guess DIN pin numbering. Selection only valid after actuator startup/stall current is verified within supply and driver ratings. https://www.meanwellaustralia.com.au/products/GST120A

1

10A ATO blade fuse

Provisional wiring-protection fuse for 16 AWG tilt power wiring. Not an actuator overload protector. Recheck rating against measured startup current; do not upsize without reviewing wires and connectors.

1

16 AWG standard ATO inline fuse holder

16 AWG two-lead ATO fuse holder, 32V DC; insert separate tiltfuse. Both leads interchangeable. Keep dry. Lazada PH listing 2712167114; select 16 AWG standard blade, not mini, and verify DC rating.

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

1

Mean Well GST120A12-R7B enclosed 12V 8.5A adapter — helical motor

Separate helical motor supply; 12V 8.5A, 102W. Factory enclosed adapter with 4-pin DIN output. Use a factory matching rated breakout lead with labelled positive/negative; do not guess DIN pin numbering. Provisional only: new 60W 90 RPM motor startup/stall current is unknown; leave motor disconnected until supply capacity is verified. Do not share positive output with other adapters. https://www.meanwellaustralia.com.au/products/GST120A

1

7.5A ATO blade fuse

Provisional 7.5A wiring-protection fuse; re-evaluate against new motor startup current and conductor ratings before use. For short 16 AWG motor supply wiring. Does not protect motor against jams; shut down immediately on a stall. Do not upsize without reviewing wires and connectors.

1

16 AWG standard ATO inline fuse holder

16 AWG two-lead ATO fuse holder, 32V DC; insert separate motorfuse. Both leads interchangeable. Keep dry. Lazada PH listing 2712167114; select 16 AWG standard blade, not mini, and verify DC rating.

1

DFRobot DRI0042 motor driver — provisional

Maker https://wiki.dfrobot.com/dri0042/ specifies 2.0–5.5V HIGH controls compatible with UNO 5V logic. Motor supply 12–36V; 12A continuous without heatsink. Outputs disconnected pending new motor current verification. 5VO output unused.

1

Resistor

10 kΩ

Through-hole resistor (current-limiting in series with an LED)

Assemble it in 9 steps

1. Identify the five measurement sensors

S1, S2 and S3 are three separate SEN0189 turbidity sensor kits, each with its probe, adapter board and cable. S4 is the SEN0550 flow sensor. S6 is the MPU6050 tilt sensor. A linear actuator is shown as an unconnected planning part; powered tilt remains disabled. Keep adapter boards and the Arduino dry and above any possible spill. These electronics measure and control an existing water path; they do not purify water themselves.

  • This is a sediment-removal experiment, not a drinking-water purifier. Nylon valves are not approved for potable water.

2. Connect every sensor to the UNO

With all power unplugged, connect each SEN0189 adapter VCC to UNO 5V and GND to UNO GND. Connect S1 SIG to A0 (inlet), S2 SIG to A1 (after settling), and S3 SIG to A2 (final outlet); set all three adapter switches to A for analog readings. Connect flow VCC to 5V, GND to GND, and OUT to D2 (pulse signal). Connect MPU6050 VIN to 5V, GND to GND, SDA to A4/SDA (data), and SCL to A5/SCL (clock); leave INT unused. Use this specified SEN0142 breakout, not a bare 3.3V-only MPU6050. Secure the angle board with X along the tube and Z upward. Place flow sensor after the filter with its arrow toward collection. Keep flow sensor water-filled and turbidity probe tops dry.

  • A0, A1, A2, A4 and A5 are the printed UNO pin labels; the circuit view may also show GPIO14, GPIO15, GPIO16, GPIO18 and GPIO19 respectively.
  • Turbidity is raw volts, not calibrated NTU. Calibrate each probe against a reference meter before reporting turbidity removal percentages. Avoid bubbles and grit on optical windows.
  • Flow calibration starts at 150 pulses per litre. Check against collected volume and a stopwatch. Below 0.5 L/min is outside the sensor specified range.
  • Compare displayed tilt with a protractor; reverse the mounting direction if positive tube tilt displays negative.

3. Plan actuator placement; keep tilt manual

Support the tube on a stable adjustable support and set its angle manually with load power off. Check it with a protractor and the angle sensor, then select the matching target on the dashboard. The 12V linear actuator is shown for visual planning only, with no electrical connections or reversing controller yet. Leave both motor leads insulated and disconnected. Confirm the actual stroke, force, lead layout and maximum current before selecting a reversing controller, fused supply and travel protection. Do not assume the existing 12V 2A adapter can power it. Mount the cleaning motor outside the wet tube with a sealed shaft and guarded coupling.

  • Secure the tube against falling or moving under the wet load. Do not connect a linear actuator directly to Arduino pins or the existing one-direction motor driver.

4. Wire the upgraded helical motor circuit

The diagram now selects the StepperOnline F4D60-12GN-18S/4GN20K 12V brushed gearmotor with 20:1 gearbox, rated 90 RPM and 5.15 Nm torque. Leave both motor leads insulated and disconnected. The existing DRI0042 driver, 12V 8.5A supply and 7.5A fuse are provisional until motor startup/stall current is verified. Firmware disables motor commands. Existing control wiring stays D7 to IN1, IN2 to GND, PWM to UNO 5V, COM to GND, with 10k IN1 pulldown; leave 5VO unused. Do not energize the motor branch until ratings and cooling are reviewed.

  • Guard the rotating helix and coupling. Support the helix with independent bearings and a coupling matched to the verified motor shaft dimensions; do not let its weight or axial thrust load the motor shaft.
  • Actual helix torque is unverified. Test uncoupled first, then briefly with an empty helix. Stop immediately on a jam; the fuse is wiring protection, not motor overload protection.
  • Rated 90 RPM is not guaranteed under every load; overload reduces speed and causes heating. Verify actual helix load before operation.

5. Connect USB and load power

USB powers UNO and sensors. The enclosed 12V 2A adapter powers only the two valves. Connect its negative to common ground; never connect its positive to Arduino 5V. Use the listed USB-C 5V supply through the UNO USB-C socket for standalone operation, not through header wires. The diagram 5V connection represents USB delivery. Disconnect the wall USB cable when connecting the computer for Deploy. No servo is used. Keep adapters above spills and unplug before touching wiring.

  • Use factory-enclosed low-voltage adapters; never wire exposed mains. Wrong polarity can destroy electronics.

6. Test before the sediment experiment

With empty plumbing and loads safely supported, verify both valves close and motor stops at startup and STOP. Confirm the 5-second drain pulse; motor command must remain off while commissioning is locked. Set and secure the tube angle manually, verify the measured tilt, and select the matching target. Run with clear water first; RUN stops after 6 minutes, invalid angle, angle error, or sustained no outlet flow. Browser disconnection does not immediately stop RUN: use STOP or disconnect load power. Keep collection capacity at least 30 L. Collect paired meter readings, stopwatch flow, protractor angles and dry sediment mass for all trials; save CSV while the dashboard is open.

  • Dashboard is a simple live digital counterpart, not a validated hydraulic simulation. Stokes/regression and ANOVA require measured calibration data and are not fabricated by firmware.

7. Wire the separate tilt supply and reversing controller

Put the separate 10A blade fuse in its inline holder. Connect the enclosed 12V 8.5A adapter labelled positive output to holder IN; holder OUT goes to DRI0042 VIN (9-36V terminal). CONTACT1 and CONTACT2 in the diagram represent the internal fuse contacts, not additional external wires. Connect adapter negative directly to PGND. Connect COM to UNO GND; join the supply negatives at a common terminal point. D9 goes to PWM (speed), D8 to IN1 and D10 to IN2 (direction). Each control input has its own 10k pulldown to ground. Leave 5VO unused. Use factory-rated matching output leads; do not guess the DIN plug pinout.

  • The tilt adapter and fuse are provisional. Verify actuator maximum/startup/stall current before energizing. This supply cannot run an actuator requiring more than 8.5A.
  • Use short 16 AWG copper power wires and suitably rated connectors, not breadboards. Route heavy-current negative wires directly to the common terminal, not through the UNO.

8. Keep actuator disconnected until commissioning

No servo or temperature sensor is used. Your actuator remains represented with insulated disconnected motor leads because its lead arrangement, current, internal limits and travel are unverified. After those are confirmed, its two motor leads would connect to controller OUT1 and OUT2, never directly to Arduino pins. This firmware deliberately holds all three tilt controls LOW; dashboard angles remain manual targets. Support and balance the tube on a pivot, verify mounting travel for 0 to 35 degrees and prevent pinch access before implementing powered motion.

  • Do not attach an ordinary single flyback diode across a reversing actuator. The existing three diodes belong only to the valves and one-direction cleaning motor.

9. Turn the system on together

Plug the four factory-enclosed adapters into one switched power strip kept dry above the water system. USB-C 5V powers UNO and five sensors; 12V 2A powers the valves; dedicated 12V 8.5A powers the helical motor; separate 12V 8.5A is reserved for the tilt controller. Keep all positive rails separate; share low-voltage ground only. Unplug the tilt adapter during initial testing. A switched strip is not a certified emergency stop; disconnect load power immediately if motion or switching is unexpected.

  • Never wire exposed mains or connect 12V to UNO 5V. Keep outlets and adapters away from spills and use an RCD/GFCI-protected outlet.

Review all connections

1. Connections between "s1" and "Arduino"

Functions1Arduino
powerVCC5V
groundGNDGND
analogSIGGPIO 14

2. Connections between "s2" and "Arduino"

Functions2Arduino
powerVCC5V
groundGNDGND
analogSIGGPIO 15

3. Connections between "s3" and "Arduino"

Functions3Arduino
powerVCC5V
groundGNDGND
analogSIGGPIO 16

4. Connections between "flow" and "Arduino"

FunctionflowArduino
powerVCC5V
groundGNDGND
digitalOUTGPIO 2

5. Connections between "imu" and "Arduino"

FunctionimuArduino
powerVIN5V
groundGNDGND
i2cSDAGPIO 18
i2cSCLGPIO 19

6. Connections between "supply12" and "Arduino"

Functionsupply12Arduino
power+12V12V
groundGNDGND

7. Connections between "feed" and "Arduino"

FunctionfeedArduino
powerPLUS12V
dataMINUS → IRLZ44N Logic-Level N-Channel MOSFET DRAINEXT

8. Connections between "feedq" and "Arduino"

FunctionfeedqArduino
groundSOURCEGND

9. Connections between "feedrg" and "Arduino"

FunctionfeedrgArduino
digitalP1GPIO 5
digitalP2 → IRLZ44N Logic-Level N-Channel MOSFET GATEEXT

10. Connections between "feedpd" and "Arduino"

FunctionfeedpdArduino
digitalP1 → IRLZ44N Logic-Level N-Channel MOSFET GATEEXT
groundP2GND

11. Connections between "feeddiode" and "Arduino"

FunctionfeeddiodeArduino
powerAnode → U.S. Solid 1/4 inch nylon 12V DC normally closed direct-acting valve MINUSEXT
powerCathode → U.S. Solid 1/4 inch nylon 12V DC normally closed direct-acting valve PLUSEXT

12. Connections between "drain" and "Arduino"

FunctiondrainArduino
powerPLUS12V
dataMINUS → IRLZ44N Logic-Level N-Channel MOSFET DRAINEXT

13. Connections between "drainq" and "Arduino"

FunctiondrainqArduino
groundSOURCEGND

14. Connections between "drainrg" and "Arduino"

FunctiondrainrgArduino
digitalP1GPIO 6
digitalP2 → IRLZ44N Logic-Level N-Channel MOSFET GATEEXT

15. Connections between "drainpd" and "Arduino"

FunctiondrainpdArduino
digitalP1 → IRLZ44N Logic-Level N-Channel MOSFET GATEEXT
groundP2GND

16. Connections between "draindiode" and "Arduino"

FunctiondraindiodeArduino
powerAnode → U.S. Solid 1/4 inch nylon 12V DC normally closed direct-acting valve MINUSEXT
powerCathode → U.S. Solid 1/4 inch nylon 12V DC normally closed direct-acting valve PLUSEXT

17. Connections between "usbpower" and "Arduino"

FunctionusbpowerArduino
power+5V5V
groundGNDGND

18. Connections between "tiltpower" and "Arduino"

FunctiontiltpowerArduino
powerPLUS → 16 AWG standard ATO inline fuse holder INEXT
groundMINUS → DFRobot DRI0042 15A reversing driver (5V-compatible controls) PGNDEXT

19. Connections between "tiltfuseholder" and "Arduino"

FunctiontiltfuseholderArduino
powerCONTACT1 → 10A ATO blade fuse P1EXT
powerOUT → DFRobot DRI0042 15A reversing driver (5V-compatible controls) VINEXT

20. Connections between "tiltfuse" and "Arduino"

FunctiontiltfuseArduino
powerP2 → 16 AWG standard ATO inline fuse holder CONTACT2EXT

21. Connections between "tiltdriver" and "Arduino"

FunctiontiltdriverArduino
groundPGNDGND
groundCOMGND
pwmPWMGPIO 9
digitalIN1GPIO 8
digitalIN2GPIO 10

22. Connections between "tiltpwm_pd" and "Arduino"

Functiontiltpwm_pdArduino
digitalP1 → DFRobot DRI0042 15A reversing driver (5V-compatible controls) PWMEXT
groundP2GND

23. Connections between "tilt1_pd" and "Arduino"

Functiontilt1_pdArduino
digitalP1 → DFRobot DRI0042 15A reversing driver (5V-compatible controls) IN1EXT
groundP2GND

24. Connections between "tilt2_pd" and "Arduino"

Functiontilt2_pdArduino
digitalP1 → DFRobot DRI0042 15A reversing driver (5V-compatible controls) IN2EXT
groundP2GND

25. Connections between "motorpower" and "Arduino"

FunctionmotorpowerArduino
powerPLUS → 16 AWG standard ATO inline fuse holder INEXT
groundMINUS → DFRobot DRI0042 motor driver — provisional PGNDEXT

26. Connections between "motorfuseholder" and "Arduino"

FunctionmotorfuseholderArduino
powerCONTACT1 → 7.5A ATO blade fuse P1EXT
powerOUT → DFRobot DRI0042 motor driver — provisional VINEXT

27. Connections between "motorfuse" and "Arduino"

FunctionmotorfuseArduino
powerP2 → 16 AWG standard ATO inline fuse holder CONTACT2EXT

28. Connections between "motordriver" and "Arduino"

FunctionmotordriverArduino
groundPGNDGND
groundCOMGND
powerPWM5V
digitalIN1GPIO 7
groundIN2GND

29. Connections between "motorinputpd" and "Arduino"

FunctionmotorinputpdArduino
digitalP1 → DFRobot DRI0042 motor driver — provisional IN1EXT
groundP2GND

Deploy the firmware

#include <Arduino.h>
#include <Wire.h>
#include <WiFiS3.h>
#include <math.h>
WiFiServer server(80);
volatile uint32_t pulses=0; uint32_t lastPulses=0, sampleAt=0, runAt=0, actionAt=0;
float volts[3]={0}, angle=NAN, flowRate=0; bool imuOK=false;
enum State {IDLE,RUN,CLEAN,DRAIN}; State state=IDLE; int target=15;
void pulse(){pulses++;}
void stop(){digitalWrite(5,LOW);digitalWrite(6,LOW);digitalWrite(7,LOW);state=IDLE;}
void imuWrite(uint8_t r,uint8_t v){Wire.beginTransmission(0x68);Wire.write(r);Wire.write(v);Wire.endTransmission();}
void tick(){
 uint32_t now=millis();
 if(state==RUN && now-runAt>360000UL) stop();
 if(state==CLEAN && now-actionAt>10000UL)stop();
 if(state==DRAIN && now-actionAt>5000UL)stop();
 if(now-sampleAt<1000)return;
 float dt=(now-sampleAt)/1000.0f; sampleAt=now;
 noInterrupts();uint32_t n=pulses;interrupts();flowRate=(n-lastPulses)*60.0f/(150.0f*dt);lastPulses=n;
 for(int i=0;i<3;i++){long sum=0;for(int j=0;j<16;j++)sum+=analogRead(A0+i);volts[i]=sum/16.0f*5.0f/4095.0f;}
 Wire.beginTransmission(0x68);Wire.write(0x3B);imuOK=Wire.endTransmission(false)==0;
 if(imuOK && Wire.requestFrom(0x68,6)==6){int16_t x=(Wire.read()<<8)|Wire.read();int16_t y=(Wire.read()<<8)|Wire.read();int16_t z=(Wire.read()<<8)|Wire.read();angle=atan2(-float(x),sqrt(float(y)*y+float(z)*z))*180/PI;}else{imuOK=false;angle=NAN;}
 if(state==RUN && (!imuOK || fabs(angle-target)>8 || (now-runAt>30000 && flowRate<0.05)))stop();
}
const char page[]=R"HTML(<!doctype html><meta name="viewport" content="width=device-width"><title>Water filter prototype</title><h2>Water filter research prototype</h2><p>Not drinking water. Turbidity shown as raw volts until calibrated.</p><pre id="live"></pre><button onclick="cmd('run')">Run (max 6 min)</button> <button onclick="cmd('stop')">STOP</button><p><button onclick="cmd('clean')">90 RPM helix (locked)</button> <button onclick="cmd('drain')">Drain 5 s</button></p><p>Manual angle target: <button onclick="cmd('tilt0')">0°</button> <button onclick="cmd('tilt15')">15°</button> <button onclick="cmd('tilt25')">25°</button> <button onclick="cmd('tilt35')">35°</button></p><button onclick="save()">Save browser readings CSV</button><p>Set feed restriction by collected volume and stopwatch. Flow sensor may under-read below 0.5 L/min. New 90 RPM motor is disconnected and locked off until electrical ratings are verified. Drain requires idle state. Guard moving parts; settling RUN keeps helix stationary. Set the tube angle manually while idle, then select its target here. 12V linear actuator provision shown in circuit; commissioning lock keeps tilt outputs off.</p><script>let rows=['seconds,inlet_V,settled_V,outlet_V,L_min,total_L,tilt_deg,state'];async function cmd(c){await fetch('/cmd?'+c,{method:'POST'});}async function poll(){try{let s=await(await fetch('/data')).text();document.getElementById('live').textContent=s; rows.push(s.trim());}catch(e){}setTimeout(poll,1000)}poll();function save(){let a=document.createElement('a');a.href=URL.createObjectURL(new Blob([rows.join('\n')],{type:'text/csv'}));a.download='filter-readings.csv';a.click();}</script>)HTML";
void setup(){
 // Tilt commissioning lock: keep reversing driver off until actuator ratings and travel are verified.
 for(int pin : {8,9,10}){digitalWrite(pin,LOW);pinMode(pin,OUTPUT);}

 digitalWrite(5,LOW);digitalWrite(6,LOW);digitalWrite(7,LOW);pinMode(5,OUTPUT);pinMode(6,OUTPUT);pinMode(7,OUTPUT);
 Serial.begin(115200);analogReadResolution(12);pinMode(2,INPUT_PULLUP);attachInterrupt(digitalPinToInterrupt(2),pulse,RISING);
 Wire.begin();imuWrite(0x6B,0);imuWrite(0x1C,0);
 if(WiFi.beginAP("FilterPrototype","FilterLab2026")!=WL_AP_LISTENING){Serial.println("WiFi failed; outputs stay off.");return;}server.begin();Serial.println(WiFi.localIP());
}
void loop(){
 tick();WiFiClient c=server.available();if(!c)return;
 String req="";uint32_t start=millis();while(c.connected() && millis()-start<300){tick();if(c.available()){char ch=c.read();if(ch=='\n')break;if(ch!='\r' && req.length()<160)req+=ch;}}
 if(req.startsWith("POST /cmd?")){
 if(req.indexOf("?stop ")>0)stop();
 else if(req.indexOf("?run ")>0 && state==IDLE && imuOK && fabs(angle-target)<8){state=RUN;runAt=millis();digitalWrite(5,HIGH);}
 else if(state==IDLE){
 if(req.indexOf("?clean ")>0){stop();} // New motor commissioning lock: current ratings unverified.
 else if(req.indexOf("?drain ")>0){state=DRAIN;actionAt=millis();digitalWrite(6,HIGH);}
 else if(req.indexOf("?tilt")>0){int t=req.substring(req.indexOf("?tilt")+5).toInt();if(t==0||t==15||t==25||t==35){target=t;}}
 }
 }
 c.println("HTTP/1.1 200 OK");c.println("Connection: close");c.println("Cache-Control: no-store");
 if(req.startsWith("GET /data")){c.println("Content-Type: text/plain\r\n");noInterrupts();uint32_t n=pulses;interrupts();c.print(millis()/1000);for(float v:volts){c.print(',');c.print(v,3);}c.print(',');c.print(flowRate,3);c.print(',');c.print(n/150.0f,3);c.print(',');c.print(angle);c.print(',');c.println(state==RUN?"RUN":state==CLEAN?"CLEAN":state==DRAIN?"DRAIN":"IDLE");}
 else if(req.startsWith("POST")){c.println("Content-Type: text/plain\r\n");c.println("OK; check live state");}
 else{c.println("Content-Type: text/html\r\n");c.print(page);}c.stop();
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik