WEBVTT

00:00.180 --> 00:06.270
This is the solution of the previous activity when you need to create an automatic light system, so

00:06.270 --> 00:12.390
with two leads, one that you just going to pull up on under a certain threshold and the other one that

00:12.390 --> 00:16.710
will be put on with the right, so you will modify the brightness.

00:17.100 --> 00:20.820
So the less light, the higher the brightness.

00:21.120 --> 00:24.540
So first of all, I'm going to define that threshold, OK?

00:24.540 --> 00:33.330
For the engineering team to do that, I'm going to open the previous project we have created with the

00:33.330 --> 00:35.160
photoresistor here.

00:37.620 --> 00:41.100
So that is the code that we have just used before.

00:41.110 --> 00:45.370
I'm just going to make sure that is plugged and to upload it.

00:47.170 --> 00:53.690
And then using the science monitor or just let's use the sale plotter here, I'm just going to see so

00:53.710 --> 00:58.120
this is the value currently that I have with the luminosity I have in my room.

00:58.290 --> 01:01.750
OK, and if I put my hand, you can see it's going down.

01:02.260 --> 01:06.840
Basically, I can see that you have 300 or 400.

01:07.150 --> 01:12.750
So let's see, I can set a threshold at three hundred and let's say 30.

01:13.000 --> 01:21.400
So I'm sure that if the luminosity is like it is right now, then I consider this as daylight.

01:21.400 --> 01:28.330
And if it is lower, so if I put my hand or it's getting darker, then the energy will be put on.

01:28.810 --> 01:37.870
So let's go back to an activity code and I'm going to create here defined let's see, luminosity.

01:41.110 --> 01:41.620
Night.

01:43.010 --> 01:49.670
Threshold, which will be three hundred and thirty, so that's the first value and of course, you can

01:49.700 --> 01:54.320
add to it depending on your hardware set up and maybe I will modify it.

01:54.470 --> 01:58.190
And when I do the experiment, that's already already by value.

01:58.190 --> 02:00.940
And then, of course, you have to tinker that way.

02:01.550 --> 02:03.110
So, no, I don't have my threshold.

02:03.110 --> 02:08.780
Let's just use some other define for or to register.

02:10.780 --> 02:19.020
Being, which is a zero, let's just initialize all the pain, so any one that's the one thing is already

02:19.030 --> 02:26.120
the pain on 12 and define energy to being, which has been number 10.

02:27.190 --> 02:34.240
So in this setup, I don't need to initialize the photoresistor PIN because this is an analogy in between.

02:34.510 --> 02:37.920
I need to use spin mode for the LCD.

02:39.750 --> 02:49.600
One thing as output and also pin code for the ability to spin as output also.

02:50.040 --> 02:57.270
So whether I use digital right or analog right on the end it is I need to initialize them as output

02:58.350 --> 03:00.400
is done in the loop.

03:03.140 --> 03:09.140
So I'm going to read the view from the photoresistor ain't within it, OK, because the value we will

03:09.140 --> 03:12.150
read will be from zero to one thousand twenty three.

03:12.860 --> 03:22.750
So let's say Luminosity is equal to another read from the photoresistor Bill.

03:23.910 --> 03:31.860
So I get the value and now I can check for the threshold if and know that here, so I'm not going to

03:31.860 --> 03:38.010
add any delay and I'm not also going to use the time functionality because, well, here we can arrive

03:38.010 --> 03:38.600
at full speed.

03:38.610 --> 03:39.810
OK, that's not a problem.

03:39.870 --> 03:42.870
We can use the analogy whenever we enter the void loop.

03:42.870 --> 03:44.330
That's not going to pose any problem.

03:44.520 --> 03:50.370
However, for example, if you want to breed, let's say you want to also print the analog read, then

03:50.370 --> 03:52.310
maybe for printing that value.

03:52.320 --> 03:54.610
That would be great to use the time functionality.

03:54.630 --> 03:57.830
OK, for example, to print every one hundred milliseconds.

03:58.110 --> 04:01.430
But here we just take the value and then we just put on some LCD.

