Introduction: Arduino Headlight Modulator for Motorcycle Safety
Motorcycles are difficult to see on the road primarily because they are only about one fourth the width of a car or truck. Since 1978 in the USA, motorcycle manufacturers have been required to make motorcycles more visible by wiring the headlights on continuously but sometimes that's not enough to distinguish them from cars and make them "more conspicuous". USA Federal and Canadian regulations allow for modulating the headlights on motorcycles. Modulation is flashing the headlights at a certain rate to make them more visible. This link shows the requirements for headlight modulators for both the USA and Canada.
Since I'm an electronics hobbyist, have some experience with microcontrollers and ride a motorcycle, I decided to make my own headlight modulator and throw in some other safety features just for me. Two features were added to enhance my convenience and safety. They are a speed indicator, what I call a "poor man's cruise control" with heads up LED display and an amber safety light at the rear. Either of these features can be added to the modulator design at any time.
The speedometer on my motorcycle is difficult to read because of its location and design. To read the speedometer means taking my eyes off the road. The speed indicator consists of a momentary set switch mounted on the handlebars near the right thumb, a hall effect device with magnet attached to the front wheel and a tri-color LED mounted to the windshield near eye level. When the desired speed is reached, the switch is pressed and immediately the LED turns blue indicating that you are going at or near your set speed. If you loose speed, the LED turns green indicating that to maintain the set speed you need to speed up. If you go too fast, the LED turns red indicating you need to slow down. The goal is to keep the LED blue.
This project was a learning project for me and I made lots of mistakes along the way (mostly in the software where changes are easy to make). I'm suggesting that, as a one-off project, you use the construction suggested in the "How its Built" section.
NOTE: This design is not intended for any commercial use and does not meet the "letter" of the law in two areas.
(d) The modulator switch shall be wired in the power lead of the beam filament being modulated and not in the ground side of the circuit.
(e) Means shall be provided so that both the lower beam and upper beam remain operable in the event of a modulator failure [NOTE: A switch can be installed across the MOSFET device to meet this requirement]
Skill set required:
- This Instructable is not a "How to", it's a "How". You will have to do some design for and adaptation to your own mototcycle.
- Ability to read and follow a schematic diagram, locate components on a prototyping board and connect them with hookup wire.
- Ability to solder
- Mechanical ability to install the modulator on a motorcycle
Step 1: Project Goal
Prior to starting any design project I like to write down a list of everything I would like the design to do. Here is my list:
- Must be "plug-n-play". Installs between headlight harness and headlights. No cuts or modification to vehicle wiring at all.
- Modulate the headlights at 240 transitions per minute between 100% and 20% brightness on either high or low beam.
- Modulate a rear caution light at 60 transitions per minute, 240 transitions per minute when the brakes are applied.
- Photo resistor mounted to the front fork sensing daylight. At dusk the headlight modulation ceases and the heads-up display dims.
- Heads up tri-color LED speed indicator. Display indicates "too fast" (red), "too slow" (green), "on speed" (blue) with programmable hysteresis.
- Handlebar mounted set switch for the heads up speed indicator.
- Hall effect device mounted to front fork with magnet glued to front wheel to sense vehicle speed.
Plans for future implementation:
- A true cruise control with handlebar mounted stepper motor to actuate the throttle.
- Amber side caution lights.
Step 2: How It's Built
Microcontrollers are very powerful in regard to what all they can do. It is fairly easy to connect devices to the pins of a microcontroller and then control them with software. I used an Arduino (or Arduino clone) for this project and several prototyping boards (one for each function). Later I designed my own circuit board. These prototyping boards plug into one another in a stack with the Arduino pins replicated on each prototyping board. The picture above shows how this project can be built in stages, one function on each prototyping board. It is suggested that you build the headlight modulator first, install it on the motorcycle and make sure it works properly before moving on to the next module. This type construction also provides the opportunity for you to invent, design and build your own special features.
Step 3: The Headlight Modulator Schematic
It is assumed you will use an Arduino UNO R3 or compatible microcontroller. Use the schematic above to wire the components for the modulator. If you have only one headlight, you can omit the second control circuit (shown in the blue box.) Even if you have two headlights, consider only flashing one. It may seem (and is) overkill to use a microcontroller to wink a headlight. The reason for using the microcontroller is for the simplicity of the electronics and the ability to perform the other module functions. To build the headlight modulator board, you will need the parts shown in the following parts list.
Step 4: The Headlight Modulator Parts List
Step 5: Headlight Modulator Cable Assemblies
These cables are needed for the headlight modulator module. Always use a wire gage than is appropriate to the circuit it serves. It is recommend that each loose wire and unpolarized connector be labeled. This should be done on each cable and both sides of the protoshield circuit board. Since your motorcycle may not use an H4 headlight bulb like mine, it will be necessary for you to:
- Determine the type bulb for your motorcycle
- Order the appropriate headlight cable extender
- Identify which of the three wires are "Ground", "High beam" and "Low beam" and connect accordingly
Step 6: Headlight Modulator Installation
The layout and connections between the components on this board are for the builder to determine. Use one 2-pin right angle header as a connector for the photo resistor cable assembly and another for the power used for supplying 12VDC to the rear caution light. Plug the headlight modulator module onto the Arduino board. The picture above shows how the modulator installs between the motorcycle's headlight and its headlight harness. All power comes from the motorcycles headlight harness.
Step 7: Photo Resistor Installation
Mount the photo resistor cable assembly using one or more cable ties to secure it to the front fork of the motorcycle pointing downward toward the ground.
Step 8: The Software
This Arduino code will operate the headlight modulator, rear caution light and "heads up" speed indicator. While not professional code by any means, it does show examples of timers and interrupts.
The central features of the headlight modulator software are:
- An 8 Hz timer.
- An array of 16 elements that store the status of the headlight for each tick of the timer. (e.g. on 100%, on 20%, on 100%, on 20%, etc.)
- A timer interrupt that reads the status array and transfers that status to the headlight pin on the Arduino.
Each time through the loop, the value of the photo resistor is read. If the value read is greater than the value stored that represents dusk, the headlights continue to modulate.
Rear Caution Light Software
The rear caution light software uses the same 8 Hz timer, timer interrupt and array as the headlight modulator but while the motorcycle’s brake is not applied, the rear caution light is on for 8 ticks and off for 8 ticks. If the brakes are applied, the rear caution light blinks on 1 tick, off 1 tick, etc. until the brake is released.
Speed Indicator Software
The central features of the speed indicator are:
- A 2000 Hz timer.
- A hardware interrupt generated by the hall effect device
- The speed set switch
- The LEDs indicating “too fast”, “too slow” and “on speed”
Each time the front wheel magnet passes by the hall effect device, a counter, driven by the 2000 Hz timer is stored; then the counter is zeroed and the count begins again. When the “speed set” button is pressed, the stored counter becomes the set speed. Thereafter the set speed is compared with the stored counter and the appropriate LED is lit indicating whether the count is less (too fast) more (too slow) or within the tolerance range for on speed calculated by adding or subtracting a percentage of the set speed. If the tolerance were not introduced, the count would have to be exactly the set speed or the blue LED would never be lit.
Step 9: The Rear Caution Light Module
The picture above shows an LED amber caution light attached to the rear seat backrest of my motorcycle. While riding, this light blinks at a steady one second on, one second off rate. When the brakes are applied, this light will flash at the same four times per second like the headlights.
Step 10: The Rear Caution Light Schematic
Use the schematic above to wire the components for the rear caution light. To build the rear caution light board, you will need the parts shown in the following parts list.
Step 11: Rear Caution Light Parts List
Step 12: Rear Caution Light Cable Assembly
Step 13: Caution Light Installation
The layout and connections between the components on this board are for the builder to determine. Use one 2-pin right angle header as a connector for the caution light cable assembly and another for the 12VDC power from the headlight modulator module.
Mount the caution light at the rear of the motorcycle and secure its cable with cable ties. Plug the caution light module into the headlight modulator module, connect the caution light 12VDC jumper from the headlight modulator module to the rear caution light module.
Step 14: The Speed Indicator Module Schematic
Step 15: Speed Indicator Parts List
Step 16: Speed Indicator Hall Effect Cable Assembly
Step 17: Speed Indicator Speed Set Switch and Brake Switch Cable Assembly
Step 18: Speed Indicator "Heads-up LED" Cable Assembly
The LED mounting is left up to the builder.
Step 19: Speed Indicator Installation
The layout and connections between the components on this board are for the builder to determine. Use one 2-pin right angle header as a connector for the speed set cable assembly and another for the brake switch cable. Use a 3-pin right angle header as a connector for the hall effect device cable assembly and a 4-pin for the speed indicator LED cable assembly.
Mount the speed set switch, hall sensor, speed indicator LED, and cable to motorcycle brake switch in accordance with the cable assembly pictures. Plug the speed indicator module into the caution light module.
Step 20: FINAL NOTES
I've been using my headlight modulator/caution light/speed indicator for over a year and it has never failed. Expect a few second delay (while the Arduino boots up) until the headlights come on and begin flashing. While it is impossible to prove a non-event, I seem to be visible to drivers around me. At least 3 people have mentioned and appreciate the amber rear caution light.
We have a be nice policy.
Please be positive and constructive.