Ford Transit USA Forum banner

WIRING: If I had it to do over again.....

9387 Views 68 Replies 19 Participants Last post by  TonyD-ROAMR
I'd use a ESP32 and a 8 channel relay board (or maybe a 16) and wire everything off that. I'd mount that beside the new house fusebox. I'd use momentary "normally open" switches to trigger the ESP based upon a "change of state" of the switch. I'd write the code so the ESP32 Inputs triggered by a ground signal. That way every switch would only need one very small wire to it from the ESP because I'd ground each one to the body locally to supply the ground. I could have used as many switches as I wanted to for every single device. If I would have done that, I could have controlled everything from my phone over a WiFi access point on the ESP and even used timers in the code if I chose to. Temperature sensors and photocells could have been implemented as well. Manual switches could have been grouped together and wired using just one cat 5 wire allowing 8 switches to be wired with just one small cat 5 wire. The sky would have been the limit and the costs would have been far less. There would have been no need for 3 way or 4 way switches and all that 14 gauge wire. Better control, centrally located components, less wiring, less voltage drop and less chance for a malfunction! The boards are only a few bucks and the 32's are inexpensive. Hindsight is 20/20 I guess!

See less See more
  • Like
Reactions: 5
21 - 40 of 69 Posts
Not sure how this will post but here we go:
FEEL FREE TO USE AND/OR MODIFY AS YOU DESIRE
Copy and past text below into Arduino
//*

// Designed for ESP32 other boards may not operate
// Use momentary normally open switches / Light duty switches are all that is needed.
// Each press of a button changes the relays state to "off" or "on"
// Changing GPIO pin numbers is not recommended
// Do not use a solid state relay board to switch DC
// Connect as many button panels as you wish to every GPIO pin can be connected to more than once
//Ground each switch back to the ESP. I'd do it through the van body.
// One ground is all that's required for all the switches in each panel location.
//The ESP must be grounded to the van body

// Buttons should be connected to GPIO pins listed below
const int ButtonOne = 27; //wire color: Orange
const int ButtonTwo = 1; //Wire Color: Orange White
const int ButtonThree = 3; //Wire Color: Blue
const int ButtonFour = 5; //Wire Color: Blue / White
const int ButtonFive = 13; //Wire Color: Green
const int ButtonSix = 14; //Wire Color: Green / White
const int ButtonSeven = 23; //Wire Color: Brown
const int ButtonEight = 26; //Wire Color: Brown / White

// Relays should be connected to GPIO pin listed below
const int RelayOne = 2;
const int RelayTwo = 4;
const int RelayThree = 12;
const int RelayFour = 16;
const int RelayFive = 17;
const int RelaySix = 18;
const int RelaySeven = 19;
const int RelayEight = 25;

int ButtonOneState = 0;
int ButtonTwoState = 0;
int ButtonThreeState = 0;
int ButtonFourState = 0;
int ButtonFiveState = 0;
int ButtonSixState = 0;
int ButtonSevenState = 0;
int ButtonEightState = 0;

int LastButtonOneState = 0;
int LastButtonTwoState = 0;
int LastButtonThreeState = 0;
int LastButtonFourState = 0;
int LastButtonFiveState = 0;
int LastButtonSixState = 0;
int LastButtonSevenState = 0;
int LastButtonEightState = 0;

int ButtonOnePushCounter = 0;
int ButtonTwoPushCounter = 0;
int ButtonThreePushCounter = 0;
int ButtonFourPushCounter = 0;
int ButtonFivePushCounter = 0;
int ButtonSixPushCounter = 0;
int ButtonSevenPushCounter = 0;
int ButtonEightPushCounter = 0;

int DeBounceTime = 20; // used to de-bounce the pushbuttons

