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

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Problems with soilwatch in mkr Fox 1200
« on: November 27, 2018, 09:44:08 AM »
Hello!

First of all, sorry about my english and i am kind a noob with arduino but i love to try new things out!  i really like soilwatch and i try it first on Arduino Uno and was accurate and work correctly.

The thing is i am starting with Mkr Fox 1200 and i do not know why i get on error on the code you provide to try the sensor in this line:

if(is1V1Output == true)
  analogReference(INTERNAL); //set ADC reference to internal 1.1V

i get this error:

exit status 1
'INTERNAL' was not declared in this scope


if i delete this line of code, the ADC turns to 900 in air and i really do not know the meaning of this.

As i said sorry for my english and sorry if this is a dumb question.

Thx you for your time.

Martín.

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #1 on: November 27, 2018, 09:51:47 AM »
Thinking about it, maybe is the Voltage ? I believe mkr Fox 1200 works with 3.3V maybe is this the problem ?

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #2 on: November 27, 2018, 10:17:40 AM »
Hi Martin,

The code provided is optimized for Arduino Uno/Mini. It does require few tweaks to work with SAMD21 based boards.

Try to delete whole this section:
Code: [Select]
if(is1V1Output == true)
  analogReference(INTERNAL); //set ADC reference to internal 1.1V

Have you set correct ADC pin:
Code: [Select]
const int analogInPin = A0;
What readings do you get in the air and in water?
Which SoilWatch 10 version do you have?
How do you power the sensor? (what voltage and source)

BTW your English is fine  :)


martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #3 on: November 27, 2018, 11:12:50 AM »
I get this readings now, wrong pin... haha

on air:
ADC = 34, Moisture value = 5
ADC = 34, Moisture value = 5
ADC = 35, Moisture value = 5
ADC = 34, Moisture value = 5
ADC = 34, Moisture value = 5
ADC = 46, Moisture value = 7
ADC = 41, Moisture value = 6
ADC = 40, Moisture value = 6
ADC = 66, Moisture value = 10
ADC = 45, Moisture value = 7

On water:
ADC = 873, Moisture value = 140
ADC = 883, Moisture value = 142
ADC = 884, Moisture value = 142
ADC = 883, Moisture value = 142
ADC = 882, Moisture value = 142
ADC = 885, Moisture value = 142
ADC = 885, Moisture value = 142
ADC = 883, Moisture value = 142
ADC = 883, Moisture value = 142

the adc is normal ? i now i have to change the min ADC and the max ADC, but i think that´s pretty normal i guess.

i power up with the vcc pin, i believe that in mkr fox 1200 is 3.3 V, now i am using USB but i will try it with 2X AA batteries

thanks for your time,

Martin

« Last Edit: November 27, 2018, 11:16:15 AM by martin.i.tycgis »

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #4 on: November 27, 2018, 12:44:15 PM »
Great :)

The ADC output is good. Now just adjust min and max ADC.
Yes the VCC on this board is 3.3V. If you plan to use the sensor with batteries then consider adding a transistor to turn on the sensor only for the measurement. Sensor consumes around 24mA and it will drain your batteries rather quickly if powered constantly.

I have quickly looked at the schematics for Arduino MKR Fox 1200 and my concern is will you still have 3.3V at the VCC when powered from 2xAA batteries?
I can't see any boost converter. Have I missed something? Here is the schematic: https://content.arduino.cc/assets/MKRFox1200V2.0_sch.pdf

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #5 on: November 28, 2018, 08:32:05 AM »
I am not sure at all, should I use another pin ?
My plan is to put the board and the sensor in an hermetic plastic box and take measures every half hour or something like that.
About the batteries, the board has like a sleep mode, I belive, that is not enough ? I mean, i really need to use a transistor ?
Thank you for the schematic, but i´m afraid i am to noob to undestand it,  :-\

But you are helping me a lot ! THANKS! ;D ;D ;D

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #6 on: November 28, 2018, 11:25:18 AM »
now i have another question i would like to use 2 soilwatch 10, one to stick on the ground and one buried 90 cm underground, so I adapt your example code to read the 2 sensors, the thing is i get this readings:

ADC = 51, Moisture value on the ground = 0
ADC = 634, Moisture value Underground (1.5 m) = 68
ADC = 51, Moisture value on the ground = 0
ADC = 636, Moisture value Underground (1.5 m) = 68
ADC = 50, Moisture value on the ground = 0
ADC = 632, Moisture value Underground (1.5 m) = 68
ADC = 52, Moisture value on the ground = 0
ADC = 635, Moisture value Underground (1.5 m) = 68
ADC = 50, Moisture value on the ground = 0
ADC = 610, Moisture value Underground (1.5 m) = 65
ADC = 52, Moisture value on the ground = 0
ADC = 624, Moisture value Underground (1.5 m) = 67
ADC = 48, Moisture value on the ground = 0

the second sensor always print the same readings, the first one works correctly and the second i believe I have an error on my circuit, one dumb question, can i plug the second sensor to other analog pin instead of A0, i am using A4 currently but no mathers the pin, readings do not change. Maybe i should change the programming ?

this is my code:

const int analogInPinOnTheGround = A0;         
int minADCground = 44;                     
int maxADCground = 907;

const int analogInPinUnderground = A4;       
int minADCunderground = 44;         //i have to change this for calibration               
int maxADCunderground = 907;     //i have to change this for calibration
 
int moistureOnTheGroundValue, mappedOnTheGroundValue;

int moistureUndergroundValue, mappedUndergroundValue;
 
void setup() {
 Serial.begin(115200);
}
 
