Building a GPS‑Timed Ventilation System for Boats: Relay‑Operated Fan with PIC16F628A
Build a reliable, GPS‑controlled fan to vent moisture from a boat cabin. The system uses a PIC16F628A microcontroller, relays, a 12V battery, and an LCD display.
Ventilation is essential in tight, damp spaces. Without proper airflow, moisture can accumulate, creating a breeding ground for mold and fungi. In my boat, where wood surfaces are abundant, I designed a simple yet effective solution: a relay‑operated fan that runs on a fixed schedule, powered by a car battery and managed by a GPS module for accurate timing.
Why Controlled Ventilation Matters
In small rooms, stagnant air leads to condensation. Over time, this dampness encourages mold growth, which can damage wood and degrade air quality. While regular cleaning can mitigate the problem, automating ventilation offers a more consistent, low‑maintenance approach.
System Overview
The fan should:
- Circulate air efficiently.
- Operate automatically on a steady schedule.
- Draw power from a 12V car battery.
- Charge the battery via a dedicated charger when the fan is off.
- Display current time and status on an LCD.
Key components include:
- 12V 4.5A fan
- PIC16F628A microcontroller
- 12V battery and charger
- Two relays (fan control & charger control)
- GPS module (Skylab SKM53‑series)
- LCD display
- Fuses (12V, 8A)
- Miscellaneous resistors, capacitors, and connectors
The fan runs for five minutes each hour—a value hard‑coded into the firmware. When the fan is active, the charger relay is de‑energized to avoid over‑charging. When the fan stops, the charger relay is re‑energized, keeping the battery topped up.
GPS Timing with the Skylab SKM53
The SKM53 provides NMEA sentences over UART each second. I use the RMC sentence to extract the current UTC time. Example:
$GPRMC,075747.000,A,2233.89990,N,11405.3368,E,3.9,357.8,260210,,,A*6AThe first six digits (075747) represent 07:57:47. The status field (the letter after the third comma) indicates a valid fix (“A”) or invalid (“V”). My firmware checks this flag before using the timestamp.
For reliable serial communication, the datasheet recommends a 10 kΩ pull‑up on both RXD and TXD and decoupling capacitors (10 µF electrolytic + 0.1 µF ceramic). I used a single 0.1 µF ceramic on the breadboard and observed no instability.
Screenshot from the Skylab datasheet (PDF).
Block Diagram
Visualizing the system as discrete blocks simplifies troubleshooting and schematic creation.

Hardware Design
The schematic follows the block diagram and shows each component’s connections.

I chose the LM7805 linear regulator for simplicity, adding additional smoothing capacitors to prevent oscillation. While a modern switching regulator would improve efficiency, the LM7805’s reliability and the parts I had on hand made it a practical choice.
All components are mounted on a sturdy PCB, with a 12V 8A fuse on both the fan and charger circuits for safety.

Firmware Structure
The C source is well‑commented and follows a clear structure:
- Include libraries and set configuration bits.
- Define constants (crystal frequency, port assignments).
- Declare global variables.
- Prototype functions.
- Implement functions with inline comments.
- Enter the main loop, which reads GPS data, manages timers, and toggles relays.
Example: UART initialization.
// FUNCTION TO INIT THE UART PORT
void uart_init(void)
{
TXSTAbits.BRGH = 0; // High baud rate disabled
TXSTAbits.SYNC = 0; // Asynchronous mode
TXSTAbits.TX9 = 0; // 8‑bit transmission
RCSTAbits.CREN = 1; // Continuous receive enable
/*
* Baud rate calculation (16 MHz crystal, 9600 bps):
* SPBRG = (16 MHz / 9600) / 64 - 1 = 25
*/
SPBRG = 25;
PIE1bits.RCIE = 1; // Enable UART receive interrupt
RCSTAbits.SPEN = 1; // Enable serial port
TXSTAbits.TXEN = 1; // Enable transmission
}
Download the full source here: jc_lettheairflow.c.zip.
Conclusion
By integrating a GPS module for precise timing, relays for power management, and a 12V battery for portability, this system keeps a boat cabin dry and mold‑free. The design is modular—easily extendable to display the date or integrate additional sensors.
Images

Try this project yourself! Download the BOM and code.
Industrial equipment
- The Complete Guide to Fiberglass Production
- Expert Guide to Designing and Manufacturing Injection Molds
- Build a Bluetooth‑Controlled Arduino Car: A Complete DIY Guide
- Boost Efficiency of Your Air Compressor Systems: Proven Tips & Strategies
- How Air Dryers Work: Keeping Compressed Air Clean & Efficient
- Comprehensive Guide to Removing Contaminants from Compressed Air
- Step‑by‑Step Guide to Replacing a Hydraulic Hose on Heavy Equipment
- DIY 12‑Volt Battery: Simple, Reliable Guide for Electronics Enthusiasts
- Industrial Air Compressor Sizing: Expert Guide to Selecting the Right Unit
- Choosing the Right Commercial Air Compressor: A Practical Guide