Saltar navegación

Activa JavaScript para disfrutar de los vídeos de la Mediateca.

Arduino: analog output - Contenido educativo

Ajuste de pantalla

El ajuste de pantalla se aprecia al ver el vídeo en pantalla completa. Elige la presentación que más te guste:

Subido el 10 de enero de 2021 por David G.

335 visualizaciones

Descargar la transcripción

Hello! In this exercise we are going to use the same circuit we used in the 00:00:00
previous exercise. You can see that we have the voltage divider connected the 00:00:05
same way we connected it the previous day. We are reading from 5 00:00:10
volts to 0 volts using the A0 analog connector and we have the LED connected 00:00:19
to the Arduino board, the usual way, but there is something different. Instead of 00:00:25
of connecting it to number 13, the LED is connected to number 11. Why number 11? You 00:00:29
can see that numbers 11, 10, 9, 6, 5 and 3 have a line in front of the number. It means 00:00:37
that they are different, these connectors are different. It means that they can provide 00:00:47
also, they can provide, I mean, digital values, the same way we have been doing during the 00:00:54
previous days, high and low digital values, but these six connectors, the one with the 00:01:00
line in front of the number, can also provide analog values. 00:01:05
It means that we can send one volts, two volts, three volts, one and a half, two and a half, 00:01:11
2.40, 3.60, 3.75, whatever. 00:01:18
And if this LED is connected to 11, for instance, 00:01:25
it means that we will be able to provide, I don't know, maybe 240, 320. 00:01:28
It means that we will be able to control the intensity of the LED. 00:01:35
We will be able to decide if the LED will shine brighter or less bright. 00:01:42
Okay? 00:01:47
So, let's have a look at the simulation, I will show the code later to you. 00:01:47
If we are reading 0 using the A0 connector, 11 doesn't send anything to the LED, it doesn't 00:01:54
change. 00:02:04
If we move a little bit higher, it means that we are reading a number higher than 0, as 00:02:05
you can see the LED is shining a little bit. 00:02:11
If we move it and we read a number even higher, the LED will shine brighter, and the higher 00:02:14
the number we read, the brighter it will shine, okay? 00:02:21
This is the brightest value. 00:02:26
We go back to 0, 5, 0, 5. 00:02:29
You can see the ranges, you can see the range of values we are reading and sending to the 00:02:33
LED. 00:02:39
Before we have a look at the code, we need to consider, we need to take into account that A0, although it reads analog values, the Arduino board will work using integer numbers. 00:02:43
You remember that the analog input reads numbers from 0 to 1023. 00:03:01
We studied it in the previous exercise. 00:03:06
It means that we are going to use 1024 values. 00:03:09
number 0 is related to 0 volts 00:03:12
number 1023 is related to 5 volts 00:03:15
and for instance if we have 5012 00:03:18
the one in the middle, we will be reading 00:03:21
or using, reading in this case 00:03:25
2.5 volts, the value in the middle, ok? 00:03:27
there is a proportional relationship between the number we use 00:03:30
and the voltage we are reading 00:03:33
when we use these numbers as 00:03:35
output values, we are going to use 00:03:39
a lower range of values. We are going to use a range of 256 values. We will use numbers 00:03:41
from 0 to 255. 0 will be related to 0 volts, 255 will be related to 5 volts, and the one 00:03:51
in the middle, for instance I think 128, will be related to 2.5. Do you understand the idea? 00:04:00
There is a proportional relationship between the integer number and the voltage. 00:04:07
But it's the same idea. 00:04:13
Although the range is four times shorter, it's the same idea. 00:04:14
So how can we program this circuit? 00:04:19
Really, really easy. 00:04:21
I want to show the code to you. 00:04:22
The first thing we need to do is creating a variable. 00:04:23
In this case, our variable is called input. 00:04:27
We read the analog input with this block, leer pasador analogico, 00:04:30
the one that is connected to a zero, 00:04:34
and we store it in the variable called input. 00:04:36
And then, what do we do? We divide this 00:04:40
variable by 4. Why? Because of the range we are going to send, 00:04:44
we are going to use as output, is 4 times shorter 00:04:48
than the range we are using to read 00:04:52
values. And we use this range to send this 00:04:56
value to 11. 11 is here. It sends the value to the LED 00:05:00
and the LED shines according to the value we are sending. 00:05:04
Zero, it doesn't shine. 00:05:08
Here in the middle, it shines just a little bit, 00:05:10
and if we move here, it shines a lot, okay? 00:05:14
So, this is the circuit. 00:05:17
This is the first thing you have to do, create the circuit. 00:05:19
But this is not the exercise. 00:05:22
This is just the first step. 00:05:23
Your exercise is going to be a little bit different. 00:05:25
Your exercise is here. 00:05:28
is the RGB, we are going to use a new component 00:05:30
that is called the RGB LED, this here 00:05:34
is an LED with 00:05:38
four pins, four connectors. One of them 00:05:44
is called the red connector, one of them is called the blue connector and one of them is called 00:05:48
the green connector. And this one is the cathode and is connected 00:05:52
to the ground through the protection resistor, the one 00:05:56
we usually use with a value of 220 ohms, ok? Don't forget it. 00:06:00
So, it means that this LED will combine three colors, ok? 00:06:06
So, we will read three different values using A0, A1 and A2, ok? 00:06:11
Can you see that we have three voltage dividers connected the way we connect them? 00:06:18
We will use three variables instead of having input. 00:06:25
We will have input 1, input 2 and input 3, for instance. 00:06:28
We will read three values the same way we read them before, and we will send three different 00:06:32
analog outputs the same way we have sent them before. 00:06:41
One for the red, one for the blue, and one for the green. 00:06:45
So let's have a look at the simulation. 00:06:48
You will understand it better with the simulation. 00:06:50
If I move this one, this is the red control. 00:06:53
It means that I'm sending 5 volts, now I'm sending 5 volts through the red wires. 00:06:56
If I connect, if I use the second one to the maximum value, now I'm sending 5 volts using 00:07:03
the blue wire and it will happen something similar with this one. 00:07:09
Now it means that I'm sending 5 volts through the green wire, ok? 00:07:15
So the important thing is that we can combine, for instance, green and blue, and what happens 00:07:20
if we combine green and blue, we have this one that is 00:07:25
a different color. What happens if we combine blue 00:07:28
and red? We have purple, okay? So the idea 00:07:33
is that every color can be 00:07:37
produced using a combination of red, green, and blue. And the way to 00:07:40
I'm not going to show the code to you, but it's really simple. It's something like repeating 00:07:45
three times the code of the previous exercise. Using a variable, reading 00:07:49
it reading a number from the connector, A0, A1, and A2, storing the number in the variable, 00:07:53
dividing the variable by 4, and sending it to the output we want, 11, 10, and 9, okay? 00:08:03
So if you understand the first exercise, and if you have the connections for this one, 00:08:09
the exercise is really, really simple. 00:08:14
This is the exercise, controlling the LED RGB using three voltage dividers, okay? 00:08:16
Good luck. 00:08:23
Autor/es:
David Gonzalez Arroyo
Subido por:
David G.
Licencia:
Reconocimiento - No comercial - Compartir igual
Visualizaciones:
335
Fecha:
10 de enero de 2021 - 18:27
Visibilidad:
Público
Centro:
IES MARIE CURIE Loeches
Duración:
08′ 25″
Relación de aspecto:
1.78:1
Resolución:
1920x1080 píxeles
Tamaño:
23.49 MBytes

Del mismo autor…

Ver más del mismo autor


EducaMadrid, Plataforma Educativa de la Comunidad de Madrid

Plataforma Educativa EducaMadrid