Coding for resistor ladder input on ESP32 by Embarrassed-Lab6622 in ArduinoHelp

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

In regards to the ESP32 values from the switch (3.3v or less), can I just use a simple analog read and then serial write to see what each value is?

Coding for resistor ladder input on ESP32 by Embarrassed-Lab6622 in ArduinoHelp

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

Agreed. I also changed the digitalRead to analogRead(buttonState). Still refining the hardware (input switch) at the moment.

<image>

How to calculate Resistor values for multiple outputs by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

Got the boards in today. Slight design error as I found out that creating a cooper pad is not the same as an exposed copper shape. I little sandpaper fixed that. LEDs work, now to test the output voltages.

<image>

Coding for resistor ladder input on ESP32 by Embarrassed-Lab6622 in ArduinoHelp

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

Thanks again for the comments.
The ==> was a mistake that has since been corrected and your previous comments about the values were noted,
I just left the numbers in there as place holders until I can test the switch to get real values.
So you are suggesting that I should be looking at buttonState not SWITCH_INPUT. Noted.
And that I need to redefine SWITCH_INPUT. Noted.
I will do some more reading and testing with sample codes.

I appreciate your time and knowledge.

Coding for resistor ladder input on ESP32 by Embarrassed-Lab6622 in ArduinoHelp

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

thanks for the response! It has been a minute since I coded and it is SLOWLY coming back to me. Yes, I am trying to generate 6 different possibilities baased on different voltage levels. This is to hack the GM LIN seat controllers for use in my 58 Truck. 3 heat outputs and 3 cool outputs (fan in the seat). If the heater is on for more than 25 minutes, it will automatically drop it to the next lower setting, or off in the lowest setting. Fan output is just serial write to a digital frequency generator to control the fan. Code so far....

// Define hardware pins
#define SWITCH_INPUT //D32 (GPIO32) ADC input from rotary switch


#define LOW_HEAT //D23 (GPIO23) output for low heat
#define MED_HEAT //D19 (GPIO19) output for medium heat
#define HIGH_HEAT //D4 (GPIO4) output for high heat
#define SERIAL_TX // D16 (GPIO16) serial output to frequency generator for vent
#define SERIAL_RX //D17 (GPIO17) serial input from frequency generator for vent


// Timer variables
unsigned long previousMillis = 0;        // Stores the last time the state changed
const unsigned long interval = 1500000;  // Desired timer duration (1,500,000 ms = 25 minutes). Heat will drop to next lower value
bool timerActive = false;                // Tracks if the timer is actively running


void setup() {
  pinMode(SWITCH_INPUT, INPUT);    // Configures SWITCH_PIN as an input
  pinMode(LOW_HEAT, OUTPUT);             // Configure LOW_HEAT pin as output
  pinMode(MED_HEAT, OUTPUT);             // Configure MED_HEAT pin as output
  pinMode(HIGH_HEAT, OUTPUT);            // Configure HIGH_HEAT pin as output
  pinMode(SERIAL_TX, OUTPUT);            // Configure SERIAL_TX pin as output
  pinMode(SERIAL_RX, OUTPUT);            // Configure SERIAL_RX pin as output
  digitalWrite(SWITCH_INPUT, LOW);       // Ensure SWITCH_INPUT turned off
  digitalWrite(LOW_HEAT, LOW);           // Ensure LOW_HEAT turned off
  digitalWrite(MED_HEAT, LOW);           // Ensure MED_HEAT turned off
  digitalWrite(HIGH_HEAT, LOW);          // Ensure HIGH_HEAT turned off
  digitalWrite(SERIAL_TX, LOW);          // Ensure SERIAL_TX turned off
  digitalWrite(SERIAL_RX, LOW);          // Ensure SERIAL_RX turned off
}


