Analogread dropping out

I have a circuit with a bunch of analog gas sensors sending their readings to a server.

Sometimes the value read will drop for all the sensors connected in one reading.

I have set it up so that the data is sent every 5 seconds, and in that time, three samples are taken, spaced apart and averaged out.

The circuit is running through to the adc through a LM358 op amp running as a straight buffer and a 10K trimpot to adjust the load.

Note that this was also occurring before with a similar setup that was using these sensors on pre-made shields with slightly different op-amps and some different sensors. These shields were a bit more ‘proper’ with the correct capacitance values etc

I am supplying more than enough power so its not that…

Any ideas folks? Thanks in advance!

@wsw, can you share your schematic?

1 Like

Pardon me for the late reply… here you go

I’m guessing you may say have to throw a capacitor in the general direction of the op-amps or something like that. Consider it was doing this as well with the other version of this which was running entirely with pre-made shields instead of a PCB.

@wsw, a few notes:

  1. You have a photocell connected between 5V and A4. First, analog inputs on the Photon are NOT 5V tolerant in analog input mode so I will assume you are using the pin in digital input mode. I’m not sure how this configuration works as the photoresistor is not in a voltage divider and in the dark, the A4 pin will essentially float if the resistance is high enough. You may want to revise this part of your circuit.

  2. All op-amps are powered by 5V so you need to be very careful not to have a condition where their output exceeds the 3.3v maximum input voltage of the analog inputs. Exceeding 3.3v can damage the Photon’s GPIO inputs when set to analog input mode.

You mention that you had this working with pre-made shields. Can you list the shields you used?

I had actually added a 10k pull-down on the LDR although it still seems to saturate very easily.

I did not actually realise that the inputs were max 3.3v although they still seem to be reading correctly apart from these drops. I’d be willing to bet in that case that overvoltage may have already damaged the GPIO which is why they are malfunctioning.

The shields I used before were dropping in the same way and they were also 5v based.

In the next revision of the circuit i will put a 5v adc on there to deal with this.

@wsw, if the input reading the photocell was in digital input mode, then you would not damage it. However, when working with resistors and voltages, the 10K resistor would not be a “pull-down” but instead would create a resistive voltage divider. If you list the shields you used, I can advise you on hardware design if you wish.

Everything is analogue so yes i was using the pull down as I not-so correctly put it as a voltage divider.

Let me get a list of all the shields I used… will take a while to pull up all the links

1 Like




Sounds sensor

There was also a GY30 light sensor and DHT11 temp/humidity sensor connected

@wsw, to avoid the possibility of exceeding 5v on the analog lines, you can either use (some) of the sensor’s onboard voltage comparator which output 5v logic (compatible with Photon digitial mode inputs) when the preset threshold is reached or use an external multi-channel ADC like the ADS7828 which uses I2C and can handle the 5V analog inputs.

We’re going for an LTC1867 by linear technology for the 16 bit resolution so I’ll let you know how it goes when it arrives. Due to shipping to Lebanon that will be a couple weeks…

@wsw, note that adding more ADC bits won’t necessarily add more accuracy as noise will become a key factor. This includes power supply noise, wifi noise, sensor and component noise, environmental RFI noise, etc. After filtering and averaging, you may find that you get at best 10-12 bits of accuracy.

1 Like

Just to give you an update… I’m now working with an ADS1115 (or two) and things are peachy! I’ve got some slightly different sensors and working on breadboard so that we can take a little more time to get a proper prototype up and running. Despite the photon on the old board being misused and fed with more than 3.3v into its ADC it still works fine although it keeps oversaturating. Its not really a useful sensor anymore but works find as a device to stream data into our dashboard to keep developing that.