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

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

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

  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): Software to control Arduino from processing.

This is the Arduino code corresponding to my Humidity Project in the general project of Agriculture Robotics. The objective is mesure de 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 switch ON in case of high soil moisture.

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 the 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 variables invented in order to identify
the pins (connectors of the Arduino). For variables names we follow  the camel case, that is 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 writting 
variables are used in other languages re 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 caracters corresponding to keywords used in instructions.*/
/* 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 float (floating point numbers). Boolean, byte and char are 8 bits long, 2^8=256 different values. integer is 16 bits (2^16=65536) in length, and finally, long and float are 32 bits (2^32=4294967296) length. 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 to +32767, one number is 0 this is why I am reducing the 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 variable I create a space in the computer's memory with a name.
// It is interesting to declare variables of the right size.
// If I add before int the word const it makes impossible to change
const int rainPin = A0;
/*In Arduino uno they are six analog imputs of ten (1024 levels) bits in ESP-32. There are 12 bits (4096 levels). We are going to calculate the resolution of the sensors and the analog imputs, talking into account that Arduino uno is a 5V microcontroller and ESP-32 is a 3.3V microcontroller. 3.3V / 4096 = 0,00080566406 V = 0,806 mV , 5V / 1024 = 0,0048828125 V = 4,88 mV.
Level 0 is 0V in Arduino, level 1 is a 4,88 mV, level 2 is 9,76 mV, level 500 is 2441 mV = 2,4 V and level 1023 is 5V. Can i mesure 6 mV? No, the solution is a better ADC (Analog Digital Converter of more bits) for example the ADS t1115 is a ADC of 16 bits (2^16 = 65536 levels) 5V / 65536 * 1000 = 0,88 mV. The advantatge is that we are capable to detect more values (more accuracy) Raspberry PI v4 doesn't have any ADC that is any analog input, connecting ADS 1115 when is avaliable.
const int greenLED = 6;
const int redLED = 7;
// You can adjust the threshold value.
int thresholdValue = 1400;
/* 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 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, 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 the Arduino.*/
/* Analog INPUT in Arduino Uno is a 10-bit 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 thatmeans 2^16=65536 values from 0-65535.
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
  Serial.begin means serial communications between devices (microcontroller and PC) and the number is the speed in bits per second or bouds.
  Digital whrite it means to write a two state valuate "high a low"" sometimes at set 0-1 as lite high and low, we need to definite first depending on the defeatures o pin. For example de pin is a0, is only analog imput, to a0 pin to a5 pin are analog imputs of 10 bits - 1024 values (0-1013-maxium value 5V) (ESP32 = 12 bits = mas de 6 entradas= 4096 values - maxium value 3,3V)  Resoluton: capacity of distingushing values 3,3/4096 mV}
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);
}
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 1400;

void setup(){
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

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: