pino-tech.eu
Products => SoilWatch 10 => Topic started by: martin.i.tycgis 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.
-
Thinking about it, maybe is the Voltage ? I believe mkr Fox 1200 works with 3.3V maybe is this the problem ?
-
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:
if(is1V1Output == true)
analogReference(INTERNAL); //set ADC reference to internal 1.1V
Have you set correct ADC pin:
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 :)
-
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
-
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 (https://content.arduino.cc/assets/MKRFox1200V2.0_sch.pdf)
-
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
-
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
-
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.
-
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
-
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
-
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
-
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) (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!.
-
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!
-
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 (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
-
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
-
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/1LUEg-T-2KOLSCw-pb6mt9N30Q3qJv0wz/view?usp=sharing)
https://drive.google.com/file/d/18nFvt-TI2rGdJ6FRyyPaC7d6DzF_s_Km/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
-
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
-
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
-
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
-
That's great! :)
Please let me know how the field tests go.
Piotr
-
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
-
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
-
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
-
Hi Martin,
You change ADC reference to internal 1.0V with:
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
-
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
-
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