void setup() {
pinMode(ButtonOne, INPUT_PULLUP); // sets pins as input pullups
pinMode(ButtonTwo, INPUT_PULLUP);
pinMode(ButtonThree, INPUT_PULLUP);
pinMode(ButtonFour, INPUT_PULLUP);
pinMode(ButtonFive, INPUT_PULLUP);
pinMode(ButtonSix, INPUT_PULLUP);
pinMode(ButtonSeven, INPUT_PULLUP);
pinMode(ButtonEight, INPUT_PULLUP);

pinMode(RelayOne, OUTPUT); // sets relay pins as outputs
pinMode(RelayTwo, OUTPUT);
pinMode(RelayThree, OUTPUT);
pinMode(RelayFour, OUTPUT);
pinMode(RelayFive, OUTPUT);
pinMode(RelaySix, OUTPUT);
pinMode(RelaySeven, OUTPUT);
pinMode(RelayEight, OUTPUT);

digitalWrite (RelayOne, LOW); // sets each relay to off when ESP boots
digitalWrite (RelayTwo, LOW);
digitalWrite (RelayThree, LOW);
digitalWrite (RelayFour, LOW);
digitalWrite (RelayFive, LOW);
digitalWrite (RelaySix, LOW);
digitalWrite (RelaySeven, LOW);
digitalWrite (RelayEight, LOW);

delay(1000); //A little time for thinking
}
void loop() {
ButtonOneState = digitalRead(ButtonOne); // reads state of button
if (ButtonOneState != LastButtonOneState) {
if (ButtonOneState == HIGH) {
ButtonOnePushCounter++;
}
else {}
}
delay (DeBounceTime);
LastButtonOneState = ButtonOneState;
if (ButtonOnePushCounter % 2 == 0) {
digitalWrite(RelayOne, HIGH);
} else {
digitalWrite(RelayOne, LOW);
}

ButtonTwoState = digitalRead(ButtonTwo);
if (ButtonTwoState != LastButtonTwoState) {
if (ButtonTwoState == HIGH) {
ButtonTwoPushCounter++;
}
else {}
}
delay (DeBounceTime);
LastButtonTwoState = ButtonTwoState;
if (ButtonTwoPushCounter % 2 == 0) {
digitalWrite(RelayTwo, HIGH);
} else {
digitalWrite(RelayTwo, LOW);
}

ButtonThreeState = digitalRead(ButtonThree);
if (ButtonThreeState != LastButtonThreeState) {
if (ButtonThreeState == HIGH) {
ButtonThreePushCounter++;
}
else {}
}
delay (DeBounceTime);
LastButtonThreeState = ButtonThreeState;
if (ButtonThreePushCounter % 2 == 0) {
digitalWrite(RelayThree, HIGH);
} else {
digitalWrite(RelayThree, LOW);
}

ButtonFourState = digitalRead(ButtonFour);
if (ButtonFourState != LastButtonFourState) {
if (ButtonFourState == HIGH) {
ButtonFourPushCounter++;
}
else {}
}
delay (DeBounceTime);
LastButtonFourState = ButtonFourState;
if (ButtonFourPushCounter % 2 == 0) {
digitalWrite(RelayFour, HIGH);
} else {
digitalWrite(RelayFour, LOW);
}
ButtonFiveState = digitalRead(ButtonFive);
if (ButtonFiveState != LastButtonFiveState) {
if (ButtonFiveState == HIGH) {
ButtonFivePushCounter++;
}
else {}
}
delay (DeBounceTime);
LastButtonFiveState = ButtonFiveState;
if (ButtonFivePushCounter % 2 == 0) {
digitalWrite(RelayFive, HIGH);
} else {
digitalWrite(RelayFive, LOW);
}
ButtonSixState = digitalRead(ButtonSix);
if (ButtonSixState != LastButtonSixState) {
if (ButtonSixState == HIGH) {
ButtonSixPushCounter++;
}
else {}
}
delay (DeBounceTime);
LastButtonSixState = ButtonSixState;
if (ButtonSixPushCounter % 2 == 0) {
digitalWrite(RelaySix, HIGH);
} else {
digitalWrite(RelaySix, LOW);
}
ButtonSevenState = digitalRead(ButtonSeven);
if (ButtonSevenState != LastButtonSevenState) {
if (ButtonSevenState == HIGH) {
ButtonSevenPushCounter++;
}
else {}
}
delay (DeBounceTime);
LastButtonSevenState = ButtonSevenState;
if (ButtonSevenPushCounter % 2 == 0) {
digitalWrite(RelaySeven, HIGH);
} else {
digitalWrite(RelaySeven, LOW);
}

ButtonEightState = digitalRead(ButtonEight);
if (ButtonEightState != LastButtonEightState) {
if (ButtonEightState == HIGH) {
ButtonEightPushCounter++;
}
else {}
}
delay (DeBounceTime);
LastButtonEightState = ButtonEightState;
if (ButtonEightPushCounter % 2 == 0) {
digitalWrite(RelayEight, HIGH);
} else {
digitalWrite(RelayEight, LOW);
}
}
See less See more
  • Like
