Ecualizador led – Itinerario de aprendizaje proyecto 3

Nuestro Itinerario de aprendizaje maker esta desarrollado para aprender todos los fundamentos y un poco más acerca de electrónica y programación.

Si completas el itinerario serás capaz de crear casi cualquier proyecto que imagines. En cada proyecto se introducen nuevos conceptos, de modo que aprenderás haciendo o creando de una manera amena y divertida.

En esta actividad introducimos los sensores analógicos. Aprende a incorporarlos en tus programas y interpretar los valores que te proporcionan.

Project Description
Project 3
MULTI SENSOR LED EQUALIZER

We will learn about analog sensors, reading a potentiometer, measuring ambient light and sound. You will build a device able to show visually how loud is your room and how darkness it's it!

Before to start
BEFORE TO START

DIFFICULTY LEVEL: Beginner
DURATION OF THE ACTIVITY: 30 min.

MATERIALS

1 Monochromatic Led light module
1 Rotary Potentiometer module
1 LDR analog light sensor
1 Sound analog sensor
1 Build&Code 4in1 board
Battery holder, USB cable and wires.

Components
3 - LED Equalizer - Components

Analog sensors senses external parameters (sound level, light intensity etc.) and gives analog voltage as an output. Usually they use some resistive element that varies according the measured agent

Sensor voltage output is readed by any of the 6 analog inputs we have in our 4in1 board. We can use many sensors at same time!

Potentiometer. Increase and reduce resitivity when turned

Analog sound sensor or microphone

If you don't have all these sensors, you can follow the exercises using any of them.

3 - LED Equalizer - Circuit
3 - LED equalizer - Circuit

The 4in1 Build&Code circuit board has 6 analog input ports and two analog outputs. Unlike digital ones, analogs cannot be inputs or outputs, we have differentiated ports for each type.

1.- Connect wire from 4in1 board A5 to Potentiometer module or LDR

2.- Connect wire from 4in1 board DIO 3, 5 and 6 to green, yellow and red LEDs respectively

3.- Connect power or batteries to main board.

Analog ports have A/D converters, in our board they can distinguish 1024 levels between 0-5V (max and minimum sensor voltage output) instead of "high" and "low" from digital inputs.
What do you think can happen if you connect an analog sensor in a digital input?

Exercise 3.1 - read potentiometer- serial port
3.1 Read potentiometer. Serial output

Analog inputs are readed as a value between 0 and 1023. According software there are different ways to see it's values in real time:

Arduino IDE

To see how values change in real time we use the serial port. We have to initialize, and then tell the program to write lines of text through it. We can view this text output opening "serial monitor".

void setup() {
 Serial.begin(9600);    //Initialize serial port
 int lectura;			//Create variable 
}

void loop() {
  lectura = analogRead(A5);       //Assign potentiometer value to variabele
  Serial.println(lectura);        //Send variable values to serial port
  delay(1);                       //Wait 1 ms to start again
}
Block Coding

With MBlock5 you should use "live" mode (see our first steps page) and then, create a variable, assign the analog value to it and you will can see it in the scenario.

You can see RX and TX leds in your 4in1 board. They blink when data is trasmitted on serial port

Exercise 3.2 - Adjust LED brightness by potentiometer
3.2 Adjust LED brightness by potentiometer

Remember you used PWM to adjust brightness? PWM values from minimum to max were 0 to 255, and out analog input has form 0 to 1023 values.

We can simply divide analog input by 4 to get closer values, but in arduino exists a more precise way to mapping both ranges, the MAP function

Block coding
Arduino code
void setup() { 
   int LED = 3;                 //Define LED pin numbrer
   pinMode(LED,OUTPUT);    	//LED pin as output
   int  valor = 0;		//Variable for analog value
   int r = 0			//Variable for PWM range
}
void loop() {
  valor=analogRead(A5);    	//Assign to variable analog input values
  r=map(valor, 0, 1024, 0, 255);//Map value from 1024 range to 256 range. 
  analogWrite(LED,r);      	//Power LED with PWM according input values
}
3.3 LED on or off using the potentiometer
3.3 LED on or off using the potentiometer

