I've done some small UNO based projects several years ago, but nothing recent. So I would appreciate any comments on the feasibility of the following:
I want to modify LED brake lights on a motorcycle trunk box into tail, stop, turn using the two available (nominal +12v) power and ground wires in the connector. The bike has separate turn and brake lights, the box has one strip of red LEDs on each side.
I propose to connect the + to the (always on) tail light supply instead of the brake light (intermittent) supply. I would use this to provide power to a Nano IOT mounted on the bike itself and a second mounted in the trunk, as well as power to the two LED strips, one on each side of the box.
The first Nano would have 3 inputs, one from the brake light circuit, one from the left turn and one from the right turn. The nominal 12v signals from the bike's circuit would be limited to 3.3v by three terminal regulators (LD1117V33) (and maybe a pull-down resistor?) at the inputs.
The second Nano would have two outputs, one to each side, controlling enhancement mode MOSFETS to power the LED strips.
The two would have to automatically pair on power up. Ideally there would be fault tolerance to ensure a pairing if the trunk was attached after the bike ignition was turned on, although this would be a rare situation.
The sketch on the first Nano would (after setting up the BT connection, etc.) consist of an infinite loop along the lines of (I realize my syntax is all wrong, I am way out of practice, this is just to illustrate the logic flow):
// LT is left turn input, RT is right turn input, BR is brake input.
// LTSTATUS, etc. is the calculated status of the left turn signal, etc.
// STATUS is the sum total and final output to the second Nano IOT.
// Status values are such that the final STATUS value must be unique for each condition.
Loop {
// brake light is easy, it's either on or off
if (BR = true) {BRSTATUS == 1}
else {BRSTATUS = = 0}
// because the bike has separate turn and brake lights, I need to allow time to determine if the signal has been turned off or is just between flashes
If LT = (true && TIMER0 = false)
{
// code to start first 1.5 second timer goes here. To Be Determined.
}
If LT = (true){
if LT = (true) {
then LTSTATUS == 2}
else {LTSTATUS == 4}
else LTSTATUS == 0}
}
// similar for the right turn signal
If (RT = true && TIMER1 == false)
{
// code to start second 1.5 second timer goes here
}
If TIMER1 = (true)
then {
if RT = (true)
then {RTSTATUS = 6}
else {RTSTATUS =8}
}
else {RTSTATUS = 0}
STATUS = (BRSTATUS + LTSTATUS + RTSTATUS)
// special case to handle 4-way flashers
if (LTSTATUS = 2 && RTSTATUS = 6)
then {STATUS ==1}
if (LTSTATUS =4 && RTSTATUS =8)
then {STATUS == 0}
// send STATUS to second Nano via bluetooth somehow -- still researching BLE vs Classic
}
Code for second Nano inside trunk box:
//again, set up BT connection, declare variables, etc.
//
Loop {
// normal running, no brakes or turn, just tail. Use PWM to dim both sides
if (STATUS == 0) {analogwrite(LEFTPIN, 125 && RIGHTPIN, 125}
// brakes, no turn. Both sides on full output
if (STATUS == 1) {analogwrite(LEFTPIN, 255 && RIGHTPIN, 255}
// left turn illuminated, no brakes. left side on full, right at tail level
if (STATUS == 2) {analogwrite(LEFTPIN, 255 && RIGHTPIN, 125}
// left turn illuminated, brakes on. Both sides on full
if (STATUS == 3) {analogwrite(LEFTPIN, 255 && RIGHTPIN, 255}
// left turn on dim part of flash sequence, no brakes. Both sides at tail level.
if (STATUS == 4) {analogwrite(LEFTPIN, 125 && RIGHTPIN, 125}
// left turn on dim part of flash sequence, brakes on. Left side dim, right side on full.
if (STATUS == 5) {analogwrite(LEFTPIN, 125 && RIGHTPIN, 255}
// right turn illuminated, no brakes
if (STATUS == 6) {analogwrite(LEFTPIN, 125 && RIGHTPIN, 255}
// right turn illuminated, brakes on
if (STATUS == 7) {analogwrite(LEFTPIN, 255 && RIGHTPIN, 255}
// right turn on dim part of flash sequence, brakes off
if (STATUS == 8) {analogwrite(LEFTPIN, 125 && RIGHTPIN, 125}
// right turn on dim part of flash sequence, brakes on
if (STATUS == 9) {analogwrite(LEFTPIN, 125 && RIGHTPIN, 255}
}
Comments? Suggestions?