Reactions: 1
Not sure how this will post but here we go:
FEEL FREE TO USE AND/OR MODIFY AS YOU DESIRE
Copy and past text below into Arduino
WOW thank you. No way I would have ever been able to come up with that one on my own!
Here's a quick diagram. In my setup, the 3.3V is just a Teensy pin going to HIGH. If the load is 24V, then you could get away with just using the mosfet. I probably wouldn't put more than half an amp through one without a heatsink (they support 49A).
Perfect Thank you! I may try to piece this together. I would just be sending a signal so I suspect it should be lower than .5A

Given my (lack of ) skills, I suspect that I may take the advice of LostInWoods and just use a 3.3 or 5V relay to then trigger the higher amp 12V relay:

If this relay (10A/30VDC) will suffice for you, great, else you could use the relay to trigger the coil of another relay running off 12V with contacts rated for whatever your load is.
I am confused. How would I use a ESP32 and a relay board? What would I control?
I'm late to the party, but I just finished installing roof rails on my van and I now want exterior lights mounted up high. I would like to control them all from the drivers seat so we can scope out what were are parking next to late at night when we pull in. I'd like to control the slider side light from near the slider door. Same with the light over the rear doors.

And then maybe turn them all on and off from bed. And since they're going to be bright, be able to PWM dim them from at least a couple places. And maybe get them to strobe if someone comes knocking on the door in the middle of the night (if you don't disorient them, at least annoy them).

Or I suppose I could just get a crap ton of three way switches and call it good.
Given my (lack of ) skills, I suspect that I may take the advice of LostInWoods and just use a 3.3 or 5V relay to then trigger the higher amp 12V relay:
That's a good idea. You could use Mosfets if you wanted to but the relay boards will handle the higher current, keep it somewhat simple and not have to worry about heating up mosfets. The draw back is not being able to dim the lights using a PWM signal which could be done with mosfets using (millis) as the timer. If you tried it with relays, they'd buzz and not last very long. The (delay) function sucks for most advanced coding. Millis is better.

You could also delete anything in the code that mentioned "eight" and use one of the cat wires as a ground return to the ESP. That would limit you to 7 switches with each cat wire but eliminate the need to use the body as a return ground and depend of Ford!

Also if you wanted indicator lights above each switch, you could run another cat to the switch panel from the outputs on the ESP. If the corresponding output was HIGH the LED would be lit.

I'd would have put three panels in my van. One near the bed. One near the kitchen and one up in the cab.

One switch could also be used to ground the RST (reset) pin on the ESP32. The way I wrote the code, if the ESP resets, everything goes LOW so it could be used as a "Master all off". Sometimes a microprocessor gets a little "sideways" and needs a reset or a smack in the forehead! That "Master Reset button would reset any malfunction that ever occurred. If you have something you want to be on when a reset occurs, just change the line to HIGH in "void setup".

Have fun!
See less See more
  • Like
