Trust is earned, not given

A different perspective

2022-02-20 · Projects

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

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