Hello,
I have about 4 analogical sensors that I need to read from an ESP8266, but it has only one analogical pin. I don't have a potentiometer or a multiplexer, so my question is, can I use Arduino as a multiplexer in order to read the sensor values using the ESP? How can I connect it to the ESP analogical pin in order to do this if it can be done?
Thank you!
The cheap Arduino boards do not have a analog output. Some have a analog output, but using that and reading the analog signal with a ESP8266 is not the right way.
I think there are two options: the Arduino to read the analog signal and pass it on digital to the ESP8266 or a mux.
The analog inputs of an Arduino are better, more linear and more accurate than the analog input of a ESP8266 or ESP32.
If you need high accuracy, then you can use a Arduino. I suggest to use serial communication between the Arduino and the ESP8266.
A older 5V Arduino board (Arduino Uno / Mega / Nano Leonardo) can be connected to the ESP8266 (not a ESP32), but with a newer SAMD ARM M0+ board that runs on 3.3V there is no voltage level conflict.
It is possible to use I2C communication, but many do that wrong. Tutorial to do it right: Use I2C for communication between Arduinos - Exhibition / Gallery - Arduino Forum.
Which sensors are they ? When they are not accurate, then you could try a analog multiplexer (mux): https://www.gammon.com.au/forum/?id=11976
I totally agree with Koepel,
the analog inputs of the ESP8266 and especially the ESP32 are pretty much unusable due to extreme non-linearities, lack of noise filtering and lack of calibration.
You might be better off with adding an external ADC breakout with multiplexed analog inputs or if you're uncomfortable with that, using an Arduino board to read its own analog input lines and transfer the resulting reads to the ESP8266 directly via Serial.
For example, it's pretty easy for the Arduno board to send single lines as strings consisting of comma-separated integer data. One data value per each analog input. Then the ESP8266 can simply read each line, split at the commas, convert from string / char-array to integer and load the result into an integer array.