Introduction: UCL - Embedded - Moisture Control of Plant
This is a school project for 2nd semester electives 2.1 UCL
Made by Emil
(Sorry that some of the pictures and video is in danish)
Step 1: Project Overview
In my school project is the main goal of this project is to fine a solution for industry of plant business water use. The solution shall help the industry to save a lot of water.
To do this I use an Arduino mega 2560. In the Arduino I code a program that can control a pump by what the two soil moisture sensor tell us. So if the moisture is low our pump will start and if the moisture is high our pump stop.
So with this object we can save a lot of water and money. Also we help the climate.
Step 2: Part List
To build this project we gonna use following item:
1 x Arduino mega 2560
1 x 12V / 3A power supplier
1 x In-line pump (17l/min)
1 x L298N DC Motordriver
2 x Soil Moisture Sensor – YL69
1 x USB cable for Arduino
3 x 220 ohm resistance
1 x Green LED
1 x Red LED
1 x Yellow LED
A lot of wires
Step 3: I/O List and Building
When we got all the item we can now build our project.
Here is the list of all pin used on Arduino also called I/O list:
Digital Outputs pin
GLED_1= 13;
RLED_1= 12;
YLED_1= 11;
TransistorPin = 7;
Analog Inputs pin
SENSE_1= 0;
SENSE_2= 1;
Power
5v for our sensors
GRN to everything
We are going to follow the electrical diagram above. Also the I/O list for the Arduino. The final result is that it should look as something like 2nd picture.
Step 4: Flow Chart, Requirements Specification and a Sequence Chart
Before we can start code our program. We need to make requirements specification and a sequence chart for our program.
Requirements specification
Our requirements specification for the Arduino program is following:
- Read the soil moisture Sensor
- If value from the sensors is under determined value. pump will start for 5 sec and wait 20 sec
- Flash red or green after which value come from the sensors
- Green if over determined value
- Red if under determined value
This is the minimum requirements for our program.
On the pictures you can see the sequence chart for some of the function in our program.
- Lyskontrol
- Pumpe
- Change
Also you can see the flowchart that gives us the overview of the program
Now we are ready to code our program.
Step 5: Code
There was some issue while programming. It wasn’t a success to start the pump with the Arduino. So had to make some changes. So instead of turning a pump up and down with PWN from Arduino. We turn an yellow LED up and down with PWN from the Arduino.
Instead of typing all the code in one file. I split them up in function and files. That helped me a lot keeping an overview of my program while programming.
Here is the final program. You will need all the file to make it work or just download the zip file.
Projekt
<p>#include "math.h" //importer math library</p><p>//Pin slot LED int GLED_1= 13; // Bekrafter om det er Wet på Digital PIN D13 int RLED_1= 12; // Bekrafter om det er Dry på Digital PIN D12 int YLED_1= 11; // Bekrafter om motor kører på Digital PIN D11</p><p>//Pint slot sensor og TransistorPin int SENSE_1= 0; //Bestemmer sensor 1 pin slot int SENSE_2= 1; //Bestemmer sensor 2 pin slot int TransistorPin = 7;</p><p>//Værdi holdere int count = 1; //tæller int value_1= 0; //til sensor værdier int value_2= 0; //til sensor værdier int SHOCK = 0; //til change int maxV= 102; //maximale værdi sensor måler (dirakte tør luft) int minV= 24; //minimale værdi sensor måler (direkte vand) int fugtighed = 50; //defualt fugtigheds grænse int hastighed = 10; //defualt hastigheds grænse</p><p>//Andre variabler char junk = ' '; unsigned long previousMillis = 0; //til delay ved hjælp af millis const long interval = 1000; //til delay ved hjælp af millis unsigned long previousMillis_2 = 0; //til delay ved hjælp af millis const long interval_2 = 5000; //til delay ved hjælp af millis</p><p>void setup() { Serial.begin(250000); //bps pinMode(GLED_1, OUTPUT); //status på pin pinMode(RLED_1, OUTPUT); //status på pin pinMode(YLED_1, OUTPUT); //status på pin pinMode(TransistorPin, OUTPUT); //status på pin } void loop() { Sensor(); //aflæser og skrive nuværende status pumpe(hastighed); //køre pumpe function med bestemt hastighed Change(); //afventer hvis der skal ændres Lys(value_1, value_2, GLED_1, RLED_1, fugtighed); //funktion der styre lysene }</p>
Sensor
<p>void Sensor()<br>{ unsigned long currentMillis = millis();//til at lave delay if (currentMillis - previousMillis >= interval) //når den når et bestemt til inden for millis, skal den køre { previousMillis = currentMillis; //gemmer tidligere millis Serial.println("-----------------------------"); Serial.println("PLANTE KONTROL"); Serial.println("-----------------------------"); value_1= analogRead(SENSE_1); //Læser signal fra analog pin slot value_1= value_1/10; //for at arbejde med minde tal value_2= analogRead(SENSE_2); //Læser signal fra analog pin slot value_2= value_2/10; //for at arbejde med minde tal Serial.print("SENSOR 1: "); Serial.print(Calculate(value_1)); //regner værdi om til procenter i forhold til fugtighed Serial.print("% / Raw data: "); Serial.println(value_1); Serial.print("SENSOR 2: "); Serial.print(Calculate(value_2)); //regner værdi om til procenter i forhold til fugtighed Serial.print("% / Raw data: "); Serial.println(value_2); Serial.println("-----------------------------"); Serial.print("Fugtigheds grænse: "); Serial.print(fugtighed); Serial.println("%"); //printer bestemte grænse Serial.print("Motor speed: "); Serial.print(hastighed); Serial.println("%"); //printer bestemte grænse Serial.println("-----------------------------"); Serial.println("Press 1 and Enter to change limit"); Serial.println("-----------------------------"); UpdatePage(8); //cheat serial monitor } }</p>
LysKontrol
<p>void Lys(float N_1,float N_2, float G, float R, float K) //N_1 = sensor 1, N_2 = sensor 2, G = grøn pin slot, R = rød pin slot og K kontrol punkt.<br>{ float kontrol = (((1-(K/100))*(maxV-minV))+minV); //Serial.println(kontrol);//testing if(N_1</p>
Pumpe
<p>void pumpe(float H) <br>{ unsigned long currentMillis_2 = millis();//til at lave delay int check=digitalRead(RLED_1); //variable der ser status for RLED pin float Pspeed= 255*(H/100); //regner den bestemte hastighed om til et tal mellem 0-255 //analogWrite(TTransistorPin, Pspeed); //Test if (currentMillis_2 - previousMillis_2 >= interval_2) //køre hvergang der er gået 5 sec { //Serial.println(count); //testing previousMillis_2 = currentMillis_2; //gemmer tidligere millis if(check == HIGH and count == 1) //count bruges så den kun køre hver 5 gang (25sec) { //Serial.println(Pspeed);//testing analogWrite(TransistorPin, Pspeed); //aktiver transistorPin med en hastighed //digitalWrite(TransistorPin, HIGH); count = 5; } else if (count > 1) { analogWrite(TransistorPin, 0); count = count - 1; } else { analogWrite(TransistorPin, 0); } } }</p>
Calculate
<p>float Calculate(int V) //V = sensor værdi<br>{ float range = maxV - minV; float NewSensorV = V - minV; float procent = ((1 - NewSensorV / range)*100); return procent; }</p>
UpdatePage
<p>void UpdatePage(int x)<br>{ for (int i=0; i <= x; i++){ Serial.println(); } }</p>
Step 6: Result and Conclusion
All in all it have been an okay project. I have learn a lot about c++ and can definite see what it can be use to in an Arduino. Sadly for this project I didn’t manage to make the pump work together with the Arduino. Because my knowledge for electricity system wasn’t good enough. Failed to use an IRF9520 it didn’t turn off the pump when it was suppose to. Later I tried to use a L298n it almost worked. But something was wrong with the power running through the device to the pump. So ended up with a temporary solution where i used a yellow LED as "pump". Will keep working on making L298n work in my system. with further programing for the pump, this will probably work and it can be a success.