Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KC868-A4S Analog Inputs
Hi.   Sorting out analog inputs using esp32home. Thank you for any response, board working well.

Using this right now..

- platform: adc
    pin: 36
    name: "ADC-IN1"
    update_interval: 5s
    attenuation: 11db
      - lambda: if (x <= 0.15) { return 0; } return x * 1.51;

Several questions:
(1) I saw some example code posted to this forum where about x of 3.1 it used a higher multiplier. Why? This code is going to cause a large increase in output value at 3.111 x. Would a better approach be to read ground and vcc to the esp, and then scale your input readings according to those two readings using those values as 0 and 100% of input span? (0-3.3 after the voltage divider, or 0-5v at the input terminal).

(2) If I want to read a 10k ntc thermistor, it looks like a voltage divider, of 5.1k/10k is already there on the input... so if I power a 10k ntc thermistor with 3.3 volts, wouldn't I be essentially just adding the resistance value of my thermistor onto the 5.1k on-board resistor? (Allowing me to subtract 5.1k from the read value, and then normalizing my reading using the on-board code). My voltage isn't what I expect if this were true. (I am not an expert on the electronics side). Just enough to be dangerous.

Code was here.
- platform: adc
pin: 36
name: "A8S A1 Voltage"
update_interval: 5s
attenuation: 11db
- lambda:
if (x >= 3.11) {
return x * 1.60256;
} else if (x <= 0.15) {
return 0;
} else {
return x * 1.51;
1. Because not all inputs have a linear relationship with the output voltage. We divided it into three intervals using different coefficients. You can also calibrate your input channels according to the actual situation

2. i suggest you use a "NTC 10K to 0-5v output converter" module, it's very cheaper, easy find by aliexpress or other online store. just need convert NTC signal to DC 0-5v output, then you can connect to board's analog input ports.
Thank you for your response.

1. If it's a 0-5v input -- it SHOULD be linear. That is what 0-5v means. 0-5v linear. I understand the adc on the esp32 isn't the greatest.

2. I don't want to do that. This is working for me. I think I may have to add a calibration at the high and low end of my span to get correct resistance. But this works and is pretty accurate through span I need (still testing). (3950 10k ntc thermistor from input to 3.3v output). The 660 is a calibration offset that seems consistent. Not sure why it is needed yet. 5100 reflects the 5.1k ohm resistor in series with the input terminal (part of your 0-5 to 0-3.3v, voltage divider).

I came up with this.

- platform: adc
pin: 36
name: "ADC-IN1"
id: 'ADC_IN1'
update_interval: 500ms
attenuation: 11db
accuracy_decimals: 3
- sliding_window_moving_average:
window_size: 128
send_every: 10
- platform: resistance
sensor: 'ADC_IN1'
id: 'ADC_IN1RES'
configuration: UPSTREAM
resistor: 10kOhm
reference_voltage: 3.375
name: "ADC-IN1RES"
- lambda: return x - 5100 + 660;
- sliding_window_moving_average:
window_size: 12
send_every: 2
- platform: ntc
name: "ADC-IN1TEMP"
sensor: 'ADC_IN1RES'
b_constant: 3950
reference_temperature: 77°F
reference_resistance: 10kOhm

Several comments:
A: The stability of your 3.3v power supply circuit isn't great. Look at it on a scope. (I know it reads smooth on a volt meter).
B: The stability of the Analog Outputs is worse. Look at it on a scope. I would be afraid to connect these to say, an actuator. It would dither horribly. Explain how this is ok. (I know it reads smooth on a volt meter). Connect your analog output to an analog input on the board, and see the results. Imagine if your analog input actually did something in the real world in this scenario. Not good.
C: has a section on minimizing noise. A 100nF cap after your voltage limiter on the adc pins of the esp32 would be appreciated, would allow users to use less software averaging to get a good result. You can see a chart on this link with no cap, with cap, and with cap and sliding window sampling.

Thanks again for your help.

Forum Jump:

Users browsing this thread:
1 Guest(s)