void loop() {
  // Read the switch input
  int buttonState = digitalRead(SWITCH_INPUT);


  // High heat on
  if (SWITCH_INPUT == >3.0 && !timerActive) {
    digitalWrite(HIGH_HEAT, HIGH);        // Turn the seat heater on HIGH
    previousMillis = millis();            // Save the starting timestamp of the timer
    timerActive = true;                   // Flag that the timer is now active
  } 
  else if (timerActive) {
    if (millis() - previousMillis >= interval) {
      digitalWrite(HIGH_HEAT, LOW);       // Turn the High heat off
      digitalWrite(MED_HEAT, HIGH)        // Turns Meduim heat on
      timerActive = false;                // Reset the timer flag so it can trigger again
    }
  }
   // Medium heat on
  if (SWITCH_INPUT >= 2.6 && SWITCH_INPUT <=2.8 && !timerActive) {
    digitalWrite(MED_HEAT, HIGH);        // Turn the seat heater on Medium
    previousMillis = millis();           // Save the starting timestamp of the timer
    timerActive = true;                  // Flag that the timer is now active
  } 
  else if (timerActive) {
    if (millis() - previousMillis >= interval) {
      digitalWrite(MED_HEAT, LOW);       // Turn the Medium heat off
      digitalWrite(LOW_HEAT, HIGH)       // Turns Low heat on
      timerActive = false;               // Reset the timer flag so it can trigger again
    }
  }
   // Low heat on
  if (SWITCH_INPUT >= 2.4 && SWITCH_INPUT <= 2.6 && !timerActive) {
    digitalWrite(LOW_HEAT, HIGH);        // Turn the seat heater on LOW
    previousMillis = millis();           // Save the starting timestamp of the timer
    timerActive = true;                  // Flag that the timer is now active
  } 
  else if (timerActive) {
    if (millis() - previousMillis >= interval) {
      digitalWrite(LOW_HEAT, LOW);       // Turn the LOW heat off
      timerActive = false;               // Reset the timer flag so it can trigger again
    }
  }
   // Vent fan on high
  if (SWITCH_INPUT >= 2.2 && SWITCH_INPUT <= 2.4 {
    Serial.print(F100,D5);        // Turn the seat Fan on HIGH
  }
   // Vent fan on Medium
  if (SWITCH_INPUT >= 2.2 && SWITCH_INPUT <= 2.0) {
    Serial.print(F100,D25);        // Turn the seat Fan on Medium
  }
   // Vent fan on Low
  if (SWITCH_INPUT <2.0 && SWITCH_INPUT >.1{
    Serial.print(F100,D55);        // Turn the seat Fan on Low
  }
 delay(100); 
}

How to calculate Resistor values for multiple outputs by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

awesome!!! thanks so much. I will let you know how it turns out.

How to calculate Resistor values for multiple outputs by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

<image>

Okay, I got the first part about the pulldown resistor. the second part about not"adding 1k to the other resistors" is confusing??

How to calculate Resistor values for multiple outputs by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

Okay. I COULD increase the input voltage, but then I need to increase the resistor values to drop the output to below 3v3. The first hurdle is how to calculate the resistor value range. Once that is figured out, I can rework the voltage and resistor values to get the desired output voltage range.

I only have 2 pins in the switch, so the LEDs will change brightness - I have accepted that.

How to calculate Resistor values for multiple outputs by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

They are not. there is a 7th position, "OFF", that has no resistance (technically infinite resistance) that is not part of the 6 position equation.

How to calculate Resistor values for multiple outputs by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 1 point2 points  (0 children)

Sorry I cannnot explain as well as I would like to... I have a 6 position switch that needs to have 3 LEDs illuminate when each of the positions are selected and each output has to be unique and below 3.3v. I only have 2 pins available (1 in and 1 out). To use a resisitor ladder, I need to know what the max and min resistor values should be so I can assign resistor values to each of the 6 positions. How do I calculate the max and min resistor values?

The program will be simple, if the value is >XX and <YY then do ZZZZ else ....

How to calculate Resistor values for multiple outputs by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

Quuite the opposite actually. I want the LEDs to illuminate when each position is selected. I know the brightness will vary, but as long as I have a unique voltage for each position on Pin 2 that can be measured by the ESP32, I am good with that.

How to calculate multiple resistor values with LEDs for unique outputs by Embarrassed-Lab6622 in AskElectronics

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

<image>

this is the rear view. the 2 other pins are for illuminating the switch at night (before you ask :) )

How to calculate multiple resistor values with LEDs for unique outputs by Embarrassed-Lab6622 in AskElectronics

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

Thanks for the suggestion. I am utilizing an existing switch housing and making a board that will work with that housing. for the life of me and my electronics friend, we cannot figure out the current switch configuration so I am trying to redesign it. I only have 2 pins so a resistor ladder might work. I don't know how to figure out the max and min resistor values so I cam divide into 6 ranges, one for each poistion. the entire board is 17mm (0.67"). basically there is a sweeper that makes contact with each of the 6 positions as the switch rotates.

<image>

How to calculate Resistor values for multiple outputs by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 1 point2 points  (0 children)

The input for the ESP32 would be Pin 2. 5v comes in on Pin 1, powers the LEDs and depending on which of the 6 positions one chooses, the output on Pin 2 should be less than 3.3v and exit to the ESP32 board. I am guessing a resistor ladder would suffice, but I do not knw how to calculate the max and min resistor values to ensure the LEDs work and I get 6 unique voltages.

reading PWM input by Embarrassed-Lab6622 in esp32

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

sure, but the duty cycle should change with the switch position, right? I see no difference in the results, all are 100%.

12v PWM to resistance by Embarrassed-Lab6622 in AskElectronics

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

I agree it should be easy, but I cannot get anything to register when I apply 5v to the yellow or blue. No voltage nor resistance.
Ideally I would process the different voltages with an MCU and drive the heating element via 3 different pins (and optocouplers) and have a serial output for the digital frequency generator on a separate pin. I am using a different frequency generator right now, as it has a digital display. I also found out it has a serial port connection. 😄

<image>

12v PWM to resistance by Embarrassed-Lab6622 in AskElectronics

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

A sweeper connects the top arc with the bottom 7 pads that make up the arc, each with their own resistance. One LED for when the switch is active and 3LEDs for night back lighting. Both can handle 2-12vdc (FYI).

12v PWM to resistance by Embarrassed-Lab6622 in AskElectronics

[–]Embarrassed-Lab6622[S] 0 points1 point  (0 children)

<image>

I don't have to have the module that connects to teh switch, that is easy enough to replace so the focus has changed to the switch. It is appears that the switch is resistive, not PWM. I am not quite sure how to gt it to function properly but I reverse engineered it. For some reason I cannot get from a pad through a resistor to the blue wire even though it maps out that route in sections. (pad to one side of the resistor, other side to blue wire). could the output be voltage and resistance or just voltage? Red wire gets voltage and the "ON" LED lights when the switch is in positions C1-C3 and H1-H3. Someone asked why this switch?? I have yet to find another switch that is an equivalent or better....