as the title says, I am using Esp 8266 wemos d1 mini to read analog values. First, I connected the wifi module with a micro USB cable to PC. Then using the code below, I read the analog values:
However the default value of A0 is changing between 3~4. What could be the reason and how could I eliminate this so that the reading value is steady?
Edit: So one reason for this floating could be that nothing is connected to the pin. I connected it now to my sensor sharing a common ground, as in the attached figure. Since the sensor requires 24 V, I converted the 4.5V from battery to 24V. Using a voltage divider I then converted the output of the sensor (0-10V) to 0-1.66V. However the reading value A0 is still floating. What could be the reason?
A delay() puts the WiFi of the WeMos AFAIK to sleep for some random time (about a second and a bit IIRC).
So use millis() to manage time between analogReads, not delay().
Can also use a single resistor (not a voltage divider) between sensor output and analogue input,
because the WeMos D1 mini already has a voltage divider buildin.
In theory, use 100k for every volt above 3.2volt, so 680k for a 0-10volt sensor.
Don't expect a lot from the A/D of an ESP8266. The one I tested did output ~8-1024 (not 0-1023).
Leo..
try it out
ADC is switched between external pin and internal connection to measure WiFi power. but the measurements influence each other without a pause between readings
the esp8266 was developed to be used as WiFi module, not as general purpose MCU
Wawa:
Can also use a single resistor (not a voltage divider) between sensor output and analogue input,
Could you tell me about the theory behind this? This sounds like a pull-up resistor, but as far as I know pull-up/down resistor only helps in floating values (when the analogue pin is connected to nothing.)
xman236:
Could you tell me about the theory behind this? This sounds like a pull-up resistor, but as far as I know pull-up/down resistor only helps in floating values (when the analogue pin is connected to nothing.)
The WeMos already has a 220k:100k voltage divider, to reduce 3.2volt to 1volt for the A/D.
Adding a 680k resistor to that 220k makes it a 900k:100k voltage divider.
Leo..
Wawa:
The WeMos already has a 220k:100k voltage divider, to reduce 3.2volt to 1volt for the A/D.
Adding a 680k resistor to that 220k makes it a 900k:100k voltage divider.
Leo..
I understand that adding a 680K resistor makes a 900k:100k voltage divider. But why would this voltage divider eliminate the noise at A0?
I don't know what the source of the noise is, or if the problem lies with the crappy A/D of an ESP8266.
You did not post any information about the sensor or the setup.
If the sensor itself produces the "noise", then a 100n cap from analogue input to ground could help.
Leo..
Wawa:
I don't know what the source of the noise is, or if the problem lies with the crappy A/D of an ESP8266.
You did not post any information about the sensor or the setup.
If the sensor itself produces the "noise", then a 100n cap from analogue input to ground could help.
Leo..
Since the resolution of the sensor is below 1mm, the noise is coming from the circuit. I also tried with Arduino Mega2560 but the noise is still there.
Following your advice, I added a low pass filter with 10 kOhm and 33 uF cap. Now the noise is reduced. However, the reading analog value is still jittering with 1~2 value (if the actual value is 209, the reading value varies between 208~210). Is there any other way to eliminate this jittering? If ESP8266 is a bad choise, what could be a better choise? All I want is to send the sensor value wireless to my PC.
Maybe the noise comes from the 24volt DC/DC converter, maybe not.
I can't tell from the limited information you have given us.
You are there, so you have the best opportunity to measure/solve this.
Grounding scheme (how/where) could also make a difference.
A common external A/D is the ADS1115.
That 15-bit A/D (single-ended) could also give you a higher resolution than the 10-bit A/D of a WeMos.
But if the noise comes from the sensor, then it could make things worse.
Leo..