If you need, you can use an analog input as a digital input. You just have to define what the state change value will be.

Block coding
Arduino code
int LED = 3; // CONNECT LED TO DIGITAL IO 3
void setup() {
  pinMode(LED,OUTPUT);      // DEFINE AS OUTPUT
}

void loop() {
int  valor=analogRead(A5);      // ASSIGN ANALOG VALUE
  if(valor<512){                // IF INPUT < 512 POWER ON LED
    digitalWrite(LED,HIGH);
  }
  else{
    digitalWrite(LED,LOW);      // IF INPUT > 512 POWER ON LED
  }
}

Usually in digital sensors "high" state is above 3V and "low" state below 2V.
4in1 board digital inputs have 2.5V as state change value.

3.4 LED and analog sensors
3.4 LED and analog sensors

You can repeat previous exercices using an LDR and the Sound sensor to see how the sensors respond to light or ambient sound.

Now we need a device to show us when there is too much noise in our room, lighting green led when all is fine, yellow for medium level, and red for too loud.

Block coding
Arduino code
int L1 = 3;         //Establecemos el pin de entrada del primer, segundo y tercer LED
int L2 = 5;
int L3 = 6;
void setup() {
  pinMode(L1, OUTPUT);    // Declaramos los LEDs como pines de salida
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
}

void loop() {
  int valor = analogRead(A5);   // Asignamos una variable para los valores del potenciómetre.
  if (valor < 341) {            // Si el valor del potenciómetro es <341 se enciende el primer LED y el resto permanecen apagados
    digitalWrite(L1, HIGH);
    digitalWrite(L2, LOW);
    digitalWrite(L3, LOW);
  }
  else if (valor >= 341 && valor <= 682) {  // Si el valor del potenciómetro está entre 341 y 682 se enciende el segundo LED y el resto permanecen apagados
    digitalWrite(L2, HIGH);
    digitalWrite(L3, LOW);
    digitalWrite(L1, LOW);
  }
  else {                                     // Si el valor del potenciómetro es > 682 se enciende el tercer LED y el resto permanecen apagados
    digitalWrite(L3, HIGH);
    digitalWrite(L1, LOW);
    digitalWrite(L2, LOW);
  }
}

Fantastic!! Try also to get a an automatic light, when less light in your room, more shining LED.

Project 3: Multi sensor LED equalizer
Final project - Multi sensor LED equalizer

Now you can play with lights! your special and personalized lamp can shine as you decide!
Find here carboard templates and sample code, but remember, you can change it and explore!

Block coding
Arduino code
int modo = 0;

void setup() {
  pinMode(2, OUTPUT);
  pinMode(13, INPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT_PULLUP);
  modo = 0;
}

void loop() {
  if (digitalRead(10)) {
    modo += 1;
    delay(700);
  }

  if (modo == 0) {
    digitalWrite(2, LOW);
  }

  if (modo == 1) {
    digitalWrite(2, HIGH);
  }

  if (!(digitalRead(12)) || digitalRead(11)) {
    digitalWrite(2, HIGH);

  } else {
    if (modo == 2) {
      digitalWrite(2, LOW);
      delay(200);
      digitalWrite(2, HIGH);
      delay(200);
    }
  }

  if (modo == 3) {
    modo = 0;
    delay(200);

  }
}
previous arrow
next arrow

El Mega Maker Kit te ofrece el todo el material que necesitas para completar el itinerario, pero si dispones de otro kit, también puedes realizar algunos proyectos. Te animamos a que los revises todos, o que compres los componentes que necesites. Puedes verificar que actividades puedes realizar en nuestra página del Itinerario de aprendizaje.

0 0
0
¿Hablamos?
Necesitas Ayuda
¿Te ayudamos? 🙂

El horario en línea actualmente es de lunes a viernes de 10:00 a 13:30 y de 16:00 a 18:30 (hora España GTM+1). Si lo prefieres puedes enviarnos un correo a info@eboticseducation.com