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: Negative Voltage Reading from Single-ended ADC Using Apogee SP-212-SS Sensor

Home Forums Environmental Sensors Negative Voltage Reading from Single-ended ADC Using Apogee SP-212-SS Sensor Reply To: Negative Voltage Reading from Single-ended ADC Using Apogee SP-212-SS Sensor

#17787
Shannon Hicks
Moderator

    First you should attach the sensor’s clear wire to the GND pin of the screw terminal board along with the black wire.

    Second, the sensor needs at least 5 volts of excitation power, and the jumper setting of the Aux Analog Grove jacks in your photo is set to the default 3v position.  You need to move that jumper to the 5v position.  See the section on the Grove jack jumper settings in the middle of this page:  https://www.envirodiy.org/mayfly/hardware/jumper-settings/

    Third, the Grove jacks only receive power when the switched voltage regulators are turned on, which only happens when you set pin D22 high.  You’ll need to add a line in your sketch to do that.  If you want to take continuous readings, then it’s fine to leave D22 high, but it’ll use more power than if you turn if off when not in use, which is important if you want to make a sleeping logger that powers all the sensors down between readings.  For constant power in your example, insert the following lines in your setup section after line 8:

    digitalWrite(22, HIGH);
    delay(1000);

    The delay line is to give the sensor a second to warm up.  In general, you don’t want to start sampling as soon as a sensor receives power since various sensors need anywhere from 100ms to 45 seconds before a reading can be taken.  Most sensor manuals will tell you what that number is, but for good measure, it’s good to wait at least a second for simple sensors, and adjust if you notice that it needs more or less time.  There will be a little red LED in the lower left corner of the Mayfly that will be on anytime the Grove jacks are powered, indicating that the switched power is on.  If you want to turn them off at any point, simply set pin 22 low.

    Fourth, the ADS1115 aux analog input has 4 channels, and they start counting with 0 (zero).  So your available channels are 0,1,2,and 3.  In your photo, you’ve got the sensor output connected to the white wire of the uppermost Grove jack, which if you look at the labels next to the jack, is analog channel 0.  So your code in lines 13-14 should be:

    int16_t adc0 = ads.readADC_SingleEnded(0);
    float voltage = adc0 * 0.1875;

    And as an aside, those sensor outputs can be pretty variable between readings on a partly-cloudy day or in a forest environment.  In your example you’re sampling once every second.  But if you deploy it for real-world monitoring and want to do 1- or 5-minute samples, we found it works well to do a loop of about 50 readings over 5 seconds to get a smoother representation of the actual light levels.