ADC fluctuates on Heltec Cubecell AB01

My Heltec Cubecell AB01 is powered via the USB connection of the PC and the serial monitor is running.

I connected a PSI pressure sensor to 3.3 volts (which is stable), GND and the ADC pin. When I use the Heltec ADC demo, the voltage fluctuates way too much (see plotter output below) while the pressure on the sensor remains the same. If I use the same sensor with an Arduino Nano the result is much better, then I have very little fluctuation.

I know that I can average measurements, but I do not think that is a good solution. Does anyone have a solution to measure on this board specifically without these fluctuations?

void loop() {
  int voltage = analogRead(ADC);



That’s really not changing all that much.

It’s likely that this processor has slightly higher ADC resolution, which is probably part of why you are seeing more variation.

Also designing a quiet analog setup for measurement is not trivial - for example, in doing so USB would usually be avoided or very very carefully decoupled.

Also you’d want to make sure your firmware was coordinated enough not to be taking ADC readings while transmitting, though LoRaWan transmissions should be infrequent enough that you’d rarely hit that anyway.

Thanks for your help, or rather an analysis :wink:

As far as transmissions are concerned, I will take that into account, but at the moment that is not an issue (see sketch).

Actually, it is a recommended approach, even when your system is quiet.

And if your system has noise which is nicely random, it can actually allow you to achieve more resolution, by statistically capturing a value in between two converter thresholds (the radio side of your node likely leverages this as part of its weak signal performance)

If you were going to do that, what you’d probably do is take a lot of measurements rather than take an infrequent one with delay.The downside is that this would cost more power than sleeping the processor in between less frequent measurements. But your current busy-wait delay() call wastes power anyway, so until you’re ready to move beyond that to actual low power sleep, there’s not much point in worrying about it.

But things are also likely to get quieter when the USB is disconnected, battery power is used, etc. There are also tricks sometimes employed to shut down on-chip peripherals when taking an ADC reading. And you may want to build some low pass filtering into how you connect the sensor to the module. Also make sure the sensor’s output is sufficiently low impedance to drive the ADC, you may want to operate the ADC at a lower conversion clock as for many they can present a lot of load to an analog source when run at a high conversion clock.

Thanks again for your explanation! After what you wrote, I have to conclude that several factors influence a correct measurement and therefore I wonder whether such an ADC measurement can ever be accurate enough. You give me an idea, tomorrow I will power the Cubecell with a battery and see if that ensures a better measurement. I will post the result here.

I’m not worried about the power consumption (delay), Heltec has a LoRa demo sketch that I’m going to use, that uses a sleep function. In other applications that worked fine.

Although the sensor probably uses 5 volts, it doesn’t seem to have a problem feeding with 3.3 volts from the Cubecell Vext pin. Naturally, the output voltage will also be somewhat lower.

The problem with the fluctuations seems to be solved by using a pause between measurements (see sketch). When I measure at a depth of about 15 cm the value on the ADC pin is 782 and every centimeter higher or lower gives a difference of about 30 points. If the sensor is at a fixed depth, the value will fluctuate about 15 points, that is 0.5 cm. In my case, for measuring the water level in a lake, it is accurate enough.

void setup() {

void loop() {
  int voltage = analogRead(ADC);

That quite strongly suggests that there’s something not yet understood going on.

Your pause is not a reliable solution, but the kind of thing likely to lead to future trouble when whatever the not-understood condition changes for some seemingly irrelevant reason.

You may well be right but I have no other option and I do not read a solution on this forum. At the moment I have the board running on a LiPo battery with the slightly modified demo sketch from Heltec, measurements are taken every 10 minutes. The data is stored in an Influx database and from there I will generate a graph with Grafana. As soon as I have relevant information I will post it here.

Actually you read several, you just rejected them from a position of inexperience.

But sometimes mistakes discovered only after they’ve cause a lot of pain are how we learn…

Fixed, measurements are consistent and hardly fluctuate.