Voltage Sensing / Automatic / Programmable Headlight Relay Mod

So here is something that came up on the new 2021 AJP PR7 – Headlight starts only after the engine startup. And no wonder why. All PR7 models do suffer from cold weather starting problems, some say it’s due to lithium batteries… but for some reason the 2021 model has no problem with that, so here is an idea how to make that headlight start only after engine startup, and hopefully that will help AJP start a little bit better by saving a little bit of battery power for the starter motor. That and the rest of the mods like better fuel pump and fuel pump relay mod – should work like a charm!

I’m writing while I’m doing the research and preparations for this mod, as I know that it won’t be an easy modification, so grab yourself a cup of coffee and let’s crack on!

At this point I’m not sure if the headlight has its own relay or all lights hooked to the same relay but…, if it has, well probably the easiest way would be to use something that gives a few seconds for the engine to start before switching on the headlight – a relay with a timer – probably the easiest way to get it done, but who’s up for “easy”!? Ha!

Use of Voltage sensitive Relay

Another idea that I had was to use a voltage sensitive switch/relay, however it made me think, what if the bike has or develops some sort of charging problem and the rider is out in the dark? The bike still could be usable till the battery no longer is able to supply enough power to produce spark, but with no headlight – game over, and potentially dangerous too.

Manual Switch

Really, a manual switch? Easy to forget, and most manufacturers make them light up straight away or after the engine is fired up – as it’s easier to see riders on the road, and with no headlight, more chances that drivers will not notice the rider, so it’s kind of a safety feature too. 

Looking for another solution

Good few hours of tracing all the nice coloured lines on PR7’s schematics, it came to my realisation that there are no wires that would go live only after the engine fired up. I could be wrong there, and the only way to find out would be to check every wire that comes out of the ECU, and I really didn’t want to mess with ECU wiring. Besides, I’m pretty sure there is nothing like it anyway, otherwise AJP would have wired the headlight relay directly to that. Finding nr2 – Relay that switches on the headlight also provides power to the rest of the lights.. duh…

After looking at all possible solutions, I came up with 2 that do not require the rider to switch on and off headlights manually.

  1. Timed relay. Replacing the original relay with a timer, and setting it up so it switches on after 3-6 seconds or so, should give enough time for the fuel pump to prime, and the rider to start the engine. However, the downside of it, that if the rider stops for a second, and has to restart the engine straight away, the fuel pump won’t have to be primed, so there is no need for the wait, however lights will not switch on till those 6 seconds have passed. 
  2. Make a programmable relay? Yeah, that’s an option. Get an empty relay box with terminals, programmable logic and relay base, sandwich it all together so this tiny device fits between original wiring and original relay. Doable? I think so!

How to make a programmable relay!

Ok, so we have 4 wires going into the relay: Yellow, Brown, Black and White Brown . 2 wires (Yellow + and Brown – ) are feed wires for the lights, the other 2 come from ignition via panic button – to power up the relays coil (White Brown +, Black – ).

We can not do much about feed wires, but the other 2 will give us some info about what’s going on with the bike. For example:

  1. If there is no feed, well in that case nothing happens as there will be no power but,
  2. if there is feed of around 12-13V means the bike’s engine is not running, 
  3. if feed is 14v and above – bike is running!

And that’s about all we need.

So… Here is what we can do with programmable logic, write a tiny program that obviously will start with ignition on as programmable logic will be powered by it too and monitor the voltage before engaging headlights relay depending on the voltage it gets.

But here is another problem, what if the stator or regulator rectifier fails, and the engine starts but does not charge the battery? Means no lights, and the way AJP is designed, means no stop lights, no low beam, no high beam – nothing but turn signals! What if it’s dark outside and the rider is just a few miles away from safety again? Can we use another feed from ignition or somewhere to let our programmable logic know that engine is running and we want those lights on? 

  1. We could use a timer again, the only difference from the timer relay would be that if the charging system is ok, headlights switch on straight away after sensing the voltage spike that comes after the engine is started.
  2. Use perhaps one of the engine sensor wires for guidance, but i’m afraid all of them receive power with ignition?
  3. Use speed sensor output, so if something – lights would switch on once the bike is moving, and stays on till ignition is switched off again? perhaps the most power saving option? but extra wires are needed, and I really don’t want that…
  4. Wire up one of the brake pedal or lever switches so it could be used as an indicator for the “heads up”  (or lights on) signal in case…silly idea….
  5. Add an extra switch on the body of the device, that could be triggered easily if the charging system has failed but there is a need for headlights? hmmm….

