Author Topic: Problems with soilwatch in mkr Fox 1200  (Read 24819 times)

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #15 on: January 29, 2019, 09:26:43 AM »
Hello Piotr!

I am trying to use the 2N7000 Mosfet (I have the BS170 too) but i do not get the desire result, I think i am following wrong your schema, right now i get almost  the same readings for the sensor with the mosfet on and off, with the mosfet on :

ADC = 174, Moisture value = 0
ADC = 194, Moisture value = 3
ADC = 190, Moisture value = 3
ADC = 967, Moisture value = 130
ADC = 188, Moisture value = 2

the low ADC is around 160-200 and the high 950-980 in water and air

with the mosfet off

ADC = 361, Moisture value = 31
ADC = 450, Moisture value = 45
ADC = 334, Moisture value = 26
ADC = 437, Moisture value = 43
ADC = 325, Moisture value = 25
ADC = 402, Moisture value = 38
ADC = 497, Moisture value = 53
ADC = 1003, Moisture value = 136
ADC = 1001, Moisture value = 136
ADC = 1002, Moisture value = 136
ADC = 1002, Moisture value = 136

the low ADC is around 330-500 (in air) and the high 1000 (in water)

i put a 1M resistor and a 100 one ( At the moment i do not have 470 Ohms resistor) i read the specs and watch a lot of tutorials and people get results with the 100 resistor, I´ve changed the Mosfet to a new one, to discard that the mosfet factory errors,

I know this is for my electronic  knowlegde, I attach 2 pics of my circuit. The blue wires are the ground ones the red the VCC the white is for reading the sensor and the orange is to control the mosfet, the resistor closest to the orange wire is the 100 ohms and the other to the ground is the 1M one.

https://drive.google.com/file/d/1LUEg-T-2KOLSCw-pb6mt9N30Q3qJv0wz/view?usp=sharing
https://drive.google.com/file/d/18nFvt-TI2rGdJ6FRyyPaC7d6DzF_s_Km/view?usp=sharing

I am pretty lost, I have tried all, and I know that is a noob error probably, wanna figure it out myself but I could not do it.

Thanks for your Help Piotr, i am learning a lot thx to you, I understand you can not loose time because you have your own things to do, but I can not thank you for all the times you´ve helped me.

Kind regards,

Martín
« Last Edit: January 29, 2019, 09:35:34 AM by martin.i.tycgis »

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #16 on: January 30, 2019, 11:24:00 AM »
Hi,

From what I can see on the picture source and drain are connected the other way round. Just swap leads on leg 1 and 3 of the MOSFET.
If everything else is ok it should work then.
Make sure you put 100ms delay in your sketch after you turn on the MOSFET.

I hope this will work now  ;)

Kind regards,
Piotr

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #17 on: January 31, 2019, 08:58:16 AM »
Hi Piotr!

It work ! I´ve change the 7N2000 for a BS 170 and work perfectly, I will try to install the SEN1480 and the other Soilwatch 10, wanna try if i can control the 3 with one MOSFET .

I let you know the results! as always Thanks!

Martin


martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #18 on: January 31, 2019, 09:49:14 AM »
Quick Update:


It Works with 2 Soilwatch 10 and the SEN0148, now i have to do field test! I will tell you how this is going!

Un abrazo! (A hug in spanish!)

Martín

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #19 on: February 04, 2019, 08:04:54 AM »
That's great!  :)

Please let me know how the field tests go.

Piotr

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #20 on: February 18, 2019, 08:49:34 AM »
Hello Piotr!

Well I´ve done fields test and so far the mosfet prevents the uncontrolled battery comsuption, I start the test  January 31st and today the batteries still on the 82%
 8) but i get some erratic readings, i think it´s because the batteries, when the MKR FOX 1200 was on the USB this doesn´t happen.

At first i get erratic readings in all the sensors, the 2 Soilwatch 10 and the SEN0148, I split the sensors with 1 transistor for controlling each one, i managed to get normal readings with the SEN0148, but still getting weird readings with the 2 Soilwatchs 10, and I didn´t really know how to solve this problem.

This is what i get in the Sigfox Backend in the messages of my device:

the mapped value it´s a percentage of teh humidity, based on the max adc and the minimum adc. I am using the 3 V Soilwatch version, should i get the 1.1V one ? I don´t know, what is the cause of this readings.



2019-02-18 09:40:26   5c8fb2411b44fc52
temperature: 22.32
humidity: 27
mappedUndergroundValue: 68
mappedOnTheGroundValue: 252
BatteryLevel: 82
             
2019-02-18 09:10:09   0000ac411b666652
temperature: 21.5
humidity: 27
mappedUndergroundValue: 102
mappedOnTheGroundValue: 102
BatteryLevel: 82   
          
