1 00:00:03,000 --> 00:00:06,750 Hello. In this video tutorial today we 2 00:00:06,750 --> 00:00:08,520 are going to learn how to control 3 00:00:08,550 --> 00:00:10,950 a temperature sensor with the arduino board 4 00:00:12,000 --> 00:00:13,410 okay we have our board and the 5 00:00:13,410 --> 00:00:15,240 first thing we need is a temperature 6 00:00:15,240 --> 00:00:15,750 sensor 7 00:00:16,890 --> 00:00:18,570 you will find it in the library 8 00:00:19,110 --> 00:00:22,290 the basic components library down here 9 00:00:25,140 --> 00:00:27,000 there it is so click and drag 10 00:00:27,000 --> 00:00:28,800 like always onto the protoboard 11 00:00:30,060 --> 00:00:32,369 and this temperature sensor has three connectors 12 00:00:32,759 --> 00:00:34,830 the first one has to be connected 13 00:00:34,830 --> 00:00:37,860 to five volts the third one or 14 00:00:37,950 --> 00:00:39,180 the other one on the end is 15 00:00:39,180 --> 00:00:41,160 connected to the ground using the black 16 00:00:41,160 --> 00:00:43,080 wire to the ground connector on the 17 00:00:43,080 --> 00:00:43,860 arduino board 18 00:00:45,030 --> 00:00:46,740 and the second one or this one 19 00:00:46,740 --> 00:00:48,690 in the middle is going to be 20 00:00:48,690 --> 00:00:51,930 connected to analog input a zero for 21 00:00:51,930 --> 00:00:54,210 instance like today and it's the one 22 00:00:54,210 --> 00:00:55,800 that's going to read the voltage from 23 00:00:55,800 --> 00:00:57,960 the sensor and the arduino board will 24 00:00:57,960 --> 00:01:00,390 read the temperature using this wire and 25 00:01:00,390 --> 00:01:01,050 this voltage 26 00:01:02,760 --> 00:01:05,220 so the connection is really easy but 27 00:01:05,220 --> 00:01:06,300 how do we program it 28 00:01:09,510 --> 00:01:11,160 so let's open the code 29 00:01:12,930 --> 00:01:14,640 and for now just forget about the 30 00:01:14,653 --> 00:01:16,770 second part the important thing here is 31 00:01:16,770 --> 00:01:19,080 this purple one this one is a 32 00:01:19,080 --> 00:01:22,680 specific input for a temperature sensor and 33 00:01:22,680 --> 00:01:24,210 what it means is that we are 34 00:01:24,210 --> 00:01:27,570 reading from this connector we can read 35 00:01:27,570 --> 00:01:29,280 from a one a two a three 36 00:01:29,280 --> 00:01:31,380 a four or a five and we're 37 00:01:31,380 --> 00:01:32,400 choosing a zero 38 00:01:32,490 --> 00:01:33,720 just for this example 39 00:01:35,460 --> 00:01:37,980 and the unit we want is degrees 40 00:01:38,010 --> 00:01:39,000 in Celsius 41 00:01:40,170 --> 00:01:41,970 so the moment we have this block 42 00:01:41,970 --> 00:01:43,710 we can store the reading in a 43 00:01:43,710 --> 00:01:47,550 variable called temperature and then we can 44 00:01:47,550 --> 00:01:49,650 send it to the serial monitor using 45 00:01:49,650 --> 00:01:51,840 the block we have already used in 46 00:01:51,840 --> 00:01:53,340 several other exercises 47 00:01:55,680 --> 00:01:57,330 so the connection and the programming are 48 00:01:57,330 --> 00:01:59,910 both very simple now let's look at 49 00:01:59,910 --> 00:02:00,750 the simulation 50 00:02:05,760 --> 00:02:07,500 so if I start the simulation 51 00:02:09,509 --> 00:02:12,630 nothing happens at first but the reading 52 00:02:12,630 --> 00:02:14,220 is here in the serial monitor 53 00:02:15,600 --> 00:02:17,550 right now the sensor is reading twenty 54 00:02:17,550 --> 00:02:21,600 four degrees why because if we click 55 00:02:21,750 --> 00:02:22,800 on the sensor 56 00:02:24,900 --> 00:02:27,210 this bar will appear and we can 57 00:02:27,210 --> 00:02:29,670 decide what the temperature it is reading 58 00:02:29,760 --> 00:02:30,570 from outside 59 00:02:31,800 --> 00:02:33,030 so if we go up to forty 60 00:02:33,030 --> 00:02:34,950 nine here then that means the arduino 61 00:02:34,950 --> 00:02:36,960 board will read forty nine in the 62 00:02:36,960 --> 00:02:37,380 monitor 63 00:02:39,120 --> 00:02:41,010 we go up to seventy six or 64 00:02:41,280 --> 00:02:43,470 seventy eight then the board will read 65 00:02:43,470 --> 00:02:46,200 the same seventy eight so the simulation 66 00:02:46,200 --> 00:02:49,110 works your exercise will be a little 67 00:02:49,110 --> 00:02:52,050 bit more complicated but just a little 68 00:02:52,050 --> 00:02:54,060 bit I'm going to show you the 69 00:02:54,060 --> 00:02:55,350 program in real life 70 00:02:57,240 --> 00:02:58,890 so here's the program and I have 71 00:02:59,280 --> 00:03:01,800 my arduino board here and the temperature 72 00:03:01,800 --> 00:03:02,430 sensor 73 00:03:03,690 --> 00:03:06,510 is over here it's very small over 74 00:03:06,510 --> 00:03:08,340 here so it's hard to see but 75 00:03:08,340 --> 00:03:09,900 we're reading it now you can see 76 00:03:09,900 --> 00:03:11,820 the measurements here in the serial monitor 77 00:03:12,450 --> 00:03:13,830 right now it says the room is 78 00:03:13,830 --> 00:03:15,030 twenty two degrees 79 00:03:18,330 --> 00:03:20,370 now if I touch it with my 80 00:03:20,370 --> 00:03:21,000 fingers 81 00:03:22,500 --> 00:03:24,690 the temperature will rise will go up 82 00:03:24,690 --> 00:03:25,530 that makes sense 83 00:03:26,670 --> 00:03:29,070 now it's reading twenty four so the 84 00:03:29,070 --> 00:03:30,150 device is working 85 00:03:31,890 --> 00:03:33,780 now I've had to make a modification 86 00:03:33,780 --> 00:03:37,050 because this reading is slightly different if 87 00:03:37,080 --> 00:03:38,700 we have a look at the text 88 00:03:38,760 --> 00:03:41,610 taken from the code on the computer 89 00:03:43,110 --> 00:03:44,370 let me show you the text 90 00:03:45,630 --> 00:03:50,130 this line here is different temperature equals 91 00:03:50,130 --> 00:03:52,860 minus forty plus number multiply by analog 92 00:03:52,860 --> 00:03:55,560 read minus twenty this line is not 93 00:03:55,560 --> 00:03:59,010 the same as this one here now 94 00:03:59,010 --> 00:04:01,020 this is because I have a different 95 00:04:01,020 --> 00:04:03,690 temperature sensor but it's not a problem 96 00:04:03,690 --> 00:04:05,760 because if you look for information 97 00:04:05,760 --> 00:04:07,170 can you look up the type for 98 00:04:07,170 --> 00:04:10,440 instance and the sensor I'm using is 99 00:04:10,440 --> 00:04:12,570 the l m thirty five so if 100 00:04:12,570 --> 00:04:14,910 I look this up online I will 101 00:04:14,910 --> 00:04:16,829 find how to connect it and I 102 00:04:16,829 --> 00:04:18,089 will find out how to read it 103 00:04:18,089 --> 00:04:19,350 using the arduino board 104 00:04:21,690 --> 00:04:23,460 all the information is here so this 105 00:04:23,460 --> 00:04:24,510 is the only line that i have 106 00:04:24,510 --> 00:04:28,740 modified now there's another modification too because 107 00:04:28,920 --> 00:04:31,530 I have added something to control a 108 00:04:31,530 --> 00:04:33,240 buzzer do remember 109 00:04:34,710 --> 00:04:37,560 now the buzzer is over here 110 00:04:39,570 --> 00:04:41,220 on my screen this is the buzzer 111 00:04:42,720 --> 00:04:44,094 and if you remember the buzzer makes 112 00:04:44,094 --> 00:04:46,440 sound you already know how to program 113 00:04:46,440 --> 00:04:48,000 it and if you don't remember you 114 00:04:48,000 --> 00:04:49,740 can go back to the exercise when 115 00:04:49,740 --> 00:04:50,430 we used it 116 00:04:51,960 --> 00:04:54,151 so we have a specific output just 117 00:04:54,151 --> 00:04:56,490 to remind you there's a specific output 118 00:04:56,490 --> 00:04:59,100 in the library so let me take 119 00:04:59,100 --> 00:05:01,590 you back to the output library 120 00:05:03,900 --> 00:05:05,460 we have a block here 121 00:05:07,020 --> 00:05:09,300 we use this block and then a 122 00:05:09,300 --> 00:05:11,130 wait block so you can control the 123 00:05:11,130 --> 00:05:11,520 buzzer 124 00:05:16,530 --> 00:05:18,480 now back to my real circuit so 125 00:05:18,480 --> 00:05:20,310 I have the arduino board here 126 00:05:21,390 --> 00:05:22,560 I have a buzzer 127 00:05:23,790 --> 00:05:26,220 and I have my temperature sensor here 128 00:05:27,480 --> 00:05:28,410 so let's have a look at how 129 00:05:28,410 --> 00:05:29,460 my sensor works 130 00:05:30,510 --> 00:05:31,980 right now we're reading twenty two 131 00:05:34,500 --> 00:05:36,270 if I touch it like before 132 00:05:39,630 --> 00:05:41,400 the temperature will rise 133 00:05:42,840 --> 00:05:44,370 and I've programmed the circuit so that 134 00:05:44,370 --> 00:05:46,200 if the temperature is higher than twenty 135 00:05:46,200 --> 00:05:48,930 five the buzzer will produce sound so 136 00:05:48,990 --> 00:05:51,630 I will touch it twenty twenty two 137 00:05:51,690 --> 00:05:54,660 twenty three twenty four twenty five twenty 138 00:05:54,660 --> 00:05:55,140 six 139 00:05:56,700 --> 00:05:57,229 do you have 140 00:05:58,680 --> 00:05:59,370 can you hear it? 141 00:06:00,570 --> 00:06:02,640 the buzzer okay so my circuit is 142 00:06:02,640 --> 00:06:04,710 working now if I remove my hand 143 00:06:04,710 --> 00:06:06,660 from the device the moment the temperature 144 00:06:06,660 --> 00:06:10,110 becomes lower it doesn't buzz anymore so 145 00:06:10,110 --> 00:06:11,820 this is the exercise you will have 146 00:06:11,820 --> 00:06:15,060 to program using the simulator you only 147 00:06:15,060 --> 00:06:16,890 need to click and drag the buzzer 148 00:06:18,660 --> 00:06:20,340 you need to connect it to ground 149 00:06:20,370 --> 00:06:22,260 and to one of the digital devices 150 00:06:24,270 --> 00:06:27,690 and using this block for sound and 151 00:06:27,690 --> 00:06:29,850 the weight block remember adding them together 152 00:06:29,850 --> 00:06:30,180 here 153 00:06:31,500 --> 00:06:33,330 and you will also need the condition 154 00:06:33,990 --> 00:06:36,900 the conditional the if block if and 155 00:06:36,900 --> 00:06:39,150 a temperature so for example if the 156 00:06:39,150 --> 00:06:42,120 temperature is higher than twenty five or 157 00:06:42,180 --> 00:06:43,680 fifty or whatever you want 158 00:06:44,910 --> 00:06:48,060 then the buzzer will produce sound now 159 00:06:48,060 --> 00:06:49,470 you should already know all the blocks 160 00:06:49,470 --> 00:06:51,750 you need and your simulation will work 161 00:06:51,750 --> 00:06:53,610 the same way my real circuit has 162 00:06:53,610 --> 00:06:55,950 worked so think about how to program 163 00:06:55,950 --> 00:06:57,270 this and good luck