04:01.440 --> 04:02.670
So let's go full speed.

04:03.120 --> 04:05.430
So if the luminosity.

04:07.230 --> 04:10.260
Is lower than the threshold.

04:11.710 --> 04:16.450
So here I can use strictly lower or lower or equal, that's not really important.

04:16.480 --> 04:19.580
We are not that that's super precise with this.

04:20.090 --> 04:21.140
Not very important.

04:21.370 --> 04:24.370
So if it's lower than the threshold, I'm going to do digital.

04:24.910 --> 04:25.540
Right.

04:25.990 --> 04:34.300
Any one being high and else I'm going to do digital.

04:34.900 --> 04:35.440
Right.

04:35.740 --> 04:36.300
Any.

04:38.280 --> 04:46.140
One thing we've know, so if it's getting too dark, we were on the Petitti, it is getting lighter

04:46.140 --> 04:47.770
with power of the editing.

04:48.330 --> 04:48.560
Right.

04:48.660 --> 04:54.200
And now what we're going to do is to use unallowed right on the edit to people.

04:54.570 --> 04:57.860
But before that, we need to compute the value for the peak.

04:57.890 --> 05:04.060
So let's say it brightness is equal to.

05:04.530 --> 05:09.450
So we're going to use the luminosity we need to divide it by four.

05:09.480 --> 05:10.430
So let me know.

05:10.470 --> 05:12.440
A city divided by four.

05:12.960 --> 05:18.270
But actually, if we do that, the more luminosity, the greater the brightness.

05:18.300 --> 05:20.970
So what do we need to do is to reverse it and to reverse it.

05:21.000 --> 05:21.990
It's really simple.

05:21.990 --> 05:26.520
You do two hundred fifty five minus luminosity divided by four.

05:27.090 --> 05:32.780
And he had no need for parentheses because this has a higher priority of the subtraction.

05:33.270 --> 05:38.140
So 255 minus the luminosity divided by four.

05:38.640 --> 05:44.820
So if we have a high luminosity we will have low brightness and if we have a low luminosity, we will

05:44.820 --> 05:46.550
have a high brightness.

05:46.980 --> 05:50.040
And now let's do analogue right.

05:51.090 --> 05:55.820
To begin with brightness and that's it.

05:55.830 --> 05:57.670
So that's not a really long program.

05:58.050 --> 06:05.730
So now what I'm going to do, I'm going to upload that code to verify and upload activity 19.

06:08.610 --> 06:14.610
So he as you can see, we have the added to the green and PIN number 10, which is both on but with

06:14.610 --> 06:22.250
not the maximum brightness and the energy, the red pin, the 12 is pulled off.

06:22.560 --> 06:28.500
I'm going to put my hand and you can see I just put my hand here on top of the sensor and the energy

06:28.500 --> 06:29.750
will be both on.

06:29.940 --> 06:33.140
I remove my hands and it is put up.

06:33.290 --> 06:40.130
OK, this is just because I have a threshold that just corresponds to this luminosity.

06:40.200 --> 06:41.620
So it's very sensitive.

06:41.650 --> 06:49.530
No, you can see I just put my hand a little bit close to the sensor and automatically the energy will

06:49.530 --> 06:50.590
be put on.

06:51.570 --> 06:57.090
So when you do that, if you see that, for example, the energy is on too quickly, what you can do

06:57.090 --> 06:59.640
is simply you can reduce the threshold.

06:59.880 --> 07:04.860
Or if you see that it's hard to put on the energy, what you can do is increase the threshold.

07:05.290 --> 07:11.100
I'm going to add more light here and OK.

07:11.370 --> 07:17.520
And you can see well, I don't know if you can see clearly, but the green energy here, the brightness

07:17.550 --> 07:18.610
is lower.

07:18.930 --> 07:23.540
OK, if I turn off the light now, the brightness is higher.

07:24.360 --> 07:24.720
All right.

07:25.110 --> 07:27.600
As you can see, this is easy to do.

07:27.600 --> 07:33.510
And now you have a automatic light system that you can use for many different applications.