2019-02-18 08:39:53   e07aac411afc5f53
temperature: 21.559998
humidity: 26
mappedUndergroundValue: 252
mappedOnTheGroundValue: 95
BatteryLevel: 83
             
2019-02-18 08:09:35   e07aac411a444d53
temperature: 21.559998
humidity: 26
mappedUndergroundValue: 68
mappedOnTheGroundValue: 77
BatteryLevel: 83
             
2019-02-18 07:39:19   3c0aad411a5c1853
temperature: 21.629997
humidity: 26
mappedUndergroundValue: 92
mappedOnTheGroundValue: 24
BatteryLevel: 83
             
2019-02-18 07:09:01   1e85ad411a340e52
temperature: 21.689999
humidity: 26
mappedUndergroundValue: 52
mappedOnTheGroundValue: 14
BatteryLevel: 82
             
2019-02-18 06:38:44   0000ae411a3b3152
temperature: 21.75
humidity: 26
mappedUndergroundValue: 59
mappedOnTheGroundValue: 49
BatteryLevel: 82
             
2019-02-18 06:08:27   703dae411b333a53
temperature: 21.779999
humidity: 27
mappedUndergroundValue: 51
mappedOnTheGroundValue: 58
BatteryLevel: 83
             
2019-02-18 05:38:11   46e1ae411b24fd53
temperature: 21.859997
humidity: 27
mappedUndergroundValue: 36
mappedOnTheGroundValue: 253
BatteryLevel: 83
             
2019-02-18 05:07:53   ae47af411b46fb53
temperature: 21.91
humidity: 27
mappedUndergroundValue: 70
mappedOnTheGroundValue: 251
BatteryLevel: 83   
          
2019-02-18 04:37:36   14aeaf411a190953
temperature: 21.96
humidity: 26
mappedUndergroundValue: 25
mappedOnTheGroundValue: 9
BatteryLevel: 83
             
2019-02-18 04:07:20   84ebaf411a501053
temperature: 21.989998
humidity: 26
mappedUndergroundValue: 80
mappedOnTheGroundValue: 16
BatteryLevel: 83
             
2019-02-18 03:37:02   e07ab0411a46fe53
temperature: 22.059998
humidity: 26
mappedUndergroundValue: 70
mappedOnTheGroundValue: 254
BatteryLevel: 83   
          
Kind regards,

Martín

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #21 on: February 18, 2019, 09:33:55 AM »
Hi Martin,

It shouldn't be possible to have over 200 value if you mapped it to 0-100. My guess would be that you somehow changed 10bit reading to 12bit. This would explain values over 200.
Erratic readings may be caused by trying to read sensor to quickly. You need to add a 100ms delay after you switch the sensor on and before you take the readings. Make sure you turn on the correct sensor before taking the readings.  ;)
Show us the code.

Regards,
Piotr

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #22 on: February 18, 2019, 10:11:10 AM »
Hi Piotr,

Here´s the code:

 #include <SHT1x.h>
#define dataPin  9
#define clockPin 10
#include <SigFox.h>
#include <ArduinoLowPower.h>
#define LED 6

SHT1x sht1x(dataPin, clockPin);
int oneshot = false; 
float voltagepercentage;
const int nMOS= 2;
const int groundMOS= 3;
const int nMOSSen0148= 1;

const int analogInPinOnTheGround = A4;
int minADCground = 130;
int maxADCground = 1000;



const int analogInPinUnderground = A0;
int minADCunderground = 130;
int maxADCunderground = 1000;



int moistureOnTheGroundValue, mappedOnTheGroundValue;


int moistureUndergroundValue, mappedUndergroundValue;

void setup() {
  LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);

  Serial.begin(115200);

 
  pinMode(nMOS,OUTPUT);//SELECCIONAMOS EL PIN
  pinMode(groundMOS,OUTPUT);
  pinMode(nMOS,OUTPUT);//SELECCIONAMOS EL PIN
  while (!Serial);
  if ( ! SigFox.begin() ) {
    Serial.println("Error ... rebooting");
    NVIC_SystemReset();
    while (1);
  }
  SigFox.reset();
  delay(100);
  SigFox.debug();
  SigFox.end();

  // We need to have to time to program the Arduino after a reset
  // Otherwise it does not respond when in low-power mode
  Serial.println("Booting...");
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
}

typedef struct __attribute__ ((packed)) sigfox_message {
  uint8_t hum;
  float temp;
  uint8_t humidityburied;
  uint8_t humidityground;
  uint8_t batterylevel;
} SigfoxMessage;



