Help me understand this diagram and setup

Hi all, I have 2 questions I am hoping I can get some guidance on.

I picked up the below cruise control button assembly that I want to repurpose and connect to a Uno Minima with 4 relay shield to trigger stuff connected to the relays, but the wiring has 3 wires instead of the usual 2 that I have come across when researching how to do this.

The Mazda schematic below shows the 3 wires are power & signal to the factory cruise module and ground.
With the Uno, my understanding is I only need to utilise the 2 wires running through the buttons with a pull up to 5v and just ignore the ground wire from the buttons?
What would the ground wire be providing in this set up (other than a short?) and is it something that should be utilised with the Uno?

I did hook it up to the Uno as per the diagram below with a 4.7kohm resistor between A0 and 5V.
I measured the voltage in the serial monitor for each button and used ChatGPT to write my code (sorry this is my first time paying with Arduinos so I don't know code but I am learning) and it worked a retreat. Pressing Set triggers relay 1, Resume triggers relay 2 and Cancel triggers relay 3.

However the trigger voltages are really low values which leads to my next question regarding pull up resistors:

Viewing the voltages on the serial monitor, with no button pressed I read 4.88v. thats good.
However the voltage when each button is pressed is:
Set: 0.2v
Cancel: 0.41v
Resume: 0.07v

These feel like very very low voltages. As I am unable to change the resistors inside the button assembly, is the only way to get higher trigger voltages is to use a lower value pull up resistor?Something like a 1kohm or even 680ohm however this then starts putting unnecessary load on the analog pin?

Is this just how it is or have I got this all wrong?

Thanks :slight_smile:

Here is some photos of the buttons:

Why do you need higher voltages? Resume is basically 0V and Cancel is 2x Set so they are spaced far enough apart.

Your diagram shows "earth unused", but if you want the Arduino to do anything you must have the "earth" connected to the Arduino ground pin.

I had read to avoid RF interference (especailly in a motor vehicle environment) you should keep analog pin voltage above 2v. Pretty new to all this so happy to take on any advice.

Hi Paul, can you elaborate a bit please. If I connect the "unused" wire to Uno GND pin, where should I connect the other 2 wires from the switch assembly?

Resistor R1 is not acting as a pullup resistor.
It is forming a voltage divider which is what is needed.
Your low voltage reading can be improved by reversing the 5v and grd connections.
Changing R1 to 1kΩ will give a larger spread between readings.

With these changes readings should be:

resume: ~4.68v
set: ~4.20v
cancel: ~3.52v


The value of Resistor R1 controls 2 things.
1: voltage spread between the readings
2: Power consumption
Your 4.7kΩ resistor give ~0.17v spread and uses ~1mA current.
A 1kΩ resistor gives ~1.15v spread and uses ~4mA current.

Thank you Hutkikz, I just learnt what a voltage divider is! :smiley:
I will pick up a 1k ohm resistor over the weekend and hook it up as you have suggested.

From what I understand now, wiring how you have suggested will also mean there will be be zero or very near to zero when no buttons are pressed?

And the 3rd wire from the switch assembly is irrelevant and unused for this purpose? (I assume the Mazda ecu did something special with it which isn't necessary for my intended use).

Yes, when no buttons are pushed R1 will act as a pull down resistor and holds the voltage at/near zero.

From what you posted I cannot tell how it was originally used. It is not needed in this case.

Well, right now, your "cruise control switch" is completely out of the circuit UNLESS one of the other switches is closed. The cruise control switch is completely useless.

1 Like

Huge thank you to Hutkikz!! I picked up a 1kohm resistor over the weekend and it works exactly how described.
This is how it is wired now:

I have also been contemplating how to utilise the extra wire through the clock spring since it is already there, rather than it just swinging in the wind so to speak, so had the thought of adding another 1kohm resistor between it and "BR" to create an alternate lower V circuit effectively bypassing the on/off switch.

Now when the switch is on it bypasses the extra resistor and reads:
Resume: 4.68v
Set: 4.17v
Cancel 3.52v

When the switch is Off it reads:
Resume: 2.41
Set: 2.27
Cancel 2.07v
Which i I may use to control my pioneer headunit.

So On/Off switch On triggers the shield relays, switch Off is headunit next track, volume etc if this dual function is possible with a Uno. I'm learning how to code so this will be a good learning experience.
And if I can't get that to work at least I can now trigger the relays like the original plan.

This is the code ChaptGPT spat out for triggering the relays:

const int analogPin = A0; // Analog pin connected to the button
const float targetVoltage1 = 4.17; // Target voltage for relay 1 trigger
const float targetVoltage2 = 4.68; // Target voltage for relay 2 trigger
const float targetVoltage3 = 3.52; // Target voltage for relay 3 trigger
const float threshold1 = 0.1; // Threshold voltage for relay 1
const float threshold2 = 0.1; // Threshold voltage for relay 2
const float threshold3 = 0.1; // Threshold voltage for relay 3

const int relayPin1 = 4; // Digital pin connected to relay 1
const int relayPin2 = 7; // Digital pin connected to relay 2
const int relayPin3 = 8; // Digital pin connected to relay 3

void setup() {
  Serial.begin(9600);
  pinMode(relayPin1, OUTPUT); // Set relay 1 pin as output
  pinMode(relayPin2, OUTPUT); // Set relay 2 pin as output
  pinMode(relayPin3, OUTPUT); // Set relay 3 pin as output
}

void loop() {
  // Read the voltage from the analog pin
  int buttonVoltage = analogRead(analogPin);

  // Convert the analog value to voltage (5V reference)
  float voltage = buttonVoltage * (5.0 / 1023.0);

  // Check if the voltage is within the threshold range around the target voltage for relay 1
  if (voltage >= targetVoltage1 - threshold1 && voltage <= targetVoltage1 + threshold1) {
    digitalWrite(relayPin1, HIGH); // Activate relay 1
    Serial.println("Relay 1 activated!");
  } else {
    digitalWrite(relayPin1, LOW); // Deactivate relay 1
  }

  // Check if the voltage is within the threshold range around the target voltage for relay 2
  if (voltage >= targetVoltage2 - threshold2 && voltage <= targetVoltage2 + threshold2) {
    digitalWrite(relayPin2, HIGH); // Activate relay 2
    Serial.println("Relay 2 activated!");
  } else {
    digitalWrite(relayPin2, LOW); // Deactivate relay 2
  }

  // Check if the voltage is within the threshold range around the target voltage for relay 3
  if (voltage >= targetVoltage3 - threshold3 && voltage <= targetVoltage3 + threshold3) {
    digitalWrite(relayPin3, HIGH); // Activate relay 3
    Serial.println("Relay 3 activated!");
  } else {
    digitalWrite(relayPin3, LOW); // Deactivate relay 3
  }

  delay(100); // Add a small delay for stability
}

A couple of tips.

#1:
Why convert the analog reading to voltage?
Floating point math is super slow on a Uno/Nano/Mega and is best avoided.
by using the analogRead directly you save the time it takes to convert it and integer math is Much faster.

#2:
Analog readings are not very stable and will vary slightly.
Lets say that a voltage of 4.68v should give a analogRead of 950(that's a guess).
In reality it is likely to vary somewhere around +/- 5 so it could read anywhere from 945 - 955. To account for that is easy.

  if (reading > 960) {
    // 5v = no buttons pushed
  }
  else if (reading > 940) {
    // We already know from the first "if" that the reading is not higher than 960
    // 4.68v = resume button pushed
  }
  else if(reading > 900) {
    // We already know from the previous "else if" that the reading is not higher than 940
1 Like

Very good points. Essentially because I had never seen Arduino code before, I put into ChatGPT that I have "this" wired like "that" and I want it to do "X" - write me code. And this is what it spat out.
Now I'm actually looking and learning how code works and how you have suggested is much better.
Thank you so much again for your tips and advice. It's put me on the right path.

Now I'm off to learn how to write code properly :smiley:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.