1 00:00:02,610 --> 00:00:04,410 hello today we are going to make 2 00:00:04,410 --> 00:00:07,800 a new circuit as always we need 3 00:00:07,860 --> 00:00:10,890 a protoboard and the arduino board 4 00:00:11,970 --> 00:00:13,590 and this circuit is going to use 5 00:00:13,590 --> 00:00:15,540 an LED as an output 6 00:00:18,000 --> 00:00:20,280 so we can drag the LED here 7 00:00:21,060 --> 00:00:22,500 and we're going to connect it the 8 00:00:22,500 --> 00:00:24,510 same way that we always have so 9 00:00:24,510 --> 00:00:26,730 we need the ground connection over here 10 00:00:26,730 --> 00:00:28,080 to the horizontal line 11 00:00:29,880 --> 00:00:31,500 and the wire will be black 12 00:00:34,500 --> 00:00:36,150 and now we will connect the ground 13 00:00:36,210 --> 00:00:39,180 to this terminal from the cathode and 14 00:00:39,180 --> 00:00:40,920 this wire is going to also be 15 00:00:40,920 --> 00:00:41,430 black 16 00:00:47,370 --> 00:00:49,410 and of course we need a protection 17 00:00:49,470 --> 00:00:52,710 resistor and remember that the protection resistor 18 00:00:52,710 --> 00:00:55,290 is always two hundred and twenty ohms 19 00:00:56,940 --> 00:00:58,830 now we connect it from the anode 20 00:00:58,860 --> 00:01:01,380 side and we're going to control the 21 00:01:01,380 --> 00:01:05,220 LED using connector number thirteen or pin 22 00:01:05,220 --> 00:01:06,120 number thirteen 23 00:01:13,920 --> 00:01:15,120 I'm going to shift it over so 24 00:01:15,120 --> 00:01:16,800 you can see it more clearly but 25 00:01:16,830 --> 00:01:18,720 the connections exactly the same this way 26 00:01:18,720 --> 00:01:21,180 it's just easier to see it and 27 00:01:22,350 --> 00:01:24,390 this wire is going to be green 28 00:01:26,490 --> 00:01:27,990 so now you can see that I 29 00:01:27,990 --> 00:01:30,480 have closed the circuit for connector number 30 00:01:30,480 --> 00:01:33,720 thirteen to the LED and we go 31 00:01:33,720 --> 00:01:34,590 back to the ground 32 00:01:38,130 --> 00:01:40,050 now this is the output part so 33 00:01:40,050 --> 00:01:41,940 we can control the LED from the 34 00:01:41,940 --> 00:01:44,760 arduino board which will either shine or 35 00:01:44,760 --> 00:01:46,890 not it just depends on what we 36 00:01:46,890 --> 00:01:48,120 want and how we program it 37 00:01:50,280 --> 00:01:51,510 the new part is that we're going 38 00:01:51,510 --> 00:01:53,880 to add a button and I'll drag 39 00:01:53,880 --> 00:01:56,880 it over here so now here's how 40 00:01:56,880 --> 00:01:58,950 we connect the button this is going 41 00:01:58,950 --> 00:02:00,270 to be the standard way of connecting 42 00:02:00,270 --> 00:02:01,830 a button every time we use one 43 00:02:02,460 --> 00:02:05,340 we're going to use the five volt 44 00:02:05,430 --> 00:02:08,669 connection from down here so we create 45 00:02:08,669 --> 00:02:09,330 a wire 46 00:02:09,389 --> 00:02:10,500 from that port 47 00:02:12,630 --> 00:02:13,230 up here 48 00:02:14,490 --> 00:02:16,380 and this wire will be red because 49 00:02:16,380 --> 00:02:18,540 that is the standard wire color for 50 00:02:18,540 --> 00:02:21,240 the five volt connection so now we 51 00:02:21,240 --> 00:02:24,000 have the wire in this position and 52 00:02:24,630 --> 00:02:27,660 from this side of the button we 53 00:02:27,660 --> 00:02:30,690 will create a wire connected to position 54 00:02:30,780 --> 00:02:31,380 twelve 55 00:02:34,920 --> 00:02:36,150 so here from the side 56 00:02:38,340 --> 00:02:39,960 drag it to twelve and this one 57 00:02:39,960 --> 00:02:41,730 can be orange 58 00:02:43,140 --> 00:02:44,490 and now we also need a pull 59 00:02:44,490 --> 00:02:47,730 down resistor the pull-down resistor is going 60 00:02:47,730 --> 00:02:49,830 to be ten kilo ohms 61 00:02:51,900 --> 00:02:54,330 and it's going to be connected from 62 00:02:54,780 --> 00:02:58,530 here remembering that the horizontal line is 63 00:02:58,530 --> 00:03:00,330 connected to the ground so do you 64 00:03:00,330 --> 00:03:00,750 see that 65 00:03:04,110 --> 00:03:05,550 so now I will explain how this 66 00:03:05,550 --> 00:03:08,130 works if the button is pressed if 67 00:03:08,130 --> 00:03:09,930 you click on it while the simulation 68 00:03:09,930 --> 00:03:12,210 is running there will be a connection 69 00:03:12,540 --> 00:03:16,560 between this orange wire and the red 70 00:03:16,560 --> 00:03:16,830 one 71 00:03:19,560 --> 00:03:22,170 so because there's a connection from one 72 00:03:22,170 --> 00:03:25,500 side to the other those five volts 73 00:03:25,500 --> 00:03:28,980 will travel over here in pin twelve 74 00:03:30,810 --> 00:03:33,300 but if we don't press the button 75 00:03:33,300 --> 00:03:34,980 then there will be no connection between 76 00:03:34,980 --> 00:03:35,850 these two points 77 00:03:37,350 --> 00:03:39,870 so this point will be connected to 78 00:03:39,870 --> 00:03:43,320 the ground through this resistor meaning that 79 00:03:43,380 --> 00:03:45,300 we will have nothing here and nothing 80 00:03:45,300 --> 00:03:45,870 and twelve 81 00:03:47,100 --> 00:03:48,630 so if we don't press the button 82 00:03:48,630 --> 00:03:51,060 we have zero in pin twelve but 83 00:03:51,060 --> 00:03:53,520 if we press it then we now 84 00:03:53,520 --> 00:03:55,770 have five volts because of the red 85 00:03:55,770 --> 00:03:56,160 wire 86 00:03:58,170 --> 00:03:59,370 now if any of this hasn't made 87 00:03:59,370 --> 00:04:01,530 sense so far you can rewind and 88 00:04:01,530 --> 00:04:03,600 just watch and listen to that explanation 89 00:04:03,600 --> 00:04:03,900 again 90 00:04:06,960 --> 00:04:09,750 now like always we need the program 91 00:04:10,560 --> 00:04:12,150 so we're going to click code 92 00:04:13,320 --> 00:04:14,040 and 93 00:04:15,300 --> 00:04:16,950 now we want to remove the previous 94 00:04:16,950 --> 00:04:19,290 program and the first thing we need 95 00:04:19,290 --> 00:04:20,459 is an input 96 00:04:23,220 --> 00:04:24,840 so we want this first block 97 00:04:26,850 --> 00:04:28,740 up here because we want it to 98 00:04:28,770 --> 00:04:31,140 read pin number twelve so that's what 99 00:04:31,140 --> 00:04:32,100 we select it 100 00:04:33,210 --> 00:04:36,030 and then we need something else called 101 00:04:36,030 --> 00:04:36,900 a variable 102 00:04:42,210 --> 00:04:44,490 now a variable is a kind of 103 00:04:44,490 --> 00:04:46,680 box to store the value or number 104 00:04:46,680 --> 00:04:47,640 that we have read 105 00:04:49,200 --> 00:04:50,580 so we're going to click here 106 00:04:51,990 --> 00:04:53,850 to create a variable and the name 107 00:04:53,850 --> 00:04:56,130 for this variable will be input because 108 00:04:56,130 --> 00:04:57,270 it's the one that we're reading 109 00:04:58,500 --> 00:05:00,000 so now we are going to use 110 00:05:00,000 --> 00:05:03,480 this block to define the input and 111 00:05:03,480 --> 00:05:05,550 then connect the blocks together like this 112 00:05:06,930 --> 00:05:08,460 so the right side is the reading 113 00:05:08,460 --> 00:05:10,860 for number twelve and this reading is 114 00:05:10,860 --> 00:05:13,140 going to be stored inside the input 115 00:05:13,170 --> 00:05:14,970 like a box to save or store 116 00:05:14,970 --> 00:05:16,770 this number for twelve 117 00:05:18,810 --> 00:05:20,700 so now that we have our input 118 00:05:20,760 --> 00:05:21,780 in the variable 119 00:05:23,130 --> 00:05:25,800 we are going to add controls so 120 00:05:25,800 --> 00:05:27,330 that we can check the value of 121 00:05:27,330 --> 00:05:29,250 the input that we have and we 122 00:05:29,250 --> 00:05:30,930 want to compare the input with the 123 00:05:30,930 --> 00:05:32,070 value for example 124 00:05:35,100 --> 00:05:36,960 so we need a block from the 125 00:05:36,960 --> 00:05:38,040 math section 126 00:05:40,470 --> 00:05:42,480 and we're going to use 127 00:05:44,670 --> 00:05:45,660 this one here 128 00:05:47,820 --> 00:05:49,350 we're going to use the section more 129 00:05:49,350 --> 00:05:50,970 later but for now the only block 130 00:05:50,970 --> 00:05:52,680 we're gonna use is this second one 131 00:05:53,250 --> 00:05:55,140 so we can compare the two values 132 00:05:55,560 --> 00:05:57,090 we can compare if one of them 133 00:05:57,090 --> 00:05:59,820 is less than less than or equal 134 00:06:00,030 --> 00:06:02,490 equal to not equal to greater or 135 00:06:02,490 --> 00:06:04,890 greater than or equal to and right 136 00:06:04,890 --> 00:06:06,960 now we want equal because we 137 00:06:06,960 --> 00:06:08,520 you want to compare the input 138 00:06:10,260 --> 00:06:11,640 yeah here's the input 139 00:06:13,890 --> 00:06:15,810 so i don't want a number I 140 00:06:15,810 --> 00:06:18,510 want two possibilities high or low because 141 00:06:18,510 --> 00:06:20,760 these are digital inputs so we can't 142 00:06:20,760 --> 00:06:22,110 compare using a number 143 00:06:23,610 --> 00:06:25,590 so digital just means high or low 144 00:06:25,620 --> 00:06:27,960 and analog means a value or a 145 00:06:27,960 --> 00:06:32,760 number so if input equals high then 146 00:06:32,760 --> 00:06:34,650 we must be pressing this button because 147 00:06:34,650 --> 00:06:36,810 it's all related to twelve since that 148 00:06:36,810 --> 00:06:38,160 value is stored here 149 00:06:39,840 --> 00:06:41,130 and now we want to compare this 150 00:06:41,130 --> 00:06:42,300 value too high 151 00:06:44,460 --> 00:06:45,870 so that what happens if we press 152 00:06:45,870 --> 00:06:47,820 the button so for instance if I 153 00:06:47,820 --> 00:06:50,820 want number thirteen high well how do 154 00:06:50,820 --> 00:06:51,300 I do it 155 00:06:54,510 --> 00:06:56,400 so we need to define the pathway 156 00:06:56,400 --> 00:06:57,450 for number thirteen 157 00:07:08,490 --> 00:07:11,610 okay so with this program if I 158 00:07:11,610 --> 00:07:13,650 press the button the LED will shine 159 00:07:14,100 --> 00:07:16,349 first it reads the value stored in 160 00:07:16,350 --> 00:07:18,660 input a compares the input with high 161 00:07:19,020 --> 00:07:21,030 and then if the input equals high 162 00:07:21,330 --> 00:07:22,650 then thirteen will be high 163 00:07:25,020 --> 00:07:28,650 and see no in english means if 164 00:07:28,650 --> 00:07:30,750 not or or else 165 00:07:37,200 --> 00:07:39,120 so that's what happens if the condition 166 00:07:39,120 --> 00:07:40,860 is not true because this is just 167 00:07:40,860 --> 00:07:41,670 a condition 168 00:07:43,920 --> 00:07:45,600 and what we want is if we're 169 00:07:45,600 --> 00:07:46,860 not pressing the button 170 00:07:48,480 --> 00:07:51,690 or if the input is low then 171 00:07:51,750 --> 00:07:53,130 we will define that here 172 00:08:04,680 --> 00:08:06,090 so now if we press the button 173 00:08:06,090 --> 00:08:08,130 we've stored that value here and we 174 00:08:08,130 --> 00:08:10,530 compare the value with high and if 175 00:08:10,530 --> 00:08:12,510 the value is high then the lcd 176 00:08:12,510 --> 00:08:14,760 will shine because it's connected to thirteen 177 00:08:15,900 --> 00:08:17,700 and if the condition is not met 178 00:08:17,970 --> 00:08:20,310 the LED connected to thirteen will not 179 00:08:20,310 --> 00:08:21,240 shine it will be low 180 00:08:28,110 --> 00:08:30,090 so now we have connected everything the 181 00:08:30,090 --> 00:08:33,270 output part we have the input part 182 00:08:33,270 --> 00:08:35,159 including the button and pull down resistor 183 00:08:35,190 --> 00:08:36,330 and we have the block so we 184 00:08:36,330 --> 00:08:38,370 have everything we need so if we 185 00:08:38,370 --> 00:08:40,650 start the simulation nothing will happen yet 186 00:08:40,890 --> 00:08:42,090 but if we press the button then 187 00:08:42,090 --> 00:08:44,130 the LED will shine and if I 188 00:08:44,130 --> 00:08:46,710 stop pressing the LED doesn't shine because 189 00:08:46,710 --> 00:08:47,520 that's how we programmed 190 00:08:47,550 --> 00:08:50,190 it so that's the exercise today just 191 00:08:50,190 --> 00:08:51,750 repeating the example okay