1 00:00:00,500 --> 00:00:06,900 Hello, in this exercise we are going to learn something new about the USB. 2 00:00:06,900 --> 00:00:10,820 The USB is the wire we use to connect the Arduino board to the computer. 3 00:00:10,820 --> 00:00:17,940 We already know that we can use this wire to program the Arduino board from the computer 4 00:00:17,940 --> 00:00:23,940 and we also know that we can use this connector to provide energy from the computer. 5 00:00:23,940 --> 00:00:30,899 but there is another possibility we can use this connector to send and receive information from 6 00:00:30,899 --> 00:00:35,619 the computer to the Arduino board and vice versa from the Arduino board to the computer okay 7 00:00:36,340 --> 00:00:43,539 in this exercise here we have the Arduino board we have the protoboard and we have a voltage 8 00:00:44,259 --> 00:00:53,700 divider okay the idea is really simple we already know how to read an analog value using 9 00:00:53,700 --> 00:00:56,979 A0 and using the voltage divider, okay? 10 00:00:58,020 --> 00:01:01,700 And we are going to program the circuit this way. I want to show the code to you. 11 00:01:03,479 --> 00:01:05,700 We are reading the 12 00:01:05,700 --> 00:01:09,500 analog pin, analog connector A0, and we store it in 13 00:01:09,500 --> 00:01:13,239 a variable called A, okay? We already know how to use it. 14 00:01:13,900 --> 00:01:16,840 The new block is the second one, the blue one. 15 00:01:19,540 --> 00:01:21,700 You have it here in the 16 00:01:21,700 --> 00:01:29,319 blue library and is this block. Imprimir en monitor serie. The interesting thing 17 00:01:29,319 --> 00:01:34,959 here is that we are going to print A. But what does it mean? And then we will use 18 00:01:34,959 --> 00:01:39,519 a weight. What does it mean Imprimir en monitor serie? Monitor serie, series 19 00:01:39,519 --> 00:01:46,819 monitor, is a tool the computer has to receive information from the Arduino 20 00:01:46,819 --> 00:01:54,079 board. Here in the simulator the series monitor is here, so it means that if we 21 00:01:54,079 --> 00:02:01,000 start the simulation here we will be reading values, the values we read from 22 00:02:01,000 --> 00:02:09,740 A0. If I move this one closer to 5 volts to 1023 you can see that the 23 00:02:09,740 --> 00:02:16,419 values become becomes higher. If we move it closer to 0 this way it becomes 24 00:02:16,419 --> 00:02:24,699 lower but I think that using the simulator doesn't give you a whole idea 25 00:02:24,699 --> 00:02:32,020 about the about the program so that's why I'm going to take the code I'm sorry 26 00:02:32,020 --> 00:02:42,680 look is stop simulation we are going to take this text I copy it and I'm going 27 00:02:42,680 --> 00:02:51,719 paste it here in the Arduino IDE, you already know it, so I paste it, I check it, okay, it works fine, 28 00:02:51,719 --> 00:02:56,919 and I'm going to upload to the Arduino board, because my Arduino board is connected to the 29 00:02:56,919 --> 00:03:05,639 computer through the USB wire that is here, here, the USB wire, okay, can you see it? So I'm going 30 00:03:05,639 --> 00:03:11,159 to send it the program, this one, the one we have programmed with the blocks to the real Arduino, 31 00:03:11,159 --> 00:03:31,520 So we will read from A0. A0 is this one. And we also have 5 volts and ground. So they are doing a board. We read the information sent by A0. So I will send it. Upload. Uploading. Okay, now it works. 32 00:03:31,520 --> 00:03:37,520 OK, fine, perfect. Where is the series monitor here? 33 00:03:37,520 --> 00:03:42,520 The series monitor is here. We click on tools and then monitor series. 34 00:03:42,520 --> 00:03:46,900 We want to make it a little bit smaller. 35 00:03:46,900 --> 00:03:52,900 Now we are reading 766. 36 00:03:52,900 --> 00:03:58,900 What happens if I turn this one? This voltage divider is higher. 37 00:03:58,900 --> 00:04:03,659 And I move it a little bit to the left, it's even higher. 38 00:04:03,800 --> 00:04:04,879 This is the maximum value. 39 00:04:05,120 --> 00:04:07,699 What happens if I move it to the right? 40 00:04:08,580 --> 00:04:11,400 It becomes lower and lower and lower. 41 00:04:11,719 --> 00:04:13,960 So I think this is really, really interesting. 42 00:04:13,960 --> 00:04:23,339 We are taking this electronic component and the value is sent using the USB, 43 00:04:23,540 --> 00:04:27,060 USB here, and it's sent to the computer and the computer can read it. 44 00:04:27,060 --> 00:04:31,060 Okay? So this is the amazing thing about this exercise. 45 00:04:31,060 --> 00:04:35,060 Okay? So let's stop the simulation here, 46 00:04:35,060 --> 00:04:39,060 and let's go back to this circuit. 47 00:04:39,060 --> 00:04:43,060 This is the exercise you have to do. You are going to copy 48 00:04:43,060 --> 00:04:47,060 this voltage divider, you are going to place another one here, for instance, 49 00:04:47,060 --> 00:04:51,060 the ground connected to the ground, the 5V wire connected to the 50 00:04:51,060 --> 00:04:55,060 5V wire, and here instead of 51 00:04:55,060 --> 00:04:58,879 connected to A0 that has been already used, you are going to connect to A1. 52 00:04:59,279 --> 00:05:02,860 So you will read two values. And so the same way 53 00:05:02,860 --> 00:05:06,819 I'm sorry, just blocks. The same way you are reading one value 54 00:05:06,819 --> 00:05:10,779 you will read another one in another variable, for instance B, and 55 00:05:10,779 --> 00:05:14,939 you will send both values to the 56 00:05:14,939 --> 00:05:19,000 series monitor, in Premiere Monitor Serie A, in Premiere Monitor Serie B. 57 00:05:19,420 --> 00:05:22,600 You will wait one second, because it means you read and you wait 58 00:05:22,600 --> 00:05:30,600 you wait one second until the next reading, and you also use the if block to compare. 59 00:05:30,600 --> 00:05:36,600 And there will be three possibilities. If A is higher than B, you will also use this blue block 60 00:05:36,600 --> 00:05:42,600 to imprimir en monitor serie to send A is higher than B, if A is higher. 61 00:05:42,600 --> 00:05:51,600 Another one, if they are equal, if A equals B, you will send, using this blue block, A equals B. 62 00:05:51,600 --> 00:05:55,600 and a third one is B is higher than A, you will type here, 63 00:05:55,600 --> 00:06:00,600 you will send through the series monitor, B is higher than A. 64 00:06:00,600 --> 00:06:04,600 So you will complete this exercise with another variable 65 00:06:04,600 --> 00:06:08,600 and you will check three conditions and you will also send 66 00:06:08,600 --> 00:06:12,600 the three conditions using the USB connector, okay? 67 00:06:12,600 --> 00:06:14,600 The serial monitor. 68 00:06:14,600 --> 00:06:18,600 Okay, and that's all, I think the exercise is not difficult. 69 00:06:18,600 --> 00:06:20,600 Good luck.