So this is a lot to explain. Also my first arduino project, and its a big one. Essentially i swapped the transfer case(controls the four wheel drive) in my truck to a completely different one. Problem is they're both electronically controlled and the new t-case wont work with the control module in the truck.
Basically there is a motor on the t-case that shifts it into 2wd, 4wd, 4 low, and neutral depending on the motors position. Motor position is monitored via a 3 wire potentiometer built in.
Im monitoring the 4 ground-trigger leds on the control panel in the truck to determine the mode it needs to be in using the digital pins and pullup function. This part works perfectly.
Im moving the motor via two relays that can rotate the motor either way. They're connected to pins 2 and 3. It is very important that once the motor is in the correct position that it doesn't try to move even if the potentiometer value changes. It should only move once when the mode selection(led's) change, then stay put unless a new mode is selected.
Problem I'm having now is the relays aren't doing anything. They work when manually triggered but there's no output to trigger them from the arduino.
The second problem im having is the motor will move when it isnt supposed to when the potentiometer value is changed. It should stay in the while loop under //hold until the selection(leds) change right?
I hope any of this made sense lol.
// C++ code
//
int twohled = 0;
int fourhled = 0;
int fourlled = 0;
int nled = 0;
int pot = 0;
void setup()
{
delay(3000);
pinMode(13, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop()
{
twohled = digitalRead(13);
fourhled = digitalRead(12);
fourlled = digitalRead(11);
nled = digitalRead(10);
//TWO HIGH MODE
if (twohled == 0 && (fourhled == 1 && (fourlled == 1 && nled == 1))) {
Serial.println("2HI");
//add analogue read
pot = analogRead(A0);
//Below
if (pot < 535) {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
Serial.println(pot);
while (pot < 535) {
pot = analogRead(A0);
Serial.println(pot);
}
}
//Above
if (pot > 555) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
Serial.println(pot);
while (pot > 555) {
pot = analogRead(A0);
Serial.println(pot);
}
}
//STOP
digitalWrite(2, LOW);
digitalWrite(3, LOW);
//add analogue read
pot = analogRead(A0);
Serial.println(pot);
//HOLD
while (twohled == 0 && (fourhled == 1 && (fourlled == 1 && nled == 1))) {
delay(1000);
pot = analogRead(A0);
Serial.print("2HL Pot:");
Serial.println(pot);
twohled = digitalRead(13);
fourhled = digitalRead(12);
fourlled = digitalRead(11);
nled = digitalRead(10);
}
}
//FOUR HIGH MODE
if (twohled == 1 && (fourhled == 0 && (fourlled == 1 && nled == 1))) {
Serial.println("4HI");
//add analogue read
pot = analogRead(A0);
if (pot < 383) {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
Serial.println(pot);
while (pot < 383) {
pot = analogRead(A0);
Serial.println(pot);
}
}
//Above
if (pot > 403) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
Serial.println(pot);
while (pot > 403) {
pot = analogRead(A0);
Serial.println(pot);
}
}
//STOP
digitalWrite(2, LOW);
digitalWrite(3, LOW);
pot = analogRead(A0);
Serial.println(pot);
//HOLD
while (twohled == 1 && (fourhled == 0 && (fourlled == 1 && nled == 1))) {
delay(1000);
pot = analogRead(A0);
Serial.print("4HIL Pot:");
Serial.println(pot);
twohled = digitalRead(13);
fourhled = digitalRead(12);
fourlled = digitalRead(11);
nled = digitalRead(10);
}
}
//FOUR LOW MODE
if (twohled == 1 && (fourhled == 1 && (fourlled == 0 && nled == 1))) {
Serial.println("4LO");
//add analogue read
pot = analogRead(A0);
//Below
if (pot < 760) {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
while (pot < 760) {
pot = analogRead(A0);
Serial.println(pot);
}
}
//Above
if (pot > 780) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
while (pot > 780) {
pot = analogRead(A0);
Serial.println(pot);
}
}
//STOP
digitalWrite(2, LOW);
digitalWrite(3, LOW);
pot = analogRead(A0);
Serial.println(pot);
//HOLD
while (twohled == 1 && (fourhled == 1 && (fourlled == 0 && nled == 1))) {
delay(1000);
pot = analogRead(A0);
Serial.print("4LL Pot:");
Serial.println(pot);
twohled = digitalRead(13);
fourhled = digitalRead(12);
fourlled = digitalRead(11);
nled = digitalRead(10);
}
}
//NEUTRAL MODE
if (twohled == 1 && (fourhled == 1 && (fourlled == 1 && nled == 0))) {
Serial.println("NEUTRAL");
//add analogue read
pot = analogRead(A0);
//Below
if (pot < 694) {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
while (pot < 694) {
pot = analogRead(A0);
Serial.println(pot);
}
}
//Above
if (pot > 714) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
while (pot > 714) {
pot = analogRead(A0);
Serial.println(pot);
}
}
//STOP
digitalWrite(2, LOW);
digitalWrite(3, LOW);
//add analogue read
pot = analogRead(A0);
Serial.println(pot);
//HOLD
while (twohled == 1 && (fourhled == 1 && (fourlled == 0 && nled == 1))) {
delay(1000);
pot = analogRead(A0);
Serial.print("NEUTRAL Pot:");
Serial.println(pot);
twohled = digitalRead(13);
fourhled = digitalRead(12);
fourlled = digitalRead(11);
nled = digitalRead(10);
}
}
delay(10);
// Delay a little bit to improve simulation performance
}



