105
edits
mNo edit summary |
mNo edit summary |
||
Line 55: | Line 55: | ||
In the project, were implemented two systems of sensors and actuators controlled by Arduino boards, and programmed in Visual Studio Code and Arduino programs. | In the project, were implemented two systems of sensors and actuators controlled by Arduino boards, and programmed in Visual Studio Code and Arduino programs. | ||
[[File:Imagen de WhatsApp 2025-01-09 a las 12.58.12 ce313d3b.jpg|alt=Sketch 2, Lemon tree archive, Dania González Sanabria|thumb|711x711px|<small>Sketch 2, Lemon tree archive, Dania González Sanabria</small>]] | [[File:Imagen de WhatsApp 2025-01-09 a las 12.58.12 ce313d3b.jpg|alt=Sketch 2, Lemon tree archive, Dania González Sanabria|thumb|711x711px|<small>Sketch 2, Lemon tree archive, Dania González Sanabria</small>]] | ||
1rts Board: | <u>1rts Board:</u> | ||
For the moving branch, it was set a system with an HC-SR04 Ultrasonic Distance Sensor controlling a 15 kg Digital Servo Motor, through an Arduino Nano and a connective board. | For the moving branch, it was set a system with an HC-SR04 Ultrasonic Distance Sensor controlling a 15 kg Digital Servo Motor, through an Arduino Nano and a connective board. | ||
Line 71: | Line 71: | ||
2nd Board: | <u>2nd Board:</u> | ||
The terrarium had a humidifier system inside. It was made with a Capacitive Soil Moisture Sensor connected to an Arduino Nano and a connective board. | The terrarium had a humidifier system inside. It was made with a Capacitive Soil Moisture Sensor connected to an Arduino Nano and a connective board. When the soil got drier (over value 400 read by that sensor, whose values are approximately this: wet is < 400, dry is > 400), a 5V Relay Module also connected to the board, activated a 5V Humidifier made with a piezoelectric. When the soil got humid again (under value 400) the humidifier stopped until the soil got dry again. The relay and humidifier received an extra supply of energy from an MB-102 3.3V/5V Power Module plugged into electricity. [[File:Imagen de WhatsApp 2025-02-22 a las 03.09.15 5fec5717.jpg|alt=Sketch 3, Lemon tree archive, Dania González Sanabria|thumb|1095x1095px|<small>Sketch 3, Lemon tree archive, Dania González Sanabria</small>]] | ||
When the soil got drier (over value 400 read by that sensor, whose values are approximately this: wet is < 400, dry is > 400), a 5V Relay Module also connected to the board, activated a 5V Humidifier made with a piezoelectric. When the soil got humid again (under value 400) the humidifier stopped until the soil got dry again. The relay and humidifier received an extra supply of energy from an MB-102 3.3V/5V Power Module plugged into electricity. | |||
[[File:Imagen de WhatsApp 2025-02-22 a las 03.09.15 5fec5717.jpg|alt=Sketch 3, Lemon tree archive, Dania González Sanabria|thumb|1095x1095px|<small>Sketch 3, Lemon tree archive, Dania González Sanabria</small>]] | |||
Line 101: | Line 98: | ||
====== Devices and code (written code is at the end) ====== | ====== Devices and code (written code is at the end) ====== | ||
1rts Board: | <u>1rts Board:</u> | ||
* Arduino Nano | * Arduino Nano | ||
Line 109: | Line 106: | ||
* Connection cables | * Connection cables | ||
2nd Board: | <u>2nd Board:</u> | ||
* Arduino Nano | * Arduino Nano | ||
Line 128: | Line 125: | ||
====== Code ====== | ====== Code ====== | ||
1rts Board: | <u>1rts Board:</u> | ||
For the platformio.ini: | For the platformio.ini: | ||
=====Fort he main.cpp:===== | =====Fort he main.cpp:===== | ||
<small>#include <Servo.h></ | <small><code>#include <Servo.h></code></small> | ||
<small>#define | <small><code>#define TRIG_PIN 2 // Pin Trig del sensor ultrasónico</code></small> | ||
<small> | <small><code>#define ECHO_PIN 3 // Pin Echo del sensor ultrasónico</code></small> | ||
<small> | <small><code>Servo myservo; </code></small> | ||
<small> | <small><code>float ang = 18; // Ángulo base de oscilación</code></small> | ||
<small>int | <small><code>int distanciaPersona = 65; // Primer umbral</code></small> | ||
<small> | <small><code>int distanciaCercana = 50; // Segundo umbral</code></small> | ||
<small> | <small><code>void setup() {</code></small> | ||
<small> | <small><code>Serial.begin(9600);</code></small> | ||
<small>pinMode( | <small><code>pinMode(TRIG_PIN, OUTPUT);</code></small> | ||
<small> | <small><code>pinMode(ECHO_PIN, INPUT);</code></small> | ||
<small> | <small><code>myservo.attach(9);</code></small> | ||
<small> | <small><code>}</code></small> | ||
<small> | <small><code>void loop() {</code></small> | ||
<small> | <small><code>long duration;</code></small> | ||
<small>/ | <small><code>int distance;</code></small> | ||
<small> | <small><code>// Enviar pulso ultrasónico</code></small> | ||
<small> | <small><code>digitalWrite(TRIG_PIN, LOW);</code></small> | ||
<small> | <small><code>delayMicroseconds(2);</code></small> | ||
<small> | <small><code>digitalWrite(TRIG_PIN, HIGH);</code></small> | ||
<small> | <small><code>delayMicroseconds(10);</code></small> | ||
<small>/ | <small><code>digitalWrite(TRIG_PIN, LOW);</code></small> | ||
<small> | <small><code>// Leer el tiempo de respuesta del eco y calcular distancia</code></small> | ||
<small> | <small><code>duration = pulseIn(ECHO_PIN, HIGH);</code></small> | ||
<small> | <small><code>distance = duration * 0.034 / 2; </code></small> | ||
<small>Serial.print( | <small><code>Serial.print("Distancia: ");</code></small> | ||
<small>Serial. | <small><code>Serial.print(distance);</code></small> | ||
<small>/ | <small><code>Serial.println(" cm");</code></small> | ||
<small> | <small><code>// Evento 2: Si la distancia es menor a 30 cm, mayor movimiento</code></small> | ||
<small> | <small><code>if (distance < distanciaCercana) {</code></small> | ||
<small> | <small><code> int maxAngulo = ang + 40; // Aumenta el rango de oscilación</code></small> | ||
<small> | <small><code> if (maxAngulo > 180) maxAngulo = 180; // Limita el ángulo a 180°</code></small> | ||
<small> | <small><code> for (int pos = 0; pos <= maxAngulo; pos += 1) {</code></small> | ||
<small> | <small><code> myservo.write(pos);</code></small> | ||
<small> | <small><code> delay(15);</code></small> | ||
<small> | <small><code> }</code></small> | ||
<small> | <small><code> for (int pos = maxAngulo; pos >= 0; pos -= 1) {</code></small> | ||
<small> | <small><code> myservo.write(pos);</code></small> | ||
<small> | <small><code> delay(15);</code></small> | ||
<small>}</small> | <small><code> }</code></small> | ||
<small>/ | <small><code>}</code></small> | ||
<small> | <small><code>// Evento 1: Si la distancia es menor a 65 cm pero mayor o igual a 30 cm</code></small> | ||
<small> | <small><code>else if (distance < distanciaPersona) {</code></small> | ||
<small> | <small><code> for (int pos = 0; pos <= ang; pos += 1) {</code></small> | ||
<small> | <small><code> myservo.write(pos);</code></small> | ||
<small> | <small><code> delay(15);</code></small> | ||
<small> | <small><code> }</code></small> | ||
<small> | <small><code> for (int pos = ang; pos >= 0; pos -= 1) {</code></small> | ||
<small> | <small><code> myservo.write(pos);</code></small> | ||
<small> | <small><code> delay(15);</code></small> | ||
<small>}</small> | <small><code> }</code></small> | ||
<small>/ | <small><code>}</code></small> | ||
<small> | <small><code>// Si no hay objeto cerca, dejar el servo en 0°</code></small> | ||
<small> | <small><code>else {</code></small> | ||
<small> | <small><code> myservo.write(0);</code></small> | ||
<small> | <small><code>}</code></small> | ||
<small> | <small><code>delay(500); // Pequeño retraso antes de la siguiente medición</code></small> | ||
<small><code>}</code></small> | |||
<code><br /></code> | |||
2nd Board: | <u>2nd Board:</u> |
edits