1 00:00:00,870 --> 00:00:04,650 hello until now we have studied digital 2 00:00:04,650 --> 00:00:06,780 inputs and digital means that there are 3 00:00:06,780 --> 00:00:10,350 only two possibilities high and low for 4 00:00:10,350 --> 00:00:12,690 instance when we press a button the 5 00:00:12,690 --> 00:00:15,330 arduino board read high with five bolts 6 00:00:15,720 --> 00:00:17,160 and when we were not pressing the 7 00:00:17,160 --> 00:00:20,130 button the board was zero or low 8 00:00:20,880 --> 00:00:22,560 they mean the same so in the 9 00:00:22,560 --> 00:00:25,650 same way then we have an LED 10 00:00:25,650 --> 00:00:27,930 like this one that's connected 11 00:00:27,930 --> 00:00:29,010 to thirteen 12 00:00:30,360 --> 00:00:32,580 for example if there was a current 13 00:00:32,580 --> 00:00:34,500 here then the output was high and 14 00:00:34,500 --> 00:00:36,840 the LED was shining but if there 15 00:00:36,840 --> 00:00:39,960 was no output the LED didn't shine 16 00:00:39,990 --> 00:00:40,800 or it was low 17 00:00:42,000 --> 00:00:45,240 okay hi the LED shines low the 18 00:00:45,240 --> 00:00:46,380 LED doesn't 19 00:00:48,120 --> 00:00:50,220 two options but today we're going to 20 00:00:50,220 --> 00:00:53,550 study something a little bit more complicated 21 00:00:53,940 --> 00:00:56,700 we're going to study analog inputs 22 00:00:57,870 --> 00:01:00,390 analog means that instead of having zero 23 00:01:00,390 --> 00:01:03,420 or five volts low or high we 24 00:01:03,420 --> 00:01:06,300 have any voltage from zero to five 25 00:01:06,630 --> 00:01:08,010 so it means we can have one 26 00:01:08,010 --> 00:01:10,560 two three one and a half two 27 00:01:10,560 --> 00:01:13,020 and a half two point two five 28 00:01:13,020 --> 00:01:16,140 three point four anything any range 29 00:01:17,310 --> 00:01:19,770 so every value from zero to five 30 00:01:19,770 --> 00:01:21,270 in that range can be read 31 00:01:22,920 --> 00:01:25,110 so how do we do that we 32 00:01:25,110 --> 00:01:27,660 are going to use a voltage divider 33 00:01:27,990 --> 00:01:28,890 like this one 34 00:01:30,360 --> 00:01:32,220 okay we have a voltage divider here 35 00:01:32,220 --> 00:01:33,900 on the board and this big picture 36 00:01:33,900 --> 00:01:34,620 on the screen 37 00:01:37,320 --> 00:01:39,990 now it has three terminals the one 38 00:01:39,990 --> 00:01:41,430 on the left will be connected to 39 00:01:41,430 --> 00:01:43,440 five volts through the red wire 40 00:01:45,840 --> 00:01:47,610 and the one on the right will 41 00:01:47,610 --> 00:01:49,920 be connected to the ground through the 42 00:01:49,920 --> 00:01:50,640 black wire 43 00:01:52,860 --> 00:01:54,090 and then the one in the middle 44 00:01:54,180 --> 00:01:56,550 is going to be the terminal variable 45 00:01:56,610 --> 00:01:58,050 and it's going to be connected here 46 00:01:58,050 --> 00:02:00,450 to this terminal at the bottom called 47 00:02:00,510 --> 00:02:01,320 a zero 48 00:02:08,250 --> 00:02:10,080 two can you see that here on 49 00:02:10,080 --> 00:02:12,270 the bottom right corner of the arduino 50 00:02:12,270 --> 00:02:14,460 board there are six analog inputs that 51 00:02:14,460 --> 00:02:17,160 say analog in it means that we're 52 00:02:17,160 --> 00:02:19,110 going to use these six connectors to 53 00:02:19,110 --> 00:02:22,320 read analog inputs so by using these 54 00:02:22,320 --> 00:02:24,930 connectors we can read a voltage any 55 00:02:24,930 --> 00:02:26,820 voltage from zero to five 56 00:02:27,720 --> 00:02:29,220 and we want to use a voltage 57 00:02:29,220 --> 00:02:31,860 divider to read them this way and 58 00:02:31,860 --> 00:02:33,900 we use the connector or the terminal 59 00:02:33,900 --> 00:02:36,930 in the middle here that is connected 60 00:02:36,930 --> 00:02:41,040 to a zero the green wire so 61 00:02:41,040 --> 00:02:43,590 how does it work so the terminals 62 00:02:43,590 --> 00:02:45,060 on the left and the right don't 63 00:02:45,060 --> 00:02:47,190 move there they are a fixed range 64 00:02:48,960 --> 00:02:50,340 the one on the left for instance 65 00:02:50,340 --> 00:02:51,840 will have five the one on the 66 00:02:51,840 --> 00:02:53,190 right will have zero 67 00:02:54,270 --> 00:02:55,650 the one that moves is the one 68 00:02:55,650 --> 00:02:57,900 in the middle so in real life 69 00:02:57,900 --> 00:02:59,940 and during the simulation you will be 70 00:02:59,940 --> 00:03:02,070 able to click and drag to move 71 00:03:02,070 --> 00:03:04,260 the dial i'll start a simulation to 72 00:03:04,260 --> 00:03:04,920 show you 73 00:03:06,000 --> 00:03:09,360 and in the program that if I 74 00:03:09,360 --> 00:03:11,640 click and drag it moves 75 00:03:12,750 --> 00:03:13,680 you can see that here 76 00:03:18,030 --> 00:03:21,480 okay now for the explanation so the 77 00:03:21,480 --> 00:03:23,730 one in the middle will move and 78 00:03:23,730 --> 00:03:25,560 the closer it is to the right 79 00:03:25,560 --> 00:03:27,540 side the one that is connected to 80 00:03:27,540 --> 00:03:30,450 the black wire the ground the closer 81 00:03:30,450 --> 00:03:32,490 this variable will be to zero 82 00:03:33,900 --> 00:03:36,150 and the closer the terminal is to 83 00:03:36,150 --> 00:03:38,730 the terminal on the left the closer 84 00:03:38,730 --> 00:03:41,370 the voltage will be to five volts 85 00:03:42,510 --> 00:03:45,150 so by clicking the middle and moving 86 00:03:45,150 --> 00:03:47,850 it will be sending different voltages from 87 00:03:47,940 --> 00:03:48,810 a zero 88 00:03:51,150 --> 00:03:54,240 from zero to five volts somewhere in 89 00:03:54,240 --> 00:03:54,840 that range 90 00:03:59,100 --> 00:04:02,130 okay so now today's exercise we're going 91 00:04:02,130 --> 00:04:03,510 to take a look at the blocks 92 00:04:03,990 --> 00:04:06,720 just forget about this last block though 93 00:04:06,720 --> 00:04:07,980 you do not need it for now 94 00:04:07,980 --> 00:04:08,970 we'll address it later 95 00:04:10,110 --> 00:04:11,760 we are going to read this as 96 00:04:11,760 --> 00:04:14,760 zero connector using the purple block for 97 00:04:14,760 --> 00:04:18,060 reading analog input a zero you can 98 00:04:18,060 --> 00:04:20,459 read from a zero to a five 99 00:04:21,690 --> 00:04:22,830 but now we're going to read a 100 00:04:22,830 --> 00:04:25,050 zero and we're going to store it 101 00:04:25,110 --> 00:04:28,350 here in the input variable 102 00:04:30,030 --> 00:04:33,000 now we've already defined the variable and 103 00:04:33,000 --> 00:04:35,070 here these four blocks 104 00:04:37,530 --> 00:04:39,720 without the last one forget about that 105 00:04:41,190 --> 00:04:44,220 well by now you can probably identify 106 00:04:44,430 --> 00:04:46,980 that these four together are a blink 107 00:04:48,030 --> 00:04:49,440 you see how we have 108 00:04:50,670 --> 00:04:51,540 thirteen high 109 00:04:52,650 --> 00:04:55,410 and we wait thirteen low and we 110 00:04:55,410 --> 00:04:57,360 wait so it's a blinking program 111 00:04:58,980 --> 00:05:01,320 but instead of having a fixed period 112 00:05:01,320 --> 00:05:04,200 of time we are using the variable 113 00:05:04,260 --> 00:05:06,600 that we have read as the blinking 114 00:05:06,600 --> 00:05:09,720 period of time because the input doesn't 115 00:05:09,720 --> 00:05:12,120 read numbers from zero to five volts 116 00:05:12,660 --> 00:05:15,600 so obviously we're reading values from zero 117 00:05:15,600 --> 00:05:17,040 to five volts but they will be 118 00:05:17,040 --> 00:05:18,720 translated from zero 119 00:05:18,720 --> 00:05:22,110 oh to one thousand twenty three okay 120 00:05:22,680 --> 00:05:24,270 we can see this in the simulation 121 00:05:33,510 --> 00:05:34,770 so I'm going to add this last 122 00:05:34,770 --> 00:05:36,720 block just to show these values that 123 00:05:36,720 --> 00:05:38,100 appear here on the bottom 124 00:05:39,120 --> 00:05:40,710 I want to start the simulation now 125 00:05:40,710 --> 00:05:42,840 watch the pointer turn on the dial 126 00:05:44,040 --> 00:05:46,440 now you can see where reading three 127 00:05:46,440 --> 00:05:47,520 hundred and forty eight 128 00:05:49,470 --> 00:05:50,640 if I move it all the way 129 00:05:50,640 --> 00:05:52,560 to the right terminal we're only reading 130 00:05:52,560 --> 00:05:52,980 zero 131 00:05:54,900 --> 00:05:56,130 the ground if I move it a 132 00:05:56,130 --> 00:05:59,310 little bit higher were reading eighty two 133 00:06:00,750 --> 00:06:01,710 if I move higher 134 00:06:03,480 --> 00:06:05,040 we're reading to twenty five 135 00:06:06,750 --> 00:06:07,950 and if I move a little bit 136 00:06:07,950 --> 00:06:09,210 closer to the red one 137 00:06:10,770 --> 00:06:12,480 it'll get higher let's wait 138 00:06:13,800 --> 00:06:15,030 it's six hundred fourteen 139 00:06:16,590 --> 00:06:18,060 and if I move even closer to 140 00:06:18,060 --> 00:06:18,510 read 141 00:06:21,240 --> 00:06:23,940 nine twenty one so it means that 142 00:06:23,940 --> 00:06:26,160 we're reading these values instead of the 143 00:06:26,160 --> 00:06:28,500 values simply being from zero to five 144 00:06:28,530 --> 00:06:31,449 they're reading from zero to one thousand 145 00:06:31,470 --> 00:06:35,010 twenty three there is a proportional relationship 146 00:06:35,880 --> 00:06:38,220 the highest is one thousand twenty three 147 00:06:39,570 --> 00:06:41,310 so this is because the arduino board 148 00:06:41,340 --> 00:06:45,270 uses integral numbers again let's forget about 149 00:06:45,270 --> 00:06:46,350 the last block 150 00:06:47,550 --> 00:06:50,220 because we are going to read a 151 00:06:50,258 --> 00:06:53,550 zero and store it in this variable 152 00:06:54,060 --> 00:06:56,940 and we are using the variable multiplied 153 00:06:56,940 --> 00:06:58,950 by two as a blinking period of 154 00:06:58,950 --> 00:07:01,530 time for the LED the LED is 155 00:07:01,530 --> 00:07:03,840 connected the same way as always terminal 156 00:07:03,840 --> 00:07:06,810 thirteen with ground connection and the protection 157 00:07:06,810 --> 00:07:07,680 resistor at 158 00:07:08,220 --> 00:07:09,810 two hundred and twenty ohms 159 00:07:16,710 --> 00:07:18,300 so again let's forget about the last 160 00:07:18,300 --> 00:07:19,740 block we're not going to use it 161 00:07:19,740 --> 00:07:20,940 anymore and I'm going to get rid 162 00:07:20,940 --> 00:07:21,240 of it 163 00:07:24,360 --> 00:07:27,540 the idea is that we're controlling the 164 00:07:27,540 --> 00:07:29,760 period of time the lcd will shine 165 00:07:29,820 --> 00:07:33,060 by using the analog input so let's 166 00:07:33,420 --> 00:07:35,400 let's actually start the simulation again 167 00:07:36,690 --> 00:07:38,160 and you will see that the closer 168 00:07:38,160 --> 00:07:41,220 the connectors to zero the shorter of 169 00:07:41,430 --> 00:07:43,830 the shorter the period of time that 170 00:07:43,830 --> 00:07:46,050 the LED will be shining and so 171 00:07:46,050 --> 00:07:47,160 the faster it will blink 172 00:07:49,260 --> 00:07:51,240 but if the number is higher 173 00:07:53,040 --> 00:07:55,650 then the period of time between blinks 174 00:07:55,680 --> 00:07:57,420 will be higher and the blinking will 175 00:07:57,420 --> 00:07:58,470 appear slower 176 00:08:00,210 --> 00:08:03,090 so this is just your first exercise 177 00:08:03,150 --> 00:08:05,280 okay you're going to reproduce this circuit 178 00:08:05,280 --> 00:08:08,010 and programme it now if you program 179 00:08:08,010 --> 00:08:09,660 it this way you'll have half of 180 00:08:09,660 --> 00:08:10,590 the assignment done 181 00:08:12,000 --> 00:08:13,200 so this is the first part 182 00:08:18,000 --> 00:08:20,880 okay let me stop the simulation and 183 00:08:20,880 --> 00:08:22,500 now to complete it and receive the 184 00:08:22,500 --> 00:08:24,870 second half of the assignment you will 185 00:08:24,870 --> 00:08:27,210 have to use a second analog dial 186 00:08:30,810 --> 00:08:32,490 you will connect it the same way 187 00:08:32,490 --> 00:08:34,289 it has been connected through a red 188 00:08:34,289 --> 00:08:35,970 wire to five volts 189 00:08:37,260 --> 00:08:38,520 maybe you will connect it in a 190 00:08:38,520 --> 00:08:41,370 different way and but with five volts 191 00:08:41,370 --> 00:08:43,020 here another red wire 192 00:08:45,210 --> 00:08:47,880 and the ground connection 193 00:08:49,980 --> 00:08:52,020 as well with the black wires 194 00:08:58,320 --> 00:08:59,910 this will be ground 195 00:09:01,140 --> 00:09:03,421 so that's the red and I mean 196 00:09:03,421 --> 00:09:03,960 need ground 197 00:09:05,370 --> 00:09:07,110 so there's a second connection to a 198 00:09:07,110 --> 00:09:09,600 one analog one and you will repeat 199 00:09:09,600 --> 00:09:11,940 this connection with a cell second LED 200 00:09:11,940 --> 00:09:15,570 connected using a second protection resistor as 201 00:09:15,570 --> 00:09:15,870 well 202 00:09:17,280 --> 00:09:21,600 and this one will be connected to 203 00:09:21,600 --> 00:09:22,110 twelve 204 00:09:23,610 --> 00:09:25,110 just right next to the first one 205 00:09:25,380 --> 00:09:25,740 okay 206 00:09:28,260 --> 00:09:29,610 another protection resistor 207 00:09:31,200 --> 00:09:32,220 two hundred twenty 208 00:09:34,950 --> 00:09:36,840 so I'll repeat the same connection with 209 00:09:36,840 --> 00:09:40,440 a second LED another resistor and the 210 00:09:40,440 --> 00:09:42,420 wires so you will have two LED 211 00:09:42,420 --> 00:09:44,700 and two voltage dividers and program 212 00:09:44,700 --> 00:09:46,830 it a different way so instead of 213 00:09:46,830 --> 00:09:49,140 controlling the blinking time you will use 214 00:09:49,140 --> 00:09:51,480 the control block since you now have 215 00:09:51,570 --> 00:09:53,520 two variables in 216 00:09:53,550 --> 00:09:55,590 put one and input two for instance 217 00:09:55,950 --> 00:09:56,880 and name them 218 00:09:58,560 --> 00:09:59,220 input one 219 00:10:01,710 --> 00:10:03,090 and you will read them the same 220 00:10:03,090 --> 00:10:05,280 way that we read the first one 221 00:10:05,520 --> 00:10:06,840 and again the same with the second 222 00:10:06,840 --> 00:10:07,170 one 223 00:10:15,690 --> 00:10:17,430 let's make this again for input two 224 00:10:21,630 --> 00:10:23,880 and that'll be called input two and 225 00:10:23,880 --> 00:10:25,530 you're going to read that for a 226 00:10:25,590 --> 00:10:28,020 a one instead of a zero 227 00:10:29,190 --> 00:10:31,320 and then here you will compare with 228 00:10:31,320 --> 00:10:33,570 the if block you already know how 229 00:10:33,570 --> 00:10:36,660 to compare higher and lower so if 230 00:10:36,930 --> 00:10:39,390 input one is higher than input two 231 00:10:40,020 --> 00:10:41,760 then one of the l these will 232 00:10:41,760 --> 00:10:42,180 blink 233 00:10:43,650 --> 00:10:45,330 if the other one is higher than 234 00:10:45,330 --> 00:10:46,110 the first one 235 00:10:47,400 --> 00:10:50,010 it means the opposite condition so maybe 236 00:10:50,010 --> 00:10:52,500 the other ltd will blank or something 237 00:10:52,500 --> 00:10:53,010 like that 238 00:10:59,460 --> 00:11:02,670 okay this is just one example I'm 239 00:11:02,730 --> 00:11:05,040 not going to complete this program on 240 00:11:05,040 --> 00:11:07,110 the video because you will complete it 241 00:11:07,140 --> 00:11:08,190 by yourselves 242 00:11:11,280 --> 00:11:13,080 so for example if the first condition 243 00:11:13,080 --> 00:11:15,690 is true then input zero is lower 244 00:11:15,690 --> 00:11:17,730 than input one and maybe thirteen will 245 00:11:17,730 --> 00:11:21,210 shine if a one is higher than 246 00:11:21,210 --> 00:11:23,880 a zero maybe twelve will shine you 247 00:11:23,880 --> 00:11:27,000 will compare the two variables input one 248 00:11:27,090 --> 00:11:27,930 input two 249 00:11:29,760 --> 00:11:31,260 input one input two 250 00:11:32,640 --> 00:11:34,621 and then you will decide which LED 251 00:11:34,621 --> 00:11:35,850 is going to shine in the 252 00:11:35,850 --> 00:11:39,300 program may be number thirteen here maybe 253 00:11:39,301 --> 00:11:40,590 number twelve here 254 00:11:42,270 --> 00:11:43,890 okay so you complete the code 255 00:11:44,940 --> 00:11:46,890 currently it is not complete if you 256 00:11:46,890 --> 00:11:48,600 try to simulate this as it is 257 00:11:48,630 --> 00:11:51,030 it won't work because it's not fully 258 00:11:51,030 --> 00:11:52,950 programmed so you will complete it 259 00:11:54,060 --> 00:11:55,230 and this is the second part of 260 00:11:55,230 --> 00:11:58,260 the exercise okay rewatch this if you 261 00:11:58,260 --> 00:12:00,390 need to and good luck