105
edits
 (info)  | 
				 (info)  | 
				||
| Line 117: | Line 117: | ||
=====Fort he main.cpp:=====  | =====Fort he main.cpp:=====  | ||
<small>#include <Servo.h></small>   | |||
<small>#define TRIG_PIN 2 // Pin Trig del sensor ultrasónico</small>  | |||
<small>#define ECHO_PIN 3 // Pin Echo del sensor ultrasónico</small>   | |||
<small>Servo myservo;  </small>   | |||
<small>float ang = 18; // Ángulo base de oscilación</small>  | |||
<small>int distanciaPersona = 65;  // Primer umbral</small>  | |||
<small>int distanciaCercana = 50;  // Segundo umbral</small>   | |||
<small>void setup() {</small>  | |||
<small>Serial.begin(9600);</small>  | |||
<small>pinMode(TRIG_PIN, OUTPUT);</small>  | |||
<small>pinMode(ECHO_PIN, INPUT);</small>  | |||
<small>myservo.attach(9);</small>  | |||
<small>}</small>   | |||
<small>void loop() {</small>  | |||
<small>long duration;</small>  | |||
<small>int distance;</small>  | |||
<small>// Enviar pulso ultrasónico</small>  | |||
<small>digitalWrite(TRIG_PIN, LOW);</small>  | |||
<small>delayMicroseconds(2);</small>  | |||
<small>digitalWrite(TRIG_PIN, HIGH);</small>  | |||
<small>delayMicroseconds(10);</small>  | |||
<small>digitalWrite(TRIG_PIN, LOW);</small>  | |||
<small>// Leer el tiempo de respuesta del eco y calcular distancia</small>  | |||
<small>duration = pulseIn(ECHO_PIN, HIGH);</small>  | |||
<small>distance = duration * 0.034 / 2;  </small>  | |||
<small>Serial.print("Distancia: ");</small>  | |||
<small>Serial.print(distance);</small>  | |||
<small>Serial.println(" cm");</small>  | |||
<small>// Evento 2: Si la distancia es menor a 30 cm, mayor movimiento</small>  | |||
<small>if (distance < distanciaCercana) {</small>  | |||
<small>  int maxAngulo = ang + 40;  // Aumenta el rango de oscilación</small>  | |||
<small>  if (maxAngulo > 180) maxAngulo = 180; // Limita el ángulo a 180°</small>  | |||
<small>  for (int pos = 0; pos <= maxAngulo; pos += 1) {</small>  | |||
<small>    myservo.write(pos);</small>  | |||
<small>    delay(15);</small>  | |||
<small>  }</small>  | |||
<small>  for (int pos = maxAngulo; pos >= 0; pos -= 1) {</small>  | |||
<small>    myservo.write(pos);</small>  | |||
<small>    delay(15);</small>  | |||
<small>  }</small>  | |||
<small>}</small>  | |||
<small>// Evento 1: Si la distancia es menor a 60 cm pero mayor o igual a 30 cm</small>  | |||
<small>else if (distance < distanciaPersona) {</small>  | |||
<small>  for (int pos = 0; pos <= ang; pos += 1) {</small>  | |||
<small>    myservo.write(pos);</small>  | |||
<small>    delay(15);</small>  | |||
<small>  }</small>  | |||
<small>  for (int pos = ang; pos >= 0; pos -= 1) {</small>  | |||
<small>    myservo.write(pos);</small>  | |||
<small>    delay(15);</small>  | |||
<small>  }</small>  | |||
<small>}</small>  | |||
<small>// Si no hay objeto cerca, dejar el servo en 0°</small>  | |||
<small>else {</small>  | |||
<small>  myservo.write(0);</small>  | |||
<small>}</small>  | |||
<small>delay(500); // Pequeño retraso antes de la siguiente medición</small>  | |||
<  | <small>}</small>  | ||
2nd Board:  | 2nd Board:  | ||
| Line 144: | Line 253: | ||
We chose the niche as our exhibition space because it allowed us to maintain a necessary distance from other sound-based projects. Additionally, this setup ensured that the work could only be viewed from the front, preventing visitors from accidentally bumping into it and disturbing any components.  | We chose the niche as our exhibition space because it allowed us to maintain a necessary distance from other sound-based projects. Additionally, this setup ensured that the work could only be viewed from the front, preventing visitors from accidentally bumping into it and disturbing any components.  | ||
*  | *  | ||
edits