Project - Our Friendly e-garderner


#1

Team Members: Gayathri, Fathima, Sreedevi


#2

Testing Components: Soil Moisture Sensor.

These are the connections -
Vcc(Sensor) - 5V (probe),
Gnd(sensor) - Gnd (probe),
AO(sensor) to Pin02 (bluey)

And i used this code:


void check_adc(void){

    int16_t adc_val=0;
    adc_val = simple_adc_get_value(SIMPLE_ADC_GAIN4, ANALOG_PIN_2);
    tfp_printf("1. ADC output is %d \n", adc_val);
}
main() {
	void (*adc_check)();
	adc_check = & check_adc;

	ms_timer_init(APP_IRQ_PRIORITY_HIGH);
	ms_timer_start(MS_TIMER0, MS_REPEATED_CALL, RTC_TICKS_MS(500), 	adc_check);
}

What i expected:
some reading (of some range) when the soil moisture sensor in water and like 0 when it is out of water

What i got:
the same reading when the moisture sensor is in water or out of water (4095) !!

Other trouble shooting:

  1. I connected the AO (moisture sensor) to a different analog pin (PIN 03/ PIN 04). Interestingly i got the same value (4095) when i should not have got any value

  2. I removed the connection from moisture sensor to the bluey board, I still get the same value (4095)

@prithvirajnarendra - what am i missing. I seem to have forgotten something from the ADC class :frowning: Help !


#3

Hi Sree,
The code that you posted shouldn’t work since you’ve not initialized the low frequency clock (lfclk_init) nor the uart. Since you say those are working, I guess this is just a snippet of your code.

For an ADC measurement like these which are not rapidly changing, you can measure the value with a multimeter first in all the different conditions. Then you’ll know the range of possible values that the sensor gives. Since in the case of nRF52 the internal reference voltage is 0.4V, you’ve to set the appropriate gain to get the sensor signal within this range. As you’ve now set the gain as 4, whatever voltage is at these pin is multipled by 4. So you’re saturating the 12 bit ADC.

Hope this helps.


#4

Timeline


#5

Hi Prithvi -

  1. i have initialized the clock and uart using this code
	hfclk_xtal_init_blocking();
	lfclk_init(LFCLK_SRC_Xtal);

// trying to check moisture when uart input = on, for testing 
	ptr_handler_receive_input = &handler_receive_input;
	hal_uart_init(HAL_UART_BAUD_9600, ptr_handler_receive_input);
  1. i removed the sensor AO to bluey analog pin, checked the analog output (voltage) using the voltimeter - it reads 0 whether the sensor is in water or out of water. Then i changed the potentiometer and read the values again - same behavior.

  2. checked the digital output (voltage) using the voltimeter - it reads 3.3/ 5V whether the sensor is in water or out of water. Then i changed the potentiometer and read the values again - same behavior.


#6

On the moisture sensor: i manipulated the gain factor to 1/6 and that gives me the results that i somewhat expected. Thanks Prithvi & Priya (for explaining it again to me :slight_smile:


#7

Here is the repo on git - https://github.com/sreedevitk/efh-project