Activa JavaScript para disfrutar de los vídeos de la Mediateca.
Arduino: analog input - Contenido educativo
Ajuste de pantallaEl ajuste de pantalla se aprecia al ver el vídeo en pantalla completa. Elige la presentación que más te guste:
Hello. Until this moment we have studied digital inputs. Digital means that there are only two possibilities, high and low.
00:00:00
For instance, when we press a button, if we were pressing it, the Arduino board read high or 5 volts. High is the same.
00:00:10
When we were not pressing the button, the Arduino board read 0 or low. It's exactly the same.
00:00:21
The same way, when we had an LED like this one connected to, for example, 13, like this one,
00:00:27
if there was current here, the output was high and the LED was shining.
00:00:34
If there was no output, the LED didn't shine, so it means low, high.
00:00:41
The LED shines low, the LED doesn't shine.
00:00:49
But today we are going to study something a little bit more complicated, just a little bit.
00:00:53
We are going to study analog inputs. Analog means that instead of having 0 or 5, low or high,
00:00:59
we have any voltage from 0 to 5. It means we can have 1, 2, 3, or maybe 1.5, or 2.5, or 2.25, or 3.40, whatever.
00:01:07
every value from 0 to 5 can be read. How can we do that? We are going to use a
00:01:22
voltage divider like this one. The voltage divider you have here in the
00:01:30
picture and also here, it has three terminals. The one on the left, for
00:01:36
instance, will be connected to five volts, okay, through the red wire. The one on the
00:01:43
right will be connected to ground through the black wires, and the one in
00:01:49
the middle is going to be the terminal variable, and it's
00:01:56
going to be connected here, to this terminal called A0. Can you see that here
00:02:01
on the bottom right corner of the Arduino board, can you see that
00:02:08
that there are six analog inputs, analog-in, can you read it? It means that we are going to use these
00:02:13
six connectors to read analog inputs. It means that using these connectors we will be able to
00:02:21
read voltages from zero to five. And we are going to use voltage divider to read them this way.
00:02:27
And we use the connector, the terminal in the middle. And here there is
00:02:36
connected to A0. Okay? So, how does it work? The terminals on the left and on the
00:02:42
right, they don't move. They are fixed. This one, for instance, will have 5, and
00:02:49
this one on the right will have, for instance, 0. The one that moves is
00:02:55
the one in the middle. In real life, we can, well, during the simulation, you
00:03:00
will be able to click and drag, you will be able to move this one in
00:03:06
I'm going to simulate it a little bit, just to show it that if I click and drag, it moves, ok?
00:03:11
Anyway, let's go back to the explanation. This one in the middle will move.
00:03:17
And the closer it is to this one, that is connected to the black wire,
00:03:22
the closer it is to the ground, the closer this variable will be to 0.
00:03:28
And the closer this terminal is to the terminal on the left, the voltage, the closer will be to 5 volts.
00:03:36
So it means that clicking this one and moving, clicking and dragging this one,
00:03:46
we will be sending different voltages to A0, from 0 to 5.
00:03:50
Okay?
00:03:56
So what's the purpose of the exercise?
00:03:58
Let's have a look to the blocks.
00:04:01
Here you have the blocks.
00:04:02
I have already...
00:04:03
Forget about this one.
00:04:04
The last one, you don't need it. I will talk about it later.
00:04:05
Forget about the last one. We are going to read
00:04:10
this A0 connector
00:04:13
using the purple
00:04:16
block, leer pasado analógico A0. You can read from A0 to A5
00:04:21
the six values that are here. Now we are going to read
00:04:26
A0 and we are going to store it here in the input variable.
00:04:29
we have already defined a variable
00:04:33
ok
00:04:35
and
00:04:37
here, these four blocks
00:04:39
I repeat, forget about this one
00:04:42
these four blocks, what are they?
00:04:44
I'm sorry
00:04:47
these four blocks, what are they?
00:04:48
I'm sure you can identify them as a blink
00:04:50
13 high
00:04:52
we wait, 13 low
00:04:54
we wait, it's a blink
00:04:56
ok
00:04:58
but instead of having
00:04:58
a fixed period of time we are using the variable we have read as a blinking
00:05:01
period of time because the input doesn't read numbers from 0 to 5 volts. Obviously
00:05:13
we are reading values from 0 to 5 volts but they will be translated from 0 to
00:05:20
1023. Let's have a look at the simulation. I'm going to add this last block just to
00:05:27
show these values here. I'm going to start the simulation. Can you see that
00:05:34
the pointer is here? Now we are reading 348. If I move it closer to the right,
00:05:40
when I'm touching the right terminal, we are reading 0. If I move a
00:05:51
little bit higher, we will be reading 82. If I move a little bit higher, we will be
00:05:56
reading 225. If I move a little bit closer to the red one, now we are reading
00:06:04
614. And if I move a little bit closer, we are reading, let's wait a little bit,
00:06:12
921. It means that we are reading values, but these values are from, instead of
00:06:21
being from 0 to 5, they are read from 0 to 1023, okay? There's a
00:06:29
proportional relationship, okay? This is because Arduino board uses
00:06:36
integer numbers, that's all. So the idea is really simple. We are going, forget
00:06:42
about this last block, I repeat it again. We are going to read a zero, we are going
00:06:47
to start to store it in this variable and we are using the
00:06:51
variable multiplied by two as a blinking period of time for the LED. The LED is
00:06:56
connected the usual way. The LED here connected to 13 for instance, the ground
00:07:03
connection here using black wires and the protection resistor, remember 220
00:07:08
So, now I repeat, I'm going to forget out this block, now we are not going to use it anymore, I can erase it, and the idea is that this way we are controlling the period of time of the LED just using this analog input.
00:07:14
Let's start the simulation again, and you will see that the closer this connector is to zero, the shorter the period of time will be, and it means the shorter the blinking period of time will be, the faster it will blink.
00:07:34
If the number is higher, the period of time will be higher, and the blinking will be slower.
00:07:52
Okay?
00:07:59
Do you understand?
00:08:00
So this is your first exercise.
00:08:00
reproduce this circuit and program it. If you program it, you will have half of
00:08:03
the mark. What do you want, what do you have to do to to have the second, I will
00:08:12
stop the simulation, what do you need to do to have the second part of
00:08:18
the mark, the second half of the mark? You will have to use a second
00:08:22
potentiometer, here for instance, you will connect it the same way it has been
00:08:29
connected, through a red wire to five volts. Maybe you will have to connect it
00:08:34
in a different way, five volts here, a red wire here, I'm sorry, red wire here,
00:08:41
here a red wire connected here, a black wire connected here, I'm sorry, the red
00:08:47
one connected here and here, not black, red, the black wire here, a second
00:08:54
connection to A1, and you will repeat this connection with a second LED
00:09:06
connected using a second resistor, protection resistor, I'm sorry, and
00:09:11
this one connected to 12, okay? Do you understand the idea? The same but complete
00:09:17
the connection, I repeat, a second LED here, a second 220 ohms
00:09:25
resistor here, and the wires. So you will use two LEDs and two voltage dividers
00:09:30
and you will program it in a different way. Instead of controlling the blinking
00:09:39
time, forget about it, you will use the control block, you will have two
00:09:44
variables, input1 and input2 for instance, for instance input1, input1
00:09:51
and a second one input2, and you will read them the same way we read the first
00:09:58
one, the same with the second one, you need a second variable, that will be
00:10:09
called input two, and you will read a one instead of a zero, okay? And here you will
00:10:20
compare if, you know the if block, if, and you know how to compare, if, you know,
00:10:27
higher, lower. If input 1 is higher than input 2, one of the LEDs will blink. If
00:10:33
the other one is higher than the first one, it means the opposite condition, the
00:10:41
the other LED will blink. So something like that. I'm not going to complete the
00:10:47
program, you will complete it by yourselves. So if the first condition is
00:10:53
true. If, for instance, input 0 is lower than input 1, for instance, 13 will shine.
00:10:59
If 13 is higher than 12, 12 will shine. I don't know, I'm sorry, if A1 is higher
00:11:07
than A0, I don't know, 12 will shine. Do you understand the idea? Here you will compare
00:11:16
the two variables, input 1, input 2, input 1, input 2, and here you will decide
00:11:22
which one is going to shine. Maybe number 13 here, maybe number 12 here. So you will
00:11:27
complete this code. This code is incomplete. Don't try to simulate it. If
00:11:34
you try to simulate it, there will be mistakes. Well, there are no mistakes but
00:11:38
it doesn't work, okay? Nothing happens because it's not properly programmed,
00:11:42
okay? So you will have to complete it. This is the second part of the exercise,
00:11:48
okay? Okay, I think everything is clear. I think you have more than enough
00:11:51
information to do the exercise, so just do it. Good luck!
00:11:57
- Autor/es:
- David Gonzalez Arroyo
- Subido por:
- David G.
- Licencia:
- Reconocimiento - No comercial - Compartir igual
- Visualizaciones:
- 356
- Fecha:
- 10 de enero de 2021 - 18:24
- Visibilidad:
- Público
- Centro:
- IES MARIE CURIE Loeches
- Duración:
- 12′ 02″
- Relación de aspecto:
- 1.78:1
- Resolución:
- 1920x1080 píxeles
- Tamaño:
- 37.63 MBytes