The Final idea of the Programmable Relay – Almost

Probably overthinking – it’s not like the charging system dies so often! So let’s just make it simple! “power on, measure measure measure, if voltage goes up to over 14v – headlights on, if not – headlights go on after 6-7 seconds after it was powered on anyway . Sounds simple enough, and the difference between this and delay relay – when things work ok, lights should come on straight after the engine is started. 

Using Digispark as a Programmable Relay

So we can use this tiny microcontroller to make this programmable relay for AJP PR7 lights (or not – could be really used in many more applications!)… Its tiny in size, so it’s perfect for what we need and it comes with integrated USB plug – easy to load custom program…, but again because how its designed, there are few things we need to know: 

  1. It can not carry enough current to keep the original relay open.. 
  2. It can be powered by a 12-14 volt supply, but it can not measure it, as it operates on 5v, and 5v is the maximum it can measure or ports will burn out. 
  3. Because it has an on-board USB plug –  it has a 5 second delay before it starts the actual program – bootloader delay.

So what are the solutions?

  1. Separate relay will be needed. Micro relay that microcontroller can keep open as long as it needs to be open. (Something with a 5V coil – as I figured out later!)
  2. Voltage divider will be needed, and for that, thinking of using 2 resistors, possibly 22k (positive side) and 10k ohm (negative side), that should keep voltage well in the range of 5v.
  3. Have no idea… best would be to use an ISP programmer (special programmer for microcontrollers) and there will be no need for a bootloader, but that’s an extra cost no one needs… Will sort that out later…

The Program For Digispark:

This program basically does this: Powers on with Micro Relay switched off for 2 seconds (off, as relay will be connected to NC (Normally Closed) terminals meaning that it lets the power trough – so it actually powers ON the OEM relay, kind of in revers a bit), then powers on the micro relay – so it cuts off the power to the OEM relay, then measures the charging voltage till conditions are met (14.2v), gives 1 second delay, double check the measurements, and if  voltage is still 14.2v or above – switch off relay to provide power to OEM relay, and then 24hour delay kicks in (if bike is kept on for that long thought!). Note that the integrated Red LED on Digispark lights up when the relay is powered up. Lights off -Led on, lights on – Led off kind of thing…

Program Sketch for Automatic lights Relay Based on Digispark

//--------------------------------------//
//------Created By TrailKnights.com-----//
//---------Powered by the WORLD---------//
//--------------2021.10.31--------------//
//-----------Special Thanks To----------//
//----------Bluebie @ github.com--------//
//--------------------------------------//
const int ChargingVoltage = 522; //(Rez:1024 units) 522 ~ 14.2V after voltage divider
void setup() {                
  pinMode(1, OUTPUT);
  pinMode(2, INPUT);
  int VoltageValue = 0;     
//------2 second lights ON at the start here----->                              
  digitalWrite(1, LOW);    
  delay(2000);         
  digitalWrite(1, HIGH);                          
}
void loop() {
  int VoltageValue = analogRead(2);       
    if (VoltageValue >= ChargingVoltage) {
          delay(1000);
            int VoltageValue = analogRead(2);
                if (VoltageValue >= ChargingVoltage) {
                    digitalWrite(1, LOW);              
                    delay(86400000);
                    }
          }
     else {
          digitalWrite(1, HIGH);            
          delay(500);
     }
}

Didn’t go with any of the fancy stuff in case the bike’s charging system is not working, though if anything, it will be very easy to pull this device out, and replug the original plug to the original relay if needed, simple as that… Oh, and why the relay is kind of in reverse, well I thought if something fails, like digispark or whatever, then the relay will constantly provide power to the original relay. Hopefully less wear on the tiny relay too… Simple.

