Programming, compiling and uploading the code to Arduino
Completion requirements
Programming, compiling and uploading the code to Arduino
On the main screen of Arduino Web Editor, click on the button NEW SKETCH to create a new sketch:

Arduino Web Editor assigns the name of the new sketch automatically. The name consists of the word sketch, an underscore, and six alphanumeric characters (the first three letters of the month, two digits for the day and a sequential letter: a, b, c, etc.).
We change the name of the new sketch to smart-irrigation following the steps shown in the figure:

Now we copy the following code and paste it in the code area on the right:
const int sensorPin = A0;
int HistoryValue = 0;
char printBuffer[128];
const int RELAY_PIN = A5; // the Arduino pin, which connects to the IN pin of relay
void setup()
{
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT); // initialize digital pin A5 as an output.
digitalWrite(RELAY_PIN, LOW); // turn off pump
}
void loop()
{
int humidity = analogRead(sensorPin); // get humidity from A0
if(((HistoryValue>=humidity) && ((HistoryValue - humidity) > 10)) || ((HistoryValue < humidity ) &&="" ((humidity="" -="" historyvalue)=""> 10)))
{
sprintf(printBuffer,"ADC%d level is %d\n",sensorPin, humidity);
Serial.print(printBuffer);
HistoryValue = humidity;
}
if(humidity < 50) // parameter should be adjusted to the soil moisture low level
{
digitalWrite(RELAY_PIN, HIGH); // turn on pump
}
if(humidity > 600) // parameter should be adjusted to the soil moisture high level
{
digitalWrite(RELAY_PIN, LOW); // turn off pump
}
}
Next, we click on the button Verify and Save. Arduino Web Editor will verify the integrity of the code (that it does not have errors) and will save it in the cloud under the assigned name:
