Hello, I'm following this tutorial Tutorial to do an IoT Based Soil Nutrient Monitoring with Arduino & ESP32, I don't know if my wiring is wrong or correct but I think my wiring is correct, I followed the schematic in the tutorial but the tutorial picture is different from the schematic and I have checked many times I have the same wiring and tutorial so I think some problem in the code or schematic me .
I moved your topic to an appropriate forum category @ufufuiguygyufiydc.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
Please extract code and schematics and post them here. Many, most(?), helpers don't spend time on watching tutorials.
Your other topic on the same subject deleted.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
I note this is your second warning in less than 1 day, continued failure to follow the forum rules will lead to a ban on posting in the forum, possibly forever.
Thank you.
I use two coding:
number 1
#include <SPI.h>
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN on Blue Pill
const uint64_t address = 0xF0F0F0F0E1LL;
#define ONE_WIRE_BUS 5
#define RE 8
#define DE 7
const byte code[] = {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
byte values[11];
SoftwareSerial mod(2, 3);
const int AirValue = 645; //you need to replace this value with Value_1
const int WaterValue = 254; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent = 0;
float temperature;
int nitrogen;
int phosphorous;
int potassium;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
struct MyVariable
{
byte soilmoisturepercent;
byte nitrogen;
byte phosphorous;
byte potassium;
byte temperature;
};
MyVariable variable;
void setup()
{
Serial.begin(9600);
mod.begin(9600);
radio.begin(); //Starting the Wireless communication
radio.openWritingPipe(address); //Setting the address where we will send the data
radio.setPALevel(RF24_PA_MIN); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
radio.stopListening(); //This sets the module as transmitter
sensors.begin();
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
}
void loop()
{
byte val;
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
if (mod.write(code, sizeof(code)) == 8)
{
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 11; i++)
{
//Serial.print(mod.read(),HEX);
values[i] = mod.read();
Serial.print(values[i], HEX);
}
Serial.println();
}
nitrogen = values[4];
phosphorous = values[6];
potassium = values[8];
delay(1500);
soilMoistureValue = analogRead(A0); //put Sensor into soil
//Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
{
if (soilmoisturepercent >= 100)
{
soilmoisturepercent = 100;
}
else if (soilmoisturepercent <= 0)
{
soilmoisturepercent = 0;
}
else if (soilmoisturepercent > 0 && soilmoisturepercent < 100)
{
soilmoisturepercent = soilmoisturepercent;
}
}
delay(1500);
sensors.requestTemperatures();
temperature = sensors.getTempCByIndex(0);
variable.soilmoisturepercent = soilmoisturepercent;
variable.nitrogen = nitrogen;
variable.phosphorous = phosphorous;
variable.potassium = potassium;
variable.temperature = temperature;
delay(1500);
Serial.print("Soil Moisture: ");
Serial.print(variable.soilmoisturepercent);
Serial.println("%");
Serial.print("Nitrogen: ");
Serial.print(variable.nitrogen);
Serial.println(" mg/kg");
Serial.print("Phosphorous: ");
Serial.print(variable.phosphorous);
Serial.println(" mg/kg");
Serial.print("Potassium: ");
Serial.print(variable.potassium);
Serial.println(" mg/kg");
Serial.print("Temperature: ");
Serial.print(variable.temperature);
Serial.println("*C");
Serial.println();
radio.write(&variable, sizeof(MyVariable));
Serial.println("Data Packet Sent");
Serial.println("");
delay(10000);
}
number 2:
#include <WiFi.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
String apiKey = "FTY1Txxxxxxx1NGU";
const char* ssid = "********************************";
const char* password = "********************************";
const char* server = "api.thingspeak.com";
RF24 radio(4, 5);
const uint64_t address = 0xF0F0F0F0E1LL;
struct MyVariable
{
byte soilmoisturepercent;
byte nitrogen;
byte phosphorous;
byte potassium;
byte temperature;
};
MyVariable variable;
WiFiClient client;
void setup()
{
Serial.begin(115200);
radio.begin(); //Starting the Wireless communication
radio.openReadingPipe(0, address); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MIN); //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
radio.startListening(); //This sets the module as receiver
Serial.println("Receiver Started....");
Serial.print("Connecting to ");
Serial.println(ssid);
Serial.println();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
int recvData()
{
if ( radio.available() )
{
radio.read(&variable, sizeof(MyVariable));
return 1;
}
return 0;
}
void loop()
{
if(recvData())
{
Serial.println("Data Received:");
Serial.print("Soil Moisture: ");
Serial.print(variable.soilmoisturepercent);
Serial.println("%");
Serial.print("Nitrogen: ");
Serial.print(variable.nitrogen);
Serial.println(" mg/kg");
Serial.print("Phosphorous: ");
Serial.print(variable.phosphorous);
Serial.println(" mg/kg");
Serial.print("Potassium: ");
Serial.print(variable.potassium);
Serial.println(" mg/kg");
Serial.print("Temperature: ");
Serial.print(variable.temperature);
Serial.println("*C");
Serial.println();
if (client.connect(server, 80))
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(variable.soilmoisturepercent);
postStr += "&field2=";
postStr += String(variable.nitrogen);
postStr += "&field3=";
postStr += String(variable.phosphorous);
postStr += "&field4=";
postStr += String(variable.potassium);
postStr += "&field5=";
postStr += String(variable.temperature);
postStr += "\r\n\r\n\r\n\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
delay(1000);
Serial.println("Data Sent to Server");
}
client.stop();
}
}
i already change the apikey, ssid and password
any particular reason why you are using two microcontrollers communicating with nRF24L01 modules?
why not dump the Arduino and connect the sensors to the ESP32 therefore making the project much simpler
The problem with that tutorial - and many like it that use an NPK type sensor - is that the authors all copy from each other. That results in many web sites posting tutorials like the one you are trying to follow without the tutorial author understanding what the code they have created/copied does.
I'll give you 3 observations to get you started:
-
There are several NPK sensors on the market. They all probably are made by the same OEM for various companies to sell under their own brand. There are differences between them and not all NPK sensors hold the soil parameters in the same modbus registers. You need to know the specifics of the sensor you have bought. The user manual should tell you this.
-
The code segment that requests the soil measurements is fundamentally flawed. It's seen on many of the NPK tutorials that can be found. It assumes that the sensor instantaneously responds with the requested data, which is not what happens.
-
The values returned by the NPK sensor are 16-bit numbers. The tutorial assumes them to be bytes and only returns part of the response.
Have a search of the forum as there are quite a few discussions about the NPK sensor - some using ESP32.
That's not schematics. It's a bird nest Fritzing picture, hopeless to use as there are no pin designations present.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.