How to program Digispark?

There are many ways, and it all depends on the operating system used. Since I’m Windows user – I used Arduino IDE and there are many many good tutorials on how to install drivers for Digispark, so please google that, try out a few blinker samples, and then load it with the program above.

How to get rid of bootloader 5 second delay on Digispark 

Ok, so I found a solution to go around the 5 second bootloader delay, took some digging around, but thankfully masterminds of the internet came up with a solution – to load a different bootloader to the digispark! Big thanks to Bluebie @ Github and the rest of the team for that!

I’ll Include the files to download at the bottom of the page, but the process is very simple – plug in Digispark to a USB port, preferably same that was used to load the program with Arduino, then take the file “main.hex” and drag and drop on the application file “Micronucleus.exe” and it will do the rest. Windows will show the progress etc, but it will actually finish a few moments after the application closes the window, so give it a few moments. It’s really as simple as 1-2-3. 

How to load a program to digispark with no bootloader delay?

It’s simple, connect GND to P0 on a Digispark but do not plug it in to USB just yet, press Upload on the Arduino Software, plug in Digispark making sure that GND and P0 are well connected, and it will load the program, and will start running it straight away! Easy!

Schematics for Automatic lights Relay Based on Digispark:

Idea is simple:

Take Digispark, stick the relay on it (double sided tape, super glue – whatever) and 

  • Connect Micro Relay coil pins to GND and Pin1 on Digispark (blue and dard blue)
  • 1x 10k Resistor to GND and Pin4 and (blue and green)
  • 1x 22k Resistor to VIN (or 12-14v supply)  and Pin 4 (red and green)

Then connect the empty relay base to digispark and then the socket on top of it.. 

  • Empty relays base pin30 to plugs pin30 and Digispark’s VIN (red)
  • Pin87 to Pin87 (purple)
  • Pin86 to Pin86 and Digispark’s GND (blue)
  • Empty Relay Base Pin85 to Micro Relay COM pin (green)
  • And finally Micro Relays (NC) Normally Close pin to Plugs pin 85 (orange)!

Congratulations! Almost there!

The rest is easy, to make the unit a bit more stable / rugged – I tried to cover it with an empty relay cover that I have left and…I tried to fill it with… hot glue because I ran out of epoxy, but it didn’t work out very well, so in the end I just left it covered in hot glue – at least I can see all the funny LED’s!

Easy peasy project, yet not sure if I would like to do it again!

Parts Used:

  • 1x Digispark.
  • 1x Empty relay box, or not sealed relay but dissected so it’s just terminals left.
  • 1x Relay Female plug with terminals obviously.
  • 1x 10k Ohm Resistor 
  • 1x 22k Ohm Resistor
  • 1x Micro relay with 5v coil (very important), or Arduino 5v relay – p/n JQC-3F
  • Some Thicker and some Thiner wires.

https://github.com/Bluebie

https://startingelectronics.org/tutorials/arduino/digispark/

https://blameitonthegoose.com/remove-5-second-startup-delay-on-digispark/

https://ohmslawcalculator.com/voltage-divider-calculator

https://www.12voltplanet.co.uk/ – Timer Relay

https://www.almsolutions.co.uk/ – Timer Relay

Some Mistakes that I have made in the process!

Oh… Some Mistakes also were made, like soldering a relay with a coil rated for 12v not 5 – the relay was a bit sticky! Then a bit of programming error – giving the relay not constant voltage but pulsating, ha! Then soldered a different relay but forgot to change the program and it failed to switch on as the new one used a bit less power! Then I realised that I cut off the usb plug part of the Digispark, tried to selder some wires, it worked, then it didn’t, so I had to re-solder all the thing all over again… and in the end it came out smaller, better too! 

Explore more!


All AJP PR7 MODS:

OR

AJP PR7 Faults, Fails and Fixes

Recommend this article on:
Scroll to Top