
void setup()
{
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{
long randomNumber = random(500);
randomNumber = random(1,100);
Serial.println(randomNumber);
delay(1000);
if (randomNumber > 50)
{
digitalWrite(9, HIGH);
delay(200); // Wait for 1000 millisecond(s)
digitalWrite(9, LOW);
delay(800); // Wait for 1000 millisecond(s)
digitalWrite(9, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(9, LOW);
delay(2000); // Wait for 1000 millisecond(s)
}
digitalWrite(8, HIGH);
delay(500); // Wait for 1000 millisecond(s)
digitalWrite(8, LOW);
delay(500); // Wait for 1000 millisecond(s)
Código de número random en arduino
Foto celda
FOTOCELDA
int foto;
void setup()
{
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);
}
void loop()
{
int foto = analogRead(A0);
if (foto < 500)
{
digitalWrite(9, HIGH);
delay(200); // Wait for 1000 millisecond(s)
digitalWrite(9, LOW);
delay(800); // Wait for 1000 millisecond(s)
digitalWrite(9, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(9, LOW);
delay(2000); // Wait for 1000 millisecond(s)
}
else {
digitalWrite(9,LOW);
}
digitalWrite(8, HIGH);
delay(500); // Wait for 1000 millisecond(s)
digitalWrite(8, LOW);
delay(500); // Wait for 1000 millisecond(s)
}
Sonido de buzzer
void setup()
{
pinMode(10, OUTPUT);
}
void loop()
{
tone(10, 261);
delay(400);
noTone(10);
delay(400);
}
buzzer y led
int buzzerPin = 10;
void setup()
{
pinMode(buzzerPin, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
tone (buzzerPin, 261,200);
digitalWrite(9, HIGH);
delay(300);
digitalWrite(9,LOW);
delay(100);
}
buzzer y melodía
int buzzerPin = 10;
int blanca = 1000;
int blancaConPuntillo = 1500;
int negra = 500;
int A = 440;
int G = 391.99;
int B = 493.88;
void setup()
{
pinMode(buzzerPin, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
tone (buzzerPin, G,900);
delay(blanca);
tone (buzzerPin, A, 400);
delay(negra);
tone (buzzerPin, B, 1300);
delay(blancaConPuntillo);
tone (buzzerPin, G, 400);
delay(negra);
tone (buzzerPin, A, 400);
delay(negra);
tone (buzzerPin,B, 400);
delay(negra);
tone (buzzerPin, A, 1300);
delay(blancaConPuntillo);
tone (buzzerPin, G, 400);
delay(negra);
tone (buzzerPin, B, 400);
delay(negra);
tone (buzzerPin, A, 400);
delay(negra);
}
sensor de proximidad
// ---------------------------------------------------------------- //
// Arduino Ultrasoninc Sensor HC-SR04
// Re-writed by Arbi Abdul Jabbaar
// Using Arduino IDE 1.8.7
// Using HC-SR04 Module
// Tested on 17 September 2019
// ---------------------------------------------------------------- //
#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04
#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04
// defines variables
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor
Serial.println("with Arduino UNO R3");
}
void loop() {
// Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Displays the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
}
sensor de proximidad y buzzer
#define trigPin 10
#define echoPin 9
int speakerPin = 13;
int numTones = 10;
int tones[ ] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440,466, 494};
// mid C C# D D# E F F# G G# A
void setup()
{ Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{ long duracion, distancia ;
digitalWrite(trigPin, LOW);
// Nos aseguramos de que el trigger está desactivado
delayMicroseconds(2);
// Para asegurarnos de que el trigger esta LOW
digitalWrite(trigPin, HIGH);
// Activamos el pulso de salida
delayMicroseconds(5);
// Esperamos 10µs. El pulso sigue active este tiempo
digitalWrite(trigPin, LOW);
// Cortamos el pulso y a esperar el echo
duracion = pulseIn(echoPin, HIGH) ;
distancia = duracion / 2 / 119.1 ;
Serial.println(String(distancia) + " cm.") ;
if ( distancia >30){
noTone(speakerPin);
}
if (distancia < 30 && distancia >10){
tone(speakerPin, tones[350 - distancia]);
delay(700);
}
else {
noTone(speakerPin);
}
if ( distancia < 10){
tone(speakerPin, tones[400]);
delay(500);
}
else{
noTone(speakerPin);
}
}
proyecto
"RADAR"



rEFERENTE
TÉCNICO
PROCESO DE CÓDIGOS
#define trigPin 10
#define echoPin 9
int speakerPin = 13;
int numTones = 10;
int tones[ ] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440,466, 494};
// mid C C# D D# E F F# G G# A B
void setup()
{ Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{ long duracion, distancia ;
digitalWrite(trigPin, LOW); // Nos aseguramos de que el trigger está desactivado
delayMicroseconds(2); // Para asegurarnos de que el trigger esta LOW
digitalWrite(trigPin, HIGH); // Activamos el pulso de salida
delayMicroseconds(2); // Esperamos 10µs. El pulso sigue active este tiempo
digitalWrite(trigPin, LOW); // Cortamos el pulso y a esperar el echo
duracion = pulseIn(echoPin, HIGH) ;
distancia = duracion / 2 ;
Serial.println(String(distancia) + " cm.") ;
if ( distancia >300){
tone(speakerPin, tones[261]);
delay(500);
}
if (distancia >10){
tone(speakerPin, tones[350]);
delay(500);
}
else {
noTone(speakerPin);
}
if ( distancia < 10){
tone(speakerPin, tones[440]);
delay(500);
}
if (distancia < 10 && distancia >20){
tone(speakerPin, tones[311]);
delay(100);
}
if ( distancia > 40 && distancia <50){
tone(speakerPin, tones[277]);
delay(700);
}
if ( distancia >50 && distancia <70){
tone(speakerPin, tones[392]);
delay(700);
}
}
Avances
#include <Servo.h>
Servo servoMotor;
#define trigPin 11
#define echoPin 10
int speakerPin = 7;
int numTones = 10;
int tones[ ] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440,466, 494};
// mid C C# D D# E F F# G G# A
void setup()
{ Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(speakerPin, OUTPUT);
pinMode(7, OUTPUT);
// Iniciamos el servo para que empiece a trabajar con el pin 9
servoMotor.attach(9);
}
void loop()
{
servoMotor.write(0);
delay(3000);
servoMotor.write(90);
delay(3000);
long duracion, distancia ;
digitalWrite(trigPin, LOW); // Nos aseguramos de que el trigger está desactivado
delayMicroseconds(2); // Para asegurarnos de que el trigger esta LOW
digitalWrite(trigPin, HIGH); // Activamos el pulso de salida
delayMicroseconds(10); // Esperamos 10µs. El pulso sigue active este tiempo
digitalWrite(trigPin, LOW); // Cortamos el pulso y a esperar el echo
duracion = pulseIn(echoPin, HIGH) ;
distancia = duracion / 2 / 29.1 ;
Serial.println(String(distancia) + " cm.") ;
if ( distancia >30){
digitalWrite(speakerPin, HIGH);
delay(100);
digitalWrite(speakerPin, LOW);
delay(100);
}
else {
noTone(speakerPin);
}
if (distancia < 40 && distancia >10){
tone(speakerPin, tones[350 - distancia]);
delay(700);
}
else {
noTone(speakerPin);
}
if ( distancia < 10){
tone(speakerPin, tones[400]);
delay(500);
}
else{
noTone(speakerPin);
}
}
Problemas:
No he logrado que el sensor de proximidad tenga una relación coherente y convencional con el sonido del Buzzer.
Algo ocurre con el sensor de proximidad ya que los datos que me genera en el Monitor Serie son falsos siempre.
Retos
1. Lograr el enlace coherente entre el sensor de proximidad y el buzzer.
2. Que los datos del sensor sean verdaderos.
3. Que el movimiento del servo motor sea más lento.
Código definitivo 1
"RADAR"
#include <Servo.h>
Servo servoMotor;
#define trigPin 11
#define echoPin 10
int speakerPin = 7;
int numTones = 10;
int tones[ ] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494};
// mid C C# D D# E F F# G G# A
int posicion = 20;
boolean estaSumando = true;
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(speakerPin, OUTPUT);
pinMode(7, OUTPUT);
// Iniciamos el servo para que empiece a trabajar con el pin 9
servoMotor.attach(9);
}
void loop()
{
long duracion, distancia ;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(8);
digitalWrite(trigPin, LOW);
duracion = pulseIn(echoPin, HIGH) ;
distancia = duracion / 2 / 29.1 ;
Serial.println(String(distancia) + " cm.") ;
servoMotor.write(posicion);
delay(300);
if(estaSumando)
{
posicion = posicion + 2;
}
else
{
posicion = posicion - 2;
}
if(posicion >= 180)
{
estaSumando = false;
}
if(posicion <= 20)
{
estaSumando = true;
}
if (distancia < 20 && distancia > 3 ){
tone(speakerPin, 830, 400);
delay(400);
}
if (distancia > 25 && distancia <60 ){
tone(speakerPin, 698, 100);
delay(1000);
}
if (distancia > 60 && distancia < 200 ){
tone(speakerPin, 554, 100);
delay(500);
}
if (distancia > 220 && distancia < 1000 ){
tone(speakerPin, 1108, 100);
delay(500);
}
/*
if (distancia < 20 ){
tone(speakerPin, tones[350]);
delay(700);
}
else {
noTone(speakerPin);
}
*/
/*
if ( distancia >30)
{
digitalWrite(speakerPin, HIGH);
delay(100);
digitalWrite(speakerPin, LOW);
delay(100);
}
else
{
noTone(speakerPin);
}
*/
}
Estructura del "radar"
exploración formal y estéticA externA


Funcionamiento del radar
La energía del radar está siendo alimentada por una pila de 9V conectada al Arduino Uno
Exploraciones instalativas
Esta exploración fue espontanea del resultado final, debido a que estaba utilizando diferentes frecuencias de tonos y tiempos, tuve el deseo genuino de explorar la posibilidad de una composición sonora poniendo objetos a distintas distancias aprovechando el movimiento lineal del radar.
Próximo reto:
Lograr obtener los valores de Monitor Serie con el Arduino alimentado por la pila 9V sin estar conectado al computador