void loop() {
 
 
// SENSOR A RAS DE SUELO
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.println(mappedOnTheGroundValue);

delay(2000);

//SENSOR ENTERRADO A 1.5 METROS DEL SUELO
 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.println(mappedUndergroundValue);

delay(2000);
}

Piotr I understand that you can not have time to answer this, but your help will be appreciated.

Thanks a lot for your help,

Martín

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #7 on: November 28, 2018, 01:09:53 PM »
Quote
I am not sure at all, should I use another pin ?
My plan is to put the board and the sensor in an hermetic plastic box and take measures every half hour or something like that.
About the batteries, the board has like a sleep mode, I belive, that is not enough ? I mean, i really need to use a transistor ?
Thank you for the schematic, but i´m afraid i am to noob to undestand it,  :-\

But you are helping me a lot ! THANKS! ;D ;D ;D

I am not sure if you still will have 3.3V on the VCC pin when you power MRK FOX from the battery. The sensor will need 3.1V minimum to operate properly. Just check it.
The other thing is will that 3.3V be disconnected during sleep. If that is true then you don't need an additional transistor.

About your additional sensor. I can't see any fault in the code. Double check your connections.
Let me know if this will solve the wrong readings.


martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #8 on: November 29, 2018, 09:58:43 AM »
The 2 sensor are working correctly now. I will let you know the results when i test with the battery.

but for know all works fine with the USB.


Thanks for the support.

Stay in touch!

Martín

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #9 on: January 03, 2019, 09:04:18 AM »
Hi Piotr, first of all happy new year!

I did a few test, with the mkrfox 1200 and the 2 sensors, indeed I need to use transistors the sensors drain the batteries to fast even in the sleepmode, I can understand how a transistor work but I do not know which one is best to use with the mkr  fox 1200 and soilwatch 10,and also i do not know how to conect them properly, I know that i need a resistor for the transistor aswell, so If i have the 3 V sensor and MKR FOX 1200 operates at 3.3 V whitch transistor and resistor should i use ? Do i need to modify my code in order to make the transistor work ?

Thanks for your time,

Best regards

Martín
« Last Edit: January 03, 2019, 09:09:02 AM by martin.i.tycgis »

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #10 on: January 03, 2019, 02:58:25 PM »
Hi Martin,

Happy new year!

I assume through hole transistor will be preferred.  The 2N7000 should work just OK to switch 2 sensors at once. But may cause problems when it gets cold as it is on the edge of specs. Or you can use bigger 3.3V logic level MOSFET.
BSS138 or FDV301N is the perfect fit but as far as I know, comes in SMD package only.

Yes, you need to modify the code to turn on the MOSFET connected to the pin. See the schematic below. To turn on the MOSFET just set high pin connected to the gate of the MOSFET and set low to turn off. After you turn on the sensor, let it settle for 100-200ms then take the measurement as before.

It is best to change the R1 to 470 ohm

Kind regards,
Piotr


martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #11 on: January 08, 2019, 09:25:46 AM »
Could I controll another sensor with 1 mosfet ? , i have also this sensor https://www.dfrobot.com/wiki/index.php/Digital_Temperature_and_Humidity_sensor_(With_Stainless_Steel_Probe)_(SKU:SEN0148).

 If i undeststand correctly i can use the mosfet as a switch for the 3 sensors to turn them on at the same time. Should I use a digital or an analog pin for the 2 connection of the mosfet ?, this project maybe is too big for me! but i will continue doing it until i finish it!

As always thank you Piotr for your time!.

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #12 on: January 09, 2019, 09:06:53 AM »
You can control (turn on/off) as many sensors as you wish with one MOSFET. You should only keep in mind how much current your MOSFET will allow. You should be able to turn on the sensor mentioned above together with 2 SoilWatch 10 sensors.
Connect a digital pin to the gate of the MOSFET. Watch few Youtube videos on how to use MOSFET as a switch and how MOSFETs work and you will be all right.

This project is not too big. You can do it!

martin.i.tycgis

  • Newbie
  • *
  • Posts: 15
Re: Problems with soilwatch in mkr Fox 1200
« Reply #13 on: January 16, 2019, 11:24:01 AM »
Hello Piotr i am trying to get the transistor you suggest me, but it´s to tiny i do not really now how to use it, i guess i need something like this ? i can not get too much information about it.

 https://www.amazon.es/iHaospace-Channel-Converter-Bi-Directional-Arduino/dp/B06Y5KKMLL/ref=sr_1_6?s=electronics&ie=UTF8&qid=1547637619&sr=1-6&keywords=Bi-Directional+Logic+Level+Converter

if i can use one of theese would be nice, on the other hand is easiest for me to get the El 2N7000 or BS170 can not work for this project ?

Kind regards,

Martin

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Problems with soilwatch in mkr Fox 1200
« Reply #14 on: January 17, 2019, 04:15:37 PM »
Hi Martin,

The 2N7000 and BS170 will most likely be good enough. Two sensors consume about 50mA which is within a specified limit of the 2N7000 and BS170. Both MOSFETs work up to around 100mA but you can read from the graph that at Gate-Source equal 3V the current is somewhere between 50-100mA. These MOSFETs are really cheap so simply ty it.
If for some reason the above solution doesn't work then you can also use one MOSFET for each sensor and turn it on with one pin.

The link you provided is for the level shifter. That is handy when you connect two devices with different core voltages and expect them to work together. "The logic level converter is a small device that safely steps down 5V signals to 3.3V AND steps up 3.3V to 5V at the same time".

So try one of these MOSFETs and let us know  ;)

Kind regards,
Piotr