Arduino is at the same time a hadware and a software, and open hadware: you can copy it, changed, for free and open software in a Integrated Developen Snvironment (IDE). With Arduino you have acces to everything, all the data and hardware components, all the software components and the source code(codi font), producing the software. Is the opposite to the propietary code and propietary hardward.

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

Processing is an open source software previus to Arduino software and compatible with Aruino, containing meny open source Processing libraries of computer vision or Arduino as example:

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

This is the Arduino code corresponding to my humidity project in the general project of agriculture robotics, in this case my objective is mesure the humidity of a plant and deppending on the soil mouisture or humidity. A red LED will be switch ON in case of low humindity and a green LED wil be ON in case of high aoil moisture

Next step wil 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 following:

 

int rainPin = A0;
/* In Arduino unothere are six analoginuts of 10 bits(1024 levels), and in ESP-32 there are 20 anolginputs of 12 bits (4096 levels). We are gooing to calculate the resulution of sensors and the analog inputs, taking into account that Arduinno uno is a 5 v microcontroler and ESP-32 is a 3.3 v microcontroler. 3.3v/4096= 0,0008056640625 v= 0,806, 5v/1024= 0,0048828125v= 4,88 mV.
Level 0 is 0v in Arduino, level 1 is 4,88mV, level 2 is 9,76mV, level 500 is 24441mV= 2,4V annd level 1023 is 5v. Can I mesure 6mV? NO, the sulution is a better ADC (Analog Digital Conoverter More bits), for example ADS1115 is a ADC of 16 bits (2^16= 65536 level) 5V / 65536 *1000 = 0,08mV, the adventage is that we are capable to detect more values (more accuracy), Raspberry pi version 4, doesn't have any adc,  so we have to connect an ADS1115 when is abiable, that it have anolg inputs.

/*int means integer variable corresponding to a integer number A0, 6 and 7 are integer numbers, A0 is a special case. Double forware slash means comment in Arduino lenguage. rAINpIN, green LED are names of the variabes in order to identifay the PINS (conector of the Arduino). For 
variables names we folow the camel case that is  the ferst latter of the first name in lower cases and the second name in the ferst letter wil be upper case. (Other
types o other posiblities of conventions for writting variables are used in other lenguages at snake case "for-example-this" and in camel case is this: "for-ExempleThis" it is impaosible to tart a vairable name with a number woth a special characters corresponding to keywords used in intructions)*/
/*Other tipes 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 pint numbers, admite decimal part). 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 variable, if the variable is signed the value is devided by 2 (exemple:2^16=65536/2= 32768 integuer 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 milliseconds or micrseconds, signde or unsigned?Wgat is correct? unsigned long time; means always posiive of time.*/
//When I declare a variable I create an space in the coputers memory with a name.
//It is interesting to declare varaibles of the right size.
//If I add before int the word "const" it makes impossible to change.

const int greenLED = 6;
contint redLED = 7;
// you can adjust the threshold value
int thresholdValue = 720;
/* A variable can be a global variable if it this defined at the beginig of the code or local if it is defined inside a fuction aor void block. If I do not assing a initial value to a global 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 inicial 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); BECASUE IT IS EASIER TO UNDERSTAND, because we give this variable name to the A0 pin becasue is the ferst anlagoinput in the Arduino.*/
*/ Analloginput in Arduino uno is a 10-bit analago digital converter (ADC) that means 2^10=1024 values from 0 to 1023.In ESP-32 microcpntroller there are 12-bit ADC that means 2^12=4096 values from 0-4095, in ADS1115 is 16-bit ADC 2^16=65535
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
  */Serial begin, mean Serial Comunication in Between the Devices of microcontroler and personal computer (PC), and this is the sped in bits for second or bouds, other common speeds are: 57600, 115200 and 9600.
}

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);
    */Means to write a two state value (HIGH, LOW, and some time in 0 and 1) in digital inputs, we need to define first the pin mode as an input and outpud, deppending on the features fo the pin, for example; if the pin is A0, i can not put un digital, just analgoic, because from A0-A5 pin are pins that only are inputs values of 10 bits (1024 values).
    */Arduino: 5volts, ESP-32: 3.3volts.
  */ESP-32: Tiene 12 bits and 2^12=4096 values.
  */Resulotion capacity of distinguixin differents values are bigger ESP-32; 3,3/4096mV, Arduino;5/1024mV
  }
  else {
    Serial.println(" - Time to water your plant");
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
  }
  delay(500);
}

 

This is the image of the circuit: