Arduino is at the same time a hardware and a software, an open hardware (you can copy it, change it, freely and open source software in a integrated devolpment environment (IDE). You have acces to everything all the data and hardware components and all the software components and the source code producing the software. Is the oposite to the propietary code and propietary hardware
Ardino 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:
This is the Arduino code corresponding to my 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 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
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 following:
/* int RainPin = A0 /* In arduino 1 there're 6 analog inputs of 10 bits (1024 levels) and in ST 32 there're 20 analog inputs of 12 bits (4096 levels).We're going to calculate the resolution of the sensors and the analog inputs, taking into account thet Arduino 1 is at 5V microcontroler and ESP-32 is a 3.3V microcontroler. 3,3 / 4096 = 0,0008056640625 = 0,806mV, 5 / 1024 = 0,0048828125 = 4,88mV. /* Level 0 is 0V in Arduino, level 1 is 4.88mV, level 2 is 9.76mV, level 500 is 2441mV = 2,4V and level 1023 is 5V. Can I mesure 6mV? NO, solution: The solution is a better ADC (Analog digital converter of more bits) for example, ADC 1115 is a ADC of 16 bits (2^16 = 65536 levels) 5 / 65536 = 0,00007 x 1000 = 0,08. The advantage is that we're captable to detect mmore values (more accuracy). Rassberry-PI v4 doesnt have any ADC that is any analog input, connecting ADS 1115 when is aviable. /* int it 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 lenguage. rainPin, greenLED and redLED are names of the variable invented in order to identify the PINS (connectors of the Arduino). For variabl names we follow the camel case that is the firts letter of the first name in lower cases and the second name in the first letter will be upper case. Other types or other posibilities of convention for writing varibles 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 coresponding to keywords used in instructions. */ /* Other tipes of variables in arduino are boolean (true/false), byte (0-255), char (character -128 - +127) int, (-32768 - +32767), long (very long numbers) float (floating point nubers). Bolean byte and char are 8 bites long, 2^8=256 different values. Integer is 16 bits (2^16=65536) in length, andlong and finaly, long and float are 32 bites (2^32=4294967296) length. There are signed and unsigned variables, if the variable is signed the value is divided by 2 (eample:2^16=65536/2=32768) integues variables will go from -32768 to 32767, onenumber is 0 this is why i'm reducing the last number by one unit. I can declare a long variable for masuring miliseconds or microseconds, signed or unsigned? What is correct? unsigned long time; means positive for time. */ // When i declare a variable I create an space in the computers memory with a name // It is interesting to declare variables of the right size // If I add before int the word const it makes inpossible to change const int rainPin = A0; int greenLED = 6; int redLED = 7; // you can adjust the threshold value int thresholdValue = 1400; /* A variable can e a global variable if it is ddefined 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 functin including thr genaral settings for example if the pinkis input or an output, the initial vlues of my circuit, the green LED will be OFF or LOW. In the pin mode function we use the previous global variables with known names, for example, pin mode (rainPin, INPUT); means is the same as (rainPin, A0); because it is easyb to uderstand because we give this variable name to the A0 pin becauseis an 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 to 1023. In ESP-32 microcontroler there are 12-bit ADC that means 2^12=4096 values from 0 to 4095, in ADS1115 is 16-bit ADC 2^16=65536 values from o to 65535. pinMode(rainPin, INPUT); pinMode(greenLED, OUTPUT); pinMode(redLED, OUTPUT); digitalWrite(greenLED, LOW); digitalWrite(redLED, LOW); // Digital write it means that a two state value, high and low, in digital inputs sometime at set 0 and 1 ass, in digital inputs, we need to define first the pin mode as output depending on the features of the pin. For example in the pin A0 is only analog input it desn't accept outputs, A of analogs 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 baunds Arduino are 57600 and 115200 } 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: