Skip to content

input hardware

doomke edited this page Aug 10, 2023 · 17 revisions

The input module offers extensive support for measuring and converting voltages.

  • pin limitations (ADC2 and WiFi)
  • averaging

Conversions

Voltage Divider

The input pins of the ESP32 can only measure up $3.3 \, \mathrm{V}$, which means that higher voltages need to be "broken down" before they can be measured correctly. For this purpose a voltage divider with two resistors of known resistance, $R_1$ and $R_2$, can be used to bring down the wanted voltage $U_0$ to the actually measured voltage $U$.
$U_0$ can then be calculated via $U_0 = \frac{R_1 + R_2}{R_2} U = \left( 1 + \frac{R_1}{R_2} \right) U$.

$$\begin{align} U_0 \hspace{20pt} & \mathrm{o} \\\ & \, | \\\ R_1 \hspace{20pt} & █ \\\ U \hspace{20pt} & ├---\mathrm{\,o \:\:\: input \: pin}\\\ R_2 \hspace{20pt} & █ \\\ \mathrm{GND} \hspace{20pt} & ⏚ \end{align}$$

It is a good idea to limit the current to about $10 \, \mathrm{mA}$ and the maximum pin voltage measured to $3 \, \mathrm{V}$, which yields a value of about $300 \, \Omega$ for $R_2$. $R_1$ can then be calculated using the maximum expected voltage $U_{\mathrm{max}}$ with $\left[U_\mathrm{max}\right] = \mathrm{V}$ via $R_1 = 100\cdot U_\mathrm{max} - 300 \, \Omega$

Measuring Resistance

As the input is limited to measuring voltages, a variable resistance can only be evaluated indirectly, by using both a reference voltage and a reference resistor. Up to a few $\mathrm{k\Omega}$ this can conveniently be done using a voltage divider with the reference voltage

$$U_0 = 3.3 \, \mathrm{V}$$

and the reference resistor

$$R_1 = R_\mathrm{ref}.$$

By using the resistance under test $R$ instead of $R_2$, the resistance can be calculated as

$$R = \frac{U_0 - U}{U} R_\mathrm{ref} = \left(\frac{U_0}{U} - 1 \right) R_\mathrm{ref}.$$

For maximum accuracy the reference resistor should be chosen considering the maximum expected resistance $R_\mathrm{max}$ and minimum expected resistance $R_\mathrm{min}$ so that

$$R_\mathrm{ref} = \sqrt{0.5 \cdot R_\mathrm{max} \cdot R_\mathrm{min}}.$$

Furthermore the maximum current of $10 \, \mathrm{mA}$ should never be exceeded,

Measruing Electrical Current

An electrical current cannot be measured directly, instead the voltage drop across a known resistor $R_\mathrm{ref}$ caused by the current can be measured. Using the relation

$$I = U \cdot \frac{1}{R_\mathrm{ref}}$$

simply multiply the voltage with $1 / R_\mathrm{ref}$, i.e. use the inverse resistance as multiplicator.

Thermistor

Thermistors are cheap components and therefore quite common ways to measure temperatures. Their resistance significantly depends on the temperature, which is why it can be used as a proxy to measure temperature.

To carry out a measurement, first the resistance needs to be evaluated. This resitance can then be converted to a temperature, if the normal temperature, normal resistance and temperature coefficient are provided. Lastly, if a measurement in an offset temperature scale like Celsius is favored, the absolute temperature can be converted by subtracting the corresponding offset.

General

Guides

Principle of Operation

Modules

Software Hardware
camera camera
infoLED infoLED
input input
macro macro
output output
servo servo
socket socket
stepper stepper
WiFi wifi

Clone this wiki locally