Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here

Reply To: Bizarre eTape Sensor Behaviour

Home Forums Environmental Sensors Bizarre eTape Sensor Behaviour Reply To: Bizarre eTape Sensor Behaviour

Shannon Hicks

    No, there is not a built-in voltage divider on the Mayfly to protect either the 1284p’s 10-bit ADC or the auxiliary 16-bit ADS1115 ADC input.  The jumpers on the Mayfly that let you select the Switched 3.3 or Switched 5v only change the voltage that’s supplied to the Grove jack’s VCC pin.   There’s nothing to protect the Mayfly’s ADC inputs from overvoltage because there’s an infinite number of input voltages someone could attach to the Mayfly, so it’s up to the users to make sure they reduce their signal to keep it under 3.3v.  (A little history:  the Mayfly board was originally designed to work with a turbidity sensor that needed 5v excitation but produced a 0-2.5v output, so overvoltage was never a concern until the board started being used by a wider audience, and later once we started using other analog-output sensors with outputs like 0-5v.)

    From the link you provided, it doesn’t appear that there’s any sort of voltage divider included in that interface device.  It specifically says it’s a 0-5 volt module, so there doesn’t appear to be any way to force it to adjust its output voltage range.  It also says it needs 6-30v excitation, so I’m curious what you’re using to power it.  I’m guessing there are other resistance-to-voltage modules out there that would operate just fine on 3.3v excitation and have a 0-2.5v or 0-3.3v output, or even better – a digital output like I2C or SPI.  You can also have your Mayfly do the resistance to voltage measurement with just a little bit of hardware and some code.

    But if you want to continue using the 0-5v module, you’ll need to lower it to a safer range in order for the Mayfly to read it properly. When I have a sensor with a 0-5v output, I put two perfectly matched 100k resistors (check the resistance with a precision ohm-meter of about a dozen 10% precision resistors and you’ll find a couple that are the same) in series between the sensor output and ground, and then read the voltage in the middle of the two resistors and you’ll get exactly half.  So for a sensor with a 0-5v output, you’ll now get a range of 0-2.5v.  If you really wanted to maximize your resolution, you could use a 2/3 resistor divider to give it a range of 0-3.3v, but with the ADS1115, we’re already getting resolution finer than a fraction of a millivolt, so it’s doubtful you’d see much improvement between using a 1/2 divider when compared to a 2/3 divider.

    As for your code, I have a few suggestions.  Line 52 should be removed.  The Pin 2 you mentioned in that pinMode statement is actually the 1284p processor’s pin 2, which is the secondary UART RX pin, so if you were using something like a Bee module, that could cause problems.  In line 38, you declared the variable eTapePin was defined as 2, and because that’s the channel number of the aux ADS1115, there’s no reason to set the pinMode for it.  You only have to use the variable name when making the readADC statement like you did in line 64. And filling an array in order to find the median uses more memory and takes lots of complicated code when compared to a simple averaging loop, especially if you later want to increase the number of readings.

    Here’s a sketch I used recently for taking 100 readings (10ms apart) from the ADS1115 aux analog pin and then averaging them and displaying the result to the serial monitor.  If the signal you’re measuring is 3.3v or less, no change is necessary.  If you’re measuring a voltage like 5v, use a 50/50 voltage divider to cut the voltage in half and then use line 76 to calculate the average voltage instead of line 74.