Reactions: 1
......since they're going to be bright, be able to PWM dim them from at least a couple places.
Not going to happen with relays. You'd need mosfets.

And maybe get them to strobe if someone comes knocking on the door in the middle of the night......
Relays would do that for a limited duration. They're mechanical so they'll give up the ghost sooner or later if operated that way. If somebody knocks at 3AM, just turn on the lights and stick the 9 out the door.
  • Like
Reactions: 1
  • Like
Reactions: 1
BTW: If you run out of input pins, you can use the old trick of using different value resistors between the switches and ground, which can be wire-OR'd together into the same pin and sorted out by measuring the voltages.
  • Like
Reactions: 1
BTW: If you run out of input pins, you can use the old trick of using different values resistors between the switches and ground, which can be wire-OR'd together into the same pin and sorted out by measuring the voltages.
I learned something! Thanks

HOW TO
I think it's awesome to see a micro-controller discussion happening here. I'm using one to manage my LiFePo4 battery heat pads, and another one to manage the cooling fans for my wifi/cellular boosting hardware. Lighting and other circuits (for me) was too simple to wedge into a digital space. I could see it for a larger build/rig.
  • Like
Reactions: 1
Not to detract from @tngw1500se's solution in the least (it appeals to my nerd senses enough to go get the parts and faff about with them), but merely for the variety's sake: Motobrain is also a bit interesting.
Motobrain is also a bit interesting.
I'd feel better if the website had at least one actual photograph of the product, rather than just 3d renderings.
  • Like
Reactions: 1
I'd feel better if the website had at least one actual photograph of the product, rather than just 3d renderings.
Hrmm... Fair point. I have an older version of their unit, got it based on the review like this one: Motobrain Power Distribution System Review. Not sure why they don't have real photos.
@tngw1500se
I am not sure if I should thank your or curse you on this one, I read this and it got my mind spinning and have been chasing it since. I really like the idea. I am fully down the rabbit hole. I have never done any programming like this before so it has been a really steep curve. I have a couple boards now and am learning as I go but was able to get the multiple buttons to work with one LED which is a bit of a miracle really for me. I have a question hopefully you can answer. I have been building on a breadboard for testing and the tutorials i have found all have me using a resistor with the LED and switch. My understanding is that this is to keep the power down so as not to burn out any of the pins. My question is will I need to use resistors when I actually wire in the relays or will the relays themselves provide the needed resistance?
Probably a very basic question, but learning on the fly here and any advice would be greatly appreciated.
See less See more
  • Like
Reactions: 1
@tngw1500se
I am not sure if I should thank your or curse you on this one,
LOL! If you don't blow up a few boards you're not learning anything.

Just use a relay board that has opto-couplers. Most relay boards have them built in.

Expensive example: LINK Better price can be found.

It isolates your 3.3 or 5 volt electronics from the 12 volt stuff. No need for resistors. DON'T USE A STANDARD AUTOMOTIVE RELAY. Just make sure the board you pick is triggered by the voltage you're using. ESP's output 3.3 volts and other micro-controlers output 5 volts. NOTE : The board may require 5 volts to operate but wants to see 3.3 as a trigger(s). If you try to trigger a relay board that wants to see a 5 volt trigger signal with 3.3 volts you'll be disappointed in the result. I'm guessing you're using resistors because you're testing with LED's. The relay board doesn't need those resistors on the triggers.

NOTE: Solid state relays might sound good but they don't like to switch DC voltage. They switch on (or off) when the AC wave form is at the zero cross over point. (See below) DC current has no cross over point. If you're switching AC they're a good choice.




NOTE: If you want more inputs or outputs than your controller has pins for, use a "shift register" or two, or three or four!!!
Now you'll really curse me ;)
See less See more
NOTE: Solid state relays might sound good but they don't like to switch DC voltage. They switch on (or off) when the AC wave form is at the zero cross over point. (See below) DC current has no cross over point. If you're switching AC they're a good choice.
When I installed my vehicle 12 volt powered inverter I wanted to delay the inverter start so inverter would start after the engine was running. I uses one of the user defined switches for the engine run signal. The user defined switches are powered in the accessary key position before engine starting so without a delay the inverter would have started before the engine started.

Bought a solid state DC time delay relay. Purchased relay did not delay the inverter start. Thought relay was defective so got a replacement relay. Second relay also did not delay the signal. Had to replace the relay with a relay with mechanical contacts. The third relay with contacts worked. A solid state relay used on 12 volt DC has enough leakage that the 12 volt signal to start the inverter was present through the relay with or without the delay.
See less See more
NOTE: If you want more inputs or outputs than your controller has pins for, use a "shift register" or two, or three or four!!!
Now you'll really curse me ;)
I've been exploring the easybutton arduino library for this. You can do short/long button presses or multiple button presses to control different functions using code rather than adding resistors or whatever which is nice. For me mostly I'm planning a short press to turn lights on full and longer press for dimming.

Just use a relay board that has opto-couplers. Most relay boards have them built in.
I like these because they have screw terminals - nice easy connection!
AmazonSmile: HiLetgo 5V 8 Channel Relay Module with OPTO-Isolated Support High and Low Level Trigger : Industrial & Scientific
@@tngw1500se
I am not sure if I should thank your or curse you on this one,
🤣

Same here. I kinda took the ball and ran with it on this one. In addition to controlling lighting I've so far added 5 ds18b20 temp sensors that'll control various tank,pipe and battery warming pads and I'm now researching adding an IR blaster to try to control my Maxxair 7500 fan. I'm also dabbling with getting an MQ-7 CO sensor that will trigger the maxxair fan and also shut down my auxiliary gasoline heater if it detects CO in the van. Not sure if I'll pull off the MQ-7 and IR stuff but it's fun toying with it!
🤣

Same here. I kinda took the ball and ran with it on this one. In addition to controlling lighting I've so far added 5 ds18b20 temp sensors that'll control various tank,pipe and battery warming pads and I'm now researching adding an IR blaster to try to control my Maxxair 7500 fan. I'm also dabbling with getting an MQ-7 CO sensor that will trigger the maxxair fan and also shut down my auxiliary gasoline heater if it detects CO in the van. Not sure if I'll pull off the MQ-7 and IR stuff but it's fun toying with it!
Sounds ambitious what are you using for a controller?

Why no cameras, GPS and servos to control the steering and brakes? Limited on GPIO's?

Some advice:

#1: Cut your hair really short so it's hard to get a good hold on it. Ripping out roots causes real damage.

#2: When editing a "working" code, the first thing I do is type a line that says:
"//Started editing a working code HERE on 11/11/2021 10:14AM"
That way if things go south, you can click "undo" and you'll know when to stop "undoing" when you get back to that line. If you're happy with the changes, you can delete the line or just leave it since it's a "//" line.

#3: Store your code on a USB flash drive or a cloud based storage. Don't depend on Bill Gates and one hard-drive to keep it for you.

#4: Program more than one micro-controller so you have a second working device. When you accidentally touch a connection with a hot or ground and the smoke comes out you'll have a spare.

KEEP US INFORMED ON PROGRESS!

Currently I'm busy with painting since my wife found the nails!!! She can't decide where she wants the pictures so she moves them a lot. (##@%**&^%$#) I thinking a 5 gallon bucket of drywall mud would be a perfect wedding present for most couples or just buy houses with metal walls and magnets on the pictures!!!
See less See more
I have been looking for ways to make wiring lighting easier.

Especially as it applies to wanting on / off switches in multiple locations and lights in multiple locations.

The wiring can become complex very quickly.

It seems like the concept is here - but the implementation - at least initially - seems complex to me.

I have not written code since Fortran in 1984, so perhaps that is why.

Might need some help to make all of this work.

Do not want to use phone / application to turn on lights - strictly with switches.
See less See more
21 - 40 of 69 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top