Rolling up car windows automatically: Arduino Nano meets the CAN bus
Modern cars run an internal network called CAN bus — every module (doors, engine, body controller) broadcasts small frames of data, and anything can listen. NissanAutoWindowCloser is an Arduino Nano + MCP2515 CAN module project for a Nissan Sylphy that listens for events and closes the windows automatically, among other behaviours.
What it does
- Close windows at key-off — detect ACC power dropping (voltage divider into A0) or a door-lock CAN frame arriving while ACC is off, wait a configurable delay, then send one "window up" frame per window, with retries.
- Hazards with any open door — watch the door-status frame's bitfield; any door open while parked → hazard lights on, all closed → off.
- Triple-unlock rolls windows down — the classic remote-start-summer convenience, triggered from unlock frame counting.
How CAN works for beginners
CAN frames have an 11- or 29-bit ID (what the message is) and up to 8 data bytes (the payload). There is no "window close" documentation — you discover IDs by logging bus traffic while pressing real buttons, then find which bytes change. The README is emphatic and worth repeating: all frame IDs and byte patterns here are placeholders. Every vehicle-specific constant is isolated in a CONFIG section at the top of the sketch, so adapting it is editing constants, not code. Sniffing your own car is legal on your own vehicle; transmitting wrong frames can confuse modules, so test with the car parked.
Code structure
The sketch is layered: MCP2515 driver init → CONFIG constants → frame-match helpers
(LOCK_FRAME_ID with byte/mask/value triples) → behaviour modules each behind its
own TRIGGER_* switch → a non-blocking main loop. Debounce timers everywhere —
cars are electrically noisy.
Repository: github.com/bobhuang1/NissanAutoWindowCloser