First of all, Arduino is a 5V device, as such to drive the 9-12V LED you will need to use one or more transistors (depending on the LEDs type, number and connection, in series or in parallel).
Also, powering the Arduino from a 9-12V is not the best option: Arduino Uno has an onboard voltage regulator, but goes up to 9V maximum and, unless you go for the original one or a reputable manufacturer (Arduino is an open source project) I wouldn't go above 6V, because non-reputable manufacturers tend to use lower specs devices, like regulators which can get too hot when powered with high voltage: consider that the regulator will have to dissipate any excess energy into heat.
Said that, and knowing nothing more than what you said about the transmission you are describing, I assume the status open
stands for open collector, meaning that it is not going to draw any current, so the following circuit is what you should use:
simulate this circuit – Schematic created using CircuitLab
The diagram assumes you are using digital pins 5 to 8 of your Arduino in INPUT
mode and the Arduino GND is at the same voltage level as the transmission: this might be a big assumption, depending on how you power your Arduino (not from a battery pack, to be clear).
When node A
is in open
state, the voltage on Arduino pin 5
will be 5V, or HIGH as Arduino reports it. When node A
is in low
state then the voltage on Arduino pin 5
will be 0V, or LOW in Arduino lingo.
Resistors from R1
to R4
are there to limit current drawn when the gearbox is in state low
.
UPDATE: I'm assuming the gearbox shares the same ground and operates at 5V,a s the Arduino does. If that's not he case and the gearbox operates at an higher voltage or does not share the same ground, the circuit will not work and you risk damaging the Arduino and/or the gearbox.
You can find a simulation of the above circuit where you can play with the different pins here.
The same occurs for the other pins, so your code will have to scan the 4 pins for their state and update your display accordingly, like:
#define PIN_A 5
#define PIN_B 6
#define PIN_C 7
#define PIN_P 8
void setup() {
pinMode(PIN_A, INPUT);
pinMode(PIN_B, INPUT);
pinMode(PIN_C, INPUT);
pinMode(PIN_P, INPUT);
}
#define PARK 0;
#define DRIVE_1 1;
#define DRIVE_2 2;
#define DRIVE_3 3;
#define OVER_DRIVE 4;
#define REVERSE 5;
#define NEUTRAL 99;
#define UNDEFINED 255;
unsigned int gear = UNDEFINED;
void loop() {
bool A = digitalRead(PIN_A);
bool B = digitalRead(PIN_B);
bool C = digitalRead(PIN_C);
bool P = digitalRead(PIN_P);
if (!A && B && C && !P) {
// Park - A=low, B=open, C=open, P=low
gear = PARK;
} else if (!A && !B && C && P) {
// Reverse - A=low, B=low, C=open, P=open
gear = REVERSE;
} else if (A && !B && C && !P) {
// Neutral - A=open, B=low, C=open, P=low
gear = NEUTRAL;
} else if (A && !B && !C && P) {
// OverDrv - A=open, B=low, C=low, P=open
gear = OVER_DRIVE;
} else if (!A && !B && !C && !P) {
// Drive 3 - A=low, B=low, C=low, P=low
gear = DRIVE_3;
} else if (!A && B && !C && P) {
// Drive 2 - A=low, B=open, C=low, P=open
gear = DRIVE_2;
} else if (A && B && !C && !P) {
// Drive 1 - A=open, B=open, C=low, P=low
gear = DRIVE_1;
} else {
// none of the above
gear = UNDEFINED;
}
// update your display here
}
Please note the above code is NOT the most efficient, but I believe it's easier to read and understand than a version using bitwise operations to identify the possible combinations.