Arduino is at the same time a hardware and a software, and open hardware: you can copy it, change it for free and open source software in a integrated development environment (IDE). You have acces to everything all the data and hardware components are all the software components and the source code(codi font) producing the software. Is the opposite to the propietary code and the propetary hardware

Arduino software is considered a c++ derivative and at the same time a Processing related software

Processing is an open source software previous to Arduino software and compatible with Arduino, containing many open source Processing libraries of computer vision or Arduino as examples:

This is the Arduino code corresponding to my humidity project in the general project of Agriculture Robotics, the objective is mesure the humidity of a plant and depending on the soil moisture or humidity a red LED will be switch on in case of low humidity and a green LED will be on in case of high soil moisture

In the next step will be to change LEDS and to use a water pump, relays to water the plant

My code for the YL-69 soil moisture sensor and LEDS is the following:



/*int means integer variable corresponding to a integer number A0, 6 and 7 are integer numbers, A0 is a special case. Double forward slash means comment in Arduino language.
RainPin,greenLED and redLED are names of the variables invented in order to identify the pins (connectors of the Arduino). 
For variables names we follow the camel case, that's the first letter of the first name in lower cases and the second name in the first letter will be upper cases
Other posibilities of convention for writing  variables are used in other languages are snake case "for-example-this" and in camel case is this "forExampleThis".
It is imposible to start a variable name with a number or with special characters corresponding to key words used in intructions.*/
/* Other types of variables in Arduino are boolean (true/false), byte (0-255), char (character -128 - +127), int (-32768 - +32767), long (very long numbers) and flo(floating point numbers). Boleante and chart are 8 bites long 2^8=256 different values. Integer is 16 bits(2^16=65536) in lenght; and finally, long and float are 32 bits (2^32=4294967296) lenght. 
There are signed and unsigned variables, if the variable is signed the value is divided by 2 (example: 2^16=65536/2=32768 integer variables will go from -32768 t+32767, one number is 0 this is why im reducing de last number by 1 unit). 
I can declare a long variable for mesuring miliseconds or microseconds, signed or unsigned? What is correct? Unsigned long time; means always positive for time.*/
// When I declare a variables I create a space in the computer's memory with a name.
// It's interesting to declare variables of the right size
// If I add before int the word const it makes impossible to change
const Pin = A0;int rain
const int greenLED = 6;
const int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 300;
/* A variable can be a global variable if it is defined at the begining of the code or local if it's defined inside a function or void bock. If I do not assign a initial value to a variable it will be 0 as a default value./*
void setup(){
/* setup is a block of code or function including the general settings for example if the pin is an input or an output, the initial values of my circuit, the green and the red LED will be off or LOW. In the pinMode function we use the previous global variables with known names, example pinMode(rainPin, INPUT); is the same as pinMode(A0, INPUT); 
because it is easier to understand because we give this variable name to the A0 pin because is the first analog imput in the Arduino.*/
/* Analog INPUT in Arduino Uno is a 10-bits analog to digital converter (ADC) that means 2^10=1024 values from 0-1023. In ESP-32 microcontroller there are 12-bit ADC that means 2^12=4096 values from 0-4095, in ADS1115 is 16-bit ADC 2^16=65536 value from 0-65535
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  //DigitalWrite means to write a two state value, HIGH and LOW sometimes 0 & 1 in digital inputs. We need to define first the input or de output depending on the features of the pin. For exmple if the pin A0 is only analog input it doesn't accept outputs, A of analog are only inputs of 10bits.
  Serial.begin(9600);
  // Serial begin it means serial communication between devices ( microcontrolers and personal computer) and the number 9600 is the speed in bits per second or  bauds, other common bauds are 57600, and 115200
}

void loop() {
  
  // read the input on analog pin 0:
  int sensorValue = analogRead(rainPin);
  Serial.println(sensorValue);
  if(sensorValue < thresholdValue){
    Serial.println(" - Doesn't need watering");
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
  }
  else {
  
    Serial.println(" - Time to water your plant");
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
  }
  delay(500);
}

This is the image of the circuit: