1 00:00:00,270 --> 00:00:07,230 Hello. In this exercise we are 2 00:00:07,230 --> 00:00:09,150 going to learn something new about the 3 00:00:09,150 --> 00:00:11,550 usb. The usb is the 4 00:00:11,550 --> 00:00:13,470 wire we use to connect the arduino 5 00:00:13,470 --> 00:00:14,790 board to the computer 6 00:00:15,870 --> 00:00:17,130 so we already know that we can 7 00:00:17,130 --> 00:00:19,860 use this wire to program the arduino 8 00:00:19,860 --> 00:00:22,290 board from the computer and we also 9 00:00:22,290 --> 00:00:24,030 know that we can use this connector 10 00:00:24,210 --> 00:00:27,120 to provide energy from the computer but 11 00:00:27,120 --> 00:00:29,340 there is another possibility we can use 12 00:00:29,340 --> 00:00:32,040 this connector to send and receive information 13 00:00:32,040 --> 00:00:34,170 from the computer to the arduino board 14 00:00:34,200 --> 00:00:36,000 and vice versa from the hardware 15 00:00:36,030 --> 00:00:37,110 aboard to the computer 16 00:00:38,730 --> 00:00:40,950 so in this exercise here we have 17 00:00:41,100 --> 00:00:43,560 the arduino board we have the 18 00:00:43,560 --> 00:00:43,980 protoboard 19 00:00:45,360 --> 00:00:48,060 and we have the voltage divider now 20 00:00:48,060 --> 00:00:50,100 the idea is really simple we already 21 00:00:50,100 --> 00:00:52,350 know how to read an analog value 22 00:00:52,350 --> 00:00:55,380 using a zero and the voltage divider 23 00:00:56,190 --> 00:00:57,510 so we are going to program the 24 00:00:57,510 --> 00:00:59,820 circuit this way so let me show 25 00:00:59,820 --> 00:01:00,930 you the code 26 00:01:05,190 --> 00:01:07,380 we are reading the analog pen or 27 00:01:07,380 --> 00:01:10,230 connector a zero we store it in 28 00:01:10,230 --> 00:01:11,940 a variable called a 29 00:01:13,500 --> 00:01:16,230 and that the new block is the 30 00:01:16,230 --> 00:01:17,700 second one this blue one 31 00:01:19,320 --> 00:01:21,600 you will find it here at the 32 00:01:21,600 --> 00:01:23,610 top in the blue library 33 00:01:27,240 --> 00:01:30,000 and it's this blog called print series 34 00:01:30,030 --> 00:01:33,120 monitor and the interesting thing here is 35 00:01:33,120 --> 00:01:35,010 that we are going to print a 36 00:01:36,540 --> 00:01:38,280 okay so then we have this weight 37 00:01:38,280 --> 00:01:38,820 block 38 00:01:40,020 --> 00:01:41,760 and so what is what is this 39 00:01:41,760 --> 00:01:43,740 blue one mean while the series monitor 40 00:01:43,740 --> 00:01:45,510 is a tool the computer has to 41 00:01:45,510 --> 00:01:48,030 receive information from the arduino board 42 00:01:50,400 --> 00:01:51,840 so here in the simulator 43 00:01:53,100 --> 00:01:56,970 the series monitor is down here so 44 00:01:57,000 --> 00:02:00,120 when we start the simulation down here 45 00:02:00,120 --> 00:02:02,340 we will be reading values ok the 46 00:02:02,340 --> 00:02:04,410 values that are coming from a zero 47 00:02:05,550 --> 00:02:07,380 if i move the divider closer to 48 00:02:07,380 --> 00:02:10,320 five volts to one thousand twenty three 49 00:02:10,949 --> 00:02:12,690 you can see that the values become 50 00:02:12,690 --> 00:02:13,170 higher 51 00:02:14,700 --> 00:02:16,110 if we move move it closer to 52 00:02:16,110 --> 00:02:18,720 zero toward the left it becomes lower 53 00:02:20,520 --> 00:02:23,040 but using the simulator here doesn't give 54 00:02:23,040 --> 00:02:25,290 you the whole idea about the program 55 00:02:25,320 --> 00:02:28,710 so I am going to take this 56 00:02:28,710 --> 00:02:29,250 code 57 00:02:30,510 --> 00:02:32,550 and we can stop the simulation 58 00:02:39,390 --> 00:02:41,280 so just the code I'm going to 59 00:02:41,280 --> 00:02:43,740 take the text right and copy and 60 00:02:43,740 --> 00:02:44,400 paste it 61 00:02:45,720 --> 00:02:48,630 into the arduino id the program you've 62 00:02:48,630 --> 00:02:51,060 already seen that so I paste it 63 00:02:51,060 --> 00:02:53,940 here and check it up here 64 00:02:55,110 --> 00:02:57,540 and it works fine and then we'll 65 00:02:57,540 --> 00:03:00,120 upload this to the arduino board because 66 00:03:00,120 --> 00:03:02,310 my arduino board on the screen is 67 00:03:02,310 --> 00:03:04,860 connected to the computer through the usb 68 00:03:04,860 --> 00:03:06,990 wire that is back here can you 69 00:03:06,990 --> 00:03:07,320 see it 70 00:03:10,260 --> 00:03:12,450 so I'm going to send this program 71 00:03:12,570 --> 00:03:14,130 the one that we programmed with the 72 00:03:14,130 --> 00:03:16,110 blocks to the arduino 73 00:03:17,340 --> 00:03:19,470 so we will read from a zero 74 00:03:19,560 --> 00:03:21,960 this one and we will also have 75 00:03:21,960 --> 00:03:24,750 the five volts and the ground 76 00:03:26,670 --> 00:03:28,290 so the arduino board will read the 77 00:03:28,290 --> 00:03:31,170 information sent by a zero so I 78 00:03:31,170 --> 00:03:34,380 will send it or click upload and 79 00:03:34,380 --> 00:03:35,340 now it works 80 00:03:36,780 --> 00:03:39,690 now the series monitor in this program 81 00:03:39,690 --> 00:03:41,610 can be found up here if we 82 00:03:41,610 --> 00:03:44,970 click on tools and then down to 83 00:03:44,970 --> 00:03:45,870 series monitor 84 00:03:47,580 --> 00:03:48,450 let's just make it a little bit 85 00:03:48,450 --> 00:03:48,960 smaller 86 00:03:51,240 --> 00:03:53,100 so right now we're reading seven hundred 87 00:03:53,100 --> 00:03:53,970 sixty six 88 00:03:55,500 --> 00:03:57,930 if I turn this real voltage divider 89 00:03:57,930 --> 00:04:00,120 higher and move it a little bit 90 00:04:01,560 --> 00:04:02,910 to the left or even all the 91 00:04:02,910 --> 00:04:05,220 way it'll go to the maximum value 92 00:04:05,250 --> 00:04:07,560 it'll read the highest if I move 93 00:04:07,560 --> 00:04:08,940 it to the to the right it 94 00:04:08,940 --> 00:04:10,470 becomes lower and lower 95 00:04:12,510 --> 00:04:13,890 and it's reading lower so this is 96 00:04:13,890 --> 00:04:16,350 really interesting because we are taking this 97 00:04:16,410 --> 00:04:19,440 electronic component and the value is sent 98 00:04:19,440 --> 00:04:22,830 using the usb here and sending it 99 00:04:22,830 --> 00:04:25,110 to the computer and the computer can 100 00:04:25,110 --> 00:04:25,680 read it 101 00:04:27,390 --> 00:04:29,730 so this is the amazing thing about 102 00:04:29,730 --> 00:04:30,630 this exercise 103 00:04:36,750 --> 00:04:38,670 so for now let's just leave this 104 00:04:38,700 --> 00:04:40,590 simulation here and go back to the 105 00:04:40,590 --> 00:04:44,130 circuit this is the exercise you have 106 00:04:44,130 --> 00:04:45,780 to do you are going to copy 107 00:04:45,780 --> 00:04:48,420 this voltage divider so place another one 108 00:04:48,420 --> 00:04:50,940 next to it for instance with the 109 00:04:50,940 --> 00:04:53,790 ground connected to the ground the five 110 00:04:53,790 --> 00:04:56,100 volts wire connected to the five volts 111 00:04:56,130 --> 00:04:56,490 and 112 00:04:56,910 --> 00:04:59,040 here instead of connecting to a zero 113 00:04:59,040 --> 00:05:01,290 which is already being used you're going 114 00:05:01,290 --> 00:05:03,540 to connect to a one so you 115 00:05:03,540 --> 00:05:05,880 will read two values and so the 116 00:05:05,880 --> 00:05:08,220 same way you're reading one value in 117 00:05:08,220 --> 00:05:10,050 the code you will read another one 118 00:05:10,530 --> 00:05:13,110 in another variable for instance you can 119 00:05:13,110 --> 00:05:13,830 make it be 120 00:05:15,330 --> 00:05:16,740 and you will send both values to 121 00:05:16,740 --> 00:05:19,740 the series monitor with a and then 122 00:05:19,740 --> 00:05:20,940 again with b 123 00:05:22,560 --> 00:05:24,300 then you await one second because it 124 00:05:24,300 --> 00:05:27,090 means you read and wait one second 125 00:05:27,090 --> 00:05:28,620 until the next one starts reading 126 00:05:30,150 --> 00:05:31,500 and then you will also use the 127 00:05:31,590 --> 00:05:33,960 if block to compare like we've done 128 00:05:35,460 --> 00:05:38,070 now there will be three possibilities if 129 00:05:38,430 --> 00:05:39,840 a is higher than b 130 00:05:41,340 --> 00:05:43,050 and you will use the blue block 131 00:05:43,050 --> 00:05:44,640 to say if a is 132 00:05:44,640 --> 00:05:45,390 higher than b 133 00:05:47,700 --> 00:05:49,740 and another one for if they are 134 00:05:49,800 --> 00:05:52,860 equal so if a equals b and 135 00:05:52,860 --> 00:05:54,420 you will send with the blue block 136 00:05:54,570 --> 00:05:55,590 a equals b 137 00:05:57,450 --> 00:05:58,980 and the third one if b is 138 00:05:58,980 --> 00:05:59,940 higher than a 139 00:06:01,290 --> 00:06:03,270 you will send that to the series 140 00:06:03,270 --> 00:06:05,220 monitor with blue if b is higher 141 00:06:05,220 --> 00:06:07,650 than a so you will complete this 142 00:06:07,650 --> 00:06:09,930 exercise with another variable and you will 143 00:06:09,930 --> 00:06:12,840 check three conditions and you will also 144 00:06:12,840 --> 00:06:14,970 send the three conditions to the usb 145 00:06:14,970 --> 00:06:20,250 connector and series monitor okay that is 146 00:06:20,370 --> 00:06:21,090 all for this 147 00:06:21,150 --> 00:06:22,890 exercise good luck