Hi guys. I am a newbie trying out some projects. I am building a smart farm project that incorporates soil moisture sensor to start a pump for watering when soil condition is dry beyond certain threshold. DHT11 sensor to update on the temperature and humidity of farm.Water level sensor to prevent the water pump from running dry without water and an LDR coupled with a buzzer to indicate intrusion. A GSM module to send an SMS update of the moisture, temperature and humidity values for offline communication of sensor measured values so that farmer can still have update when he/she is not connected online
I am also feeding the output signals of the moisture sensor and DHT11 sensor ESP8266 wifi module for IoT monitoring as well.
I have the working codes for the individual sensors but my problem is how to combine everything without having compilation problems. I have tried and having issues.
Any reference to any code that combines all these functionalities?
The only way to combine code sensibly is to first make sure that you understand what every line of each individual program does, and then take only those parts that are required for the project, and arrange them in the correct order. You will probably also have to make modifications to the shared parts.
That is a very advanced project for a beginner. If you want dedicated help, post on the Gigs and Collaborations forum section. You may be asked to pay for the service.
If you tried to get everything working in one shot, you're likely to have problems. Start with the smallest part you can manage and then add functionality a piece at a time, testing as you go.
Maybe start with the moisture sensor and the pump, then add the low water sensing.
Here are some general instructions on merging 2 sketches but it is essential that you understand how each of them work before you start combining them
Start with one of the sketches and move all of the code in the loop() function to a new function with a sensible name. Copy all of the code from the loop() function of the second sketch into a second new function of the combined sketch. Now you have two functions that can be called from loop() in the combined function so add calls to both of them to loop()
Copy all of the code from setup() in the second sketch into setup() in the combined sketch. Now the setup() function contains code to set up inputs, outputs etc for the combined sketch
Copy any functions other than setup() and loop() from the second sketch to the combined sketch. Now the combined sketch has all of the functions of both sketches
Copy all of the global variable declarations from the second sketch into the combined sketch. Now all of the variables required by the combined sketch will be available
Save the combined sketch with a new name.
Now the fun starts
Resolve any conflicts of variable names caused by the same name being used in both sketches. If this is the case then change the name of one set of variables both where they are declared and in any functions
Resolve any conflicts of function names caused by the same name being used in both sketches. If this is the case then change the name of one set of functions both where they are declared and in any functions they are called from
Compile the program. If it compiles OK then upload and test it. It may compile but may not do what you want because of delay()s etc in the program and the order in which functions are called