Arduino is at the same time a hardware at the sofware, an open hardware: you can copy it change it for free and an open surce sofware in a integrate development environment (IDE). You have acces to everithing, all the data and harware components are all the sofware components and the source code ( Codigo fuente) producing the sofware. Is the oposite to the propietary code and propietary hardware

arduino sofware is considered a C++ derivative and at the same time a Procesing related sofware.

Processing is an open source sofware previous to arduino sofware and is copatible with it, containing many open source Processing libraries of computer vision:

  1. BlobDetection (author: Julien 'v3ga' Gachadoat) Computer vision library for finding blobs in an image
  2. BoofCV for Processing (author: Peter Abeles): Processing interface for BoofCV
  3. Arduino (Firmata)(author: David A. Mellis): sofware to control arduino from Processing

This is the arduino code correspoding to the humidity project in the general project of the agriculture robotics, in this case my objective is mesure the humidity of a plant and depending on the soil misture or humidity a red LED will be switch on in case of low humiditty and a green LED will be on in case of high soil moisture

Next step will be to change LEDS and to use water pump, relays to water the plant

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


/*Analogic: 
/* in arduino 1 there are 6 analog inputs of 10 bits(1024 levels), and in ESP32 there are 20 analog inputs of 12 bits(4096 levels). We are going to calculate the reslution of the sensors and the analog inputs, taking into acount that Arduino uno is at 5 V microcontroller and ESP-32 is a 3.3 V microcontroller. 3.3/4096=0,00080566 V = 0,806 mV, 5V/1024 = 0,00488V = 4,88 mV. level 0 is 0V in Arduino, level one is 4.88 mV, level 2 is  9.97 mV, level  500 is 2441 mV= 2.44V and level 1023 is 5V. Can i mesure 6mV ? No, the solution is a beter ADC (analog digital converter of morre bits) for exemple, ADS 1115 is a ADC off 16 bits(2^16=65536 levels) 5V/65536=0,08mv. The advantatge is that we are capable to detect more values (more accuracy). Raspberry Pi v4 doesn't have any analog input, connecting ADS 1115 when is avaliable 
/* int means integer variable corresonding to an integer number A, 6 and 7 are ineteger
numbers, a0 is a special case, double forward slash means comment in arduino lenguage.
rainPin, greenLED and redLED are names of the variable invented in order to identfy 
the pins (connectors of arduino). For variable names we follow the camel case that is
the first leter of the first name in lower cases and the second name in the first 
letter will be uper cases. Other tipes or posibilities of conventions for writing
variables are used in other lenguages are snake case "for-example-this" and in camel
case is this :"forExampleThis" it's imposible to start a variable name with a number
or with especial characters corresponding to keywords used in instractions. */
/* other tipes of variables i arduino are boolean (True/False), byte (0, 255) char(character -128 a +127), int(-32768, +32767), long (very long numbers), Float( floating point numbers[Decimales]). Bolean, byte and char are 8 bits long, (2^8= 256) different values. Integers are 16 bits long (2^16=65536), and long variables and float variables are 32 bits long(2^32=4294967296)) there are signed and unsigned variables, if a variable is signed the variable is signed the value is divided by 2 (ex: 2^16=65536/2=32768 integers variables will go from -32768 to +32767,  one number is 0 this is why i m reducting the last numberby 1 unit). I can declare a long variable for measuring milisecond or microsecond, signed or unsigned? What is correct? Unsigned long time; means always positive for time */
// when i declare a variable i create an space in the computer memory with a name.
// it is interesting to declare variables of the right size to not waste inecesary space.
// if i add before int the word const it makes impossible to change
const int rainPin = A0
const int greenLED = 6;
const int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 800;
/*a variable can be a global variable if it is defined at the begining
of the code or local if it is defined inside a function or void block. 
If i do not assign a initial value to a variable it will be a 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 funton we use the previous global variables with Known names, for 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 INPUT in arduino.*/
/* Analog INPUT in arduino 1 is a 10-bit analog digital converter (ADC) that means 2^10=1024 values from 0 to 1023, in ESP-32 microcontroller there are 12-bit AACD that means 2^12=4096 values from 04095, in ADS1115 is 16 bit ADC
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
 /* it means serial comunnication betwin devices (microcontrolers and pc) and the number 9600 
 bits is the speed in bits/second(bouds). Other common speeds are: 57600 and 115200. */
 /*digitalWrite means to create a 2 state value: Hig and low, 0 and 1... We need to define 
 first the pin mode as imput on an output dependin on the features the pin.*/
  
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(rainPin);
  Serial.print(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