Activa JavaScript para disfrutar de los vídeos de la Mediateca.
Arduino: digital 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, today we are going to make a new circuit. As always we need the protoboard,
00:00:00
we need the Arduino board, and this circuit is going to use an LED as an output. So let's look
00:00:08
for the LED here, and we are going to connect it the same way we have done it the previous days.
00:00:16
We need the ground connection, we are going to connect it here to the horizontal line,
00:00:22
and the wire is going to be black. Okay, and again we are going to connect the ground
00:00:28
to this terminal, to the anode, to the cathode, I'm sorry, and this wire is going to be black again,
00:00:38
and again we need the protection resistor. Remember that the protection resistor is always
00:00:45
a 220 ohms one, change it here, and we connect it to this connector, the one that is called the anode,
00:00:51
and we are going to control the circuit, we are going to control the LED, I'm sorry,
00:01:03
using the connector number 13, to change the way the wires are connected, but it's exactly the same.
00:01:08
Ok, this wire is easier to see it, and this wire is going to be green just because.
00:01:16
So can you see that I have closed the circuit from connector number 13 to the LED and we
00:01:24
go back to the ground.
00:01:32
Ok, now this is the output part, because we are going to control the LED from the Arduino
00:01:33
board.
00:01:38
It will shine or it won't, it depends on the things we want.
00:01:39
Now the new part. We are going to add a button. We click and drag and the button is here now.
00:01:45
So we are going to connect the button this way. This is the standard way of connecting
00:01:54
buttons. Every time we need a button, we are going to connect it this way. We are going
00:01:58
to use a 5V connection that is here. We click from this one to here. The wire I am going
00:02:04
to use we're going to be red just because well red is the usual color for a five volts connection
00:02:14
so okay we can see that you can we see the wire from this position to this one and here in the
00:02:20
other a connector of the of the button we are going to connect it to for instance from this
00:02:26
position to 12. and color for instance i don't know orange right so and we need something else
00:02:33
we need a pull-down resistor. You are going to see how to connect it. The pull-down resistor
00:02:42
is a 10 kilo ohms one. Can you see that it's a 10 kilo ohms one? And it's going to be connected
00:02:48
this way. And here realize that this is the ground. Can you see that here is the ground
00:02:54
because of the horizontal line? So now using the drawing I'm going to explain the button.
00:02:59
If the button is pressed, if you click here while the circuit is being simulated, if you
00:03:04
press here, there will be a connection between this wire, between this point, and
00:03:12
this point. It means this wire. So because there is a connection between this one
00:03:16
and this one, if we have this one and this one, if we have five poles here, we
00:03:20
will have five poles here, and five poles will be here in pin number 12. Okay. But
00:03:24
if we don't press the button, there will be no connection between this point and
00:03:31
this point. So this point will be connected to ground through this
00:03:35
resistor. It means that we will have zero here, we will have zero here in pin
00:03:41
number 12. So it means that if we don't press, we have zero here in pin number
00:03:46
12. If we press, we have five volts because of the red wire, okay? Do you
00:03:52
understand? If you don't understand, try to watch it a second time and I think it
00:04:00
will be easier. Now, what do we need now? We need the program. So we click here on
00:04:04
code and now we have the program we click and drag to the left the previous program we remove it and
00:04:10
we are going to start programming the first thing we need is an is an input input so
00:04:16
okay we are going to use this block leer pasado digital for instance 12 because it's the one we
00:04:25
are reading okay so we are going to read it here and but we need something else we need a variable
00:04:32
A variable is a kind of a box to store something, some values, some number we have read.
00:04:41
So we are going to use a variable, variable, create variable.
00:04:46
And the name for this variable will be, for instance, input, because it's the one we are reading.
00:04:50
So we are going to use this block, define input this way.
00:04:55
So let's see if you understand.
00:05:01
This is the reading from number 12.
00:05:03
And this reading will be stored here.
00:05:06
Input is like a box.
00:05:09
It's a place to save, to store this number, the number from number 12, okay?
00:05:10
So now we have our input in the variable input.
00:05:15
Now, what we are going to do now?
00:05:20
What are we going to do now?
00:05:22
We are going to check the value of the input, of the value that is here.
00:05:24
And we are going to compare the input with something else, with a value, for instance.
00:05:33
What do we want?
00:05:37
We want to use this block. The block is here in the green
00:05:38
library, the one about maths. We are going to use
00:05:42
it later, but for the moment the only block we are going to use is this one, the second one.
00:05:46
Here we can compare two values. We can compare if one of them is lower,
00:05:50
lower or equal, equal, not equal,
00:05:54
higher or equal. For the moment let's use
00:05:58
equal. And what do we want to compare?
00:06:02
compare? We want to compare the input. If the input
00:06:06
equals
00:06:11
this is the one I was
00:06:12
looking for. I don't want a number. I want two
00:06:29
possibilities. High or low because these are digital inputs. We cannot
00:06:32
compare this one with a number because we are reading digital inputs.
00:06:36
Take it into account. Digital means high or low.
00:06:40
Analog means whatever value you need. So if input equals high it means
00:06:43
that we are pressing this button because we are reading 12. Remember we are reading
00:06:52
12. This value is stored here and now we are comparing this value with high. So
00:06:56
what happens if we are pressing the value? So for instance I want number 13
00:07:01
high. How can I do it? Here, in salida, definir. Puls, pasador, 13, and alta. Number 13, high.
00:07:06
Okay, perfect. So, with this program, if I press the button, the LED will shine. Do you
00:07:16
agree? We read the value, we store it here in input, we compare the input with high,
00:07:22
C, if input equals high, 13 will be high.
00:07:29
And C no, what does it mean, C no?
00:07:35
In English we say else.
00:07:37
Else is the things that will happen if the condition is not true,
00:07:38
because this is a condition.
00:07:42
What do we want if we are not pressing the button?
00:07:43
If input is low, we want, just because we want it this way,
00:07:46
we want that 13 is low, baja.
00:07:52
So this way, if we press the button, we store the value here, we compare the value with high, and if the value is high, the LED will shine because it's connected to 13.
00:07:58
And if the condition is not true, the LED connected to 13 will be low.
00:08:11
This is the idea.
00:08:17
We have connected everything, the output part, we have the input part with the button and the pull-down resistor, and we have the blocks.
00:08:18
We have everything we need.
00:08:26
So let's start the simulation.
00:08:28
Okay, apparently nothing happens,
00:08:30
but if we press the button, we click here,
00:08:33
the LED is shining. Can you see it?
00:08:36
And if I finish pressing it, the LED doesn't shine.
00:08:38
Everything according to our program.
00:08:41
Okay, so the exercise today is just repeating this example.
00:08:44
Nothing else. Okay, good luck.
00:08:48
- Autor/es:
- David Gonzalez Arroyo
- Subido por:
- David G.
- Licencia:
- Reconocimiento - No comercial - Compartir igual
- Visualizaciones:
- 247
- Fecha:
- 10 de enero de 2021 - 18:19
- Visibilidad:
- Público
- Centro:
- IES MARIE CURIE Loeches
- Duración:
- 08′ 51″
- Relación de aspecto:
- 1.78:1
- Resolución:
- 1920x1080 píxeles
- Tamaño:
- 24.70 MBytes