void loop() {

digitalWrite(nMOS,HIGH); //ENCENDEMOS EL CIRCUITO

digitalWrite(nMOSSen0148,HIGH);

digitalWrite(groundMOS,HIGH);

  delay(500);

  // SENSOR A RAS DE SUELO
  delay(100);
  moistureOnTheGroundValue = analogRead(analogInPinOnTheGround);
   

  Serial.print("ADC = " );
  Serial.print(moistureOnTheGroundValue);
  Serial.print(", " );

  mappedOnTheGroundValue = map(moistureOnTheGroundValue, minADCground, maxADCground, 0, 100);

  Serial.print("Moisture value on the ground = " );
  Serial.print(mappedOnTheGroundValue);
  Serial.println("%");

  delay(2000);



  //SENSOR ENTERRADO A 1.5 METROS DEL SUELO
  delay(100);
  moistureUndergroundValue = analogRead(analogInPinUnderground);

  Serial.print("ADC = " );
  Serial.print(moistureUndergroundValue);
  Serial.print(", " );

  mappedUndergroundValue = map(moistureUndergroundValue, minADCunderground, maxADCunderground, 0, 100);

  Serial.print("Moisture value Underground (1.5 m) = " );
  Serial.print(mappedUndergroundValue);
  Serial.println("%");

  delay(2000);



  //SENSOR DE TEMPERATURA AMBIENTE Y HUMEDAD
  float temp_c;
  float temp_f;
  float humidity;

  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  // Print the values to the serial port
  Serial.print("Temperature: ");
  Serial.print(temp_c, DEC);
  Serial.print("C / ");
  Serial.print(temp_f, DEC);
  Serial.print("F. Humidity: ");
  Serial.print(humidity);
  Serial.println("%");

  delay(2000);

  analogReadResolution(10);
  analogReference(AR_INTERNAL1V0); //AR_DEFAULT: the default analog reference of 3.3V // AR_INTERNAL1V0: a built-in 1.0V reference
 
  // read the input on analog pin 0:
  int sensorValue = analogRead(ADC_BATTERY);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 4.3V):
  float voltage = sensorValue * (3 / 1023.0);


//convertimos valor a porcentaje.

  voltagepercentage = (voltage/3)*100;

  // print out the value you read:
  Serial.print(voltagepercentage);
  Serial.println("%");

  delay(500);

  SigFox.begin();
  delay(100);

  SigFox.status();
  SigfoxMessage msg;
  msg.temp = (float)sht1x.readTemperatureC();
  msg.hum = (uint8_t)sht1x.readHumidity();
  msg.humidityground = (uint8_t) mappedOnTheGroundValue;
  msg.humidityburied = (uint8_t) mappedUndergroundValue;
  msg.batterylevel =(uint8_t) voltagepercentage;
  SigFox.beginPacket();

  SigFox.write(msg.temp);
  SigFox.write(msg.hum);
  SigFox.write(msg.humidityground);
  SigFox.write(msg.humidityburied);
  SigFox.write(msg.batterylevel);
  SigFox.endPacket(false);
  SigFox.end();

digitalWrite(nMOS,LOW); //APAGAMOS EL CIRCUITO
digitalWrite(nMOSSen0148,LOW);
digitalWrite(groundMOS,LOW);

  // Wait for 10 minutes.
  // Low Power version - be carefull of bug
  LowPower.sleep(30*60*1000);

}


void dummy() {
  volatile int aaa=0;
}

the dummy void is just to awake the board.

Thanks for all the support,

 Martín

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #23 on: February 18, 2019, 11:42:28 AM »
Hi Martin,

You change ADC reference to internal 1.0V with:
Code: [Select]
analogReference(AR_INTERNAL1V0); //AR_DEFAULT: the default analog reference of 3.3V // AR_INTERNAL1V0: a built-in 1.0V reference
Once you change it, all readings will be taken with this reference. Because as far as I remember, you have 3V version sensor, you should set analogReference to AR_DEFAULT before reading sensor.
Some boards need some time after the reference has been changed. Some may cause first reading after the change to be corrupted. Check if this is not the case with MKR FOX 1200.

Regards,
Piotr

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #24 on: February 18, 2019, 12:40:21 PM »
It works!

I made that code to read the level of the batteries, now the 2 sensors work, I have to find a better way to know the level of the batteries,

As always thanks you Piotr, and the rest of the team in PINOTECH,

 I will let you know how the field test go,

Thanks for all

Martín



pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #25 on: February 18, 2019, 02:29:44 PM »
Hi Martin,

To read the battery voltage you can use a voltage divider to bring the voltage to the safe level for ADC.

You are welcome :)
Let us know how the tests go.

Regards,
Piotr