WEBVTT

00:00.180 --> 00:06.810
Now that you understand how analog input pins work, let's actually make some tests with our newly installed

00:06.810 --> 00:11.370
potentiometer so you can open here a new sketch on your Arduino ID.

00:11.520 --> 00:20.370
And, well, first things first, as always, we are going to use define for the PIN number we use for

00:20.370 --> 00:25.500
the potentiometer, and we are going to name it very simply, potentiometer.

00:27.380 --> 00:34.310
You know, all the bouquets and then the number of the pin is a two, so you can write a two.

00:34.550 --> 00:40.910
This is not a proper integer number, but this is something that is recognized by the Arduino.

00:41.240 --> 00:43.130
This is in the library.

00:43.160 --> 00:48.380
So you can use a zero, a one, a two until a five here for the Arduino UNO.

00:48.680 --> 00:51.260
It will be recognized as the PIN number.

00:51.710 --> 00:54.380
All right, then what do we need to do in the setup?

00:54.410 --> 01:00.770
Well, usually what we did before is to use the PIN mode function to set up the mode so either input

01:00.770 --> 01:02.740
or output for the pin.

01:02.750 --> 01:10.280
But if you remember from the previous lesson or analog input pins, we don't need to do the pin mode

01:10.280 --> 01:14.270
function because they are already analog input bits.

01:14.570 --> 01:18.440
So the pin is already input, so the pin already has the input mode.

01:18.440 --> 01:20.980
So nothing to do in the setup.

01:20.990 --> 01:24.560
Just what I'm going to do is say that begin.

01:24.920 --> 01:26.510
Okay, because we are going to print.

01:27.730 --> 01:32.830
The value from the potentiometer on the style monitor so we can actually monitor it.

01:33.100 --> 01:33.520
All right.

01:33.520 --> 01:39.610
I know in the loop function, what we are going to do is simply to print the value from the potentiometer.

01:39.610 --> 01:41.560
So still that.

01:42.250 --> 01:43.180
Praying to them.

01:44.760 --> 01:50.610
And then to read the value from an analog input pin, you will simply use the function analog.

01:51.620 --> 02:00.030
Read with, of course, the pin number so we can replace with potentiometer pin here.

02:00.210 --> 02:03.020
Now close to parenthesis and the semicolon.

02:03.320 --> 02:09.380
And then so we don't print too fast, I'm going to add a delay of 100 milliseconds.

02:09.380 --> 02:14.420
So we are going to print the value from the potentiometer at about ten hertz.

02:14.630 --> 02:19.160
Now, as you can see, this is very, very similar to what we did with the push button.

02:19.550 --> 02:25.970
With the push button, we simply printed the value from the button using digital read, but with the

02:25.970 --> 02:30.110
potentiometer, because this is an analog input pin, we use analog rate.

02:30.110 --> 02:37.100
So the name of the function here is very simple and analog read will give you a value between zero and

02:37.100 --> 02:38.780
1023.

02:38.810 --> 02:39.920
Let's check that.

02:39.920 --> 02:46.670
So make sure now your board is correctly connected and let's upload code.

02:46.670 --> 02:47.450
Let's name it.

02:48.450 --> 02:49.380
Put on your mirror.

02:53.210 --> 02:58.260
And now let's open the sale monitor to see what value we have.

02:58.280 --> 03:04.010
And as you can see here, so we have the first value, which is 590.

03:04.520 --> 03:10.950
This is just because the potentiometer here is at a certain position between the minimum and the maximum.

03:10.970 --> 03:15.230
Now, I'm going to move it from one side here.

03:15.680 --> 03:18.560
So I move it and you can see the value is decreasing.

03:19.040 --> 03:23.180
I move it all the way up, all the way down to zero.

03:23.180 --> 03:29.510
And though I can move it the other way all the way up to 1023.

03:30.020 --> 03:36.920
So depending on your setup, the minimum and maximum value may be inverted from my setup.

03:36.920 --> 03:44.870
But the important thing is that you can go from 0 to 1023 and back to zero, and then you can have any

03:44.870 --> 03:47.060
intermediate value between them.

03:49.620 --> 03:57.480
And one other nice thing you can see is with this soil plot, you will be able to plot the value from

03:57.480 --> 04:00.060
0 to 1023.

04:01.290 --> 04:07.500
You can make a nice plot, so you can better visualize what is the value.

04:08.280 --> 04:08.880
All right.

04:09.710 --> 04:15.200
This is nice to have, but not really needed for what we need to do in the following of this course

04:15.200 --> 04:17.090
and also for the final project.

04:17.120 --> 04:17.450
Great.

04:17.450 --> 04:20.150
So now you can read a value from the potentiometer.
