All language subtitles for gfdhjhkjffff

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian Download
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,080 --> 00:00:03,600 arduino is an open source electronics 2 00:00:02,159 --> 00:00:06,080 platform based on 3 00:00:03,600 --> 00:00:07,600 easy to use hardware and software this 4 00:00:06,080 --> 00:00:08,639 course from ashish will teach you 5 00:00:07,600 --> 00:00:10,639 everything you need to know 6 00:00:08,639 --> 00:00:11,920 to start creating your own electronics 7 00:00:10,639 --> 00:00:13,599 with arduino 8 00:00:11,920 --> 00:00:15,280 and you don't even have to have any 9 00:00:13,599 --> 00:00:17,279 hardware to follow along 10 00:00:15,280 --> 00:00:20,160 hello everyone thank you for joining 11 00:00:17,279 --> 00:00:22,000 this arduino course for beginners 12 00:00:20,160 --> 00:00:24,080 this course is created for people who 13 00:00:22,000 --> 00:00:25,199 have no or very little prior experience 14 00:00:24,080 --> 00:00:28,480 in electronics 15 00:00:25,199 --> 00:00:30,160 and programming so in this course i'm 16 00:00:28,480 --> 00:00:32,000 going to help you get started with your 17 00:00:30,160 --> 00:00:32,559 arduino adventures and by the end of the 18 00:00:32,000 --> 00:00:34,320 course 19 00:00:32,559 --> 00:00:35,920 we will have some basic knowledge of the 20 00:00:34,320 --> 00:00:39,440 most common hardware components 21 00:00:35,920 --> 00:00:42,879 such as breadboard resistor led etc 22 00:00:39,440 --> 00:00:44,879 and their usage in electronic circuits 23 00:00:42,879 --> 00:00:47,520 you will also be able to write arduino 24 00:00:44,879 --> 00:00:49,840 programs on your own 25 00:00:47,520 --> 00:00:50,559 this course is built in such a way that 26 00:00:49,840 --> 00:00:52,960 it would cover 27 00:00:50,559 --> 00:00:54,719 things which absolute beginners face 28 00:00:52,960 --> 00:00:55,760 while understanding the code written by 29 00:00:54,719 --> 00:00:57,680 other creators 30 00:00:55,760 --> 00:01:00,320 while creating this course i've kept in 31 00:00:57,680 --> 00:01:02,559 my mind what problems i had faced 32 00:01:00,320 --> 00:01:04,720 when i started my own journey with 33 00:01:02,559 --> 00:01:07,280 arduino and made it like a course 34 00:01:04,720 --> 00:01:07,840 which i wished i had watched before 35 00:01:07,280 --> 00:01:11,119 starting 36 00:01:07,840 --> 00:01:12,960 anything at all if you don't have an 37 00:01:11,119 --> 00:01:13,520 arduino and other components with you 38 00:01:12,960 --> 00:01:15,439 right now 39 00:01:13,520 --> 00:01:16,640 you can still follow along the course 40 00:01:15,439 --> 00:01:18,240 and get one later 41 00:01:16,640 --> 00:01:20,159 to perform your experiments which you 42 00:01:18,240 --> 00:01:22,400 have in your mind so let's get 43 00:01:20,159 --> 00:01:24,400 started this section will be a quick 44 00:01:22,400 --> 00:01:26,080 overview to practical electronics and 45 00:01:24,400 --> 00:01:27,840 some of the most common electronics 46 00:01:26,080 --> 00:01:30,560 components that we will be using 47 00:01:27,840 --> 00:01:32,320 throughout the course with the arduino 48 00:01:30,560 --> 00:01:34,240 you can always revisit this section if 49 00:01:32,320 --> 00:01:36,799 you find any term confusing or you need 50 00:01:34,240 --> 00:01:39,119 to understand something again 51 00:01:36,799 --> 00:01:40,720 so let us start with electricity i'm 52 00:01:39,119 --> 00:01:42,159 pretty sure that you all must have heard 53 00:01:40,720 --> 00:01:44,000 of this term at least once in your 54 00:01:42,159 --> 00:01:46,000 lifetime 55 00:01:44,000 --> 00:01:47,759 if not let me tell you that electricity 56 00:01:46,000 --> 00:01:49,360 has played a major role in letting you 57 00:01:47,759 --> 00:01:51,200 watch this video on your computer or 58 00:01:49,360 --> 00:01:53,200 your laptop 59 00:01:51,200 --> 00:01:55,200 electricity is a type of energy that can 60 00:01:53,200 --> 00:01:56,560 be built up in one place or flow from 61 00:01:55,200 --> 00:01:58,560 one place to another 62 00:01:56,560 --> 00:02:00,719 when electricity gathers in one place it 63 00:01:58,560 --> 00:02:03,600 is known as static electricity 64 00:02:00,719 --> 00:02:04,479 and electricity when moves from one 65 00:02:03,600 --> 00:02:09,840 place to another 66 00:02:04,479 --> 00:02:09,840 is called current electricity 67 00:02:10,479 --> 00:02:14,319 have you felt a sudden painful jolt when 68 00:02:12,640 --> 00:02:15,920 you brush someone's arm 69 00:02:14,319 --> 00:02:18,160 or crackling sounds when you take off 70 00:02:15,920 --> 00:02:21,120 your sweaters or have you 71 00:02:18,160 --> 00:02:23,120 tried to attract paper bits by a comb 72 00:02:21,120 --> 00:02:26,319 all this happens due to static charges 73 00:02:23,120 --> 00:02:28,239 that were accumulated at a place 74 00:02:26,319 --> 00:02:29,760 believe it or not even the lightning 75 00:02:28,239 --> 00:02:32,720 that happens in the sky 76 00:02:29,760 --> 00:02:34,879 happens due to static electricity so why 77 00:02:32,720 --> 00:02:36,879 does this happen 78 00:02:34,879 --> 00:02:39,120 everything in this universe is made up 79 00:02:36,879 --> 00:02:40,160 of atoms which are made up of protons 80 00:02:39,120 --> 00:02:41,840 and electrons 81 00:02:40,160 --> 00:02:43,680 protons are positively charged and 82 00:02:41,840 --> 00:02:45,920 electrons are negatively charged 83 00:02:43,680 --> 00:02:48,239 in an atom generally the number of 84 00:02:45,920 --> 00:02:50,000 protons and electrons are equal 85 00:02:48,239 --> 00:02:52,400 hence the electric state of atom is 86 00:02:50,000 --> 00:02:54,720 neutral but when some atoms lose their 87 00:02:52,400 --> 00:02:57,040 electrons they become positively charged 88 00:02:54,720 --> 00:02:59,680 and when some atoms gain electrons they 89 00:02:57,040 --> 00:03:01,280 become negatively charged 90 00:02:59,680 --> 00:03:02,959 the short learning which i want you to 91 00:03:01,280 --> 00:03:05,440 take from this lesson 92 00:03:02,959 --> 00:03:07,280 is that similar charges repel and 93 00:03:05,440 --> 00:03:09,680 opposite charges attract each other 94 00:03:07,280 --> 00:03:11,280 as shown in this diagram static 95 00:03:09,680 --> 00:03:13,280 electricity is a very deep topic 96 00:03:11,280 --> 00:03:15,040 and has a separate study called as 97 00:03:13,280 --> 00:03:16,840 electrostatics 98 00:03:15,040 --> 00:03:19,040 which will go beyond the scope of this 99 00:03:16,840 --> 00:03:20,959 course 100 00:03:19,040 --> 00:03:22,159 the other reason i told you about static 101 00:03:20,959 --> 00:03:24,560 electricity is that 102 00:03:22,159 --> 00:03:26,239 the static electric charges in our hands 103 00:03:24,560 --> 00:03:26,959 may damage your electronic components 104 00:03:26,239 --> 00:03:28,959 sometimes 105 00:03:26,959 --> 00:03:30,400 so just make sure you keep your stuff on 106 00:03:28,959 --> 00:03:32,080 hard and solid surfaces 107 00:03:30,400 --> 00:03:34,480 and keep your components back in the 108 00:03:32,080 --> 00:03:37,680 anti-static packets which you got 109 00:03:34,480 --> 00:03:39,680 along with the components current 110 00:03:37,680 --> 00:03:41,280 electricity is the form of electricity 111 00:03:39,680 --> 00:03:42,400 which makes all of our electronic 112 00:03:41,280 --> 00:03:44,799 gadgets work 113 00:03:42,400 --> 00:03:47,040 this form of electricity exists when 114 00:03:44,799 --> 00:03:49,280 charges are able to constantly flow 115 00:03:47,040 --> 00:03:51,360 as opposed to static electricity where 116 00:03:49,280 --> 00:03:54,159 charges gather and remain at rest 117 00:03:51,360 --> 00:03:55,599 current electricity is dynamic charges 118 00:03:54,159 --> 00:03:57,360 are always on the move 119 00:03:55,599 --> 00:03:59,040 we will be focusing on this form of 120 00:03:57,360 --> 00:04:01,120 electricity throughout 121 00:03:59,040 --> 00:04:02,400 the rest of our course so in the next 122 00:04:01,120 --> 00:04:04,239 video we will talk about 123 00:04:02,400 --> 00:04:05,599 voltage which is one of the most 124 00:04:04,239 --> 00:04:07,519 important concepts 125 00:04:05,599 --> 00:04:09,439 for the existence of this current 126 00:04:07,519 --> 00:04:11,920 electricity so i will see you in the 127 00:04:09,439 --> 00:04:13,519 next video 128 00:04:11,920 --> 00:04:15,360 in this video we will learn about 129 00:04:13,519 --> 00:04:17,600 voltage voltage is a force 130 00:04:15,360 --> 00:04:18,639 that makes electrons move through a wire 131 00:04:17,600 --> 00:04:21,600 it is measured in 132 00:04:18,639 --> 00:04:22,720 volts and the symbol is v okay voltage 133 00:04:21,600 --> 00:04:26,320 is also called as 134 00:04:22,720 --> 00:04:28,720 electromotive force or emf which 135 00:04:26,320 --> 00:04:30,160 drives the electrons inside a wire 136 00:04:28,720 --> 00:04:30,560 voltage was named after a scientist 137 00:04:30,160 --> 00:04:32,880 called 138 00:04:30,560 --> 00:04:34,720 alessandro volta so now technically 139 00:04:32,880 --> 00:04:35,840 speaking the voltage is a difference in 140 00:04:34,720 --> 00:04:38,639 electric potential 141 00:04:35,840 --> 00:04:39,600 between two points for example the 142 00:04:38,639 --> 00:04:41,759 difference between 143 00:04:39,600 --> 00:04:43,280 the positive and the negative terminal 144 00:04:41,759 --> 00:04:46,320 of a battery 145 00:04:43,280 --> 00:04:48,720 let's say this battery is of 5 volts so 146 00:04:46,320 --> 00:04:50,720 the potential at this point can be 5 147 00:04:48,720 --> 00:04:52,000 volts and the potential at this point 148 00:04:50,720 --> 00:04:54,479 can be 0 volts 149 00:04:52,000 --> 00:04:55,199 so the potential difference is 5 volts 150 00:04:54,479 --> 00:04:57,600 okay 151 00:04:55,199 --> 00:04:59,680 it can also be 10 volts here and 5 volts 152 00:04:57,600 --> 00:05:01,600 here resulting into a difference of 5 153 00:04:59,680 --> 00:05:03,759 volts it can also be 0 here 154 00:05:01,600 --> 00:05:04,960 and minus 5 here then also the 155 00:05:03,759 --> 00:05:07,680 difference will be 156 00:05:04,960 --> 00:05:08,320 5 volt so this battery provides some 157 00:05:07,680 --> 00:05:10,160 force 158 00:05:08,320 --> 00:05:11,520 on electrons so that they can move 159 00:05:10,160 --> 00:05:13,360 inside a wire 160 00:05:11,520 --> 00:05:15,280 like this you can see these electrons 161 00:05:13,360 --> 00:05:18,080 are moving inside a wire 162 00:05:15,280 --> 00:05:18,639 and and this bulb is glowing now let us 163 00:05:18,080 --> 00:05:21,120 understand 164 00:05:18,639 --> 00:05:22,240 voltage by a water analogy this is a 165 00:05:21,120 --> 00:05:24,800 water tank 166 00:05:22,240 --> 00:05:25,759 and the pressure at the end of the hose 167 00:05:24,800 --> 00:05:28,479 can represent 168 00:05:25,759 --> 00:05:29,199 voltage the water in the tank represents 169 00:05:28,479 --> 00:05:30,960 charge 170 00:05:29,199 --> 00:05:32,320 more the water in the tank the higher is 171 00:05:30,960 --> 00:05:34,479 the charge and 172 00:05:32,320 --> 00:05:36,479 more is the pressure at the end of the 173 00:05:34,479 --> 00:05:37,280 hose we can think of this tank as a 174 00:05:36,479 --> 00:05:38,960 battery 175 00:05:37,280 --> 00:05:40,639 a place where we can store certain 176 00:05:38,960 --> 00:05:42,720 amount of energy and then 177 00:05:40,639 --> 00:05:44,560 release it if we drain our tank a 178 00:05:42,720 --> 00:05:45,680 certain amount the pressure created at 179 00:05:44,560 --> 00:05:48,240 the end of the hose 180 00:05:45,680 --> 00:05:50,720 also goes down right what i mean to say 181 00:05:48,240 --> 00:05:53,199 is we can think of this as a decrease in 182 00:05:50,720 --> 00:05:54,080 voltage like when the flashlights which 183 00:05:53,199 --> 00:05:57,039 use batteries 184 00:05:54,080 --> 00:05:58,800 glow dimmer as the batteries run down 185 00:05:57,039 --> 00:06:00,479 and then there is also a decrease in 186 00:05:58,800 --> 00:06:01,280 amount of water that will flow through 187 00:06:00,479 --> 00:06:03,039 this hose 188 00:06:01,280 --> 00:06:04,960 less pressure means less water is 189 00:06:03,039 --> 00:06:05,520 flowing so we can consider this flowing 190 00:06:04,960 --> 00:06:08,080 water 191 00:06:05,520 --> 00:06:09,039 as current which we will discuss in the 192 00:06:08,080 --> 00:06:10,800 next video 193 00:06:09,039 --> 00:06:13,280 in this video we will learn about 194 00:06:10,800 --> 00:06:15,120 current on a very basic note the rate of 195 00:06:13,280 --> 00:06:16,720 flow of charge is known as current 196 00:06:15,120 --> 00:06:18,160 when electrons move from a negative 197 00:06:16,720 --> 00:06:18,880 terminal to positive terminal of a 198 00:06:18,160 --> 00:06:21,120 battery 199 00:06:18,880 --> 00:06:22,160 they give rise to current the unit of 200 00:06:21,120 --> 00:06:24,160 current is 201 00:06:22,160 --> 00:06:26,080 amperes and the direction in which the 202 00:06:24,160 --> 00:06:28,479 current flows is is the opposite 203 00:06:26,080 --> 00:06:29,280 to the direction of electrons what that 204 00:06:28,479 --> 00:06:30,639 means is 205 00:06:29,280 --> 00:06:32,800 if electrons are moving in this 206 00:06:30,639 --> 00:06:35,680 direction then the current will move in 207 00:06:32,800 --> 00:06:36,720 this direction all right so now on a 208 00:06:35,680 --> 00:06:38,560 more technical note 209 00:06:36,720 --> 00:06:40,880 current is the amount of electric charge 210 00:06:38,560 --> 00:06:43,919 that flows when one coulomb of charge 211 00:06:40,880 --> 00:06:45,120 moves past somewhere in one second and 212 00:06:43,919 --> 00:06:47,360 that current is 213 00:06:45,120 --> 00:06:48,720 one ampere coulomb is the measuring unit 214 00:06:47,360 --> 00:06:50,800 of charge 215 00:06:48,720 --> 00:06:53,120 all right and to measure the current at 216 00:06:50,800 --> 00:06:54,880 any point we can use an ammeter 217 00:06:53,120 --> 00:06:56,639 we can also understand the flow of 218 00:06:54,880 --> 00:06:58,160 current by water analogy 219 00:06:56,639 --> 00:07:00,400 let's say this is a tank filled with 220 00:06:58,160 --> 00:07:02,400 water and this water is flowing due to 221 00:07:00,400 --> 00:07:03,599 potential energy of water which we 222 00:07:02,400 --> 00:07:05,680 learned is called as 223 00:07:03,599 --> 00:07:07,120 voltage in the previous video so here 224 00:07:05,680 --> 00:07:09,840 the size of 225 00:07:07,120 --> 00:07:10,639 hose is acting as resistance a bigger 226 00:07:09,840 --> 00:07:12,240 size hose 227 00:07:10,639 --> 00:07:14,960 offers less resistance and the smaller 228 00:07:12,240 --> 00:07:18,240 size hose offers more resistance 229 00:07:14,960 --> 00:07:20,560 so the path which has 230 00:07:18,240 --> 00:07:22,560 lower resistance more current can flow 231 00:07:20,560 --> 00:07:24,240 through that path 232 00:07:22,560 --> 00:07:26,319 and the path which offers more 233 00:07:24,240 --> 00:07:30,560 resistance less current can 234 00:07:26,319 --> 00:07:33,440 flow through that path okay so here 235 00:07:30,560 --> 00:07:35,280 since the voltage is equal and 236 00:07:33,440 --> 00:07:37,120 resistance is lower in this case 237 00:07:35,280 --> 00:07:39,199 the water flowing here will be more and 238 00:07:37,120 --> 00:07:42,240 the water flowing here will be less 239 00:07:39,199 --> 00:07:43,840 okay so this has given 240 00:07:42,240 --> 00:07:45,360 rise to another term called as 241 00:07:43,840 --> 00:07:46,400 resistance and we will learn about 242 00:07:45,360 --> 00:07:48,240 resistance in 243 00:07:46,400 --> 00:07:49,680 next video but before that i would like 244 00:07:48,240 --> 00:07:50,160 to tell you that there are two types of 245 00:07:49,680 --> 00:07:51,759 current 246 00:07:50,160 --> 00:07:53,840 one is direct current and one is 247 00:07:51,759 --> 00:07:55,759 alternating current in dc current 248 00:07:53,840 --> 00:07:57,520 the flow of electrons stay in the same 249 00:07:55,759 --> 00:07:59,520 direction and the voltage stays 250 00:07:57,520 --> 00:08:00,560 steady with the time as you can see from 251 00:07:59,520 --> 00:08:03,599 the graph 252 00:08:00,560 --> 00:08:05,280 while in ac the flow of electrons change 253 00:08:03,599 --> 00:08:07,360 and the voltage does not stay steady 254 00:08:05,280 --> 00:08:07,759 with time that also you can see from the 255 00:08:07,360 --> 00:08:09,440 graph 256 00:08:07,759 --> 00:08:10,960 don't worry if you could not understand 257 00:08:09,440 --> 00:08:12,400 all this at this moment 258 00:08:10,960 --> 00:08:14,319 at this point you only need to 259 00:08:12,400 --> 00:08:16,800 understand that the current 260 00:08:14,319 --> 00:08:18,800 which you see in your home that is the 261 00:08:16,800 --> 00:08:20,080 current which drives your fans 262 00:08:18,800 --> 00:08:21,919 and other appliances like air 263 00:08:20,080 --> 00:08:25,039 conditioners televisions 264 00:08:21,919 --> 00:08:26,960 etc is known as ac current and the 265 00:08:25,039 --> 00:08:29,759 current which you get from the batteries 266 00:08:26,960 --> 00:08:31,680 or specific power supplies is dc or 267 00:08:29,759 --> 00:08:33,760 direct current the current you get 268 00:08:31,680 --> 00:08:35,440 from your laptop or computer's usb port 269 00:08:33,760 --> 00:08:37,279 is also dc current 270 00:08:35,440 --> 00:08:39,839 and for our course we will be dealing 271 00:08:37,279 --> 00:08:41,839 with the dc current only 272 00:08:39,839 --> 00:08:43,279 if you have understood just this part 273 00:08:41,839 --> 00:08:45,760 you are good to go 274 00:08:43,279 --> 00:08:47,519 so i will see you in the next video now 275 00:08:45,760 --> 00:08:48,880 we will take a look at resistance 276 00:08:47,519 --> 00:08:51,040 the electrical resistance of any 277 00:08:48,880 --> 00:08:52,480 component is a measure of difficulty of 278 00:08:51,040 --> 00:08:54,080 passing an electric current 279 00:08:52,480 --> 00:08:56,240 through that substance with more 280 00:08:54,080 --> 00:08:57,440 resistance in a circuit less electricity 281 00:08:56,240 --> 00:08:59,440 will flow through the circuit 282 00:08:57,440 --> 00:09:01,360 based on this term resistance there is 283 00:08:59,440 --> 00:09:02,240 an electrical component known as a 284 00:09:01,360 --> 00:09:03,920 resistor 285 00:09:02,240 --> 00:09:05,440 a resistor is a device which limits the 286 00:09:03,920 --> 00:09:07,680 flow of a current in a circuit 287 00:09:05,440 --> 00:09:09,519 we may need resistor inner circuits 288 00:09:07,680 --> 00:09:11,519 where we need to drive leds 289 00:09:09,519 --> 00:09:13,440 which require limited amount of current 290 00:09:11,519 --> 00:09:14,240 so that we can prevent it from burning 291 00:09:13,440 --> 00:09:16,640 off 292 00:09:14,240 --> 00:09:18,080 right now if we see the resistance with 293 00:09:16,640 --> 00:09:20,399 the water analogy 294 00:09:18,080 --> 00:09:21,360 we can see this is a pipe and this is 295 00:09:20,399 --> 00:09:22,880 one another pipe 296 00:09:21,360 --> 00:09:25,200 the water can flow easily through this 297 00:09:22,880 --> 00:09:26,480 pipe because it offers less resistance 298 00:09:25,200 --> 00:09:29,200 the flowing water can be 299 00:09:26,480 --> 00:09:30,800 synonymous to flowing current okay and 300 00:09:29,200 --> 00:09:32,399 when there is more resistance 301 00:09:30,800 --> 00:09:33,600 less current will pass through it one 302 00:09:32,399 --> 00:09:34,560 important thing which you would like to 303 00:09:33,600 --> 00:09:37,120 know is 304 00:09:34,560 --> 00:09:38,880 that the current always takes the least 305 00:09:37,120 --> 00:09:41,040 resistive path 306 00:09:38,880 --> 00:09:42,000 for example if you offer two parts for 307 00:09:41,040 --> 00:09:43,519 current to flow 308 00:09:42,000 --> 00:09:45,600 it will try to flow from the least 309 00:09:43,519 --> 00:09:48,240 resistive path out of them 310 00:09:45,600 --> 00:09:50,000 okay so in the next video we will study 311 00:09:48,240 --> 00:09:52,560 the relation between current voltage 312 00:09:50,000 --> 00:09:53,440 and resistance and in upcoming videos we 313 00:09:52,560 --> 00:09:55,120 will also learn 314 00:09:53,440 --> 00:09:56,880 how to identify the value of the 315 00:09:55,120 --> 00:09:59,040 resistor the value 316 00:09:56,880 --> 00:10:00,560 of the resistor is measured in ohms more 317 00:09:59,040 --> 00:10:02,160 the value of resistor 318 00:10:00,560 --> 00:10:04,240 more the resistance it will offer in the 319 00:10:02,160 --> 00:10:05,040 circuit so now i will see you in the 320 00:10:04,240 --> 00:10:07,120 next video 321 00:10:05,040 --> 00:10:08,959 so till now i'm sure that you all must 322 00:10:07,120 --> 00:10:11,279 have inferred that somehow 323 00:10:08,959 --> 00:10:14,000 all these terms are interconnected if 324 00:10:11,279 --> 00:10:16,399 you have then you are absolutely correct 325 00:10:14,000 --> 00:10:18,959 there is a law known as ohm's law which 326 00:10:16,399 --> 00:10:21,680 tells the correlation of these terms 327 00:10:18,959 --> 00:10:22,720 a german physicist george simon ohm 328 00:10:21,680 --> 00:10:24,160 stated 329 00:10:22,720 --> 00:10:26,000 that the electric current flowing 330 00:10:24,160 --> 00:10:26,720 through a metallic wire is directly 331 00:10:26,000 --> 00:10:28,880 proportional 332 00:10:26,720 --> 00:10:29,760 to the potential difference across it 333 00:10:28,880 --> 00:10:33,519 provided 334 00:10:29,760 --> 00:10:36,079 temperature remains the same that means 335 00:10:33,519 --> 00:10:37,040 like i said earlier more the force more 336 00:10:36,079 --> 00:10:38,880 the current 337 00:10:37,040 --> 00:10:41,680 so potential difference is the force 338 00:10:38,880 --> 00:10:45,200 here which we talked about earlier 339 00:10:41,680 --> 00:10:47,839 so mathematically we get voltage v 340 00:10:45,200 --> 00:10:48,320 is equal to the product of resistance r 341 00:10:47,839 --> 00:10:52,730 and 342 00:10:48,320 --> 00:10:54,880 current a or i for that matter 343 00:10:52,730 --> 00:10:56,959 [Music] 344 00:10:54,880 --> 00:10:59,200 if any one of them is unknown we can 345 00:10:56,959 --> 00:11:01,279 find out by doing the math 346 00:10:59,200 --> 00:11:02,320 there's an easy way to find that out 347 00:11:01,279 --> 00:11:04,410 there is a triangle 348 00:11:02,320 --> 00:11:06,480 known as ohm's law triangle 349 00:11:04,410 --> 00:11:09,120 [Music] 350 00:11:06,480 --> 00:11:10,399 we just hide the unknown quantity and we 351 00:11:09,120 --> 00:11:13,519 get 352 00:11:10,399 --> 00:11:16,240 the answer for example if we hide v 353 00:11:13,519 --> 00:11:16,800 so i and r looks in a multiplication 354 00:11:16,240 --> 00:11:20,800 position 355 00:11:16,800 --> 00:11:22,399 so v is equal to i multiplied by r 356 00:11:20,800 --> 00:11:24,720 if we have to find resistance we will 357 00:11:22,399 --> 00:11:27,839 cover up r then v and i 358 00:11:24,720 --> 00:11:30,560 appear in a division like position so r 359 00:11:27,839 --> 00:11:33,680 is equal to v divided by i 360 00:11:30,560 --> 00:11:37,120 then we have i as unknown quantity 361 00:11:33,680 --> 00:11:40,880 then we can do i is equal to v by r 362 00:11:37,120 --> 00:11:42,880 based on the similar reason 363 00:11:40,880 --> 00:11:44,720 this interesting image shows that if we 364 00:11:42,880 --> 00:11:45,680 consider voltage current and resistance 365 00:11:44,720 --> 00:11:47,680 as people 366 00:11:45,680 --> 00:11:49,200 how would they behave the voltage would 367 00:11:47,680 --> 00:11:51,279 keep pushing the current 368 00:11:49,200 --> 00:11:52,720 and resistance would create difficulty 369 00:11:51,279 --> 00:11:56,000 for it to pass 370 00:11:52,720 --> 00:11:58,639 isn't it funny so now let's see how 371 00:11:56,000 --> 00:12:00,079 do we use ohm's law to calculate the 372 00:11:58,639 --> 00:12:02,480 unknown values in a circuit 373 00:12:00,079 --> 00:12:03,920 this is a circuit and this is a very 374 00:12:02,480 --> 00:12:07,279 basic circuit right 375 00:12:03,920 --> 00:12:08,240 and here is the resistance of value 600 376 00:12:07,279 --> 00:12:10,399 ohms 377 00:12:08,240 --> 00:12:11,360 and this is the circuit representation 378 00:12:10,399 --> 00:12:14,399 of a resistance 379 00:12:11,360 --> 00:12:16,959 which is a zigzag line right 380 00:12:14,399 --> 00:12:17,760 here we have a battery which measures 12 381 00:12:16,959 --> 00:12:20,320 volts 382 00:12:17,760 --> 00:12:21,440 and this is the connecting wire so can 383 00:12:20,320 --> 00:12:22,959 you figure out 384 00:12:21,440 --> 00:12:25,440 how much current is flowing in the 385 00:12:22,959 --> 00:12:26,480 circuit right now we will use ohm's law 386 00:12:25,440 --> 00:12:29,680 to find out 387 00:12:26,480 --> 00:12:32,160 okay so here what quantity is unknown 388 00:12:29,680 --> 00:12:32,800 i which is current right so we will be 389 00:12:32,160 --> 00:12:36,000 using i 390 00:12:32,800 --> 00:12:40,720 is equal to v by r so we'll do 391 00:12:36,000 --> 00:12:44,399 12 upon 600 which would be 0.02 amperes 392 00:12:40,720 --> 00:12:45,279 okay so now if we change the value of 393 00:12:44,399 --> 00:12:48,320 our resistance 394 00:12:45,279 --> 00:12:52,560 and make it 6 ohms instead of 600 395 00:12:48,320 --> 00:12:55,680 so can you tell me the new value 396 00:12:52,560 --> 00:12:58,160 we just need to do 12 by 6 now 397 00:12:55,680 --> 00:12:59,120 which would turn out to be 2 amperes all 398 00:12:58,160 --> 00:13:01,040 right 399 00:12:59,120 --> 00:13:02,320 so did you observe that if we reduce the 400 00:13:01,040 --> 00:13:03,839 resistance in a circuit 401 00:13:02,320 --> 00:13:06,560 the current flowing in the circuit 402 00:13:03,839 --> 00:13:07,040 increased earlier it was 0.02 amperes 403 00:13:06,560 --> 00:13:10,160 and now 404 00:13:07,040 --> 00:13:13,200 it is 2 amperes right 405 00:13:10,160 --> 00:13:15,920 now if we change the voltage 406 00:13:13,200 --> 00:13:17,839 of the battery as well let's say 24 so 407 00:13:15,920 --> 00:13:20,480 now the current flowing will be 408 00:13:17,839 --> 00:13:22,399 4 amperes right so we increase the 409 00:13:20,480 --> 00:13:23,760 voltage and reduce the resistance 410 00:13:22,399 --> 00:13:26,079 so the overall current flowing in the 411 00:13:23,760 --> 00:13:28,079 circuit was 4 amperes 412 00:13:26,079 --> 00:13:29,760 so i guess you must be able to see the 413 00:13:28,079 --> 00:13:31,279 relation between voltage 414 00:13:29,760 --> 00:13:32,880 resistance and the current flowing in 415 00:13:31,279 --> 00:13:35,440 the circuit one thing you need to learn 416 00:13:32,880 --> 00:13:38,320 about using resistances in a circuit 417 00:13:35,440 --> 00:13:39,519 is that there are multiple ways we can 418 00:13:38,320 --> 00:13:41,279 use resistances 419 00:13:39,519 --> 00:13:42,800 like we can use them in series we can 420 00:13:41,279 --> 00:13:44,639 use them in parallel 421 00:13:42,800 --> 00:13:47,120 so now i will show you how to use 422 00:13:44,639 --> 00:13:49,040 resistances in series and parallel 423 00:13:47,120 --> 00:13:51,199 if i give you a general idea about 424 00:13:49,040 --> 00:13:54,079 resistances in series in parallel 425 00:13:51,199 --> 00:13:56,079 i would say in a series circuit the 426 00:13:54,079 --> 00:13:59,040 output current of the first resistor 427 00:13:56,079 --> 00:14:00,240 flows into the second resistor and into 428 00:13:59,040 --> 00:14:03,120 the third resistor 429 00:14:00,240 --> 00:14:04,800 therefore the current is the same in 430 00:14:03,120 --> 00:14:07,040 each resistor 431 00:14:04,800 --> 00:14:08,320 while in parallel all the resistors are 432 00:14:07,040 --> 00:14:11,360 connected to each other 433 00:14:08,320 --> 00:14:12,079 in a manner shown here right all the 434 00:14:11,360 --> 00:14:14,240 ends 435 00:14:12,079 --> 00:14:15,199 are connected to each other like this so 436 00:14:14,240 --> 00:14:17,519 now we will look at 437 00:14:15,199 --> 00:14:18,320 series circuit in a bit more detail so 438 00:14:17,519 --> 00:14:20,639 if we look at 439 00:14:18,320 --> 00:14:21,519 the circuit here we can see that three 440 00:14:20,639 --> 00:14:24,399 resistances 441 00:14:21,519 --> 00:14:26,959 r1 r2 and r3 are connected in series 442 00:14:24,399 --> 00:14:28,720 across a battery of a certain voltage 443 00:14:26,959 --> 00:14:30,240 okay we don't know what voltage is that 444 00:14:28,720 --> 00:14:33,440 right now but let's say 445 00:14:30,240 --> 00:14:34,079 that voltage is v right so now since 446 00:14:33,440 --> 00:14:35,920 there is just 447 00:14:34,079 --> 00:14:37,199 one path for current to flow in this 448 00:14:35,920 --> 00:14:38,720 circuit the 449 00:14:37,199 --> 00:14:40,959 value of current flowing in the circuit 450 00:14:38,720 --> 00:14:43,839 would be same let's say 451 00:14:40,959 --> 00:14:44,240 it would be equal to i okay so due to 452 00:14:43,839 --> 00:14:46,399 that 453 00:14:44,240 --> 00:14:47,839 in a series circuit the voltage drop 454 00:14:46,399 --> 00:14:49,920 across each resistor 455 00:14:47,839 --> 00:14:50,880 would be different and interestingly the 456 00:14:49,920 --> 00:14:53,360 sum of v1 457 00:14:50,880 --> 00:14:54,240 v2 and v3 that is the voltage across 458 00:14:53,360 --> 00:14:56,639 each resistor 459 00:14:54,240 --> 00:14:57,360 will be equal to the voltage of the 460 00:14:56,639 --> 00:14:59,120 battery 461 00:14:57,360 --> 00:15:01,040 right let's say if the voltage of the 462 00:14:59,120 --> 00:15:03,600 battery is 12 volts okay 463 00:15:01,040 --> 00:15:04,639 so the voltages which we will get across 464 00:15:03,600 --> 00:15:07,279 these resistances 465 00:15:04,639 --> 00:15:08,079 would add up to 12 and from this circuit 466 00:15:07,279 --> 00:15:10,399 we can create 467 00:15:08,079 --> 00:15:12,240 an equivalent circuit like this where 468 00:15:10,399 --> 00:15:13,920 where the equivalent resistance is the 469 00:15:12,240 --> 00:15:15,680 algebraic sum of 470 00:15:13,920 --> 00:15:17,920 all the resistances which we have used 471 00:15:15,680 --> 00:15:19,760 so let us now see an example 472 00:15:17,920 --> 00:15:21,519 where you can apply this learning right 473 00:15:19,760 --> 00:15:24,079 so here we have a circuit 474 00:15:21,519 --> 00:15:24,639 with five resistances connected in 475 00:15:24,079 --> 00:15:26,320 series 476 00:15:24,639 --> 00:15:28,480 and which are connected across a battery 477 00:15:26,320 --> 00:15:30,240 which measures 9 volts 478 00:15:28,480 --> 00:15:31,519 so what we need to do is we need to find 479 00:15:30,240 --> 00:15:33,440 the equivalent resistance 480 00:15:31,519 --> 00:15:34,720 the current flowing in this circuit and 481 00:15:33,440 --> 00:15:37,680 individual voltages 482 00:15:34,720 --> 00:15:39,519 across each resistance right let's have 483 00:15:37,680 --> 00:15:44,240 our diagram handy with ourself 484 00:15:39,519 --> 00:15:44,240 which we use to remember the ohm's law 485 00:15:44,399 --> 00:15:48,160 so let us first calculate the equivalent 486 00:15:47,360 --> 00:15:49,600 resistance 487 00:15:48,160 --> 00:15:51,279 as i told you to calculate the 488 00:15:49,600 --> 00:15:51,920 equivalent resistance in a series 489 00:15:51,279 --> 00:15:53,680 circuit 490 00:15:51,920 --> 00:15:55,279 we just take the algebraic sum of all 491 00:15:53,680 --> 00:15:58,399 the resistances 492 00:15:55,279 --> 00:16:02,240 right so here 493 00:15:58,399 --> 00:16:05,120 it will be 20 plus 20 plus 20 plus 20 494 00:16:02,240 --> 00:16:05,759 and plus 10 which is equal to 90 ohms 495 00:16:05,120 --> 00:16:06,959 right 496 00:16:05,759 --> 00:16:08,720 now since we have this equivalent 497 00:16:06,959 --> 00:16:10,720 resistance to calculate the current 498 00:16:08,720 --> 00:16:14,639 flowing in the circuit we would use 499 00:16:10,720 --> 00:16:17,040 this formula i is equal to v by r right 500 00:16:14,639 --> 00:16:18,000 the only difference is instead of using 501 00:16:17,040 --> 00:16:20,000 r we will use 502 00:16:18,000 --> 00:16:21,600 r equivalent because we will be using 503 00:16:20,000 --> 00:16:24,880 the equivalent resistance in the circuit 504 00:16:21,600 --> 00:16:28,320 right that would be 9 upon 90 which is 505 00:16:24,880 --> 00:16:30,880 0.1 amperes so now we know 506 00:16:28,320 --> 00:16:32,560 that 0.1 amperes is flowing in this 507 00:16:30,880 --> 00:16:34,800 circuit 508 00:16:32,560 --> 00:16:36,079 so to calculate individual voltages 509 00:16:34,800 --> 00:16:38,720 across the resistances 510 00:16:36,079 --> 00:16:40,240 what we can do we'll use the ohm's law 511 00:16:38,720 --> 00:16:42,560 once again 512 00:16:40,240 --> 00:16:44,240 but this time we will use this formula 513 00:16:42,560 --> 00:16:45,120 we need to calculate v is equal to i 514 00:16:44,240 --> 00:16:48,399 into r 515 00:16:45,120 --> 00:16:51,839 so i is 0.1 and r is 20. 516 00:16:48,399 --> 00:16:53,920 so 0.1 into 20 is 2 volts okay 517 00:16:51,839 --> 00:16:55,920 similarly this will also measure 2 volts 518 00:16:53,920 --> 00:16:57,279 this will also measure 2 volts this will 519 00:16:55,920 --> 00:17:00,079 also measure 2 volts 520 00:16:57,279 --> 00:17:00,720 and this one will be 1 volt because 0.1 521 00:17:00,079 --> 00:17:03,759 into 10 522 00:17:00,720 --> 00:17:07,280 is 1 right so now you notice that 523 00:17:03,759 --> 00:17:10,160 2 plus 2 plus 2 plus 2 and plus 1 524 00:17:07,280 --> 00:17:10,480 is equal to 9 right as we saw earlier as 525 00:17:10,160 --> 00:17:12,559 well 526 00:17:10,480 --> 00:17:15,120 all the voltages also add up to the 527 00:17:12,559 --> 00:17:17,360 voltage of the battery which is 9 volt 528 00:17:15,120 --> 00:17:19,039 all right so this is about series 529 00:17:17,360 --> 00:17:21,439 circuit now we will look at 530 00:17:19,039 --> 00:17:23,039 the parallel circuits so the resistors 531 00:17:21,439 --> 00:17:25,199 are in parallel when one end 532 00:17:23,039 --> 00:17:27,120 of all the resistors are connected by a 533 00:17:25,199 --> 00:17:27,919 continuous wire of negligible resistance 534 00:17:27,120 --> 00:17:29,520 and similarly 535 00:17:27,919 --> 00:17:31,760 other ends are also connected to each 536 00:17:29,520 --> 00:17:33,840 other through a similar wire 537 00:17:31,760 --> 00:17:35,039 since all the resistances in parallel 538 00:17:33,840 --> 00:17:37,280 are connected directly 539 00:17:35,039 --> 00:17:38,400 to the battery you can say the voltage 540 00:17:37,280 --> 00:17:40,799 across all of them 541 00:17:38,400 --> 00:17:41,600 is equal right but unlike the resistors 542 00:17:40,799 --> 00:17:43,600 in series 543 00:17:41,600 --> 00:17:45,280 where there is just one path for current 544 00:17:43,600 --> 00:17:46,960 to flow in parallel circuits 545 00:17:45,280 --> 00:17:49,360 there are multiple paths for resistance 546 00:17:46,960 --> 00:17:52,160 to flow like in the circuit you can see 547 00:17:49,360 --> 00:17:53,360 current has two parts if the current 548 00:17:52,160 --> 00:17:54,960 flowing in the circuit is i 549 00:17:53,360 --> 00:17:56,400 then it will divide into two parts let's 550 00:17:54,960 --> 00:17:58,160 say i1 and i2 551 00:17:56,400 --> 00:18:00,320 if there were more resistances we would 552 00:17:58,160 --> 00:18:02,400 say like i3 and i4 etc 553 00:18:00,320 --> 00:18:03,520 and when that current flows it comes 554 00:18:02,400 --> 00:18:06,400 back and 555 00:18:03,520 --> 00:18:08,000 it adds up and becomes i again and if we 556 00:18:06,400 --> 00:18:08,799 wish to calculate the values of i1 and 557 00:18:08,000 --> 00:18:10,960 i2 558 00:18:08,799 --> 00:18:13,120 again we can use the ohm's law here 559 00:18:10,960 --> 00:18:14,880 right because the voltage 560 00:18:13,120 --> 00:18:16,160 across this resistors is equal to the 561 00:18:14,880 --> 00:18:19,440 battery's voltage 562 00:18:16,160 --> 00:18:22,080 and the value of resistor is also known 563 00:18:19,440 --> 00:18:22,960 so we can calculate i using ohm's law 564 00:18:22,080 --> 00:18:25,760 right 565 00:18:22,960 --> 00:18:26,880 you should remember that v1 and v2 will 566 00:18:25,760 --> 00:18:30,400 always be equal to 567 00:18:26,880 --> 00:18:33,440 v and i will be equal to 568 00:18:30,400 --> 00:18:35,840 i1 plus i2 right 569 00:18:33,440 --> 00:18:36,880 now we can also calculate the equivalent 570 00:18:35,840 --> 00:18:39,200 resistance 571 00:18:36,880 --> 00:18:40,240 this combination of resistors will offer 572 00:18:39,200 --> 00:18:42,320 in the circuit 573 00:18:40,240 --> 00:18:44,080 and to do that there is a very simple 574 00:18:42,320 --> 00:18:46,640 formula 575 00:18:44,080 --> 00:18:48,000 one upon req that is equivalent 576 00:18:46,640 --> 00:18:51,679 resistance is equal to 577 00:18:48,000 --> 00:18:54,799 1 by r1 plus 1 by r2 plus 1 by r3 578 00:18:51,679 --> 00:18:55,520 and so on right so let us see one 579 00:18:54,799 --> 00:18:59,120 example 580 00:18:55,520 --> 00:19:01,679 and let us keep that diagram handy again 581 00:18:59,120 --> 00:19:02,880 right so what we need to do in this 582 00:19:01,679 --> 00:19:04,880 question is 583 00:19:02,880 --> 00:19:06,160 we need to find out the current flowing 584 00:19:04,880 --> 00:19:09,280 in this circuit 585 00:19:06,160 --> 00:19:10,880 and the individual current flowing in 586 00:19:09,280 --> 00:19:13,840 these resistances 587 00:19:10,880 --> 00:19:15,600 right so one approach can be we can find 588 00:19:13,840 --> 00:19:17,840 out the equivalent resistance first 589 00:19:15,600 --> 00:19:20,960 using the formula we just saw let us 590 00:19:17,840 --> 00:19:20,960 place the values inside it 591 00:19:21,280 --> 00:19:28,160 right 1 by req is equal to 1 by 1 592 00:19:24,799 --> 00:19:30,240 plus 1 by 2 plus 1 by 2. 593 00:19:28,160 --> 00:19:32,799 we have just replaced these values by 594 00:19:30,240 --> 00:19:36,400 the values of the resistors 595 00:19:32,799 --> 00:19:39,919 right so now we will take lcm 596 00:19:36,400 --> 00:19:42,960 and which turns out to be 4 by 2 597 00:19:39,919 --> 00:19:43,760 but please note that this is 1 by r 598 00:19:42,960 --> 00:19:46,720 equivalent 599 00:19:43,760 --> 00:19:48,640 all right so to calculate r equivalent 600 00:19:46,720 --> 00:19:52,240 we will take the reciprocal of this 601 00:19:48,640 --> 00:19:56,480 value which would turn out to be 602 00:19:52,240 --> 00:19:58,160 0.5 ohms right so now we have 603 00:19:56,480 --> 00:20:00,160 the equivalent resistance of this 604 00:19:58,160 --> 00:20:03,840 circuit we can simply use 605 00:20:00,160 --> 00:20:07,120 the formula i is equal to v by r v is 3 606 00:20:03,840 --> 00:20:10,640 and r is 0.5 607 00:20:07,120 --> 00:20:12,720 so the answer would be 6 amperes right 608 00:20:10,640 --> 00:20:13,760 so 6 amperes will be flowing in this 609 00:20:12,720 --> 00:20:16,080 circuit 610 00:20:13,760 --> 00:20:17,840 now if we want to calculate the 611 00:20:16,080 --> 00:20:20,159 individual currents in these 612 00:20:17,840 --> 00:20:21,039 resistances what we will do is we will 613 00:20:20,159 --> 00:20:24,080 use 614 00:20:21,039 --> 00:20:28,559 this formula again because v is same 615 00:20:24,080 --> 00:20:31,760 and r is known right so in this resistor 616 00:20:28,559 --> 00:20:34,080 v is three and r is one so in this 617 00:20:31,760 --> 00:20:35,840 resistor three amperes will be flowing 618 00:20:34,080 --> 00:20:39,760 in this resistor 619 00:20:35,840 --> 00:20:42,000 three by two that means one point five 620 00:20:39,760 --> 00:20:43,039 would be flowing right and in this 621 00:20:42,000 --> 00:20:45,360 resistance as well 622 00:20:43,039 --> 00:20:46,320 1.5 amperes would be flowing so now if 623 00:20:45,360 --> 00:20:48,240 we add up 624 00:20:46,320 --> 00:20:49,360 all these currents in these three 625 00:20:48,240 --> 00:20:51,440 resistances 626 00:20:49,360 --> 00:20:53,760 that would come out to be six so again 627 00:20:51,440 --> 00:20:55,440 we verified the things we just studied 628 00:20:53,760 --> 00:20:56,799 and i don't know if you noticed or not 629 00:20:55,440 --> 00:20:59,440 the equivalent resistance 630 00:20:56,799 --> 00:21:00,799 of 0.5 was even lesser than the lowest 631 00:20:59,440 --> 00:21:03,600 of the resistance is used 632 00:21:00,799 --> 00:21:04,960 right so this will always be the case 633 00:21:03,600 --> 00:21:07,200 the equivalent resistances 634 00:21:04,960 --> 00:21:08,240 in the parallel circuits will always 635 00:21:07,200 --> 00:21:09,840 come out to be 636 00:21:08,240 --> 00:21:12,320 lesser than the lowest value of the 637 00:21:09,840 --> 00:21:14,960 resistance in those combinations 638 00:21:12,320 --> 00:21:15,600 all right so this was about parallel 639 00:21:14,960 --> 00:21:17,520 circuits 640 00:21:15,600 --> 00:21:18,960 and now we will see a slightly more 641 00:21:17,520 --> 00:21:21,200 complicated circuit 642 00:21:18,960 --> 00:21:22,720 which involves series and parallel 643 00:21:21,200 --> 00:21:25,600 circuits both 644 00:21:22,720 --> 00:21:26,480 so here we have such a circuit where 645 00:21:25,600 --> 00:21:28,720 resistances 646 00:21:26,480 --> 00:21:29,520 are present in series as well and panel 647 00:21:28,720 --> 00:21:31,520 as well 648 00:21:29,520 --> 00:21:32,640 so now i will tell you how to find out 649 00:21:31,520 --> 00:21:35,200 unknown values 650 00:21:32,640 --> 00:21:36,559 in such kind of circuits right so first 651 00:21:35,200 --> 00:21:38,640 of all 652 00:21:36,559 --> 00:21:40,080 we need to work in sections of the 653 00:21:38,640 --> 00:21:42,080 circuit for example 654 00:21:40,080 --> 00:21:43,760 in this circuit i have taken up this 655 00:21:42,080 --> 00:21:44,799 section we can see that these two 656 00:21:43,760 --> 00:21:48,159 resistances 657 00:21:44,799 --> 00:21:48,799 r3 and r4 are in series right so using 658 00:21:48,159 --> 00:21:51,280 our regular 659 00:21:48,799 --> 00:21:53,360 resistances in series formula which is r 660 00:21:51,280 --> 00:21:54,799 equivalent is equal to r1 plus r2 plus 661 00:21:53,360 --> 00:21:57,039 r3 and so on 662 00:21:54,799 --> 00:21:58,480 right so here are two resistances so we 663 00:21:57,039 --> 00:21:59,280 have just taken some of those two 664 00:21:58,480 --> 00:22:02,240 resistances 665 00:21:59,280 --> 00:22:03,120 which is 10 ohm then in our mind we will 666 00:22:02,240 --> 00:22:05,600 think of it as 667 00:22:03,120 --> 00:22:06,559 one single resistor right which is in 668 00:22:05,600 --> 00:22:09,760 parallel with 669 00:22:06,559 --> 00:22:11,440 this resistance right so now we will use 670 00:22:09,760 --> 00:22:14,240 our parallel formula 671 00:22:11,440 --> 00:22:14,799 which is 1 by r equivalent is equal to 1 672 00:22:14,240 --> 00:22:18,080 by 673 00:22:14,799 --> 00:22:20,720 r1 plus 1 by r2 right 674 00:22:18,080 --> 00:22:22,720 so both of the resistances are of 10 675 00:22:20,720 --> 00:22:24,720 ohms so if you plug the values 676 00:22:22,720 --> 00:22:26,559 in this formula you will get 5 ohms you 677 00:22:24,720 --> 00:22:29,120 can try it on your own right 678 00:22:26,559 --> 00:22:30,240 then we will reduce that circuit in our 679 00:22:29,120 --> 00:22:33,600 mind only 680 00:22:30,240 --> 00:22:34,559 with 5 ohms as a resistance then this 681 00:22:33,600 --> 00:22:37,600 equivalent resistance 682 00:22:34,559 --> 00:22:40,080 is in series with 7 ohm resistor right 683 00:22:37,600 --> 00:22:41,520 again we will use our resistance in 684 00:22:40,080 --> 00:22:43,600 series formula 685 00:22:41,520 --> 00:22:45,840 so the equivalent resistance will turn 686 00:22:43,600 --> 00:22:48,559 out to be 12 ohms 687 00:22:45,840 --> 00:22:49,600 so now let's have our ohm's law formula 688 00:22:48,559 --> 00:22:52,559 handy 689 00:22:49,600 --> 00:22:54,400 right so what we can find out now is how 690 00:22:52,559 --> 00:22:56,080 much current is flowing in this circuit 691 00:22:54,400 --> 00:22:58,159 how we can do that we will use this 692 00:22:56,080 --> 00:23:01,360 formula i is equal to v by 693 00:22:58,159 --> 00:23:04,720 r where v is 24 and r is 694 00:23:01,360 --> 00:23:07,360 12 so we will get 2 amperes 695 00:23:04,720 --> 00:23:07,760 right so now if we want to know voltages 696 00:23:07,360 --> 00:23:10,159 across 697 00:23:07,760 --> 00:23:11,440 each resistance and current flowing in 698 00:23:10,159 --> 00:23:14,480 each resistance 699 00:23:11,440 --> 00:23:16,000 we can work our way backwards now right 700 00:23:14,480 --> 00:23:18,159 so we know two amperes is flowing in 701 00:23:16,000 --> 00:23:19,200 this circuit so we can calculate the 702 00:23:18,159 --> 00:23:21,840 voltages across 703 00:23:19,200 --> 00:23:22,480 these two resistances right so first we 704 00:23:21,840 --> 00:23:24,799 will calculate 705 00:23:22,480 --> 00:23:27,039 across 7 ohm resistor so how will we do 706 00:23:24,799 --> 00:23:30,400 that we'll use v is equal to 707 00:23:27,039 --> 00:23:33,440 i into r i is 2 and r is 7 708 00:23:30,400 --> 00:23:37,919 so we will get 14 volts across this 709 00:23:33,440 --> 00:23:42,240 okay and here we will get 710 00:23:37,919 --> 00:23:44,880 2 into 5 10 volts right so you can see 711 00:23:42,240 --> 00:23:47,200 14 plus 10 is 24 we are satisfying the 712 00:23:44,880 --> 00:23:50,000 things which we have studied so far 713 00:23:47,200 --> 00:23:51,600 now we'll move one step back so we knew 714 00:23:50,000 --> 00:23:54,720 voltage across this resistance 715 00:23:51,600 --> 00:23:55,679 was 10 volts right so in this section 716 00:23:54,720 --> 00:23:58,640 also 717 00:23:55,679 --> 00:24:00,400 the voltage will be 10 volts so now 718 00:23:58,640 --> 00:24:02,000 since this is a parallel circuit in both 719 00:24:00,400 --> 00:24:04,640 of the resistances 720 00:24:02,000 --> 00:24:05,279 voltage will be 10 volts so now we can 721 00:24:04,640 --> 00:24:08,159 calculate 722 00:24:05,279 --> 00:24:09,360 current in this right by using this 723 00:24:08,159 --> 00:24:12,559 formula again 724 00:24:09,360 --> 00:24:15,200 right v is 10 and r is also 10 725 00:24:12,559 --> 00:24:16,720 so 1 ampere would be flowing inside it 726 00:24:15,200 --> 00:24:17,679 the answer would be same for this one as 727 00:24:16,720 --> 00:24:20,720 well 728 00:24:17,679 --> 00:24:22,960 right now if we take one step back again 729 00:24:20,720 --> 00:24:24,640 we'll have to calculate voltage across 730 00:24:22,960 --> 00:24:26,559 these two resistances how will we do 731 00:24:24,640 --> 00:24:29,440 that again we'll use this formula 732 00:24:26,559 --> 00:24:30,640 v is equal to i into r so current was 1 733 00:24:29,440 --> 00:24:33,120 ampere in this 734 00:24:30,640 --> 00:24:34,480 so in this as well it will be 1 ampere 735 00:24:33,120 --> 00:24:37,520 so we know 736 00:24:34,480 --> 00:24:41,200 6 into 1 is 6 volts 737 00:24:37,520 --> 00:24:44,080 and across this one we'll have 4 volts 738 00:24:41,200 --> 00:24:45,440 using the same formula right so we have 739 00:24:44,080 --> 00:24:47,679 all the unknown values 740 00:24:45,440 --> 00:24:49,679 right now since there were so many 741 00:24:47,679 --> 00:24:51,279 values i can understand it must be a 742 00:24:49,679 --> 00:24:52,240 little difficult for some of you to 743 00:24:51,279 --> 00:24:54,400 visualize it 744 00:24:52,240 --> 00:24:55,520 so i have created a circuit to help you 745 00:24:54,400 --> 00:24:58,000 visualize a little 746 00:24:55,520 --> 00:24:59,520 right let's have a look at it so here is 747 00:24:58,000 --> 00:25:01,520 that visualization 748 00:24:59,520 --> 00:25:02,799 so you can see exactly similar circuit 749 00:25:01,520 --> 00:25:04,480 which we saw earlier 750 00:25:02,799 --> 00:25:06,559 and i have written all the values of 751 00:25:04,480 --> 00:25:08,720 current flowing in each resistance 752 00:25:06,559 --> 00:25:11,840 and now i will show you the voltages 753 00:25:08,720 --> 00:25:11,840 across each resistance 754 00:25:12,240 --> 00:25:17,760 let's keep this formula handy as always 755 00:25:15,440 --> 00:25:19,679 now i will show you voltage across each 756 00:25:17,760 --> 00:25:22,799 resistance 757 00:25:19,679 --> 00:25:24,159 it is 14 volts across 7 ohms 6 volts 758 00:25:22,799 --> 00:25:26,880 across 6 ohms 759 00:25:24,159 --> 00:25:27,360 4 volts across 4 ohms and 10 volts 760 00:25:26,880 --> 00:25:29,679 across 761 00:25:27,360 --> 00:25:30,480 10 ohms right so if you have understood 762 00:25:29,679 --> 00:25:32,960 this part 763 00:25:30,480 --> 00:25:34,240 i can say you have understood really 764 00:25:32,960 --> 00:25:36,320 important fundamental 765 00:25:34,240 --> 00:25:37,520 about using resistances in series and 766 00:25:36,320 --> 00:25:40,000 parallel but 767 00:25:37,520 --> 00:25:40,799 you may also find circuits like this 768 00:25:40,000 --> 00:25:43,360 okay 769 00:25:40,799 --> 00:25:44,320 where we have two batteries right in 770 00:25:43,360 --> 00:25:46,159 circuits like these 771 00:25:44,320 --> 00:25:47,679 you cannot simplify the circuits which 772 00:25:46,159 --> 00:25:49,440 we have seen so far 773 00:25:47,679 --> 00:25:50,880 so there are some advanced concepts such 774 00:25:49,440 --> 00:25:52,880 as kirchhoff's law 775 00:25:50,880 --> 00:25:54,640 okay which is used to calculate the 776 00:25:52,880 --> 00:25:56,480 unknown values in the circuit 777 00:25:54,640 --> 00:25:58,159 but that will go beyond the scope of our 778 00:25:56,480 --> 00:26:00,240 course right now so one last thing about 779 00:25:58,159 --> 00:26:02,240 resistances i want to tell you is 780 00:26:00,240 --> 00:26:04,320 identifying the resistance is based on 781 00:26:02,240 --> 00:26:06,320 the color bands 782 00:26:04,320 --> 00:26:07,520 let's have a look at that now 783 00:26:06,320 --> 00:26:09,919 resistances 784 00:26:07,520 --> 00:26:11,760 come with the four or five color bands 785 00:26:09,919 --> 00:26:15,039 denoting the value of resistance 786 00:26:11,760 --> 00:26:15,039 it will offer in the circuit 787 00:26:15,919 --> 00:26:19,760 so you see in this diagram there are 788 00:26:18,880 --> 00:26:21,600 four band 789 00:26:19,760 --> 00:26:22,880 resistors and there are five band 790 00:26:21,600 --> 00:26:25,840 resistors 791 00:26:22,880 --> 00:26:28,080 okay in a four band register the first 792 00:26:25,840 --> 00:26:29,919 band will tell you the first digit 793 00:26:28,080 --> 00:26:31,279 the second band will tell you the second 794 00:26:29,919 --> 00:26:33,120 digit 795 00:26:31,279 --> 00:26:35,440 the third band will tell you the number 796 00:26:33,120 --> 00:26:36,880 of zeros which you need to put after the 797 00:26:35,440 --> 00:26:38,880 first two digits 798 00:26:36,880 --> 00:26:39,919 and the fourth band tells the error 799 00:26:38,880 --> 00:26:42,320 percentage 800 00:26:39,919 --> 00:26:43,279 means it can be that much percentage 801 00:26:42,320 --> 00:26:46,559 above or below 802 00:26:43,279 --> 00:26:47,440 the stated value now see the first band 803 00:26:46,559 --> 00:26:50,640 in this case 804 00:26:47,440 --> 00:26:53,520 is yellow so it the first digit will be 805 00:26:50,640 --> 00:26:54,799 four the second band is violet so the 806 00:26:53,520 --> 00:26:57,840 second digit will be 807 00:26:54,799 --> 00:27:00,640 seven the third band is origin color 808 00:26:57,840 --> 00:27:02,480 so the multiplier will be one thousand 809 00:27:00,640 --> 00:27:05,440 so we get the value of 810 00:27:02,480 --> 00:27:06,480 forty seven thousand and the fourth band 811 00:27:05,440 --> 00:27:09,200 is 812 00:27:06,480 --> 00:27:10,559 gold so that means it will have a 813 00:27:09,200 --> 00:27:13,039 tolerance of plus minus 814 00:27:10,559 --> 00:27:13,840 five percent so the net value of this 815 00:27:13,039 --> 00:27:17,120 resistance is 816 00:27:13,840 --> 00:27:20,080 47 000 ohms 817 00:27:17,120 --> 00:27:21,600 or you can say 47 kilo ohms with the 818 00:27:20,080 --> 00:27:24,720 tolerance of five percent 819 00:27:21,600 --> 00:27:26,720 now we see the five band code okay 820 00:27:24,720 --> 00:27:28,480 the first band tells the first digit the 821 00:27:26,720 --> 00:27:30,640 second man tells you the second digit 822 00:27:28,480 --> 00:27:32,159 the third bank tells you the third digit 823 00:27:30,640 --> 00:27:32,640 fourth band tells you the multiplier 824 00:27:32,159 --> 00:27:35,200 here 825 00:27:32,640 --> 00:27:37,039 and first bank tells you the tolerance 826 00:27:35,200 --> 00:27:38,880 we'll consider this example 827 00:27:37,039 --> 00:27:40,480 first band is orange and color so the 828 00:27:38,880 --> 00:27:43,679 first digit will be three 829 00:27:40,480 --> 00:27:44,320 second band is green so the value will 830 00:27:43,679 --> 00:27:49,440 be 831 00:27:44,320 --> 00:27:52,960 five the third band is black in color 832 00:27:49,440 --> 00:27:55,760 so the third value will be zero 833 00:27:52,960 --> 00:27:56,240 and fourth band is red so the multiplier 834 00:27:55,760 --> 00:28:00,240 will be 835 00:27:56,240 --> 00:28:03,840 hundred till now we get three five zero 836 00:28:00,240 --> 00:28:06,960 and double zero so this is 35 000 837 00:28:03,840 --> 00:28:09,360 and the last band is brown in color so 838 00:28:06,960 --> 00:28:10,320 one percent of tolerance so the net 839 00:28:09,360 --> 00:28:13,120 answer will be 840 00:28:10,320 --> 00:28:15,120 35 kilo ohms with a tolerance of one 841 00:28:13,120 --> 00:28:16,880 percent 842 00:28:15,120 --> 00:28:18,080 you can refer to this chart whenever you 843 00:28:16,880 --> 00:28:19,360 need to find the value of your 844 00:28:18,080 --> 00:28:21,919 resistances 845 00:28:19,360 --> 00:28:23,840 and i understand this might be confusing 846 00:28:21,919 --> 00:28:26,480 at first but with practice 847 00:28:23,840 --> 00:28:27,279 you can understand this very easily in 848 00:28:26,480 --> 00:28:29,440 this section 849 00:28:27,279 --> 00:28:31,440 we will finally take a look at the main 850 00:28:29,440 --> 00:28:33,600 thing most of you must be already 851 00:28:31,440 --> 00:28:35,279 waiting for this section to come up 852 00:28:33,600 --> 00:28:38,240 so this blue colored thing which is 853 00:28:35,279 --> 00:28:40,799 present in your kit is the arduino board 854 00:28:38,240 --> 00:28:41,440 i will tell you what is it what it can 855 00:28:40,799 --> 00:28:44,880 do 856 00:28:41,440 --> 00:28:46,480 and how to start using it finally 857 00:28:44,880 --> 00:28:48,399 but before that i would like to tell you 858 00:28:46,480 --> 00:28:50,399 about some terms which you may 859 00:28:48,399 --> 00:28:51,679 or may not have heard about before 860 00:28:50,399 --> 00:28:53,600 starting this course 861 00:28:51,679 --> 00:28:54,880 so these terms are microprocessor 862 00:28:53,600 --> 00:28:59,440 microcontroller 863 00:28:54,880 --> 00:29:01,760 memory integrated circuits etc 864 00:28:59,440 --> 00:29:02,880 microprocessors are known as a brain of 865 00:29:01,760 --> 00:29:05,520 any computer 866 00:29:02,880 --> 00:29:07,039 they consist of a cpu which stands for 867 00:29:05,520 --> 00:29:08,799 central processing unit 868 00:29:07,039 --> 00:29:10,559 which is responsible for doing all the 869 00:29:08,799 --> 00:29:12,000 computations and calculations which we 870 00:29:10,559 --> 00:29:13,840 need to carry out 871 00:29:12,000 --> 00:29:16,240 they need additional peripherals like 872 00:29:13,840 --> 00:29:19,200 ram and rom in order to function 873 00:29:16,240 --> 00:29:20,799 example of a microprocessor is the cpu 874 00:29:19,200 --> 00:29:22,159 which is being used in your computer 875 00:29:20,799 --> 00:29:23,760 right now 876 00:29:22,159 --> 00:29:25,440 if you go and check the history of 877 00:29:23,760 --> 00:29:27,679 microprocessors you will see the 878 00:29:25,440 --> 00:29:29,039 microprocessors have come a long way 879 00:29:27,679 --> 00:29:31,200 after so many improvements in 880 00:29:29,039 --> 00:29:33,760 developments microprocessors 881 00:29:31,200 --> 00:29:35,600 and graphic processors are used where 882 00:29:33,760 --> 00:29:36,240 there is a need of heavy computational 883 00:29:35,600 --> 00:29:38,080 cycles 884 00:29:36,240 --> 00:29:39,760 like artificial intelligence deep 885 00:29:38,080 --> 00:29:42,240 learning self-driving cars 886 00:29:39,760 --> 00:29:44,000 and high-end robots our daily 887 00:29:42,240 --> 00:29:46,399 applications like playing games 888 00:29:44,000 --> 00:29:49,440 movies browsing internet also requires 889 00:29:46,399 --> 00:29:49,440 our microprocessors 890 00:29:49,600 --> 00:29:54,240 and then there are microcontrollers 891 00:29:52,159 --> 00:29:56,240 microcontrollers are integrated chips 892 00:29:54,240 --> 00:29:58,159 that are basically tiny computers but 893 00:29:56,240 --> 00:29:58,720 are powerful enough to do a lot many 894 00:29:58,159 --> 00:30:01,200 tasks 895 00:29:58,720 --> 00:30:03,200 like controlling motors pumps other 896 00:30:01,200 --> 00:30:05,279 appliances or they can send some sensor 897 00:30:03,200 --> 00:30:07,520 data to internet cloud 898 00:30:05,279 --> 00:30:10,159 control basic displays and even act as 899 00:30:07,520 --> 00:30:12,880 brains of some intermediate level robots 900 00:30:10,159 --> 00:30:14,559 applications are endless trust me the 901 00:30:12,880 --> 00:30:15,919 power requirements of such integrated 902 00:30:14,559 --> 00:30:18,080 chips is very low 903 00:30:15,919 --> 00:30:19,120 and you can even run these chips on 904 00:30:18,080 --> 00:30:22,159 batteries 905 00:30:19,120 --> 00:30:24,080 for days or even months they have all 906 00:30:22,159 --> 00:30:24,559 the peripherals like memory and flash 907 00:30:24,080 --> 00:30:25,740 storage 908 00:30:24,559 --> 00:30:28,159 built on the same chip 909 00:30:25,740 --> 00:30:30,080 [Music] 910 00:30:28,159 --> 00:30:31,200 if we compare microcontroller and 911 00:30:30,080 --> 00:30:33,600 microprocessor 912 00:30:31,200 --> 00:30:35,919 in terms of cost a microcontroller is 913 00:30:33,600 --> 00:30:36,960 far cheaper than a microprocessor 914 00:30:35,919 --> 00:30:38,720 however 915 00:30:36,960 --> 00:30:40,000 microcontroller cannot be used in place 916 00:30:38,720 --> 00:30:42,000 of a microprocessor 917 00:30:40,000 --> 00:30:44,159 and using a microprocessor is not 918 00:30:42,000 --> 00:30:48,399 advised in place of a microcontroller 919 00:30:44,159 --> 00:30:50,640 as it makes the application quite costly 920 00:30:48,399 --> 00:30:52,399 if we compare them in terms of speed if 921 00:30:50,640 --> 00:30:54,080 we say human brain is fast 922 00:30:52,399 --> 00:30:56,399 then microcontroller is faster and 923 00:30:54,080 --> 00:30:58,159 microprocessor is fastest 924 00:30:56,399 --> 00:31:00,240 but please note we are talking in a very 925 00:30:58,159 --> 00:31:02,000 general way this won't be applicable if 926 00:31:00,240 --> 00:31:03,279 you compare an old generation thing with 927 00:31:02,000 --> 00:31:05,519 a new generation thing 928 00:31:03,279 --> 00:31:06,799 as technology advances it won't make any 929 00:31:05,519 --> 00:31:09,120 sense to compare 930 00:31:06,799 --> 00:31:11,600 and also some exceptions are always 931 00:31:09,120 --> 00:31:13,810 there it is really possible that you 932 00:31:11,600 --> 00:31:15,840 or any human may be faster 933 00:31:13,810 --> 00:31:17,440 [Music] 934 00:31:15,840 --> 00:31:21,200 so do you have any guesses in which 935 00:31:17,440 --> 00:31:21,200 category or arduino board will fall 936 00:31:21,760 --> 00:31:25,919 if you said microcontroller then you are 937 00:31:24,240 --> 00:31:27,919 partially right 938 00:31:25,919 --> 00:31:29,360 an absolutely correct answer is that 939 00:31:27,919 --> 00:31:31,519 arduino is a circuit board 940 00:31:29,360 --> 00:31:35,120 which has a microcontroller on it which 941 00:31:31,519 --> 00:31:37,120 act as the heart of that board 942 00:31:35,120 --> 00:31:38,880 the arduino board given to you in your 943 00:31:37,120 --> 00:31:42,399 kit is arduino uno 944 00:31:38,880 --> 00:31:44,240 which uses microcontroller atmega328 945 00:31:42,399 --> 00:31:45,440 there are many more kinds of arduino 946 00:31:44,240 --> 00:31:46,799 boards available with other 947 00:31:45,440 --> 00:31:48,760 microcontrollers 948 00:31:46,799 --> 00:31:50,080 which may be superior or inferior to 949 00:31:48,760 --> 00:31:52,159 atmega328 950 00:31:50,080 --> 00:31:53,440 but arduino uno is just right for our 951 00:31:52,159 --> 00:31:55,360 applications 952 00:31:53,440 --> 00:31:56,720 you may want to pause the video here to 953 00:31:55,360 --> 00:31:59,039 have a look at all these 954 00:31:56,720 --> 00:32:01,840 boards and admire how beautifully they 955 00:31:59,039 --> 00:32:01,840 are made 956 00:32:04,159 --> 00:32:08,480 so arduino is basically a company in 957 00:32:06,640 --> 00:32:10,399 italy which made it really easy for 958 00:32:08,480 --> 00:32:12,880 people to use microcontrollers for their 959 00:32:10,399 --> 00:32:12,880 application 960 00:32:13,279 --> 00:32:16,799 the hardware and software of arduino is 961 00:32:15,360 --> 00:32:18,799 open source which means 962 00:32:16,799 --> 00:32:21,360 one can have access to the files and 963 00:32:18,799 --> 00:32:23,039 even modify them for their own work 964 00:32:21,360 --> 00:32:24,799 since it is open source many other 965 00:32:23,039 --> 00:32:26,399 companies take their design and 966 00:32:24,799 --> 00:32:27,039 manufacture their own versions of 967 00:32:26,399 --> 00:32:29,440 arduino 968 00:32:27,039 --> 00:32:30,680 so it is really easy to clone and modify 969 00:32:29,440 --> 00:32:32,399 the arduino board 970 00:32:30,680 --> 00:32:34,559 [Music] 971 00:32:32,399 --> 00:32:36,399 what makes arduino a beginner-friendly 972 00:32:34,559 --> 00:32:39,840 tool is their easy to use 973 00:32:36,399 --> 00:32:40,799 hardware and software it can be used 974 00:32:39,840 --> 00:32:44,080 even by people 975 00:32:40,799 --> 00:32:46,080 having no technical background 976 00:32:44,080 --> 00:32:47,919 earlier people would have to use very 977 00:32:46,080 --> 00:32:49,039 difficult assembly language to control 978 00:32:47,919 --> 00:32:52,159 their votes 979 00:32:49,039 --> 00:32:53,840 but it is not the case with arduino 980 00:32:52,159 --> 00:32:56,080 as you progress with the course you will 981 00:32:53,840 --> 00:32:58,159 see yourself with how easy and intuitive 982 00:32:56,080 --> 00:33:00,559 this tool is 983 00:32:58,159 --> 00:33:02,960 you will see that uploading the code is 984 00:33:00,559 --> 00:33:04,559 as simple as plugging a usb cable and 985 00:33:02,960 --> 00:33:06,720 clicking upload button 986 00:33:04,559 --> 00:33:10,640 in this video we will see the parts 987 00:33:06,720 --> 00:33:12,640 which make up the arduino board 988 00:33:10,640 --> 00:33:14,640 so this is the diagram of arduino board 989 00:33:12,640 --> 00:33:16,159 which shows the typical components which 990 00:33:14,640 --> 00:33:19,039 are placed on it 991 00:33:16,159 --> 00:33:20,159 so we will begin by the digital pins the 992 00:33:19,039 --> 00:33:23,200 pins which you see 993 00:33:20,159 --> 00:33:26,159 here which are numbered 0 to 13 994 00:33:23,200 --> 00:33:26,559 and some pins have a special symbol like 995 00:33:26,159 --> 00:33:28,399 this 996 00:33:26,559 --> 00:33:30,480 curvy symbol on in front of it which 997 00:33:28,399 --> 00:33:33,200 denotes pwm capability 998 00:33:30,480 --> 00:33:33,760 that means these pins support pwm other 999 00:33:33,200 --> 00:33:36,480 than that 1000 00:33:33,760 --> 00:33:38,320 these pins take digital input from 1001 00:33:36,480 --> 00:33:41,760 sensors and give digital output 1002 00:33:38,320 --> 00:33:44,880 to some of the components all right so 1003 00:33:41,760 --> 00:33:48,159 then we move to the built-in led 1004 00:33:44,880 --> 00:33:50,559 which is shown by this led 1005 00:33:48,159 --> 00:33:53,200 this led by default is connected to pin 1006 00:33:50,559 --> 00:33:54,159 number 13. so whenever pin number 13 1007 00:33:53,200 --> 00:33:56,640 goes high 1008 00:33:54,159 --> 00:33:57,440 this led will turn on and when that pin 1009 00:33:56,640 --> 00:34:01,600 goes low 1010 00:33:57,440 --> 00:34:04,559 this led will turn off and then 1011 00:34:01,600 --> 00:34:05,679 we will see the power led this is the 1012 00:34:04,559 --> 00:34:08,320 power led 1013 00:34:05,679 --> 00:34:09,760 if this led is turned on that means your 1014 00:34:08,320 --> 00:34:12,960 arduino is plugged in 1015 00:34:09,760 --> 00:34:13,599 that means it's turned on right now then 1016 00:34:12,960 --> 00:34:17,200 we have 1017 00:34:13,599 --> 00:34:19,919 the main component the atmega328 chip 1018 00:34:17,200 --> 00:34:20,720 it controls all the main functions of 1019 00:34:19,919 --> 00:34:23,760 this board 1020 00:34:20,720 --> 00:34:24,639 whatever is happening on this board is 1021 00:34:23,760 --> 00:34:27,839 due to 1022 00:34:24,639 --> 00:34:30,800 this ship then we have 1023 00:34:27,839 --> 00:34:31,599 analog pins we have six analog pins on 1024 00:34:30,800 --> 00:34:34,639 this board 1025 00:34:31,599 --> 00:34:36,560 numbered from a0 to a5 1026 00:34:34,639 --> 00:34:38,639 we can connect any analog sensor on 1027 00:34:36,560 --> 00:34:41,200 these pins 1028 00:34:38,639 --> 00:34:42,960 then we have the power pins these are 1029 00:34:41,200 --> 00:34:46,639 the power pins 1030 00:34:42,960 --> 00:34:49,599 you can power any component using these 1031 00:34:46,639 --> 00:34:50,960 pins but make sure that you don't your 1032 00:34:49,599 --> 00:34:51,599 components are not drawing a lot of 1033 00:34:50,960 --> 00:34:53,760 current 1034 00:34:51,599 --> 00:34:54,879 basic sensors and basic you know 1035 00:34:53,760 --> 00:34:58,800 breadboard circuits 1036 00:34:54,879 --> 00:34:58,800 are fine with these pins 1037 00:34:59,520 --> 00:35:03,280 then we see the power dc jack if you 1038 00:35:02,560 --> 00:35:05,119 want to connect 1039 00:35:03,280 --> 00:35:07,200 your arduino externally through a dc 1040 00:35:05,119 --> 00:35:09,680 jack you can connect it 1041 00:35:07,200 --> 00:35:11,599 through this jack the voltage input it 1042 00:35:09,680 --> 00:35:16,160 can accept is 7 volts to 1043 00:35:11,599 --> 00:35:18,800 12 volts then we have tx and rx leds 1044 00:35:16,160 --> 00:35:20,560 these are the tx and rx leds rx means 1045 00:35:18,800 --> 00:35:23,359 receive tx means send 1046 00:35:20,560 --> 00:35:24,480 transmit okay so whenever these leds are 1047 00:35:23,359 --> 00:35:26,800 blinking that means 1048 00:35:24,480 --> 00:35:27,839 cardinal board is either communicating 1049 00:35:26,800 --> 00:35:31,359 with the computer 1050 00:35:27,839 --> 00:35:34,079 or some other another arduino board 1051 00:35:31,359 --> 00:35:35,760 then we have the usb jack you connect 1052 00:35:34,079 --> 00:35:38,640 your arduino board with your computer 1053 00:35:35,760 --> 00:35:38,640 using this jack 1054 00:35:39,200 --> 00:35:44,320 then we have the reset button this 1055 00:35:41,200 --> 00:35:45,520 button reloads the entire code which is 1056 00:35:44,320 --> 00:35:47,520 running on the 1057 00:35:45,520 --> 00:35:48,560 arduino board but please note that this 1058 00:35:47,520 --> 00:35:52,000 button does not 1059 00:35:48,560 --> 00:35:52,000 clears the memory of arduino 1060 00:35:52,560 --> 00:35:56,160 here are few technical specifications of 1061 00:35:54,800 --> 00:35:58,400 arduino uno 1062 00:35:56,160 --> 00:35:59,680 by technical specifications i mean the 1063 00:35:58,400 --> 00:36:02,480 information which you look 1064 00:35:59,680 --> 00:36:04,160 while buying any item or a computer like 1065 00:36:02,480 --> 00:36:04,960 in a computer you see how much disk 1066 00:36:04,160 --> 00:36:06,960 space is there 1067 00:36:04,960 --> 00:36:08,800 how much ram does it have or processor 1068 00:36:06,960 --> 00:36:10,640 it has similarly 1069 00:36:08,800 --> 00:36:12,960 arduino being a microcontroller board 1070 00:36:10,640 --> 00:36:17,040 has some technical specifications 1071 00:36:12,960 --> 00:36:20,480 like it has atmega328 as the main chip 1072 00:36:17,040 --> 00:36:21,280 which does all the work it operates at 5 1073 00:36:20,480 --> 00:36:23,760 volts 1074 00:36:21,280 --> 00:36:26,400 the input voltage which it can accept is 1075 00:36:23,760 --> 00:36:28,400 5 to 12 volts 1076 00:36:26,400 --> 00:36:29,520 although according to the data sheet of 1077 00:36:28,400 --> 00:36:32,320 arduino 1078 00:36:29,520 --> 00:36:33,359 the recommended voltage is 7 to 12 volts 1079 00:36:32,320 --> 00:36:36,960 and the limits 1080 00:36:33,359 --> 00:36:39,440 are 6 to 20 volts so i recommend that 1081 00:36:36,960 --> 00:36:40,000 5 to 12 volts is a good enough voltage 1082 00:36:39,440 --> 00:36:43,040 to operate 1083 00:36:40,000 --> 00:36:46,079 arduino with and then there are 1084 00:36:43,040 --> 00:36:47,040 14 digital pins out of which six are pwm 1085 00:36:46,079 --> 00:36:49,520 capable 1086 00:36:47,040 --> 00:36:52,839 don't worry about pwm right now but just 1087 00:36:49,520 --> 00:36:54,000 think having pwm capability is a good 1088 00:36:52,839 --> 00:36:56,240 thing 1089 00:36:54,000 --> 00:36:58,160 then there are six analog pins which are 1090 00:36:56,240 --> 00:36:59,119 used to connect analog sensors to the 1091 00:36:58,160 --> 00:37:01,680 arduino 1092 00:36:59,119 --> 00:37:03,200 you can understand that these pins are 1093 00:37:01,680 --> 00:37:06,640 connected to arduino 1094 00:37:03,200 --> 00:37:08,480 through a 10 bit adc an adc is 1095 00:37:06,640 --> 00:37:10,240 an analog to digital converter we'll 1096 00:37:08,480 --> 00:37:13,359 talk about adc 1097 00:37:10,240 --> 00:37:13,359 in further lectures 1098 00:37:13,839 --> 00:37:17,839 the i o pins are capable of supplying 40 1099 00:37:16,400 --> 00:37:20,160 milliamperes of current 1100 00:37:17,839 --> 00:37:22,000 so these pins cannot drive large 1101 00:37:20,160 --> 00:37:24,400 appliances or the things which require 1102 00:37:22,000 --> 00:37:25,440 more current like motors and it is not 1103 00:37:24,400 --> 00:37:28,079 even recommended 1104 00:37:25,440 --> 00:37:30,400 that you run motors through arduino but 1105 00:37:28,079 --> 00:37:32,000 few leds and most sensors which we use 1106 00:37:30,400 --> 00:37:33,040 in this course do not draw very large 1107 00:37:32,000 --> 00:37:36,960 amount of current 1108 00:37:33,040 --> 00:37:39,839 so these pins are just fine 1109 00:37:36,960 --> 00:37:41,920 there is a 3.3 volt pin as well and the 1110 00:37:39,839 --> 00:37:45,040 maximum current you can draw from it is 1111 00:37:41,920 --> 00:37:45,040 50 milliamperes 1112 00:37:46,480 --> 00:37:50,720 and there is a flash memory of 32 kb 1113 00:37:49,359 --> 00:37:54,079 which we use 1114 00:37:50,720 --> 00:37:56,400 to store all the programs into it 32 kb 1115 00:37:54,079 --> 00:37:59,599 must be seeming like a very less amount 1116 00:37:56,400 --> 00:38:03,040 but trust me you can store lines 1117 00:37:59,599 --> 00:38:05,359 of 1000 even 2000 lines of code in this 1118 00:38:03,040 --> 00:38:06,240 and it won't even exceed 10 percent of 1119 00:38:05,359 --> 00:38:09,520 the storage 1120 00:38:06,240 --> 00:38:10,560 then it have sram of 2kb which is a 1121 00:38:09,520 --> 00:38:12,560 volatile memory 1122 00:38:10,560 --> 00:38:13,920 or more generally it is similar to ram 1123 00:38:12,560 --> 00:38:16,480 on your computer 1124 00:38:13,920 --> 00:38:17,599 again it would seem too less and i would 1125 00:38:16,480 --> 00:38:20,000 repeat 1126 00:38:17,599 --> 00:38:21,520 what i said for the flash memory that it 1127 00:38:20,000 --> 00:38:24,880 is more than enough 1128 00:38:21,520 --> 00:38:25,359 it also has 1 kb of eep rom which can 1129 00:38:24,880 --> 00:38:27,359 store 1130 00:38:25,359 --> 00:38:28,480 some variables even after you switch off 1131 00:38:27,359 --> 00:38:31,119 the arduino 1132 00:38:28,480 --> 00:38:32,560 clock speed is 16 megahertz clock speed 1133 00:38:31,119 --> 00:38:34,560 is the speed that microprocessor 1134 00:38:32,560 --> 00:38:36,560 executes each instruction 1135 00:38:34,560 --> 00:38:38,720 one megahertz representing one million 1136 00:38:36,560 --> 00:38:40,560 cycles per second 1137 00:38:38,720 --> 00:38:42,320 i understand a lot of information in 1138 00:38:40,560 --> 00:38:43,040 this video might have just bounced over 1139 00:38:42,320 --> 00:38:44,720 your head 1140 00:38:43,040 --> 00:38:46,400 and it's perfectly okay if you don't 1141 00:38:44,720 --> 00:38:48,160 understand some portion of it 1142 00:38:46,400 --> 00:38:50,480 i would just say don't lose your 1143 00:38:48,160 --> 00:38:52,560 motivation and just stick with us 1144 00:38:50,480 --> 00:38:53,680 and i promise you you will understand 1145 00:38:52,560 --> 00:38:56,079 each and every part 1146 00:38:53,680 --> 00:38:58,960 of it by the end of the course if not we 1147 00:38:56,079 --> 00:39:01,119 are always here for help 1148 00:38:58,960 --> 00:39:02,640 in this section i will tell you about 1149 00:39:01,119 --> 00:39:04,800 arduino ide 1150 00:39:02,640 --> 00:39:06,960 but before we jump into that first of 1151 00:39:04,800 --> 00:39:10,640 all we need to understand what an ide 1152 00:39:06,960 --> 00:39:12,400 is a text editor like a notepad 1153 00:39:10,640 --> 00:39:14,000 along with the compiler is a bare 1154 00:39:12,400 --> 00:39:17,839 minimum requirement to start 1155 00:39:14,000 --> 00:39:19,839 coding but wait what is a compiler 1156 00:39:17,839 --> 00:39:21,440 compiler is a special program that 1157 00:39:19,839 --> 00:39:22,720 processes statements written in a 1158 00:39:21,440 --> 00:39:24,640 programming language 1159 00:39:22,720 --> 00:39:26,480 and turns them into a machine language 1160 00:39:24,640 --> 00:39:28,400 which are basically zeros and ones which 1161 00:39:26,480 --> 00:39:31,119 a computer can understand 1162 00:39:28,400 --> 00:39:32,800 but unlike text editor an ide which 1163 00:39:31,119 --> 00:39:33,599 stands for integrated development 1164 00:39:32,800 --> 00:39:35,440 environment 1165 00:39:33,599 --> 00:39:37,599 is a software tool which has a lot more 1166 00:39:35,440 --> 00:39:38,800 functionality to make programming easier 1167 00:39:37,599 --> 00:39:40,640 for the user 1168 00:39:38,800 --> 00:39:43,200 it has a built-in text editor and 1169 00:39:40,640 --> 00:39:46,240 compiler along with easy to use tools 1170 00:39:43,200 --> 00:39:50,320 menus and buttons to compile 1171 00:39:46,240 --> 00:39:53,359 run debug analyze 1172 00:39:50,320 --> 00:39:55,839 and save the programs 1173 00:39:53,359 --> 00:39:56,960 considering arduino they also have one 1174 00:39:55,839 --> 00:39:59,040 official ide 1175 00:39:56,960 --> 00:40:00,800 which has buttons to verify and upload 1176 00:39:59,040 --> 00:40:03,280 the sketches they also have 1177 00:40:00,800 --> 00:40:03,839 easy to use menus to select boards and 1178 00:40:03,280 --> 00:40:05,520 ports 1179 00:40:03,839 --> 00:40:07,200 throughout the course we will be using 1180 00:40:05,520 --> 00:40:09,839 the official arduino ide 1181 00:40:07,200 --> 00:40:11,440 and for that in the following sections 1182 00:40:09,839 --> 00:40:15,680 we will be downloading 1183 00:40:11,440 --> 00:40:15,680 and installing the official arduino ide 1184 00:40:16,240 --> 00:40:19,839 now i will tell you how to install the 1185 00:40:18,400 --> 00:40:22,880 official ide 1186 00:40:19,839 --> 00:40:26,560 for that go to any browser and go to 1187 00:40:22,880 --> 00:40:28,480 arduino dot cc then click on software 1188 00:40:26,560 --> 00:40:30,800 tab 1189 00:40:28,480 --> 00:40:34,319 you will find many options here we will 1190 00:40:30,800 --> 00:40:34,319 go with the windows installer 1191 00:40:34,800 --> 00:40:38,480 click on just download if you don't wish 1192 00:40:36,800 --> 00:40:40,880 to donate anything 1193 00:40:38,480 --> 00:40:44,560 donations like these help open source 1194 00:40:40,880 --> 00:40:44,560 communities to fund themselves 1195 00:40:44,720 --> 00:40:47,920 once the download completes 1196 00:40:48,640 --> 00:40:52,079 we will click on it and when the 1197 00:40:50,960 --> 00:40:54,480 installation starts 1198 00:40:52,079 --> 00:40:55,359 click on i agree make sure that all 1199 00:40:54,480 --> 00:40:57,839 these boxes 1200 00:40:55,359 --> 00:40:59,200 are checked these are the essential 1201 00:40:57,839 --> 00:41:01,200 drivers which are required 1202 00:40:59,200 --> 00:41:02,240 for your computer to detect and 1203 00:41:01,200 --> 00:41:07,119 communicate with the 1204 00:41:02,240 --> 00:41:08,800 arduino board right we'll click on next 1205 00:41:07,119 --> 00:41:11,920 then we will choose the destination 1206 00:41:08,800 --> 00:41:15,119 folder i will go with the default one 1207 00:41:11,920 --> 00:41:15,119 and click on install 1208 00:41:15,599 --> 00:41:19,440 this process may take some time let's 1209 00:41:18,560 --> 00:41:21,839 wait for it 1210 00:41:19,440 --> 00:41:21,839 to finish 1211 00:41:26,319 --> 00:41:31,200 in my screen it says completed but some 1212 00:41:29,520 --> 00:41:32,720 people may get additional prompts to 1213 00:41:31,200 --> 00:41:34,319 install those additional drivers 1214 00:41:32,720 --> 00:41:36,400 all you need to do is just click on 1215 00:41:34,319 --> 00:41:39,520 install on them as well 1216 00:41:36,400 --> 00:41:41,680 and then once it is completed for you 1217 00:41:39,520 --> 00:41:42,880 click on close and then you will find 1218 00:41:41,680 --> 00:41:45,119 the arduino icon 1219 00:41:42,880 --> 00:41:47,599 on your desktop then you just double 1220 00:41:45,119 --> 00:41:49,680 click on it 1221 00:41:47,599 --> 00:41:50,720 and here is your fully functional 1222 00:41:49,680 --> 00:41:53,119 arduino ide 1223 00:41:50,720 --> 00:41:55,200 window so now we will set up our 1224 00:41:53,119 --> 00:41:56,240 computer for uploading our first basic 1225 00:41:55,200 --> 00:41:57,839 sketch 1226 00:41:56,240 --> 00:42:00,079 there is nothing complicated we need to 1227 00:41:57,839 --> 00:42:02,319 do the first step is 1228 00:42:00,079 --> 00:42:04,640 we need to plug in an arduino board with 1229 00:42:02,319 --> 00:42:06,800 the usb cable given 1230 00:42:04,640 --> 00:42:08,400 in the box and once you do that your 1231 00:42:06,800 --> 00:42:10,000 computer will automatically detect that 1232 00:42:08,400 --> 00:42:12,319 arduino has been plugged in 1233 00:42:10,000 --> 00:42:13,440 and it will list it out on a specific 1234 00:42:12,319 --> 00:42:16,079 serial port 1235 00:42:13,440 --> 00:42:17,680 in windows it is known as a com port 1236 00:42:16,079 --> 00:42:20,160 which you need to go 1237 00:42:17,680 --> 00:42:21,280 and select using tools go to tools and 1238 00:42:20,160 --> 00:42:23,119 then go to port 1239 00:42:21,280 --> 00:42:24,960 and you will automatically see a com 1240 00:42:23,119 --> 00:42:27,200 port here 1241 00:42:24,960 --> 00:42:28,960 it is very likely that you see com3 if 1242 00:42:27,200 --> 00:42:30,560 you have plugged your arduino for the 1243 00:42:28,960 --> 00:42:33,680 very first time 1244 00:42:30,560 --> 00:42:36,800 okay so you will see arduino genuine 1245 00:42:33,680 --> 00:42:38,240 uno written over here if you're using 1246 00:42:36,800 --> 00:42:40,160 mac 1247 00:42:38,240 --> 00:42:41,280 then you will see something like this 1248 00:42:40,160 --> 00:42:44,400 forward slash dev 1249 00:42:41,280 --> 00:42:45,520 dot forward slash cu dot usb modem this 1250 00:42:44,400 --> 00:42:47,200 is the port number 1251 00:42:45,520 --> 00:42:48,800 and you will see arduino uno here 1252 00:42:47,200 --> 00:42:50,240 instead of adding omega i have tested 1253 00:42:48,800 --> 00:42:51,119 with arduino mega that's why it is 1254 00:42:50,240 --> 00:42:53,839 showing it 1255 00:42:51,119 --> 00:42:54,160 like that but you will see arduino uno 1256 00:42:53,839 --> 00:42:55,599 right 1257 00:42:54,160 --> 00:42:57,440 if you're using linux you will see 1258 00:42:55,599 --> 00:43:00,560 serial port as 1259 00:42:57,440 --> 00:43:02,000 power slash dev tty acm0 it is most 1260 00:43:00,560 --> 00:43:05,119 likely will find it at 1261 00:43:02,000 --> 00:43:06,880 at acm 0. after this step 1262 00:43:05,119 --> 00:43:09,040 we are just ready to upload our first 1263 00:43:06,880 --> 00:43:10,880 basic sketch 1264 00:43:09,040 --> 00:43:12,880 so finally we will be testing our 1265 00:43:10,880 --> 00:43:16,720 arduino boards and for that we will be 1266 00:43:12,880 --> 00:43:16,720 using the built-in example sketches 1267 00:43:17,359 --> 00:43:21,440 so in order to upload our first sketch 1268 00:43:19,119 --> 00:43:23,839 we'll go to examples we'll go to basics 1269 00:43:21,440 --> 00:43:25,520 and then we'll select the blink sketch 1270 00:43:23,839 --> 00:43:26,560 this is the first sketch which will be 1271 00:43:25,520 --> 00:43:29,680 uploading 1272 00:43:26,560 --> 00:43:31,839 on our arduino board we'll go to tools 1273 00:43:29,680 --> 00:43:32,960 we'll select our board as arduino uno 1274 00:43:31,839 --> 00:43:36,720 and we'll select 1275 00:43:32,960 --> 00:43:38,880 our port as com3 and 1276 00:43:36,720 --> 00:43:40,560 then we will go to upload button we'll 1277 00:43:38,880 --> 00:43:41,920 click on upload in order to upload the 1278 00:43:40,560 --> 00:43:43,920 code 1279 00:43:41,920 --> 00:43:46,160 there are more buttons like verify save 1280 00:43:43,920 --> 00:43:48,319 open we will talk about these buttons 1281 00:43:46,160 --> 00:43:50,640 in upcoming sections but now we'll click 1282 00:43:48,319 --> 00:43:52,400 on upload 1283 00:43:50,640 --> 00:43:54,560 it will first compile the sketch and 1284 00:43:52,400 --> 00:43:56,079 then it will upload the code to the 1285 00:43:54,560 --> 00:43:58,160 board 1286 00:43:56,079 --> 00:44:00,640 after uploading you will see done 1287 00:43:58,160 --> 00:44:04,240 uploading will appear 1288 00:44:00,640 --> 00:44:06,480 in the messages done uploading right 1289 00:44:04,240 --> 00:44:09,839 and you will see that led is blinking 1290 00:44:06,480 --> 00:44:12,319 with this gap of one second 1291 00:44:09,839 --> 00:44:14,560 is it blinking right if it is blinking 1292 00:44:12,319 --> 00:44:22,800 then congratulations you have done your 1293 00:44:14,560 --> 00:44:24,880 first example 1294 00:44:22,800 --> 00:44:27,440 at this point the viewers without an 1295 00:44:24,880 --> 00:44:29,119 arduino must be feeling a little stuck 1296 00:44:27,440 --> 00:44:30,560 but please don't worry i've got you 1297 00:44:29,119 --> 00:44:33,839 covered all you need to do 1298 00:44:30,560 --> 00:44:36,880 is use an online simulator like 1299 00:44:33,839 --> 00:44:39,119 autodesk tinkercad and for that you need 1300 00:44:36,880 --> 00:44:42,960 to go to 1301 00:44:39,119 --> 00:44:46,480 the website of tinkercad 1302 00:44:42,960 --> 00:44:46,480 right this one 1303 00:44:49,359 --> 00:44:52,960 and you need to create an account if you 1304 00:44:51,599 --> 00:44:54,800 don't have it already 1305 00:44:52,960 --> 00:44:58,000 you can choose the option relevant to 1306 00:44:54,800 --> 00:44:58,000 you make an account 1307 00:44:58,079 --> 00:45:01,280 and after creating your account you will 1308 00:44:59,680 --> 00:45:03,920 see a screen like this 1309 00:45:01,280 --> 00:45:07,200 all you need to do is click on circuits 1310 00:45:03,920 --> 00:45:11,520 and create a new circuit 1311 00:45:07,200 --> 00:45:14,960 at this window we need to search 1312 00:45:11,520 --> 00:45:18,079 arduino uno r3 1313 00:45:14,960 --> 00:45:20,640 and just drag it over here 1314 00:45:18,079 --> 00:45:21,760 right so now you have your virtual 1315 00:45:20,640 --> 00:45:24,079 arduino board 1316 00:45:21,760 --> 00:45:25,200 it will just function exactly like the 1317 00:45:24,079 --> 00:45:28,000 actual arduino board 1318 00:45:25,200 --> 00:45:29,200 and whatever code i write in official id 1319 00:45:28,000 --> 00:45:33,839 in the following videos 1320 00:45:29,200 --> 00:45:33,839 you need to write that into this window 1321 00:45:36,079 --> 00:45:39,440 right so you will have this window over 1322 00:45:38,720 --> 00:45:41,119 here 1323 00:45:39,440 --> 00:45:42,960 whatever code i am writing in the 1324 00:45:41,119 --> 00:45:46,079 official id you just need to 1325 00:45:42,960 --> 00:45:46,560 write that in this area okay so just as 1326 00:45:46,079 --> 00:45:48,960 you saw 1327 00:45:46,560 --> 00:45:49,760 few moments ago that we tested our 1328 00:45:48,960 --> 00:45:51,920 arduino board 1329 00:45:49,760 --> 00:45:53,520 so we will now test our arduino board 1330 00:45:51,920 --> 00:45:56,079 over here 1331 00:45:53,520 --> 00:45:57,599 right so this is the same code which we 1332 00:45:56,079 --> 00:46:00,319 wrote over there 1333 00:45:57,599 --> 00:46:02,640 only the comments are not here right so 1334 00:46:00,319 --> 00:46:04,720 this is exactly the same code 1335 00:46:02,640 --> 00:46:07,440 and what we need to do after that is 1336 00:46:04,720 --> 00:46:10,640 start simulation 1337 00:46:07,440 --> 00:46:12,560 okay so it will be plugged in and 1338 00:46:10,640 --> 00:46:13,839 you know we can see the outcome of our 1339 00:46:12,560 --> 00:46:15,920 code over here 1340 00:46:13,839 --> 00:46:17,280 and in some portions of the video you 1341 00:46:15,920 --> 00:46:19,119 will also see that i am 1342 00:46:17,280 --> 00:46:20,400 printing out the outputs of some code on 1343 00:46:19,119 --> 00:46:23,040 the serial monitor 1344 00:46:20,400 --> 00:46:24,480 so the serial monitor in this simulator 1345 00:46:23,040 --> 00:46:26,480 is this 1346 00:46:24,480 --> 00:46:28,160 right so you will see whatever outputs 1347 00:46:26,480 --> 00:46:29,359 i'm showing in the videos you can see 1348 00:46:28,160 --> 00:46:31,280 them here 1349 00:46:29,359 --> 00:46:33,119 okay so don't worry if you don't have an 1350 00:46:31,280 --> 00:46:36,000 arduino at this point you can still 1351 00:46:33,119 --> 00:46:37,280 follow along the video so before we move 1352 00:46:36,000 --> 00:46:39,040 forward from this point 1353 00:46:37,280 --> 00:46:41,359 having the knowledge of a few more 1354 00:46:39,040 --> 00:46:44,319 things would be greatly beneficial 1355 00:46:41,359 --> 00:46:45,680 things such as breadboard how to make 1356 00:46:44,319 --> 00:46:48,319 connections in breadboard 1357 00:46:45,680 --> 00:46:48,720 some safety instructions for the arduino 1358 00:46:48,319 --> 00:46:51,440 and 1359 00:46:48,720 --> 00:46:52,720 some basic terms like input output 1360 00:46:51,440 --> 00:46:55,920 sensors analog 1361 00:46:52,720 --> 00:46:57,280 digital bit and byte you may want to 1362 00:46:55,920 --> 00:46:58,880 revisit this section as well 1363 00:46:57,280 --> 00:47:02,000 if you find yourself forgetting about 1364 00:46:58,880 --> 00:47:05,359 these concepts as we proceed 1365 00:47:02,000 --> 00:47:06,960 all right so let's start with breadboard 1366 00:47:05,359 --> 00:47:08,960 is this the first thought which came to 1367 00:47:06,960 --> 00:47:12,319 your mind when you heard of breadboard 1368 00:47:08,960 --> 00:47:13,520 well that's a perfectly genuine thought 1369 00:47:12,319 --> 00:47:17,520 when i stepped in the field of 1370 00:47:13,520 --> 00:47:17,520 electronics i myself had this thought 1371 00:47:17,599 --> 00:47:21,119 but when i learned that the breadboard 1372 00:47:19,280 --> 00:47:21,520 in electronics is a completely different 1373 00:47:21,119 --> 00:47:25,040 thing 1374 00:47:21,520 --> 00:47:26,559 i had a really big face pump moment 1375 00:47:25,040 --> 00:47:28,559 let's discuss this in the comment 1376 00:47:26,559 --> 00:47:29,440 section as to why it is called as 1377 00:47:28,559 --> 00:47:31,599 breadboard 1378 00:47:29,440 --> 00:47:32,640 or from where it got its name we will 1379 00:47:31,599 --> 00:47:36,880 just talk 1380 00:47:32,640 --> 00:47:38,800 about breadboard in terms of electronics 1381 00:47:36,880 --> 00:47:40,400 breadboards are meant to make quick 1382 00:47:38,800 --> 00:47:42,160 non-permanent connections between 1383 00:47:40,400 --> 00:47:44,160 electronic components 1384 00:47:42,160 --> 00:47:45,280 and they are covered with tiny socket 1385 00:47:44,160 --> 00:47:49,280 holes which are 1386 00:47:45,280 --> 00:47:51,440 connected in rows the breadboard 1387 00:47:49,280 --> 00:47:53,119 itself is broken into four sections 1388 00:47:51,440 --> 00:47:54,960 there are two inner sections full of 1389 00:47:53,119 --> 00:47:56,800 short horizontal rows 1390 00:47:54,960 --> 00:47:58,000 and two outer sections with long 1391 00:47:56,800 --> 00:47:59,520 vertical rows 1392 00:47:58,000 --> 00:48:00,640 if we remove the adhesive which is 1393 00:47:59,520 --> 00:48:02,160 present on the back side of the 1394 00:48:00,640 --> 00:48:05,599 breadboard we would see 1395 00:48:02,160 --> 00:48:08,640 something like this a series of 1396 00:48:05,599 --> 00:48:11,119 metal connections do you see that 1397 00:48:08,640 --> 00:48:12,160 we'll discuss what this means in a few 1398 00:48:11,119 --> 00:48:14,000 moments 1399 00:48:12,160 --> 00:48:16,559 but before that i would like to show you 1400 00:48:14,000 --> 00:48:19,200 the strip which is connected inside that 1401 00:48:16,559 --> 00:48:20,880 it is a single strip which is taken out 1402 00:48:19,200 --> 00:48:21,520 from that bright board and it would look 1403 00:48:20,880 --> 00:48:25,040 like that 1404 00:48:21,520 --> 00:48:28,240 so you see this entire metal piece 1405 00:48:25,040 --> 00:48:29,839 so when we make connections on that 1406 00:48:28,240 --> 00:48:32,000 you know it is internally connected 1407 00:48:29,839 --> 00:48:35,680 automatically 1408 00:48:32,000 --> 00:48:38,880 coming back to this if we consider 1409 00:48:35,680 --> 00:48:42,880 this row corresponds to this 1410 00:48:38,880 --> 00:48:45,520 all right so that means these points 1411 00:48:42,880 --> 00:48:47,359 are connected among themselves 1412 00:48:45,520 --> 00:48:50,559 automatically 1413 00:48:47,359 --> 00:48:53,119 and like these rails are connected 1414 00:48:50,559 --> 00:48:54,480 so these points are also connected from 1415 00:48:53,119 --> 00:48:56,240 inside 1416 00:48:54,480 --> 00:48:59,839 we'll discuss this in detail we'll also 1417 00:48:56,240 --> 00:49:01,119 make circuits don't worry about that 1418 00:48:59,839 --> 00:49:02,400 if you're wondering what kind of 1419 00:49:01,119 --> 00:49:03,040 circuits which we can make on a 1420 00:49:02,400 --> 00:49:04,400 breadboard 1421 00:49:03,040 --> 00:49:06,480 i would like to tell you that you can 1422 00:49:04,400 --> 00:49:08,000 also make your arduino uno 1423 00:49:06,480 --> 00:49:10,480 on the breadboard and it would look like 1424 00:49:08,000 --> 00:49:12,240 this now we will see 1425 00:49:10,480 --> 00:49:13,680 how to use a breadboard we will also 1426 00:49:12,240 --> 00:49:17,599 understand the connections 1427 00:49:13,680 --> 00:49:20,559 in details all right 1428 00:49:17,599 --> 00:49:21,040 so this is our breadboard okay can you 1429 00:49:20,559 --> 00:49:24,240 see 1430 00:49:21,040 --> 00:49:26,160 all these holes like this 1431 00:49:24,240 --> 00:49:28,160 which are getting highlighted in blue 1432 00:49:26,160 --> 00:49:29,280 right these are the holes 1433 00:49:28,160 --> 00:49:31,280 which i was talking about in the 1434 00:49:29,280 --> 00:49:32,960 previous video 1435 00:49:31,280 --> 00:49:35,440 okay so i'll now show you how they are 1436 00:49:32,960 --> 00:49:37,359 interconnected for example 1437 00:49:35,440 --> 00:49:38,800 these points are interconnected the 1438 00:49:37,359 --> 00:49:39,680 yellow ones all of these are 1439 00:49:38,800 --> 00:49:42,800 interconnected 1440 00:49:39,680 --> 00:49:43,680 within themselves right like these all 1441 00:49:42,800 --> 00:49:45,920 these points 1442 00:49:43,680 --> 00:49:46,880 are connected among themselves but 1443 00:49:45,920 --> 00:49:48,720 please note 1444 00:49:46,880 --> 00:49:50,559 that this point is not connected to this 1445 00:49:48,720 --> 00:49:52,640 point internally 1446 00:49:50,559 --> 00:49:54,079 this point is only connected to these 1447 00:49:52,640 --> 00:49:57,119 points like can you see 1448 00:49:54,079 --> 00:49:59,839 right like this all these points are 1449 00:49:57,119 --> 00:50:04,160 interconnected 1450 00:49:59,839 --> 00:50:07,200 all right so then we'll see these points 1451 00:50:04,160 --> 00:50:09,040 these are the external points all of 1452 00:50:07,200 --> 00:50:12,079 these points are interconnected 1453 00:50:09,040 --> 00:50:14,960 like this right 1454 00:50:12,079 --> 00:50:16,960 like this and like this in some 1455 00:50:14,960 --> 00:50:20,960 breadboards there are connection break 1456 00:50:16,960 --> 00:50:23,520 at this point so you will just see 1457 00:50:20,960 --> 00:50:24,319 that the points are connected only till 1458 00:50:23,520 --> 00:50:26,400 here 1459 00:50:24,319 --> 00:50:28,160 and these points are connected till here 1460 00:50:26,400 --> 00:50:28,559 but this point is not connected to this 1461 00:50:28,160 --> 00:50:30,240 point 1462 00:50:28,559 --> 00:50:32,079 in some breadboards but in most 1463 00:50:30,240 --> 00:50:36,640 breadboards they are all connected 1464 00:50:32,079 --> 00:50:38,839 like this can you see that okay 1465 00:50:36,640 --> 00:50:40,319 so now i'll tell you if you want to 1466 00:50:38,839 --> 00:50:42,480 connect 1467 00:50:40,319 --> 00:50:43,359 some two points for example we'll take a 1468 00:50:42,480 --> 00:50:47,520 wire 1469 00:50:43,359 --> 00:50:48,960 and we'll join this so now 1470 00:50:47,520 --> 00:50:51,920 these points are connected among 1471 00:50:48,960 --> 00:50:55,839 themselves right 1472 00:50:51,920 --> 00:51:00,160 no matter how many wires we join here 1473 00:50:55,839 --> 00:51:03,280 these will still stay connected okay 1474 00:51:00,160 --> 00:51:05,839 and what if i connect a wire here 1475 00:51:03,280 --> 00:51:07,440 then all these points will get connected 1476 00:51:05,839 --> 00:51:09,599 you see that 1477 00:51:07,440 --> 00:51:11,520 right i think it is really interesting 1478 00:51:09,599 --> 00:51:13,359 to see that how easy 1479 00:51:11,520 --> 00:51:14,720 it makes for us to make connections on 1480 00:51:13,359 --> 00:51:16,880 the breadboard 1481 00:51:14,720 --> 00:51:18,000 right so now we'll see how to make a 1482 00:51:16,880 --> 00:51:21,280 series connection 1483 00:51:18,000 --> 00:51:26,319 right we'll take a resistance 1484 00:51:21,280 --> 00:51:29,760 like this okay and we'll place it here 1485 00:51:26,319 --> 00:51:32,960 okay now i will take another resistance 1486 00:51:29,760 --> 00:51:36,400 and connect it here okay 1487 00:51:32,960 --> 00:51:37,920 so now these resistances are in series 1488 00:51:36,400 --> 00:51:39,520 now if i make want to make another 1489 00:51:37,920 --> 00:51:40,720 resistance which i want to take in 1490 00:51:39,520 --> 00:51:44,559 series 1491 00:51:40,720 --> 00:51:46,960 i'll place them here 1492 00:51:44,559 --> 00:51:48,240 all right now these three resistance are 1493 00:51:46,960 --> 00:51:51,280 connected in series 1494 00:51:48,240 --> 00:51:52,240 how for example these points were 1495 00:51:51,280 --> 00:51:55,520 interconnected 1496 00:51:52,240 --> 00:51:57,200 okay and so we connected our resistance 1497 00:51:55,520 --> 00:52:00,880 here so that means they are in 1498 00:51:57,200 --> 00:52:04,079 a continuous position now similarly 1499 00:52:00,880 --> 00:52:05,280 here as well okay i would like to tell 1500 00:52:04,079 --> 00:52:07,359 you that some people 1501 00:52:05,280 --> 00:52:10,640 make a mistake and to make a series 1502 00:52:07,359 --> 00:52:14,000 connection they would go like this 1503 00:52:10,640 --> 00:52:17,599 they will place the resistance here 1504 00:52:14,000 --> 00:52:20,240 instead of placing it here 1505 00:52:17,599 --> 00:52:21,440 right this is a series connection but 1506 00:52:20,240 --> 00:52:22,880 this is 1507 00:52:21,440 --> 00:52:24,720 no connection at all because these 1508 00:52:22,880 --> 00:52:28,079 points are not interconnected 1509 00:52:24,720 --> 00:52:29,839 however if we join a wire like this 1510 00:52:28,079 --> 00:52:31,359 okay so now these points are 1511 00:52:29,839 --> 00:52:37,040 interconnected 1512 00:52:31,359 --> 00:52:38,960 okay i hope i am making you myself clear 1513 00:52:37,040 --> 00:52:40,480 now we will try to understand a parallel 1514 00:52:38,960 --> 00:52:43,839 connection 1515 00:52:40,480 --> 00:52:47,280 similarly we'll take resistance 1516 00:52:43,839 --> 00:52:49,440 and we'll place it here now since 1517 00:52:47,280 --> 00:52:50,800 in parallel connections all of the 1518 00:52:49,440 --> 00:52:52,960 points are you know 1519 00:52:50,800 --> 00:52:54,800 originating and ending at the same point 1520 00:52:52,960 --> 00:52:57,599 and these points are interconnected 1521 00:52:54,800 --> 00:52:58,880 so we'll take another resistance and 1522 00:52:57,599 --> 00:53:01,119 place it here 1523 00:52:58,880 --> 00:53:02,480 so these two resistance are in parallel 1524 00:53:01,119 --> 00:53:04,559 now if you want to 1525 00:53:02,480 --> 00:53:06,640 take a third resistance as well and 1526 00:53:04,559 --> 00:53:08,480 we'll take it and place it here now 1527 00:53:06,640 --> 00:53:11,839 these three resistances are 1528 00:53:08,480 --> 00:53:12,800 in parallel okay now we want to make a 1529 00:53:11,839 --> 00:53:14,800 connection 1530 00:53:12,800 --> 00:53:16,240 in which there is a resistance in series 1531 00:53:14,800 --> 00:53:17,119 and then there are two resistances in 1532 00:53:16,240 --> 00:53:20,480 parallel 1533 00:53:17,119 --> 00:53:20,480 we'll try to make that circuit 1534 00:53:21,920 --> 00:53:27,200 this is one resistance okay and then 1535 00:53:27,680 --> 00:53:30,800 if we make it like this 1536 00:53:31,119 --> 00:53:39,680 like this 1537 00:53:34,800 --> 00:53:42,720 okay and we take another resistance 1538 00:53:39,680 --> 00:53:43,839 and we place it like this okay so what 1539 00:53:42,720 --> 00:53:46,880 that is representing 1540 00:53:43,839 --> 00:53:49,200 it is one resistance which is in series 1541 00:53:46,880 --> 00:53:50,640 with this resistances which are in 1542 00:53:49,200 --> 00:53:52,480 parallel among themselves 1543 00:53:50,640 --> 00:53:55,359 and then there's another resistance 1544 00:53:52,480 --> 00:53:58,000 which is in series with that 1545 00:53:55,359 --> 00:53:59,440 okay okay it's all right if you don't 1546 00:53:58,000 --> 00:53:59,760 understand what i'm trying to say right 1547 00:53:59,440 --> 00:54:01,520 now 1548 00:53:59,760 --> 00:54:04,000 we'll understand this with one more 1549 00:54:01,520 --> 00:54:04,000 example 1550 00:54:05,040 --> 00:54:08,640 so before i begin with my second example 1551 00:54:07,440 --> 00:54:11,760 i would like to tell you 1552 00:54:08,640 --> 00:54:14,400 a few more things like i told you 1553 00:54:11,760 --> 00:54:16,160 in the previous video if we connect a 1554 00:54:14,400 --> 00:54:19,200 wire like this 1555 00:54:16,160 --> 00:54:23,520 the points become interconnected 1556 00:54:19,200 --> 00:54:25,839 but if you take a resistance and connect 1557 00:54:23,520 --> 00:54:25,839 it like this 1558 00:54:25,990 --> 00:54:29,440 [Music] 1559 00:54:27,680 --> 00:54:31,440 so these points are not connected to 1560 00:54:29,440 --> 00:54:33,280 these points right because it is a 1561 00:54:31,440 --> 00:54:36,319 resistance 1562 00:54:33,280 --> 00:54:37,200 you see that in this case these points 1563 00:54:36,319 --> 00:54:39,520 are interconnected 1564 00:54:37,200 --> 00:54:41,599 but in the case of resistance these 1565 00:54:39,520 --> 00:54:43,040 points are not interconnected 1566 00:54:41,599 --> 00:54:45,040 now another point which i want you to 1567 00:54:43,040 --> 00:54:48,799 notice every connected wire 1568 00:54:45,040 --> 00:54:50,240 like this it won't make any sense 1569 00:54:48,799 --> 00:54:52,880 as these points are already 1570 00:54:50,240 --> 00:54:55,200 interconnected right 1571 00:54:52,880 --> 00:54:56,559 so this wire will not make any 1572 00:54:55,200 --> 00:54:58,559 difference 1573 00:54:56,559 --> 00:54:59,920 so now another thing which i want you to 1574 00:54:58,559 --> 00:55:02,559 notice 1575 00:54:59,920 --> 00:55:03,070 if we take a resistance and if we place 1576 00:55:02,559 --> 00:55:04,839 it like 1577 00:55:03,070 --> 00:55:07,200 [Music] 1578 00:55:04,839 --> 00:55:10,480 this 1579 00:55:07,200 --> 00:55:12,400 like this then also 1580 00:55:10,480 --> 00:55:14,799 it won't make any difference because as 1581 00:55:12,400 --> 00:55:16,240 we all know the current always takes the 1582 00:55:14,799 --> 00:55:17,760 least resistive path 1583 00:55:16,240 --> 00:55:19,200 so connecting a resistance like this 1584 00:55:17,760 --> 00:55:20,799 won't make any difference because the 1585 00:55:19,200 --> 00:55:22,960 current will travel 1586 00:55:20,799 --> 00:55:25,520 through the rails only this resistance 1587 00:55:22,960 --> 00:55:28,079 will not add any value to the circuit 1588 00:55:25,520 --> 00:55:30,559 okay but however if you connect a 1589 00:55:28,079 --> 00:55:33,040 resistance like this 1590 00:55:30,559 --> 00:55:35,000 then it would make some sense okay how 1591 00:55:33,040 --> 00:55:36,720 it will make some sense we will see 1592 00:55:35,000 --> 00:55:41,760 [Music] 1593 00:55:36,720 --> 00:55:41,760 for example we can connect it like this 1594 00:55:42,640 --> 00:55:49,119 and like this 1595 00:55:47,040 --> 00:55:52,799 okay so this is a series connection now 1596 00:55:49,119 --> 00:55:52,799 these two resistances are in series 1597 00:55:53,280 --> 00:55:56,990 but yeah please note that these 1598 00:55:55,119 --> 00:55:58,319 resistances 1599 00:55:56,990 --> 00:56:02,390 [Music] 1600 00:55:58,319 --> 00:56:10,079 are not in parallel 1601 00:56:02,390 --> 00:56:12,480 [Music] 1602 00:56:10,079 --> 00:56:13,599 but please note that these resistances 1603 00:56:12,480 --> 00:56:16,000 are not in parallel 1604 00:56:13,599 --> 00:56:16,640 because these points are not connected 1605 00:56:16,000 --> 00:56:18,480 okay 1606 00:56:16,640 --> 00:56:20,319 now we will begin with our second 1607 00:56:18,480 --> 00:56:22,240 example in this example 1608 00:56:20,319 --> 00:56:24,160 we will just connect an led with a push 1609 00:56:22,240 --> 00:56:27,040 button and a battery 1610 00:56:24,160 --> 00:56:28,000 okay so when we press the push button 1611 00:56:27,040 --> 00:56:30,799 that led will 1612 00:56:28,000 --> 00:56:32,400 blow so we will make a circuit on that 1613 00:56:30,799 --> 00:56:34,319 so for that we'll take a push button 1614 00:56:32,400 --> 00:56:36,480 circuit first of all 1615 00:56:34,319 --> 00:56:38,640 okay this is a push button circuit i'll 1616 00:56:36,480 --> 00:56:40,400 tell you about push button circuit 1617 00:56:38,640 --> 00:56:41,760 that internally this terminal is 1618 00:56:40,400 --> 00:56:45,359 connected to this terminal 1619 00:56:41,760 --> 00:56:46,799 okay so automatically this rail will get 1620 00:56:45,359 --> 00:56:49,839 connected to this rail 1621 00:56:46,799 --> 00:56:52,000 okay like this 1622 00:56:49,839 --> 00:56:55,680 and this terminal is connected to this 1623 00:56:52,000 --> 00:56:55,680 terminal so these points will also get 1624 00:56:56,839 --> 00:56:59,839 interconnected 1625 00:57:01,040 --> 00:57:06,480 okay so when you press this button 1626 00:57:04,559 --> 00:57:07,599 this terminal gets connected to this 1627 00:57:06,480 --> 00:57:09,599 terminal 1628 00:57:07,599 --> 00:57:10,720 okay so these points will get connected 1629 00:57:09,599 --> 00:57:14,720 when you press 1630 00:57:10,720 --> 00:57:17,119 the switch all right then we will take a 1631 00:57:14,720 --> 00:57:17,119 battery 1632 00:57:17,920 --> 00:57:23,839 let's take this battery this is a simple 1633 00:57:20,880 --> 00:57:25,599 battery 3.7 volts 1634 00:57:23,839 --> 00:57:27,599 let's place it here this has a positive 1635 00:57:25,599 --> 00:57:31,680 terminal and a negative terminal 1636 00:57:27,599 --> 00:57:31,680 we'll try to connect it on a rail 1637 00:57:33,280 --> 00:57:37,040 let's make this wire as red color 1638 00:57:35,250 --> 00:57:41,839 [Music] 1639 00:57:37,040 --> 00:57:41,839 and the black wire as 1640 00:57:46,319 --> 00:57:49,440 the black one okay in general 1641 00:57:48,559 --> 00:57:52,160 electronics 1642 00:57:49,440 --> 00:57:53,839 this is also a convention that the red 1643 00:57:52,160 --> 00:57:54,079 wire represents positive terminal and 1644 00:57:53,839 --> 00:57:55,920 the 1645 00:57:54,079 --> 00:57:57,680 black wire represents the negative 1646 00:57:55,920 --> 00:58:00,960 terminal okay so now 1647 00:57:57,680 --> 00:58:02,480 these and this entire rail okay so now 1648 00:58:00,960 --> 00:58:05,520 this entire rail 1649 00:58:02,480 --> 00:58:07,040 is positive okay as we have connected 1650 00:58:05,520 --> 00:58:10,160 the positive terminal of the battery 1651 00:58:07,040 --> 00:58:10,160 here just see that 1652 00:58:11,280 --> 00:58:16,400 and this terminal is negative this 1653 00:58:14,160 --> 00:58:18,799 entire rail is negative 1654 00:58:16,400 --> 00:58:20,319 okay so we will start by placing a 1655 00:58:18,799 --> 00:58:21,520 resistor 1656 00:58:20,319 --> 00:58:23,359 as we should always connect our 1657 00:58:21,520 --> 00:58:27,200 resistance in series 1658 00:58:23,359 --> 00:58:27,200 when using a led 1659 00:58:27,920 --> 00:58:33,280 replace it like this okay 1660 00:58:30,960 --> 00:58:35,119 so that means this point and this point 1661 00:58:33,280 --> 00:58:37,040 are interconnected so this resistance is 1662 00:58:35,119 --> 00:58:40,319 in series with this switch 1663 00:58:37,040 --> 00:58:40,319 and then we'll take one led 1664 00:58:41,520 --> 00:58:47,280 this is the led okay 1665 00:58:45,520 --> 00:58:49,520 as we all know there is a positive end 1666 00:58:47,280 --> 00:58:53,760 and the negative end 1667 00:58:49,520 --> 00:58:55,200 of the led so this is the positive end 1668 00:58:53,760 --> 00:58:56,559 and this is the negative end we have 1669 00:58:55,200 --> 00:58:58,079 connected the negative end to the 1670 00:58:56,559 --> 00:59:00,319 resistance 1671 00:58:58,079 --> 00:59:02,000 okay to make the led glow we have to 1672 00:59:00,319 --> 00:59:04,880 always connect the positive end 1673 00:59:02,000 --> 00:59:06,000 of the led to the positive end of the 1674 00:59:04,880 --> 00:59:08,079 battery 1675 00:59:06,000 --> 00:59:09,599 okay so first of all what we'll do is 1676 00:59:08,079 --> 00:59:12,000 we'll take a positive wire 1677 00:59:09,599 --> 00:59:13,440 from here right as we know all know this 1678 00:59:12,000 --> 00:59:15,839 entire rail is positive 1679 00:59:13,440 --> 00:59:16,640 so from any point on this rail we can 1680 00:59:15,839 --> 00:59:18,559 take 1681 00:59:16,640 --> 00:59:19,760 positive line so we'll take a positive 1682 00:59:18,559 --> 00:59:22,640 line from here 1683 00:59:19,760 --> 00:59:22,640 and connect it here 1684 00:59:23,680 --> 00:59:27,680 this is a general wire so we'll make it 1685 00:59:25,280 --> 00:59:31,040 blue all right 1686 00:59:27,680 --> 00:59:32,880 and then what we want is we need to 1687 00:59:31,040 --> 00:59:35,520 complete the circuit like this 1688 00:59:32,880 --> 00:59:37,680 we'll take a black wire from here and 1689 00:59:35,520 --> 00:59:40,960 connect it here 1690 00:59:37,680 --> 00:59:46,079 okay so this is our circuit 1691 00:59:40,960 --> 00:59:48,079 completed whenever we press this switch 1692 00:59:46,079 --> 00:59:49,200 this circuit will get completed the 1693 00:59:48,079 --> 00:59:51,359 positive 1694 00:59:49,200 --> 00:59:54,400 wire will go from here the current will 1695 00:59:51,359 --> 00:59:55,839 flow from positive terminal like this 1696 00:59:54,400 --> 00:59:58,079 it will flow from resistance and it will 1697 00:59:55,839 --> 01:00:00,319 go from circuit and then 1698 00:59:58,079 --> 01:00:01,599 to the negative end and back to the 1699 01:00:00,319 --> 01:00:03,599 battery 1700 01:00:01,599 --> 01:00:05,680 but whenever we release the switch the 1701 01:00:03,599 --> 01:00:06,240 circuit will break and the led will stop 1702 01:00:05,680 --> 01:00:08,880 glowing 1703 01:00:06,240 --> 01:00:09,359 this was the very basic example of a led 1704 01:00:08,880 --> 01:00:12,480 in a 1705 01:00:09,359 --> 01:00:13,119 breadboard in this video we will discuss 1706 01:00:12,480 --> 01:00:14,720 about 1707 01:00:13,119 --> 01:00:16,400 some of the safety instructions which we 1708 01:00:14,720 --> 01:00:16,799 need to follow while using our arduino 1709 01:00:16,400 --> 01:00:18,160 board 1710 01:00:16,799 --> 01:00:19,760 the first thing which you need to keep 1711 01:00:18,160 --> 01:00:20,240 in your mind is you never have to 1712 01:00:19,760 --> 01:00:23,200 connect 1713 01:00:20,240 --> 01:00:23,680 any voltage of over 5 volts on any i o 1714 01:00:23,200 --> 01:00:26,240 pin 1715 01:00:23,680 --> 01:00:27,040 okay any i o pin means any input output 1716 01:00:26,240 --> 01:00:29,040 pin 1717 01:00:27,040 --> 01:00:30,960 be it the digital pins or the analog 1718 01:00:29,040 --> 01:00:33,200 pins you just don't have to connect any 1719 01:00:30,960 --> 01:00:34,160 voltage over 5 volts on those pins you 1720 01:00:33,200 --> 01:00:37,040 can only use 1721 01:00:34,160 --> 01:00:37,599 any voltage over 5 volts to power the 1722 01:00:37,040 --> 01:00:40,079 arduino 1723 01:00:37,599 --> 01:00:40,880 through v in pin and you cannot connect 1724 01:00:40,079 --> 01:00:44,079 any pin 1725 01:00:40,880 --> 01:00:46,480 to a voltage over 5 volts okay 1726 01:00:44,079 --> 01:00:48,079 next important thing you need to notice 1727 01:00:46,480 --> 01:00:51,200 you never have to connect 1728 01:00:48,079 --> 01:00:52,640 a 5 volt pin to a ground pin this way 1729 01:00:51,200 --> 01:00:54,880 you will short it down 1730 01:00:52,640 --> 01:00:57,440 an arduino will turn off the next point 1731 01:00:54,880 --> 01:00:59,520 is you have to take care of the polarity 1732 01:00:57,440 --> 01:01:01,040 polarity means you cannot connect 1733 01:00:59,520 --> 01:01:02,799 positive and negative terminals in 1734 01:01:01,040 --> 01:01:04,319 opposite ways what i mean is you cannot 1735 01:01:02,799 --> 01:01:05,680 connect a positive pin 1736 01:01:04,319 --> 01:01:08,000 to a negative pin of some other 1737 01:01:05,680 --> 01:01:09,520 component and vice versa if there is no 1738 01:01:08,000 --> 01:01:10,960 polarity management circuit on the 1739 01:01:09,520 --> 01:01:13,119 device which you are using it will 1740 01:01:10,960 --> 01:01:15,520 simply damage the device one more point 1741 01:01:13,119 --> 01:01:17,359 is you have to be careful while using 1742 01:01:15,520 --> 01:01:19,200 external power in this course for all 1743 01:01:17,359 --> 01:01:21,040 the project the usb power 1744 01:01:19,200 --> 01:01:22,400 would be more than enough but still if 1745 01:01:21,040 --> 01:01:25,440 you need any external power 1746 01:01:22,400 --> 01:01:26,000 you can use it through dc jack or vn 1747 01:01:25,440 --> 01:01:27,760 pins 1748 01:01:26,000 --> 01:01:29,599 and in that case also please make sure 1749 01:01:27,760 --> 01:01:30,079 you don't connect any voltage above 12 1750 01:01:29,599 --> 01:01:32,240 volts 1751 01:01:30,079 --> 01:01:33,200 although arduino can tolerate up to 20 1752 01:01:32,240 --> 01:01:35,520 volts but still 1753 01:01:33,200 --> 01:01:37,119 it i advise you that don't use above 12 1754 01:01:35,520 --> 01:01:39,599 volts otherwise you will see 1755 01:01:37,119 --> 01:01:40,160 unnecessary heating on the arduino board 1756 01:01:39,599 --> 01:01:42,000 okay 1757 01:01:40,160 --> 01:01:43,440 so these were the main safety 1758 01:01:42,000 --> 01:01:45,760 instructions which you need to follow 1759 01:01:43,440 --> 01:01:47,119 or you may damage your arduino and while 1760 01:01:45,760 --> 01:01:48,799 doing our experiments 1761 01:01:47,119 --> 01:01:50,799 i will also tell you about more safety 1762 01:01:48,799 --> 01:01:52,720 instructions if they are required 1763 01:01:50,799 --> 01:01:54,160 okay so now i will see you in the next 1764 01:01:52,720 --> 01:01:56,319 video in this video 1765 01:01:54,160 --> 01:01:58,079 i will talk about input and output and 1766 01:01:56,319 --> 01:02:00,559 how to understand it with respect to 1767 01:01:58,079 --> 01:02:02,799 arduino you may want to revisit this 1768 01:02:00,559 --> 01:02:04,240 video when we study pin mode function 1769 01:02:02,799 --> 01:02:05,839 it has been taught in arduino 1770 01:02:04,240 --> 01:02:06,480 programming section so generally 1771 01:02:05,839 --> 01:02:10,319 speaking 1772 01:02:06,480 --> 01:02:11,839 input is something which goes inside 1773 01:02:10,319 --> 01:02:13,599 an output is something which comes 1774 01:02:11,839 --> 01:02:16,000 outside 1775 01:02:13,599 --> 01:02:18,319 speaking technically input is some data 1776 01:02:16,000 --> 01:02:20,480 or signal which goes into the system 1777 01:02:18,319 --> 01:02:22,960 an output is some process information or 1778 01:02:20,480 --> 01:02:26,000 signal which comes out of that system 1779 01:02:22,960 --> 01:02:28,720 the system may be anything like in our 1780 01:02:26,000 --> 01:02:30,400 case the system would mostly be arduino 1781 01:02:28,720 --> 01:02:32,480 the sensors would be giving the data to 1782 01:02:30,400 --> 01:02:33,119 the arduino an arduino would act on that 1783 01:02:32,480 --> 01:02:35,200 data 1784 01:02:33,119 --> 01:02:36,720 and give an output based on how you have 1785 01:02:35,200 --> 01:02:38,640 programmed it 1786 01:02:36,720 --> 01:02:41,119 please bear in mind that input and 1787 01:02:38,640 --> 01:02:43,440 output is never absolute 1788 01:02:41,119 --> 01:02:45,280 it is always relative to something as 1789 01:02:43,440 --> 01:02:47,599 you may have been told in junior classes 1790 01:02:45,280 --> 01:02:49,839 that input and output devices are fixed 1791 01:02:47,599 --> 01:02:52,720 yes they are fixed but with the 1792 01:02:49,839 --> 01:02:54,720 reference to the computer 1793 01:02:52,720 --> 01:02:56,640 like a mouse is an input device to the 1794 01:02:54,720 --> 01:02:57,359 computer but if we look in the mouse 1795 01:02:56,640 --> 01:02:59,440 itself 1796 01:02:57,359 --> 01:03:00,559 there would be several more devices like 1797 01:02:59,440 --> 01:03:02,480 an optical reader 1798 01:03:00,559 --> 01:03:04,640 which takes the movement of the mouse as 1799 01:03:02,480 --> 01:03:07,520 input and gives its output 1800 01:03:04,640 --> 01:03:10,960 to the chip inside which processes it 1801 01:03:07,520 --> 01:03:12,720 and gives the cursor position as output 1802 01:03:10,960 --> 01:03:14,160 similarly we have been told that a 1803 01:03:12,720 --> 01:03:16,079 printer is an output device 1804 01:03:14,160 --> 01:03:18,000 yes it is certainly an output device but 1805 01:03:16,079 --> 01:03:19,520 with reference to the computer 1806 01:03:18,000 --> 01:03:21,119 now if we see in a printer as well there 1807 01:03:19,520 --> 01:03:22,880 is a main controller board which takes 1808 01:03:21,119 --> 01:03:25,119 the input signal which is coming out 1809 01:03:22,880 --> 01:03:26,960 from the computer and then that 1810 01:03:25,119 --> 01:03:29,520 controller takes the decision 1811 01:03:26,960 --> 01:03:31,200 that how to move the motors which colors 1812 01:03:29,520 --> 01:03:33,760 to select 1813 01:03:31,200 --> 01:03:36,640 in order to print the page i hope i am 1814 01:03:33,760 --> 01:03:39,119 making some sense to you 1815 01:03:36,640 --> 01:03:40,480 now if we see in reference to our course 1816 01:03:39,119 --> 01:03:42,480 there are lot many things 1817 01:03:40,480 --> 01:03:43,599 and sensors which act as input devices 1818 01:03:42,480 --> 01:03:45,440 for the arduino 1819 01:03:43,599 --> 01:03:48,720 like these sensors which you can see on 1820 01:03:45,440 --> 01:03:50,880 the screen but wait what are sensors 1821 01:03:48,720 --> 01:03:52,799 like humans have five senses which help 1822 01:03:50,880 --> 01:03:54,319 us get aware of our surroundings and act 1823 01:03:52,799 --> 01:03:56,720 accordingly 1824 01:03:54,319 --> 01:03:58,720 similarly in electronics sensors help 1825 01:03:56,720 --> 01:04:00,400 the controller to take decisions 1826 01:03:58,720 --> 01:04:02,480 and give output based on the 1827 01:04:00,400 --> 01:04:03,359 environmental data which is given by 1828 01:04:02,480 --> 01:04:05,200 them 1829 01:04:03,359 --> 01:04:06,559 sensors tell something to the controller 1830 01:04:05,200 --> 01:04:08,240 by changing its voltage 1831 01:04:06,559 --> 01:04:11,119 a change in voltage is read by the 1832 01:04:08,240 --> 01:04:13,039 controller like we see in this image 1833 01:04:11,119 --> 01:04:14,880 there is an autonomous car which has n 1834 01:04:13,039 --> 01:04:16,960 number of sensors placed on it which are 1835 01:04:14,880 --> 01:04:19,280 telling it about the other cars 1836 01:04:16,960 --> 01:04:21,520 battery level fuel level humidity level 1837 01:04:19,280 --> 01:04:23,359 etc 1838 01:04:21,520 --> 01:04:24,960 now i will briefly discuss about these 1839 01:04:23,359 --> 01:04:26,880 sensors which you see on the screen 1840 01:04:24,960 --> 01:04:28,880 we will also discuss these sensors in 1841 01:04:26,880 --> 01:04:30,799 detail when we use these particular 1842 01:04:28,880 --> 01:04:32,880 sensors first of all we see is a 1843 01:04:30,799 --> 01:04:34,720 rotatory potentiometer 1844 01:04:32,880 --> 01:04:36,400 this device would change the resistance 1845 01:04:34,720 --> 01:04:39,200 it offers if we rotate the knob 1846 01:04:36,400 --> 01:04:40,880 clockwise or anti-clockwise 1847 01:04:39,200 --> 01:04:42,559 then we have a momentary push button 1848 01:04:40,880 --> 01:04:44,000 switch when we press the switch it will 1849 01:04:42,559 --> 01:04:45,440 close the circuit when we 1850 01:04:44,000 --> 01:04:47,520 release the switch it will open the 1851 01:04:45,440 --> 01:04:48,720 circuit then we have a force sensing 1852 01:04:47,520 --> 01:04:50,640 resistor 1853 01:04:48,720 --> 01:04:54,480 this resistor changes its resistance 1854 01:04:50,640 --> 01:04:56,400 based on the force applied on it 1855 01:04:54,480 --> 01:04:58,960 then we have a light dependent resistor 1856 01:04:56,400 --> 01:05:02,319 this resistance change its resistance 1857 01:04:58,960 --> 01:05:04,799 based on the light falling on it then we 1858 01:05:02,319 --> 01:05:07,119 have a triple axis accelerometer 1859 01:05:04,799 --> 01:05:08,880 usually we see accelerometers in phones 1860 01:05:07,119 --> 01:05:10,400 and gaming devices 1861 01:05:08,880 --> 01:05:12,480 okay the basic purpose of the 1862 01:05:10,400 --> 01:05:13,200 accelerometer is to get the orientation 1863 01:05:12,480 --> 01:05:16,400 of the object 1864 01:05:13,200 --> 01:05:17,280 on which it is placed then we have a 1865 01:05:16,400 --> 01:05:19,440 joystick 1866 01:05:17,280 --> 01:05:21,200 joystick is nothing but a basic input 1867 01:05:19,440 --> 01:05:24,640 controller you must have seen it on 1868 01:05:21,200 --> 01:05:26,240 on the gaming consoles then we have a 1869 01:05:24,640 --> 01:05:28,160 microphone or a sound sensor 1870 01:05:26,240 --> 01:05:29,760 it will capture the environmental sound 1871 01:05:28,160 --> 01:05:31,599 and noises 1872 01:05:29,760 --> 01:05:34,400 we may want to record them or take some 1873 01:05:31,599 --> 01:05:36,400 decisions based on that 1874 01:05:34,400 --> 01:05:38,319 then we have a touch sensor it will just 1875 01:05:36,400 --> 01:05:40,480 see if someone is touching it or not 1876 01:05:38,319 --> 01:05:42,240 then we have a rotary encoder 1877 01:05:40,480 --> 01:05:44,160 this sensor senses the rotation 1878 01:05:42,240 --> 01:05:45,839 basically for example 1879 01:05:44,160 --> 01:05:47,839 you can attach this rotary encoder to a 1880 01:05:45,839 --> 01:05:49,599 motor shaft and we can see the 1881 01:05:47,839 --> 01:05:51,440 rotational speed of that motor 1882 01:05:49,599 --> 01:05:53,359 how many rotations it have taken or you 1883 01:05:51,440 --> 01:05:55,520 must have seen a rotary encoder in 1884 01:05:53,359 --> 01:05:57,280 our volume knobs in your music systems 1885 01:05:55,520 --> 01:05:57,839 and we have an ultrasonic distance 1886 01:05:57,280 --> 01:06:00,240 sensor 1887 01:05:57,839 --> 01:06:01,680 it uses ultrasonic waves like in a sonar 1888 01:06:00,240 --> 01:06:04,400 to tell the distance between 1889 01:06:01,680 --> 01:06:06,160 the sensor and the object in front of it 1890 01:06:04,400 --> 01:06:07,440 then we have a temperature sensor as the 1891 01:06:06,160 --> 01:06:08,960 name suggests it will tell the 1892 01:06:07,440 --> 01:06:10,480 temperature around it 1893 01:06:08,960 --> 01:06:12,880 we have a temperature and humidity 1894 01:06:10,480 --> 01:06:13,839 sensor it tells humidity as well along 1895 01:06:12,880 --> 01:06:16,640 with the temperature 1896 01:06:13,839 --> 01:06:19,119 then we have an infrared sensor this is 1897 01:06:16,640 --> 01:06:20,720 basically an obstacle detection sensor 1898 01:06:19,119 --> 01:06:23,200 it can tell if an object is there in 1899 01:06:20,720 --> 01:06:26,960 front of it or not 1900 01:06:23,200 --> 01:06:28,799 then we also have output devices 1901 01:06:26,960 --> 01:06:30,400 output devices are those devices that 1902 01:06:28,799 --> 01:06:32,079 can convert the output 1903 01:06:30,400 --> 01:06:33,599 given by the arduino to some human 1904 01:06:32,079 --> 01:06:35,839 readable form 1905 01:06:33,599 --> 01:06:37,920 right for example i'll tell you there is 1906 01:06:35,839 --> 01:06:39,200 an led which is known as light emitting 1907 01:06:37,920 --> 01:06:42,079 diode it will basically 1908 01:06:39,200 --> 01:06:43,440 just glow if any pin on arduino is set 1909 01:06:42,079 --> 01:06:46,079 to high 1910 01:06:43,440 --> 01:06:46,559 and we have an rgb led this is a special 1911 01:06:46,079 --> 01:06:48,960 led 1912 01:06:46,559 --> 01:06:50,880 it has all the colors uh red green and 1913 01:06:48,960 --> 01:06:53,119 blue leds and it can form 1914 01:06:50,880 --> 01:06:54,240 n number of colors and we have a buzzer 1915 01:06:53,119 --> 01:06:56,480 it will make some sound 1916 01:06:54,240 --> 01:06:57,839 if high voltage is given to it it will 1917 01:06:56,480 --> 01:06:58,960 make some sound then we have a 1918 01:06:57,839 --> 01:07:00,880 loudspeaker 1919 01:06:58,960 --> 01:07:02,799 like this general speaker which you have 1920 01:07:00,880 --> 01:07:03,599 seen in your mobiles and your laptops 1921 01:07:02,799 --> 01:07:06,720 which you know 1922 01:07:03,599 --> 01:07:08,319 you play music through and we have an 1923 01:07:06,720 --> 01:07:10,319 oled display 1924 01:07:08,319 --> 01:07:12,160 it is a full-fledged display you can 1925 01:07:10,319 --> 01:07:13,760 just click graphics on it we have lcd 1926 01:07:12,160 --> 01:07:14,400 display this is liquid crystal display 1927 01:07:13,760 --> 01:07:16,400 you can 1928 01:07:14,400 --> 01:07:18,319 display characters on it okay for 1929 01:07:16,400 --> 01:07:19,200 example some value of a sensor or 1930 01:07:18,319 --> 01:07:21,440 someone's name 1931 01:07:19,200 --> 01:07:22,559 etc the seven segment display consists 1932 01:07:21,440 --> 01:07:24,559 of seven leds 1933 01:07:22,559 --> 01:07:25,839 arranged in a rectangular fashion as 1934 01:07:24,559 --> 01:07:28,880 shown 1935 01:07:25,839 --> 01:07:30,799 it is used to display numbers on it 1936 01:07:28,880 --> 01:07:32,640 for example if we want to display seven 1937 01:07:30,799 --> 01:07:33,680 so we will highlight this one this one 1938 01:07:32,640 --> 01:07:35,520 and this one 1939 01:07:33,680 --> 01:07:37,039 so we will see that seven is appearing 1940 01:07:35,520 --> 01:07:40,079 if we want to show zero 1941 01:07:37,039 --> 01:07:42,319 then we will highlight these ones 1942 01:07:40,079 --> 01:07:44,079 okay and if you want to display eight we 1943 01:07:42,319 --> 01:07:46,640 will highlight all of them and it will 1944 01:07:44,079 --> 01:07:48,960 look like it is coming on we have a dot 1945 01:07:46,640 --> 01:07:52,079 matrix display dot matrix display is an 1946 01:07:48,960 --> 01:07:53,520 array of multiple leds okay we can show 1947 01:07:52,079 --> 01:07:55,200 even characters on it 1948 01:07:53,520 --> 01:07:56,880 you must have seen a dot matrix display 1949 01:07:55,200 --> 01:07:58,799 in delhi mid to display 1950 01:07:56,880 --> 01:08:01,280 or even you know scrolling displays you 1951 01:07:58,799 --> 01:08:04,480 must have seen in front of some shops 1952 01:08:01,280 --> 01:08:06,640 which display the shop's name so that is 1953 01:08:04,480 --> 01:08:08,160 a dot matrix display then we have a dc 1954 01:08:06,640 --> 01:08:10,240 motor it basically 1955 01:08:08,160 --> 01:08:12,160 moves clockwise or anti-clockwise if it 1956 01:08:10,240 --> 01:08:13,359 is given some voltage across it then we 1957 01:08:12,160 --> 01:08:15,119 have servo motor so 1958 01:08:13,359 --> 01:08:17,600 this is a special kind of motor we can 1959 01:08:15,119 --> 01:08:19,759 stop it at specific angles then we have 1960 01:08:17,600 --> 01:08:21,120 a stepper motor a stepper motor is just 1961 01:08:19,759 --> 01:08:23,359 like a dc motor 1962 01:08:21,120 --> 01:08:25,600 but you know the entire rotation is 1963 01:08:23,359 --> 01:08:27,920 divided into equal steps 1964 01:08:25,600 --> 01:08:29,120 so like servo motor we can also stop it 1965 01:08:27,920 --> 01:08:30,960 at specific angles and 1966 01:08:29,120 --> 01:08:32,799 even lift heavier loads we can drive 1967 01:08:30,960 --> 01:08:34,480 heavier loads using a stepper motor so 1968 01:08:32,799 --> 01:08:34,799 to conclude this video i would like to 1969 01:08:34,480 --> 01:08:36,480 say 1970 01:08:34,799 --> 01:08:39,279 since we know about input and output 1971 01:08:36,480 --> 01:08:40,960 properly now we can easily understand 1972 01:08:39,279 --> 01:08:42,719 how arduino interacts with the 1973 01:08:40,960 --> 01:08:44,719 environment and we can make some 1974 01:08:42,719 --> 01:08:47,199 meaningful projects after knowing this 1975 01:08:44,719 --> 01:08:49,199 see you in the next video in this video 1976 01:08:47,199 --> 01:08:50,239 we will talk about analog and digital so 1977 01:08:49,199 --> 01:08:52,000 to begin with 1978 01:08:50,239 --> 01:08:54,000 i would like to tell you that our world 1979 01:08:52,000 --> 01:08:56,000 is full of analog information 1980 01:08:54,000 --> 01:08:57,920 like the colors we see fragrances we 1981 01:08:56,000 --> 01:09:00,560 smell flavors we taste 1982 01:08:57,920 --> 01:09:01,120 sounds we hear temperature we feel all 1983 01:09:00,560 --> 01:09:03,440 these 1984 01:09:01,120 --> 01:09:04,880 have just endless number of values there 1985 01:09:03,440 --> 01:09:07,679 can be millions of colors 1986 01:09:04,880 --> 01:09:09,040 smells flavors sounds etc this was in a 1987 01:09:07,679 --> 01:09:10,400 very general sense 1988 01:09:09,040 --> 01:09:12,640 now if we see in the terms of 1989 01:09:10,400 --> 01:09:15,359 electronics something which is analog 1990 01:09:12,640 --> 01:09:17,199 can have infinite number of values let's 1991 01:09:15,359 --> 01:09:18,960 say your wall clock 1992 01:09:17,199 --> 01:09:20,400 it can show endless number of time 1993 01:09:18,960 --> 01:09:22,480 intervals though 1994 01:09:20,400 --> 01:09:23,759 they are not marked on it but yet it 1995 01:09:22,480 --> 01:09:25,600 holds the capability 1996 01:09:23,759 --> 01:09:27,600 to tell you even smaller fractions of 1997 01:09:25,600 --> 01:09:29,440 time while digital is something 1998 01:09:27,600 --> 01:09:32,080 with discrete or limited number of 1999 01:09:29,440 --> 01:09:34,239 values like a digital clock 2000 01:09:32,080 --> 01:09:36,080 that clock can show you limited number 2001 01:09:34,239 --> 01:09:39,199 of digits let's say it's 2 pm 2002 01:09:36,080 --> 01:09:40,319 or 10 minutes past 2 pm depending on the 2003 01:09:39,199 --> 01:09:42,480 precision of that clock 2004 01:09:40,319 --> 01:09:43,520 it may still show you seconds but it is 2005 01:09:42,480 --> 01:09:45,520 still limited to 2006 01:09:43,520 --> 01:09:47,600 some values only so before we move 2007 01:09:45,520 --> 01:09:48,319 further we also need to understand one 2008 01:09:47,600 --> 01:09:50,400 more term 2009 01:09:48,319 --> 01:09:52,319 called as signal signals are used to 2010 01:09:50,400 --> 01:09:54,800 convey some information to someone 2011 01:09:52,319 --> 01:09:56,080 like these road signs are passing on 2012 01:09:54,800 --> 01:09:57,840 some information to us 2013 01:09:56,080 --> 01:09:59,520 like that we need to stop or we cannot 2014 01:09:57,840 --> 01:10:01,679 park here etc 2015 01:09:59,520 --> 01:10:03,440 similarly when we speak we generate a 2016 01:10:01,679 --> 01:10:05,120 signal and that signal contains the 2017 01:10:03,440 --> 01:10:06,159 information which we want to pass on to 2018 01:10:05,120 --> 01:10:07,440 the listener 2019 01:10:06,159 --> 01:10:09,120 like i'm speaking right now i'm 2020 01:10:07,440 --> 01:10:10,560 generating an audio signal which you can 2021 01:10:09,120 --> 01:10:12,159 see on this screen 2022 01:10:10,560 --> 01:10:13,920 this is the audio signal which i have 2023 01:10:12,159 --> 01:10:17,840 generated with my 2024 01:10:13,920 --> 01:10:17,840 voice okay 2025 01:10:18,000 --> 01:10:22,000 so this signal passes through my mouth 2026 01:10:20,239 --> 01:10:24,800 through air and to your ear 2027 01:10:22,000 --> 01:10:27,120 and you make some sense out of it okay 2028 01:10:24,800 --> 01:10:28,880 this audio signal is analog in nature 2029 01:10:27,120 --> 01:10:30,320 because there are infinite number of 2030 01:10:28,880 --> 01:10:33,440 values which are changing 2031 01:10:30,320 --> 01:10:35,679 okay in electronics signals are some 2032 01:10:33,440 --> 01:10:37,280 time varying quantities which convey 2033 01:10:35,679 --> 01:10:39,600 some sort of information 2034 01:10:37,280 --> 01:10:40,719 usually that time varying quantity is 2035 01:10:39,600 --> 01:10:44,239 voltage 2036 01:10:40,719 --> 01:10:47,360 that means with time the voltage changes 2037 01:10:44,239 --> 01:10:49,760 okay or sometimes it is also current 2038 01:10:47,360 --> 01:10:51,440 but usually it is voltage then those 2039 01:10:49,760 --> 01:10:53,280 time varying signals are passed between 2040 01:10:51,440 --> 01:10:53,920 the devices in order to send and receive 2041 01:10:53,280 --> 01:10:56,320 information 2042 01:10:53,920 --> 01:10:57,679 which might be video audio or some sort 2043 01:10:56,320 --> 01:10:59,920 of encoded data 2044 01:10:57,679 --> 01:11:02,000 usually signals are transmitted through 2045 01:10:59,920 --> 01:11:02,400 wires but they can also be passed 2046 01:11:02,000 --> 01:11:04,880 through 2047 01:11:02,400 --> 01:11:06,960 air wirelessly okay so there is an 2048 01:11:04,880 --> 01:11:09,199 entire field of study 2049 01:11:06,960 --> 01:11:10,800 which is based just on signals like 2050 01:11:09,199 --> 01:11:12,640 digital signal processing 2051 01:11:10,800 --> 01:11:15,520 signals and systems there are some 2052 01:11:12,640 --> 01:11:17,520 entire subjects based on signals only 2053 01:11:15,520 --> 01:11:18,880 okay but for the scope of this course we 2054 01:11:17,520 --> 01:11:19,600 will just tell you the required 2055 01:11:18,880 --> 01:11:22,000 information 2056 01:11:19,600 --> 01:11:23,840 so now there are two types of signals 2057 01:11:22,000 --> 01:11:26,320 one is analog signal and one is 2058 01:11:23,840 --> 01:11:28,560 digital signal like we just saw that our 2059 01:11:26,320 --> 01:11:30,320 sound is a type of analog signal 2060 01:11:28,560 --> 01:11:32,080 similarly there can be other analog 2061 01:11:30,320 --> 01:11:34,080 signals as well 2062 01:11:32,080 --> 01:11:36,239 typically an analog signal would look 2063 01:11:34,080 --> 01:11:38,560 like this that means we have plotted 2064 01:11:36,239 --> 01:11:40,000 time on the x-axis and voltage on the 2065 01:11:38,560 --> 01:11:41,199 y-axis so with time 2066 01:11:40,000 --> 01:11:43,760 the voltage is increasing then 2067 01:11:41,199 --> 01:11:46,400 decreasing then going into negative part 2068 01:11:43,760 --> 01:11:48,560 then increasing this is an analog signal 2069 01:11:46,400 --> 01:11:51,280 it is not necessary that it stays 2070 01:11:48,560 --> 01:11:51,760 this smooth it can be little messy as 2071 01:11:51,280 --> 01:11:54,960 well 2072 01:11:51,760 --> 01:11:57,360 like this this is also an analog signal 2073 01:11:54,960 --> 01:11:58,560 okay and then there is a digital signal 2074 01:11:57,360 --> 01:12:00,400 in digital signals 2075 01:11:58,560 --> 01:12:02,400 there are only two discrete values 2076 01:12:00,400 --> 01:12:05,040 either it is on or either it is 2077 01:12:02,400 --> 01:12:06,960 off where 5 volts represents on and 0 2078 01:12:05,040 --> 01:12:09,920 volts represent off so you can see 2079 01:12:06,960 --> 01:12:10,239 with time here it is on it is off on off 2080 01:12:09,920 --> 01:12:14,159 on 2081 01:12:10,239 --> 01:12:15,840 off on and off right now the sensors 2082 01:12:14,159 --> 01:12:17,199 and the sensors which we use in our 2083 01:12:15,840 --> 01:12:20,080 course will either give 2084 01:12:17,199 --> 01:12:22,000 analog signal or either digital signal 2085 01:12:20,080 --> 01:12:24,560 and we have to use arduino to read 2086 01:12:22,000 --> 01:12:25,199 those signals okay we will see an 2087 01:12:24,560 --> 01:12:27,040 example 2088 01:12:25,199 --> 01:12:28,239 let's say we have a gaming console here 2089 01:12:27,040 --> 01:12:30,480 this is the joystick 2090 01:12:28,239 --> 01:12:32,159 this is a device which would give some 2091 01:12:30,480 --> 01:12:34,080 analog signal 2092 01:12:32,159 --> 01:12:35,760 and these are the buttons and these 2093 01:12:34,080 --> 01:12:37,520 devices will give some digital 2094 01:12:35,760 --> 01:12:39,040 information so this game machine can be 2095 01:12:37,520 --> 01:12:41,280 programmed to read this 2096 01:12:39,040 --> 01:12:42,960 state of the joystick for example we can 2097 01:12:41,280 --> 01:12:45,040 make a character move 2098 01:12:42,960 --> 01:12:46,960 forward when the joystick is moved 2099 01:12:45,040 --> 01:12:49,040 forward we can also control the moving 2100 01:12:46,960 --> 01:12:50,880 speed of that character for example 2101 01:12:49,040 --> 01:12:52,400 if we make the joystick move a little 2102 01:12:50,880 --> 01:12:54,480 forward then it will move slow 2103 01:12:52,400 --> 01:12:56,320 and if we move it a little more ahead 2104 01:12:54,480 --> 01:12:58,320 then it will move faster 2105 01:12:56,320 --> 01:13:00,000 but this cannot be the case with the 2106 01:12:58,320 --> 01:13:00,400 digital button we can just press the 2107 01:13:00,000 --> 01:13:01,840 switch 2108 01:13:00,400 --> 01:13:03,679 and tell the character to move forward 2109 01:13:01,840 --> 01:13:04,080 we cannot decide the speed we can only 2110 01:13:03,679 --> 01:13:06,000 set 2111 01:13:04,080 --> 01:13:07,199 one speed there or we can program it to 2112 01:13:06,000 --> 01:13:09,440 move forward 2113 01:13:07,199 --> 01:13:10,560 fast based on some time okay but we 2114 01:13:09,440 --> 01:13:12,640 cannot input 2115 01:13:10,560 --> 01:13:14,000 the speed through buttons right so this 2116 01:13:12,640 --> 01:13:16,640 joystick is sending some 2117 01:13:14,000 --> 01:13:18,159 analog signal into the computer or the 2118 01:13:16,640 --> 01:13:19,760 controller which is placed inside this 2119 01:13:18,159 --> 01:13:21,679 gaming machine and these buttons 2120 01:13:19,760 --> 01:13:24,320 are sending some digital information 2121 01:13:21,679 --> 01:13:26,960 like either they are pressed or not 2122 01:13:24,320 --> 01:13:27,920 they are on or off okay but this is a 2123 01:13:26,960 --> 01:13:30,480 digital signal 2124 01:13:27,920 --> 01:13:32,239 i'll give you one more example we have 2125 01:13:30,480 --> 01:13:35,280 potentiometer here 2126 01:13:32,239 --> 01:13:36,880 and we can move it as a knob 2127 01:13:35,280 --> 01:13:39,360 and we have infinite number of values 2128 01:13:36,880 --> 01:13:40,480 here we have a switch which is either on 2129 01:13:39,360 --> 01:13:42,080 or off 2130 01:13:40,480 --> 01:13:43,520 this represents analog and this 2131 01:13:42,080 --> 01:13:45,920 represents digital 2132 01:13:43,520 --> 01:13:47,199 so whenever we use analog sensor or 2133 01:13:45,920 --> 01:13:49,840 component we will use 2134 01:13:47,199 --> 01:13:50,719 analog pins of the arduino and we use 2135 01:13:49,840 --> 01:13:53,199 digital pins 2136 01:13:50,719 --> 01:13:55,040 for digital sensors or components okay i 2137 01:13:53,199 --> 01:13:56,960 have given more insights on this topic 2138 01:13:55,040 --> 01:13:58,719 in analog read and digital read video in 2139 01:13:56,960 --> 01:14:00,000 programming section once you reach there 2140 01:13:58,719 --> 01:14:01,760 and watch those videos as well 2141 01:14:00,000 --> 01:14:03,360 it will be crystal clear to you and if 2142 01:14:01,760 --> 01:14:04,480 not you can just comment down below or 2143 01:14:03,360 --> 01:14:06,719 send us a message 2144 01:14:04,480 --> 01:14:08,239 in this video we will talk about bit and 2145 01:14:06,719 --> 01:14:10,960 buy so basically what is 2146 01:14:08,239 --> 01:14:12,880 bit bit is the smallest storage or 2147 01:14:10,960 --> 01:14:13,679 memory size which can store a value of 2148 01:14:12,880 --> 01:14:16,400 either zero 2149 01:14:13,679 --> 01:14:17,280 or either one this box represents a bit 2150 01:14:16,400 --> 01:14:19,520 here 2151 01:14:17,280 --> 01:14:20,880 okay similarly if eight bits are 2152 01:14:19,520 --> 01:14:23,520 combined then it forms 2153 01:14:20,880 --> 01:14:24,320 a byte okay so we can say eight bits is 2154 01:14:23,520 --> 01:14:27,520 equal to 2155 01:14:24,320 --> 01:14:30,480 one byte so one byte can store zero 2156 01:14:27,520 --> 01:14:31,600 as the smallest number why because in 2157 01:14:30,480 --> 01:14:34,080 that case 2158 01:14:31,600 --> 01:14:34,640 all the eight boxes or all the eight 2159 01:14:34,080 --> 01:14:37,600 bits 2160 01:14:34,640 --> 01:14:38,880 are holding zero inside it as i told you 2161 01:14:37,600 --> 01:14:42,640 it can either store zero 2162 01:14:38,880 --> 01:14:45,280 or one okay so each box 2163 01:14:42,640 --> 01:14:46,239 has a multiplier and we take the value 2164 01:14:45,280 --> 01:14:49,760 from this box 2165 01:14:46,239 --> 01:14:52,000 and we multiply it with this box okay 2166 01:14:49,760 --> 01:14:53,440 and calculate the value here and in the 2167 01:14:52,000 --> 01:14:56,400 end we take sum of 2168 01:14:53,440 --> 01:14:58,159 all the values so here what will happen 2169 01:14:56,400 --> 01:15:01,679 0 multiplied by 2 to the power 2170 01:14:58,159 --> 01:15:04,640 0 2 to the power 0 is 1 0 into 0 is 0 2171 01:15:01,679 --> 01:15:06,239 0 into this is 0 0 into anything is 0 2172 01:15:04,640 --> 01:15:08,800 similarly in all the boxes 2173 01:15:06,239 --> 01:15:09,360 we'll get 0 so hence the smallest value 2174 01:15:08,800 --> 01:15:12,800 will be 2175 01:15:09,360 --> 01:15:16,159 0 and when will be the maximum value 2176 01:15:12,800 --> 01:15:16,880 if all the boxes are 1 right so here we 2177 01:15:16,159 --> 01:15:20,000 will get 2178 01:15:16,880 --> 01:15:22,800 1 into 2 to the power 0 that is 1 2179 01:15:20,000 --> 01:15:23,120 and 2 to the power 1 is 2 here we'll get 2180 01:15:22,800 --> 01:15:25,600 2 2181 01:15:23,120 --> 01:15:26,480 here we will get 4 here we will get 8 2182 01:15:25,600 --> 01:15:30,400 here it will be 2183 01:15:26,480 --> 01:15:32,239 16 here it will be 32 64 and 128 2184 01:15:30,400 --> 01:15:33,840 now if you take a sum of all these value 2185 01:15:32,239 --> 01:15:34,159 you can calculate it on your own we will 2186 01:15:33,840 --> 01:15:36,960 get 2187 01:15:34,159 --> 01:15:38,880 255. now in case if we want to store a 2188 01:15:36,960 --> 01:15:40,960 value greater than 255 2189 01:15:38,880 --> 01:15:42,320 so now in that case we will have to take 2190 01:15:40,960 --> 01:15:45,600 one more bit 2191 01:15:42,320 --> 01:15:49,600 aside this so it will become 9 bit 2192 01:15:45,600 --> 01:15:51,120 so the 9 bits can store 511 values 2193 01:15:49,600 --> 01:15:52,960 and what if we have to store a bigger 2194 01:15:51,120 --> 01:15:54,640 number than that then we will add 2195 01:15:52,960 --> 01:15:57,040 another bit here as well and it will 2196 01:15:54,640 --> 01:15:57,760 become 10 bits so 10 bits will be able 2197 01:15:57,040 --> 01:16:00,320 to store 2198 01:15:57,760 --> 01:16:01,360 a value till 1 0 2 3. so now what you 2199 01:16:00,320 --> 01:16:02,719 have to keep in mind is 2200 01:16:01,360 --> 01:16:05,440 you will be needing this information 2201 01:16:02,719 --> 01:16:06,239 whenever i say 8 bits 10 bits 12 bits in 2202 01:16:05,440 --> 01:16:07,920 the course 2203 01:16:06,239 --> 01:16:09,760 so we can only store values up to the 2204 01:16:07,920 --> 01:16:11,360 upper limit of that space 2205 01:16:09,760 --> 01:16:12,880 okay so this information will be 2206 01:16:11,360 --> 01:16:13,679 sufficient for you to carry on the 2207 01:16:12,880 --> 01:16:15,600 course 2208 01:16:13,679 --> 01:16:17,440 but yeah if you want to know more about 2209 01:16:15,600 --> 01:16:19,280 binary math you can just google 2210 01:16:17,440 --> 01:16:20,960 binary maths and you will get really 2211 01:16:19,280 --> 01:16:21,679 good links from wikipedia and other 2212 01:16:20,960 --> 01:16:23,280 websites 2213 01:16:21,679 --> 01:16:24,719 and you can just read them if you face 2214 01:16:23,280 --> 01:16:25,199 any problem you can always comment down 2215 01:16:24,719 --> 01:16:27,199 below 2216 01:16:25,199 --> 01:16:29,040 and we will get back to you in this 2217 01:16:27,199 --> 01:16:30,800 section i would cover all the essential 2218 01:16:29,040 --> 01:16:32,840 programming concepts that you would need 2219 01:16:30,800 --> 01:16:34,800 to get working and make projects with 2220 01:16:32,840 --> 01:16:36,560 arduino i would like to tell you that 2221 01:16:34,800 --> 01:16:38,320 programming is a game of practice 2222 01:16:36,560 --> 01:16:40,239 the more you practice the more you get 2223 01:16:38,320 --> 01:16:42,159 better at that so i would cover all the 2224 01:16:40,239 --> 01:16:43,840 essential topics to get you started and 2225 01:16:42,159 --> 01:16:45,040 i will also tell you about concepts as 2226 01:16:43,840 --> 01:16:46,880 we progress ahead 2227 01:16:45,040 --> 01:16:48,400 so let's get started before we know 2228 01:16:46,880 --> 01:16:50,080 about arduino programming we need to 2229 01:16:48,400 --> 01:16:51,600 understand what programming is 2230 01:16:50,080 --> 01:16:53,679 programming is something which we do to 2231 01:16:51,600 --> 01:16:54,719 tell a computer or a controller what to 2232 01:16:53,679 --> 01:16:56,400 do 2233 01:16:54,719 --> 01:16:58,159 computers don't understand the language 2234 01:16:56,400 --> 01:16:58,880 which humans use to communicate with 2235 01:16:58,159 --> 01:17:01,040 each other 2236 01:16:58,880 --> 01:17:03,360 computers only understand the zeros and 2237 01:17:01,040 --> 01:17:05,280 ones so by programming we tell it 2238 01:17:03,360 --> 01:17:07,520 what to do in our language and a 2239 01:17:05,280 --> 01:17:08,880 compiler or an interpreter converts that 2240 01:17:07,520 --> 01:17:09,679 into a language which computer 2241 01:17:08,880 --> 01:17:12,080 understands 2242 01:17:09,679 --> 01:17:13,600 and the computer finally acts on it so 2243 01:17:12,080 --> 01:17:14,400 there are many programming languages 2244 01:17:13,600 --> 01:17:17,679 over there 2245 01:17:14,400 --> 01:17:20,239 like c c plus plus c sharp python java 2246 01:17:17,679 --> 01:17:21,840 etc all of them have their own benefits 2247 01:17:20,239 --> 01:17:23,679 and drawback the language which we use 2248 01:17:21,840 --> 01:17:24,080 to program the arduino is a mixture of c 2249 01:17:23,679 --> 01:17:26,320 and c 2250 01:17:24,080 --> 01:17:27,120 plus plus which arduino makers call as 2251 01:17:26,320 --> 01:17:28,880 wiring 2252 01:17:27,120 --> 01:17:30,640 the best part of this arduino language 2253 01:17:28,880 --> 01:17:31,360 is that it is uniform across all 2254 01:17:30,640 --> 01:17:33,360 platforms 2255 01:17:31,360 --> 01:17:35,520 that means it won't matter if you use 2256 01:17:33,360 --> 01:17:37,360 windows mac or linux the output of the 2257 01:17:35,520 --> 01:17:39,040 code would be the same 2258 01:17:37,360 --> 01:17:40,719 so in the next video we will start to 2259 01:17:39,040 --> 01:17:41,679 look at arduino programming in a bit 2260 01:17:40,719 --> 01:17:43,840 more detail 2261 01:17:41,679 --> 01:17:45,199 so let's start by opening up our arduino 2262 01:17:43,840 --> 01:17:48,239 ide 2263 01:17:45,199 --> 01:17:52,080 once it opens you would see this window 2264 01:17:48,239 --> 01:17:53,920 all right and we see void setup and void 2265 01:17:52,080 --> 01:17:55,520 loop is written over here 2266 01:17:53,920 --> 01:17:57,760 let's discuss whatever we see on the 2267 01:17:55,520 --> 01:18:01,280 screen the first line which we see is 2268 01:17:57,760 --> 01:18:04,480 white setup right it says void 2269 01:18:01,280 --> 01:18:06,800 then setup then a pair of brackets 2270 01:18:04,480 --> 01:18:08,640 then a curly bracket then we have two 2271 01:18:06,800 --> 01:18:10,480 forward slashes then it says put your 2272 01:18:08,640 --> 01:18:12,560 setup code here to run once 2273 01:18:10,480 --> 01:18:14,239 and then we have another curly bracket 2274 01:18:12,560 --> 01:18:16,159 so what we have done here is 2275 01:18:14,239 --> 01:18:17,280 we have declared a mandatory function 2276 01:18:16,159 --> 01:18:19,199 known as setup 2277 01:18:17,280 --> 01:18:21,520 and this is how you declare functions in 2278 01:18:19,199 --> 01:18:22,880 arduino then we have a curly bracket in 2279 01:18:21,520 --> 01:18:24,880 most programming languages 2280 01:18:22,880 --> 01:18:26,960 these curly brackets indicate a block of 2281 01:18:24,880 --> 01:18:28,000 code this left curly bracket means the 2282 01:18:26,960 --> 01:18:30,000 start of the block 2283 01:18:28,000 --> 01:18:31,040 and this right bracket shows the end of 2284 01:18:30,000 --> 01:18:32,960 the block 2285 01:18:31,040 --> 01:18:34,719 whatever code which goes inside this 2286 01:18:32,960 --> 01:18:36,640 block belongs to this function 2287 01:18:34,719 --> 01:18:37,760 the arduino id would help you recognize 2288 01:18:36,640 --> 01:18:39,760 the blocks of codes 2289 01:18:37,760 --> 01:18:41,120 when you click on these brackets for 2290 01:18:39,760 --> 01:18:42,800 example when you click here 2291 01:18:41,120 --> 01:18:44,239 it would highlight this bracket 2292 01:18:42,800 --> 01:18:45,679 automatically that means 2293 01:18:44,239 --> 01:18:47,360 this is the start of your function and 2294 01:18:45,679 --> 01:18:48,560 this is the end of your function 2295 01:18:47,360 --> 01:18:51,120 whenever you click here then it would 2296 01:18:48,560 --> 01:18:54,239 highlight the ending can you see that 2297 01:18:51,120 --> 01:18:54,800 all right then we see these two forward 2298 01:18:54,239 --> 01:18:56,960 slashes 2299 01:18:54,800 --> 01:18:58,640 these forward slashes mean a single line 2300 01:18:56,960 --> 01:19:00,640 command whenever we write a comment 2301 01:18:58,640 --> 01:19:01,760 compiler entirely ignores whatever is 2302 01:19:00,640 --> 01:19:04,000 written after that 2303 01:19:01,760 --> 01:19:05,440 so coming back to void setup this 2304 01:19:04,000 --> 01:19:07,040 mandatory function contains 2305 01:19:05,440 --> 01:19:09,360 all the lines of code which we want 2306 01:19:07,040 --> 01:19:11,040 arduino to run once when it is turned on 2307 01:19:09,360 --> 01:19:12,400 or when we press reset button 2308 01:19:11,040 --> 01:19:14,640 we'll talk more on this in coming 2309 01:19:12,400 --> 01:19:16,480 lectures similarly there is void loop 2310 01:19:14,640 --> 01:19:18,000 in this section we write all the code 2311 01:19:16,480 --> 01:19:20,960 which we want arduino to run 2312 01:19:18,000 --> 01:19:22,719 all the time repeatedly that means 2313 01:19:20,960 --> 01:19:24,800 whatever is written in this section 2314 01:19:22,719 --> 01:19:25,760 would run until the arduino is switched 2315 01:19:24,800 --> 01:19:27,840 off the void loop 2316 01:19:25,760 --> 01:19:29,679 runs after void setup so in the next 2317 01:19:27,840 --> 01:19:30,239 lecture we would see the blink led 2318 01:19:29,679 --> 01:19:32,159 example 2319 01:19:30,239 --> 01:19:34,080 which we used to test our arduino in a 2320 01:19:32,159 --> 01:19:35,440 little more detail we will understand 2321 01:19:34,080 --> 01:19:38,080 each part of that code 2322 01:19:35,440 --> 01:19:39,760 so see you in the next lecture so till 2323 01:19:38,080 --> 01:19:42,159 now we have understood that the two 2324 01:19:39,760 --> 01:19:44,159 functions void setup and void loop 2325 01:19:42,159 --> 01:19:45,280 are the bare minimum requirement to run 2326 01:19:44,159 --> 01:19:46,960 our code successfully 2327 01:19:45,280 --> 01:19:48,960 why are they mandatory i will just show 2328 01:19:46,960 --> 01:19:50,080 you in a moment i am removing these 2329 01:19:48,960 --> 01:19:52,960 functions 2330 01:19:50,080 --> 01:19:55,120 and i'm hitting compile the compiler has 2331 01:19:52,960 --> 01:19:56,880 passed us with errors 2332 01:19:55,120 --> 01:19:59,040 just read them undefined reference to 2333 01:19:56,880 --> 01:20:00,880 set up undefined reference to loop 2334 01:19:59,040 --> 01:20:02,880 that means it is expecting that we must 2335 01:20:00,880 --> 01:20:05,120 define these functions now i will 2336 01:20:02,880 --> 01:20:06,880 bring back these functions now i'll hit 2337 01:20:05,120 --> 01:20:08,480 compile once again 2338 01:20:06,880 --> 01:20:10,239 now the compiler has successfully 2339 01:20:08,480 --> 01:20:12,080 compiled the code so with that we can 2340 01:20:10,239 --> 01:20:13,920 say arduino ids compiler 2341 01:20:12,080 --> 01:20:15,520 expects these two functions like some 2342 01:20:13,920 --> 01:20:16,480 other programming languages expect the 2343 01:20:15,520 --> 01:20:18,800 main function 2344 01:20:16,480 --> 01:20:20,800 without that we won't be able to run the 2345 01:20:18,800 --> 01:20:22,639 code we would get an error as you saw so 2346 01:20:20,800 --> 01:20:24,080 now we will see some more concepts in 2347 01:20:22,639 --> 01:20:27,360 the blink led experiment 2348 01:20:24,080 --> 01:20:32,320 so for that we'll go to files 2349 01:20:27,360 --> 01:20:34,159 examples basics and then blink 2350 01:20:32,320 --> 01:20:36,159 all right so this is our blink example 2351 01:20:34,159 --> 01:20:38,239 this is that same code which you used 2352 01:20:36,159 --> 01:20:39,679 to test your arduino so we see a huge 2353 01:20:38,239 --> 01:20:42,080 chunk of lines here 2354 01:20:39,679 --> 01:20:43,760 this is a block of multi-line comments 2355 01:20:42,080 --> 01:20:45,360 like we saw a single line comment in the 2356 01:20:43,760 --> 01:20:47,280 previous video we start a multi-line 2357 01:20:45,360 --> 01:20:48,080 comment by a forward slash followed by a 2358 01:20:47,280 --> 01:20:50,080 star 2359 01:20:48,080 --> 01:20:51,520 and then we write whatever we want and 2360 01:20:50,080 --> 01:20:53,520 then we end it 2361 01:20:51,520 --> 01:20:54,960 by a star followed by a forward slash so 2362 01:20:53,520 --> 01:20:56,960 anything which is written in between is 2363 01:20:54,960 --> 01:20:58,880 ignored by the compiler you may ask then 2364 01:20:56,960 --> 01:21:00,719 why do we write comment the answer is 2365 01:20:58,880 --> 01:21:02,320 the comments help us to document the 2366 01:21:00,719 --> 01:21:04,080 code and they also help the other 2367 01:21:02,320 --> 01:21:05,440 readers of the code to understand what 2368 01:21:04,080 --> 01:21:07,520 is done by the author of the code 2369 01:21:05,440 --> 01:21:09,760 comments also help the author himself 2370 01:21:07,520 --> 01:21:11,120 to recall what he did when he sees his 2371 01:21:09,760 --> 01:21:12,800 code at the latest date 2372 01:21:11,120 --> 01:21:14,960 since comments are totally ignored by 2373 01:21:12,800 --> 01:21:15,760 the compiler not writing them won't make 2374 01:21:14,960 --> 01:21:18,880 any difference 2375 01:21:15,760 --> 01:21:20,880 for example if i remove this comment 2376 01:21:18,880 --> 01:21:23,120 and compile the code it will still 2377 01:21:20,880 --> 01:21:24,159 compile and with the comments also it 2378 01:21:23,120 --> 01:21:26,080 will run just like that 2379 01:21:24,159 --> 01:21:27,679 since these comments don't serve any 2380 01:21:26,080 --> 01:21:30,159 technical purpose in the code 2381 01:21:27,679 --> 01:21:32,320 most developers develop a habit of not 2382 01:21:30,159 --> 01:21:34,480 writing that comment which is certainly 2383 01:21:32,320 --> 01:21:36,000 not a good practice it is always advised 2384 01:21:34,480 --> 01:21:37,679 to write comments for the reasons which 2385 01:21:36,000 --> 01:21:39,440 i have already told so now 2386 01:21:37,679 --> 01:21:41,360 i will tell you about the white spaces 2387 01:21:39,440 --> 01:21:42,639 and case sensitivity the spaces which 2388 01:21:41,360 --> 01:21:46,239 you see here 2389 01:21:42,639 --> 01:21:48,880 here here etc like here 2390 01:21:46,239 --> 01:21:50,719 here won't make any difference as the 2391 01:21:48,880 --> 01:21:52,800 compiler would ignore them like the 2392 01:21:50,719 --> 01:21:56,000 comments now what i mean to say by this 2393 01:21:52,800 --> 01:21:59,440 is that we can add as many spaces 2394 01:21:56,000 --> 01:22:02,000 as we want wherever we want 2395 01:21:59,440 --> 01:22:03,360 and the compiler won't say anything to 2396 01:22:02,000 --> 01:22:05,199 us 2397 01:22:03,360 --> 01:22:07,120 it will still successfully compile the 2398 01:22:05,199 --> 01:22:10,000 code 2399 01:22:07,120 --> 01:22:12,880 like this all right but what we can't do 2400 01:22:10,000 --> 01:22:14,719 is we can't add spaces in between 2401 01:22:12,880 --> 01:22:16,560 like this otherwise you will get an 2402 01:22:14,719 --> 01:22:18,159 error if you compile now 2403 01:22:16,560 --> 01:22:19,920 just see that how many errors we have 2404 01:22:18,159 --> 01:22:21,920 got so now you will ask what's the 2405 01:22:19,920 --> 01:22:22,880 purpose of white spaces white spaces 2406 01:22:21,920 --> 01:22:25,280 basically help us 2407 01:22:22,880 --> 01:22:27,440 indent the code it makes it easier for 2408 01:22:25,280 --> 01:22:29,679 us to identify the blocks of code 2409 01:22:27,440 --> 01:22:31,199 it also makes the code look beautiful 2410 01:22:29,679 --> 01:22:34,719 for example 2411 01:22:31,199 --> 01:22:34,719 if i write something like this 2412 01:22:36,400 --> 01:22:41,840 what do you think this code looks better 2413 01:22:39,440 --> 01:22:43,120 or this code looks better obviously this 2414 01:22:41,840 --> 01:22:45,679 one 2415 01:22:43,120 --> 01:22:46,400 all right so proper indentation is 2416 01:22:45,679 --> 01:22:48,719 important 2417 01:22:46,400 --> 01:22:50,480 now coming to case sensitivity arduino 2418 01:22:48,719 --> 01:22:51,280 language is case sensitive what i mean 2419 01:22:50,480 --> 01:22:53,120 by that is 2420 01:22:51,280 --> 01:22:54,639 the small character would come as small 2421 01:22:53,120 --> 01:22:55,360 and the capital character would come as 2422 01:22:54,639 --> 01:22:57,440 capital 2423 01:22:55,360 --> 01:23:00,159 you can't interchange that for example 2424 01:22:57,440 --> 01:23:03,920 this void cannot be written as 2425 01:23:00,159 --> 01:23:06,320 this it will give an error 2426 01:23:03,920 --> 01:23:08,239 white does not name a type right in this 2427 01:23:06,320 --> 01:23:12,159 pin mode you see we cannot write 2428 01:23:08,239 --> 01:23:16,159 pin mode as the spin mode 2429 01:23:12,159 --> 01:23:16,159 right then also it will give an error 2430 01:23:17,280 --> 01:23:21,040 so same goes for everything what you see 2431 01:23:19,280 --> 01:23:25,199 here like this high 2432 01:23:21,040 --> 01:23:25,199 cannot be written as high 2433 01:23:26,080 --> 01:23:30,239 or anything for that matter you have to 2434 01:23:27,760 --> 01:23:34,000 write it exactly like 2435 01:23:30,239 --> 01:23:35,600 this don't worry if you find it too 2436 01:23:34,000 --> 01:23:37,520 difficult to remember you will get a 2437 01:23:35,600 --> 01:23:38,560 hang of it very soon remember what i 2438 01:23:37,520 --> 01:23:42,080 told about programming 2439 01:23:38,560 --> 01:23:44,480 it is the game of practice it is very 2440 01:23:42,080 --> 01:23:46,880 common to mess up so the arduino ide has 2441 01:23:44,480 --> 01:23:48,639 built-in provision to help us with that 2442 01:23:46,880 --> 01:23:50,639 what i mean to say by that is if you 2443 01:23:48,639 --> 01:23:52,000 ever mess up the casing by mistake 2444 01:23:50,639 --> 01:23:54,080 you would see that this is no more 2445 01:23:52,000 --> 01:23:56,560 coming in orange color 2446 01:23:54,080 --> 01:23:57,920 right now it is coming back in orange 2447 01:23:56,560 --> 01:24:00,320 color 2448 01:23:57,920 --> 01:24:02,000 same goes here so if you ever see that 2449 01:24:00,320 --> 01:24:03,600 these critical words are not showing up 2450 01:24:02,000 --> 01:24:05,280 in color form you can guess that you 2451 01:24:03,600 --> 01:24:07,600 have made a mistake now let's see what 2452 01:24:05,280 --> 01:24:11,520 is done here in void setup 2453 01:24:07,600 --> 01:24:13,600 it says pin mode led built-in 2454 01:24:11,520 --> 01:24:15,600 output this pin mode is a built-in 2455 01:24:13,600 --> 01:24:17,920 function which configures the specified 2456 01:24:15,600 --> 01:24:18,719 pin to behave either as an input or an 2457 01:24:17,920 --> 01:24:20,560 output 2458 01:24:18,719 --> 01:24:22,400 this input and output is in reference to 2459 01:24:20,560 --> 01:24:23,840 the arduino if something is going into 2460 01:24:22,400 --> 01:24:26,159 the arduino through that pin 2461 01:24:23,840 --> 01:24:27,600 we would configure it as input or if 2462 01:24:26,159 --> 01:24:28,320 something is coming out of arduino 2463 01:24:27,600 --> 01:24:30,400 through that pin 2464 01:24:28,320 --> 01:24:32,239 it will be output in our case the 2465 01:24:30,400 --> 01:24:33,440 built-in led would need some sort of 2466 01:24:32,239 --> 01:24:36,000 output from arduino 2467 01:24:33,440 --> 01:24:36,800 so we will use output so if we see this 2468 01:24:36,000 --> 01:24:39,199 line 2469 01:24:36,800 --> 01:24:41,199 in a little more detail we have written 2470 01:24:39,199 --> 01:24:43,040 pin mode then there is an open bracket 2471 01:24:41,199 --> 01:24:45,600 then we have written led built in then 2472 01:24:43,040 --> 01:24:47,840 there is a comma then there is output 2473 01:24:45,600 --> 01:24:49,840 then there is bracket close and there is 2474 01:24:47,840 --> 01:24:51,440 a semicolon 2475 01:24:49,840 --> 01:24:53,360 i won't be surprised if you have not 2476 01:24:51,440 --> 01:24:55,120 noticed this semicolon till now 2477 01:24:53,360 --> 01:24:57,199 i won't be surprised because it is very 2478 01:24:55,120 --> 01:24:58,400 very common to forget this semicolon 2479 01:24:57,199 --> 01:25:00,800 this semicolon 2480 01:24:58,400 --> 01:25:02,400 marks the end of a statement that means 2481 01:25:00,800 --> 01:25:03,280 we are telling the compiler we are done 2482 01:25:02,400 --> 01:25:05,280 with the statement 2483 01:25:03,280 --> 01:25:06,719 we have finished one line if we remove 2484 01:25:05,280 --> 01:25:10,159 the semicolon 2485 01:25:06,719 --> 01:25:12,719 we would get an error you see expected 2486 01:25:10,159 --> 01:25:15,679 semicolon before this 2487 01:25:12,719 --> 01:25:16,560 so back to that what this line means is 2488 01:25:15,679 --> 01:25:18,880 we have called 2489 01:25:16,560 --> 01:25:20,560 a built-in function called pin mode 2490 01:25:18,880 --> 01:25:22,560 which has two arguments 2491 01:25:20,560 --> 01:25:24,560 the first argument is the pin number 2492 01:25:22,560 --> 01:25:26,159 which we want to configure 2493 01:25:24,560 --> 01:25:28,719 and the second argument tells the 2494 01:25:26,159 --> 01:25:30,719 configuration which we wanted to act as 2495 01:25:28,719 --> 01:25:32,639 this built-in led is connected to pin 2496 01:25:30,719 --> 01:25:34,639 number 13 of arduino so we are telling 2497 01:25:32,639 --> 01:25:35,440 arduino to set the configuration of pin 2498 01:25:34,639 --> 01:25:37,679 number 13 2499 01:25:35,440 --> 01:25:39,120 as output okay this is what this line is 2500 01:25:37,679 --> 01:25:41,040 doing 2501 01:25:39,120 --> 01:25:43,440 also note that this line is written 2502 01:25:41,040 --> 01:25:46,320 inside the block of void setup 2503 01:25:43,440 --> 01:25:48,159 can you see that right one more thing 2504 01:25:46,320 --> 01:25:50,320 which i would like you to note is 2505 01:25:48,159 --> 01:25:52,320 this led built in the compiler is 2506 01:25:50,320 --> 01:25:52,639 automatically replacing this led built 2507 01:25:52,320 --> 01:25:54,800 in 2508 01:25:52,639 --> 01:25:56,560 with pin number 13. also note that the 2509 01:25:54,800 --> 01:25:57,760 compiler is not changing the led 2510 01:25:56,560 --> 01:26:00,159 built-in to 13 2511 01:25:57,760 --> 01:26:01,760 magically it has been fed somewhere else 2512 01:26:00,159 --> 01:26:03,520 in the arduino libraries 2513 01:26:01,760 --> 01:26:05,760 we will talk about libraries in coming 2514 01:26:03,520 --> 01:26:06,400 lectures but what i want to say right 2515 01:26:05,760 --> 01:26:09,360 now is 2516 01:26:06,400 --> 01:26:11,280 this is equivalent to this for those 2517 01:26:09,360 --> 01:26:12,000 people who felt a little uncomfortable 2518 01:26:11,280 --> 01:26:14,320 when i said 2519 01:26:12,000 --> 01:26:15,520 we are calling a function here which has 2520 01:26:14,320 --> 01:26:17,679 two arguments 2521 01:26:15,520 --> 01:26:19,600 i just want all of those people to know 2522 01:26:17,679 --> 01:26:21,360 that we will talk about functions 2523 01:26:19,600 --> 01:26:22,960 calling functions arguments of the 2524 01:26:21,360 --> 01:26:25,120 functions in a lecture 2525 01:26:22,960 --> 01:26:26,639 in which we talk about creating custom 2526 01:26:25,120 --> 01:26:28,800 functions then you will be able to 2527 01:26:26,639 --> 01:26:31,360 relate what i said here exactly 2528 01:26:28,800 --> 01:26:32,080 but for now just understand we use pin 2529 01:26:31,360 --> 01:26:34,080 mode function 2530 01:26:32,080 --> 01:26:36,080 like this we will have to use it 2531 01:26:34,080 --> 01:26:38,719 whenever we have to configure a pin 2532 01:26:36,080 --> 01:26:40,320 and using this inside setup means that 2533 01:26:38,719 --> 01:26:43,120 we want this function to run 2534 01:26:40,320 --> 01:26:44,560 once whenever we turn on the arduino or 2535 01:26:43,120 --> 01:26:46,560 reset our arduino 2536 01:26:44,560 --> 01:26:48,400 all right so now we will see what we 2537 01:26:46,560 --> 01:26:50,560 have done in void loop 2538 01:26:48,400 --> 01:26:52,800 the first thing which we see is digital 2539 01:26:50,560 --> 01:26:56,159 right when it is led built in 2540 01:26:52,800 --> 01:26:56,639 then we have high okay so the digital 2541 01:26:56,159 --> 01:26:58,400 right 2542 01:26:56,639 --> 01:27:00,080 is an inbuilt function which is used to 2543 01:26:58,400 --> 01:27:02,239 manipulate the digital pins 2544 01:27:00,080 --> 01:27:03,760 and we can also manipulate analog pins 2545 01:27:02,239 --> 01:27:04,960 using digital write if the pin is 2546 01:27:03,760 --> 01:27:07,679 declared as output 2547 01:27:04,960 --> 01:27:09,840 in setup using pin mode digital write 2548 01:27:07,679 --> 01:27:13,120 will write a value of 5 volt if we use 2549 01:27:09,840 --> 01:27:14,480 high and to 0 if we use low but do make 2550 01:27:13,120 --> 01:27:15,120 sure that you have declared the pin as 2551 01:27:14,480 --> 01:27:17,280 output 2552 01:27:15,120 --> 01:27:18,960 otherwise you may see unexpected results 2553 01:27:17,280 --> 01:27:21,760 then after this line we have 2554 01:27:18,960 --> 01:27:22,639 delay the value of 1000 in that as the 2555 01:27:21,760 --> 01:27:24,480 name suggests 2556 01:27:22,639 --> 01:27:26,159 the function would pause the code here 2557 01:27:24,480 --> 01:27:28,719 for a specified amount of time 2558 01:27:26,159 --> 01:27:29,920 in our case it is 1000 milliseconds 2559 01:27:28,719 --> 01:27:31,920 which is one second 2560 01:27:29,920 --> 01:27:33,520 whenever we use delay the entire state 2561 01:27:31,920 --> 01:27:34,880 of arduino is preserved and nothing 2562 01:27:33,520 --> 01:27:36,719 happens during that time 2563 01:27:34,880 --> 01:27:38,159 then we have another digital write which 2564 01:27:36,719 --> 01:27:40,400 would write low 2565 01:27:38,159 --> 01:27:42,239 to the led built in that means the led 2566 01:27:40,400 --> 01:27:44,080 will turn off here the led will turn on 2567 01:27:42,239 --> 01:27:45,360 here it will turn off and this another 2568 01:27:44,080 --> 01:27:47,199 delay will keep it off 2569 01:27:45,360 --> 01:27:49,199 for one second and this entire process 2570 01:27:47,199 --> 01:27:51,199 would keep on repeating unless we turn 2571 01:27:49,199 --> 01:27:52,880 off the arduino as this is inside 2572 01:27:51,199 --> 01:27:55,920 white loop so if we change the value of 2573 01:27:52,880 --> 01:27:57,840 this delay to 500 2574 01:27:55,920 --> 01:27:59,600 we would see the change in blinking 2575 01:27:57,840 --> 01:28:01,120 pattern i would like you to try changing 2576 01:27:59,600 --> 01:28:02,960 the value to your desired value 2577 01:28:01,120 --> 01:28:04,800 and comment down below if you were able 2578 01:28:02,960 --> 01:28:05,280 to see the change now i would like to 2579 01:28:04,800 --> 01:28:07,840 tell you 2580 01:28:05,280 --> 01:28:10,000 that you can also store this delay value 2581 01:28:07,840 --> 01:28:11,600 into an imaginary container known as a 2582 01:28:10,000 --> 01:28:14,880 variable we can do that by 2583 01:28:11,600 --> 01:28:18,480 writing int my delay 2584 01:28:14,880 --> 01:28:20,480 value is equal to 100. 2585 01:28:18,480 --> 01:28:22,400 you can also choose some other name over 2586 01:28:20,480 --> 01:28:23,600 here there are some rules to deciding 2587 01:28:22,400 --> 01:28:25,360 the variable name and you would 2588 01:28:23,600 --> 01:28:28,239 gradually get to know those rules 2589 01:28:25,360 --> 01:28:29,360 as we progress along the course so now 2590 01:28:28,239 --> 01:28:33,120 we can take this value 2591 01:28:29,360 --> 01:28:33,120 and replace it here 2592 01:28:33,760 --> 01:28:36,960 so now while the arduino is looping on 2593 01:28:35,679 --> 01:28:39,760 this code it will take 2594 01:28:36,960 --> 01:28:41,679 my delay as 100 instead of some other 2595 01:28:39,760 --> 01:28:42,080 value what benefit do we have to use 2596 01:28:41,679 --> 01:28:45,440 this 2597 01:28:42,080 --> 01:28:46,400 we can change our value to any other 2598 01:28:45,440 --> 01:28:50,159 value 2599 01:28:46,400 --> 01:28:52,560 like this or this 2600 01:28:50,159 --> 01:28:54,840 if we need to change the value instead 2601 01:28:52,560 --> 01:28:58,000 of changing here 2602 01:28:54,840 --> 01:29:01,040 twice and making our code error prone 2603 01:28:58,000 --> 01:29:03,600 we can just change the value here 2604 01:29:01,040 --> 01:29:05,520 it will save our time and also make our 2605 01:29:03,600 --> 01:29:07,760 code less prone to errors 2606 01:29:05,520 --> 01:29:09,440 we can also make our own variable to 2607 01:29:07,760 --> 01:29:12,800 define led pin 2608 01:29:09,440 --> 01:29:16,159 and we would do that by hint 2609 01:29:12,800 --> 01:29:18,239 led pin is equal to 13 2610 01:29:16,159 --> 01:29:25,280 and now we will take this led pin and we 2611 01:29:18,239 --> 01:29:27,520 will replace it here 2612 01:29:25,280 --> 01:29:29,679 right so this code will work exactly 2613 01:29:27,520 --> 01:29:30,560 like the earlier code and it would work 2614 01:29:29,679 --> 01:29:32,560 flawlessly 2615 01:29:30,560 --> 01:29:34,159 the benefit of using our own pin is that 2616 01:29:32,560 --> 01:29:34,719 we can change the pin which we want to 2617 01:29:34,159 --> 01:29:37,280 use 2618 01:29:34,719 --> 01:29:38,000 later for example now i have decided to 2619 01:29:37,280 --> 01:29:39,760 use pin number 2620 01:29:38,000 --> 01:29:41,600 two instead of pin number 30. so instead 2621 01:29:39,760 --> 01:29:43,679 of changing the pin number 2622 01:29:41,600 --> 01:29:45,440 from 13 to 2 everywhere i can just 2623 01:29:43,679 --> 01:29:47,360 change it to 2 here 2624 01:29:45,440 --> 01:29:49,040 so now automatically the compiler will 2625 01:29:47,360 --> 01:29:51,120 pick the value of 2 2626 01:29:49,040 --> 01:29:52,719 of led pin and replace them here now 2627 01:29:51,120 --> 01:29:54,400 some of you must have noticed the way 2628 01:29:52,719 --> 01:29:56,719 how i am writing led pin 2629 01:29:54,400 --> 01:29:58,480 like small ln and capital p what's the 2630 01:29:56,719 --> 01:30:01,199 reason behind that 2631 01:29:58,480 --> 01:30:02,239 now since we cannot keep spaces between 2632 01:30:01,199 --> 01:30:04,639 our variable names 2633 01:30:02,239 --> 01:30:06,639 and led and pin are two different names 2634 01:30:04,639 --> 01:30:07,840 so the compiler will throw an error 2635 01:30:06,639 --> 01:30:10,320 and some people came up with the 2636 01:30:07,840 --> 01:30:10,880 solution that to name variables like 2637 01:30:10,320 --> 01:30:12,480 this 2638 01:30:10,880 --> 01:30:14,080 we can keep the first character of the 2639 01:30:12,480 --> 01:30:15,120 second word capital in order to 2640 01:30:14,080 --> 01:30:16,400 differentiate 2641 01:30:15,120 --> 01:30:18,080 so now our eyes are able to 2642 01:30:16,400 --> 01:30:19,120 differentiate between led and pin 2643 01:30:18,080 --> 01:30:20,719 properly 2644 01:30:19,120 --> 01:30:22,880 and this technique is known as camel 2645 01:30:20,719 --> 01:30:23,840 casing if i have to use more than two 2646 01:30:22,880 --> 01:30:28,560 words 2647 01:30:23,840 --> 01:30:28,560 what i can do is like this 2648 01:30:29,600 --> 01:30:33,440 so now my eyes are able to read my led 2649 01:30:31,679 --> 01:30:35,600 pin as three different words 2650 01:30:33,440 --> 01:30:36,960 instead of one word but for the compiler 2651 01:30:35,600 --> 01:30:38,320 it is just the one word 2652 01:30:36,960 --> 01:30:41,360 and now some of you must be wondering 2653 01:30:38,320 --> 01:30:43,520 what is int why we have declared it here 2654 01:30:41,360 --> 01:30:44,960 right so in the next video we'll talk 2655 01:30:43,520 --> 01:30:47,520 about this int 2656 01:30:44,960 --> 01:30:48,239 and the other data types variables and 2657 01:30:47,520 --> 01:30:52,159 more about 2658 01:30:48,239 --> 01:30:54,239 variable scope see you in the next video 2659 01:30:52,159 --> 01:30:56,080 so now we will discuss about variables 2660 01:30:54,239 --> 01:30:58,000 what exactly are variables 2661 01:30:56,080 --> 01:30:59,520 variables are nothing but they are kind 2662 01:30:58,000 --> 01:31:01,840 of a virtual containers 2663 01:30:59,520 --> 01:31:03,440 which is used by a compiler and we store 2664 01:31:01,840 --> 01:31:04,960 some values in those containers 2665 01:31:03,440 --> 01:31:06,320 there are different kinds of data which 2666 01:31:04,960 --> 01:31:06,960 we can hold in different kinds of 2667 01:31:06,320 --> 01:31:09,520 container 2668 01:31:06,960 --> 01:31:11,120 for example at your home you store sugar 2669 01:31:09,520 --> 01:31:11,679 in some kind of specific container you 2670 01:31:11,120 --> 01:31:13,920 store 2671 01:31:11,679 --> 01:31:15,760 tea in the tea container oil in the oil 2672 01:31:13,920 --> 01:31:16,400 container similarly in programming as 2673 01:31:15,760 --> 01:31:18,400 well 2674 01:31:16,400 --> 01:31:20,639 we have some sort of containers and 2675 01:31:18,400 --> 01:31:21,199 those can store some sort of specific 2676 01:31:20,639 --> 01:31:23,199 data 2677 01:31:21,199 --> 01:31:25,440 the variables are available in different 2678 01:31:23,199 --> 01:31:27,199 sizes and we will be talking about just 2679 01:31:25,440 --> 01:31:28,480 the default variables which are used in 2680 01:31:27,199 --> 01:31:30,159 the arduino programming 2681 01:31:28,480 --> 01:31:31,679 the thing to note here is the bigger the 2682 01:31:30,159 --> 01:31:32,080 container the bigger the value it can 2683 01:31:31,679 --> 01:31:33,600 store 2684 01:31:32,080 --> 01:31:36,000 the first kind of data type which we 2685 01:31:33,600 --> 01:31:38,400 will see is int if you can recall 2686 01:31:36,000 --> 01:31:40,480 we used in in the previous video when we 2687 01:31:38,400 --> 01:31:43,199 declared our led pins and our own 2688 01:31:40,480 --> 01:31:44,560 delay values right so int is basically a 2689 01:31:43,199 --> 01:31:46,480 container which can hold 2690 01:31:44,560 --> 01:31:47,679 integer values and i hope you're aware 2691 01:31:46,480 --> 01:31:49,360 what integers are 2692 01:31:47,679 --> 01:31:50,960 if not i will just quickly tell you that 2693 01:31:49,360 --> 01:31:51,840 the number line is there the whole 2694 01:31:50,960 --> 01:31:54,320 numbers from 2695 01:31:51,840 --> 01:31:54,880 negative infinity to positive infinity 2696 01:31:54,320 --> 01:31:57,440 are all 2697 01:31:54,880 --> 01:32:00,080 integers which you can see here in this 2698 01:31:57,440 --> 01:32:03,440 video like minus 4 minus 3 minus 2 2699 01:32:00,080 --> 01:32:04,880 0 1 2 3 4. the numbers greater than 0 2700 01:32:03,440 --> 01:32:06,800 are positive integers and 2701 01:32:04,880 --> 01:32:08,800 the numbers less than 0 are negative 2702 01:32:06,800 --> 01:32:10,159 integers the default integer which we 2703 01:32:08,800 --> 01:32:14,400 use in arduino programming 2704 01:32:10,159 --> 01:32:18,320 has a range of minus 32 768 2705 01:32:14,400 --> 01:32:20,080 to positive 32 767 right what this means 2706 01:32:18,320 --> 01:32:22,560 is the size of integer 2707 01:32:20,080 --> 01:32:23,440 can hold these many values if you try to 2708 01:32:22,560 --> 01:32:24,960 store value 2709 01:32:23,440 --> 01:32:26,719 beyond this range the values will 2710 01:32:24,960 --> 01:32:28,960 overflow now i will tell you 2711 01:32:26,719 --> 01:32:29,840 how to declare an integer in programming 2712 01:32:28,960 --> 01:32:32,080 language 2713 01:32:29,840 --> 01:32:32,880 first of all we write int then we name 2714 01:32:32,080 --> 01:32:34,320 the variable 2715 01:32:32,880 --> 01:32:36,560 like in this case the name of the 2716 01:32:34,320 --> 01:32:38,239 variable is value and then we assign a 2717 01:32:36,560 --> 01:32:40,719 value to it for example 2718 01:32:38,239 --> 01:32:42,159 we have assigned a value of 5 here right 2719 01:32:40,719 --> 01:32:44,480 and then a semicolon 2720 01:32:42,159 --> 01:32:46,080 we can also assign it like this we write 2721 01:32:44,480 --> 01:32:47,760 int then value 2722 01:32:46,080 --> 01:32:50,480 and we do not initialize it with any 2723 01:32:47,760 --> 01:32:52,480 value if we do not initialize any value 2724 01:32:50,480 --> 01:32:53,920 the default value is zero i'm going to 2725 01:32:52,480 --> 01:32:55,600 say is if you do not initialize the 2726 01:32:53,920 --> 01:32:56,159 variable the default value which it 2727 01:32:55,600 --> 01:32:58,719 holds is 2728 01:32:56,159 --> 01:33:00,800 0. we will see more about integers in a 2729 01:32:58,719 --> 01:33:03,520 moment so before i can demonstrate how 2730 01:33:00,800 --> 01:33:04,480 int exactly works in the code i need you 2731 01:33:03,520 --> 01:33:06,560 to understand 2732 01:33:04,480 --> 01:33:08,639 these three critical functions first one 2733 01:33:06,560 --> 01:33:12,080 of them is serial.begin 2734 01:33:08,639 --> 01:33:13,840 bracket 9600 bracket close basically 2735 01:33:12,080 --> 01:33:16,080 this function enables the serial 2736 01:33:13,840 --> 01:33:18,080 communication between arduino 2737 01:33:16,080 --> 01:33:19,199 and the computer what serial 2738 01:33:18,080 --> 01:33:21,440 communication is 2739 01:33:19,199 --> 01:33:22,400 and what these functions are we will 2740 01:33:21,440 --> 01:33:24,639 talk in detail 2741 01:33:22,400 --> 01:33:25,679 in coming lectures but for now just 2742 01:33:24,639 --> 01:33:27,360 understand we 2743 01:33:25,679 --> 01:33:29,280 have to write this statement whenever we 2744 01:33:27,360 --> 01:33:30,080 want any communication to happen between 2745 01:33:29,280 --> 01:33:31,840 the arduino 2746 01:33:30,080 --> 01:33:33,520 and the computer then there is 2747 01:33:31,840 --> 01:33:36,480 serial.print bracket 2748 01:33:33,520 --> 01:33:38,320 semicolon right we use this function 2749 01:33:36,480 --> 01:33:39,360 whenever we want to print something on 2750 01:33:38,320 --> 01:33:41,199 the serial monitor 2751 01:33:39,360 --> 01:33:43,280 we will see serial monitor in a moment 2752 01:33:41,199 --> 01:33:45,040 and then we have serial.println 2753 01:33:43,280 --> 01:33:47,600 the difference between serial.print and 2754 01:33:45,040 --> 01:33:47,920 serial.println is that serial.println 2755 01:33:47,600 --> 01:33:50,080 just 2756 01:33:47,920 --> 01:33:51,040 adds an additional line after printing 2757 01:33:50,080 --> 01:33:52,960 whatever is 2758 01:33:51,040 --> 01:33:54,400 ours to print now without any further 2759 01:33:52,960 --> 01:33:56,800 delay we'll just see 2760 01:33:54,400 --> 01:33:57,440 how integer works so now let's start 2761 01:33:56,800 --> 01:33:59,920 afresh 2762 01:33:57,440 --> 01:34:02,400 by learning about integers let me open a 2763 01:33:59,920 --> 01:34:02,400 new file 2764 01:34:02,560 --> 01:34:07,120 all right so i'm declaring my first ever 2765 01:34:05,120 --> 01:34:10,880 integer above void setup 2766 01:34:07,120 --> 01:34:14,400 like this end my 2767 01:34:10,880 --> 01:34:16,159 variable is equal to 5 2768 01:34:14,400 --> 01:34:18,000 it is similar to something which we saw 2769 01:34:16,159 --> 01:34:19,360 in the presentation when i told you 2770 01:34:18,000 --> 01:34:21,520 about integers 2771 01:34:19,360 --> 01:34:22,719 now to see the value of my variable i 2772 01:34:21,520 --> 01:34:25,040 will start 2773 01:34:22,719 --> 01:34:25,920 serial communication with my computer 2774 01:34:25,040 --> 01:34:29,440 like this 2775 01:34:25,920 --> 01:34:34,480 and now to see the value i will print 2776 01:34:29,440 --> 01:34:39,040 the value serial dot println 2777 01:34:34,480 --> 01:34:40,800 my variable so now i'll upload the code 2778 01:34:39,040 --> 01:34:43,199 it's done uploading and now i will see 2779 01:34:40,800 --> 01:34:46,159 the serial monitor 2780 01:34:43,199 --> 01:34:48,480 so you see it has printed the value of 5 2781 01:34:46,159 --> 01:34:51,360 that means the value of my variable is 5 2782 01:34:48,480 --> 01:34:51,360 as we have declared 2783 01:34:51,840 --> 01:34:54,880 similarly when i said if we don't 2784 01:34:53,440 --> 01:34:58,000 initialize it 2785 01:34:54,880 --> 01:34:58,880 the value is 0. we'll upload the code 2786 01:34:58,000 --> 01:35:02,159 and see it again 2787 01:34:58,880 --> 01:35:02,159 let me name the file first 2788 01:35:04,800 --> 01:35:10,480 right if now we have not declared it so 2789 01:35:07,440 --> 01:35:10,480 now we will see the value 2790 01:35:10,560 --> 01:35:14,400 it says zero so now i will be telling 2791 01:35:13,199 --> 01:35:17,679 you about how we can 2792 01:35:14,400 --> 01:35:20,000 modify our variables for example 2793 01:35:17,679 --> 01:35:21,119 the first thing which we can do is we 2794 01:35:20,000 --> 01:35:24,880 will take our variable 2795 01:35:21,119 --> 01:35:24,880 and add 2 to it 2796 01:35:24,960 --> 01:35:29,440 so first operator which you see is plus 2797 01:35:27,840 --> 01:35:31,119 these are arithmetic operators and we 2798 01:35:29,440 --> 01:35:34,880 will be discussing more about these 2799 01:35:31,119 --> 01:35:38,159 shortly now if you print our variable 2800 01:35:34,880 --> 01:35:38,159 serial dot println 2801 01:35:38,880 --> 01:35:46,480 my variable 2802 01:35:42,080 --> 01:35:46,480 right so the answer would be 2. 2803 01:35:47,360 --> 01:35:51,840 so the value of my variable initially 2804 01:35:49,119 --> 01:35:54,480 was 0 and now we have added 2 to it 2805 01:35:51,840 --> 01:35:56,320 so we have 2 here now for example if we 2806 01:35:54,480 --> 01:35:59,840 had initiated it 2807 01:35:56,320 --> 01:36:03,440 with 5 so now we will get 2808 01:35:59,840 --> 01:36:06,719 7 right okay 2809 01:36:03,440 --> 01:36:09,760 as expected now the variable value is 7 2810 01:36:06,719 --> 01:36:13,280 right so now we will manipulate it 2811 01:36:09,760 --> 01:36:15,199 by subtracting 2 from it 2812 01:36:13,280 --> 01:36:16,880 now again we will get 5. let me tell you 2813 01:36:15,199 --> 01:36:17,360 that shortcut to open the serial monitor 2814 01:36:16,880 --> 01:36:25,840 is 2815 01:36:17,360 --> 01:36:28,960 this button and then we will print it 2816 01:36:25,840 --> 01:36:29,679 right 5 7 and 5 i hope i am making some 2817 01:36:28,960 --> 01:36:31,520 sense 2818 01:36:29,679 --> 01:36:33,920 similarly there is a multiplication 2819 01:36:31,520 --> 01:36:37,360 operator and a division operator 2820 01:36:33,920 --> 01:36:41,280 what we can do is let's say 2821 01:36:37,360 --> 01:36:44,880 my variable is equal to my variable 2822 01:36:41,280 --> 01:36:47,360 into 5 let's say now we will print my 2823 01:36:44,880 --> 01:36:47,360 variable 2824 01:36:47,520 --> 01:36:54,639 so what will we get in guesses 2825 01:36:51,119 --> 01:36:56,960 we'll get 25 right so 5 was the value of 2826 01:36:54,639 --> 01:36:59,119 my variable and we multiplied it by 5 so 2827 01:36:56,960 --> 01:37:03,199 we have 25 so now let's divide 2828 01:36:59,119 --> 01:37:08,320 my variable by 25 divide by 2829 01:37:03,199 --> 01:37:08,320 25 what will we get one right 2830 01:37:16,639 --> 01:37:20,960 right we got one now the important thing 2831 01:37:19,520 --> 01:37:23,119 which i want you to notice 2832 01:37:20,960 --> 01:37:25,440 the integer variable can only hold 2833 01:37:23,119 --> 01:37:28,000 integers it cannot hold 2834 01:37:25,440 --> 01:37:30,400 fractions for example i'll tell you let 2835 01:37:28,000 --> 01:37:33,600 me delete all this code 2836 01:37:30,400 --> 01:37:37,920 for example if my variable was 3 right 2837 01:37:33,600 --> 01:37:40,960 and what if we divide my variable 2838 01:37:37,920 --> 01:37:44,000 by 2 mathematically 2839 01:37:40,960 --> 01:37:46,080 the answer should be 1.5 but since 2840 01:37:44,000 --> 01:37:47,920 our integer variable can't hold decimal 2841 01:37:46,080 --> 01:37:48,719 values so can you guess what will it 2842 01:37:47,920 --> 01:37:52,480 print now 2843 01:37:48,719 --> 01:37:54,960 it will print one why 2844 01:37:52,480 --> 01:37:56,480 because it can only hold integer part of 2845 01:37:54,960 --> 01:37:59,119 any decimal the answer was 2846 01:37:56,480 --> 01:37:59,679 1.5 but it will pick only the integer 2847 01:37:59,119 --> 01:38:02,000 value 2848 01:37:59,679 --> 01:38:03,679 so if you want decimal values as well we 2849 01:38:02,000 --> 01:38:05,440 will use float and we will soon learn 2850 01:38:03,679 --> 01:38:07,119 about float 2851 01:38:05,440 --> 01:38:09,040 now there is another interesting 2852 01:38:07,119 --> 01:38:11,840 operator known as modulo 2853 01:38:09,040 --> 01:38:13,520 it will give us the remainder after 2854 01:38:11,840 --> 01:38:17,840 division 2855 01:38:13,520 --> 01:38:17,840 let's say my variable is 6 okay 2856 01:38:18,880 --> 01:38:22,400 and i want to get the value of the 2857 01:38:21,040 --> 01:38:25,119 remainder we will say 2858 01:38:22,400 --> 01:38:25,119 my variable 2859 01:38:25,440 --> 01:38:31,679 equal to my variable modulo 2860 01:38:28,800 --> 01:38:33,840 the symbol of modulo is percentage sign 2861 01:38:31,679 --> 01:38:36,800 if we divide 6 by 2862 01:38:33,840 --> 01:38:38,560 2 so it will completely divide by 2 2863 01:38:36,800 --> 01:38:40,800 right so the remainder will be 2864 01:38:38,560 --> 01:38:42,840 0. so if we print my variable we should 2865 01:38:40,800 --> 01:38:46,400 get a value of 0 2866 01:38:42,840 --> 01:38:49,679 right as expected 2867 01:38:46,400 --> 01:38:54,639 if we divide six by three 2868 01:38:49,679 --> 01:38:54,639 then also we'll get a remainder of zero 2869 01:38:55,440 --> 01:38:59,119 but if we divide six by four we get a 2870 01:38:58,080 --> 01:39:02,719 remainder of 2871 01:38:59,119 --> 01:39:05,520 two right we will get two here now 2872 01:39:02,719 --> 01:39:06,320 as expected now can you guess what if we 2873 01:39:05,520 --> 01:39:09,440 divided by 2874 01:39:06,320 --> 01:39:13,520 five what remainder will be 2875 01:39:09,440 --> 01:39:16,239 we'll get one right as expected 2876 01:39:13,520 --> 01:39:17,760 so these were the main arithmetic 2877 01:39:16,239 --> 01:39:21,360 operators which we can use 2878 01:39:17,760 --> 01:39:23,199 to modify our variables now for example 2879 01:39:21,360 --> 01:39:24,639 we have more than one variables in our 2880 01:39:23,199 --> 01:39:29,360 code 2881 01:39:24,639 --> 01:39:32,320 my second variable 2882 01:39:29,360 --> 01:39:34,880 and the value of that is 5. now what we 2883 01:39:32,320 --> 01:39:34,880 can do is 2884 01:39:39,040 --> 01:39:44,000 now let's see what will we get my 2885 01:39:40,880 --> 01:39:44,000 variable plus 2886 01:39:45,600 --> 01:39:51,119 my second variable right 2887 01:39:48,719 --> 01:39:54,000 so can you guess what will we get we'll 2888 01:39:51,119 --> 01:39:58,239 get 11. 2889 01:39:54,000 --> 01:40:01,040 right as expected and what if we 2890 01:39:58,239 --> 01:40:01,040 subtract it 2891 01:40:03,600 --> 01:40:09,280 are we correct absolutely similarly we 2892 01:40:06,480 --> 01:40:12,800 can also multiply 2893 01:40:09,280 --> 01:40:16,639 what should we get 6 multiplied by 5 is 2894 01:40:12,800 --> 01:40:18,000 30 right what another thing which we can 2895 01:40:16,639 --> 01:40:21,840 do is we can store 2896 01:40:18,000 --> 01:40:22,800 these values here our results are not 2897 01:40:21,840 --> 01:40:25,440 getting stored 2898 01:40:22,800 --> 01:40:26,880 here they are just being displayed what 2899 01:40:25,440 --> 01:40:30,159 if we want to store it 2900 01:40:26,880 --> 01:40:31,520 we can take another variable my third 2901 01:40:30,159 --> 01:40:34,239 variable 2902 01:40:31,520 --> 01:40:37,760 and let's not initialize it okay so what 2903 01:40:34,239 --> 01:40:41,040 we can do is 2904 01:40:37,760 --> 01:40:44,800 let's take my third variable 2905 01:40:41,040 --> 01:40:47,920 okay and let's store the value 2906 01:40:44,800 --> 01:40:47,920 of my variable 2907 01:40:48,400 --> 01:40:52,159 plus my second value 2908 01:40:52,880 --> 01:41:00,320 and let's print the third variable 2909 01:40:56,639 --> 01:41:02,880 we should get 11 here exactly 2910 01:41:00,320 --> 01:41:04,159 so similarly we can do whatever we want 2911 01:41:02,880 --> 01:41:05,760 with the variables 2912 01:41:04,159 --> 01:41:07,440 but the most important thing which i 2913 01:41:05,760 --> 01:41:10,239 want you to notice is before 2914 01:41:07,440 --> 01:41:12,000 using the variable we have to declare it 2915 01:41:10,239 --> 01:41:16,080 for example 2916 01:41:12,000 --> 01:41:20,080 if we do not declare my third variable 2917 01:41:16,080 --> 01:41:22,239 okay and try to do something with it 2918 01:41:20,080 --> 01:41:23,920 the compiler will throw us an error my 2919 01:41:22,239 --> 01:41:25,199 third variable was not declared in this 2920 01:41:23,920 --> 01:41:27,119 scope 2921 01:41:25,199 --> 01:41:28,320 all right we'll discuss about scope in 2922 01:41:27,119 --> 01:41:30,320 coming videos 2923 01:41:28,320 --> 01:41:31,360 just wait for some time you also need to 2924 01:41:30,320 --> 01:41:33,280 note that 2925 01:41:31,360 --> 01:41:34,800 you have to declare the variable before 2926 01:41:33,280 --> 01:41:37,760 using it right 2927 01:41:34,800 --> 01:41:38,400 you cannot do this as well for example 2928 01:41:37,760 --> 01:41:42,159 you 2929 01:41:38,400 --> 01:41:45,119 try to declare your third variable here 2930 01:41:42,159 --> 01:41:47,520 right then also you will get an error 2931 01:41:45,119 --> 01:41:49,199 you have to declare it before using it 2932 01:41:47,520 --> 01:41:50,719 you cannot declare it after using it 2933 01:41:49,199 --> 01:41:52,639 right 2934 01:41:50,719 --> 01:41:54,320 the last important operator which you 2935 01:41:52,639 --> 01:41:54,960 need to know to be comfortable with the 2936 01:41:54,320 --> 01:41:56,639 course 2937 01:41:54,960 --> 01:41:59,440 is the increment and the decrement 2938 01:41:56,639 --> 01:42:02,000 operator there are two types of each 2939 01:41:59,440 --> 01:42:04,400 one is post increment and pre-increment 2940 01:42:02,000 --> 01:42:06,080 and post decrement and pre-decrement 2941 01:42:04,400 --> 01:42:08,159 all right the purpose of increment 2942 01:42:06,080 --> 01:42:09,679 operator is to increase the value of 2943 01:42:08,159 --> 01:42:12,480 variable by one 2944 01:42:09,679 --> 01:42:14,719 and the purpose of decrement operator is 2945 01:42:12,480 --> 01:42:17,520 to decrease the value of our variable by 2946 01:42:14,719 --> 01:42:18,080 1. i'll show you this by an example we 2947 01:42:17,520 --> 01:42:20,239 have 2948 01:42:18,080 --> 01:42:22,000 my variable and the value of my variable 2949 01:42:20,239 --> 01:42:25,040 is 6. so now 2950 01:42:22,000 --> 01:42:28,239 if i take my variable and do 2951 01:42:25,040 --> 01:42:30,719 plus plus this plus plus is post 2952 01:42:28,239 --> 01:42:32,239 increment operator okay and now if i 2953 01:42:30,719 --> 01:42:36,239 print my variable 2954 01:42:32,239 --> 01:42:36,239 you will see that we will get 7 2955 01:42:37,760 --> 01:42:44,639 right so now if i use 2956 01:42:41,199 --> 01:42:48,080 pre-increment operator then also 2957 01:42:44,639 --> 01:42:49,600 we'll get the value of 7 see 2958 01:42:48,080 --> 01:42:51,360 so now you may ask what is the 2959 01:42:49,600 --> 01:42:52,239 difference between post increment and 2960 01:42:51,360 --> 01:42:54,719 pre-increment 2961 01:42:52,239 --> 01:42:56,239 well there is actually a difference and 2962 01:42:54,719 --> 01:42:57,040 you will get to know that difference 2963 01:42:56,239 --> 01:42:59,520 when we use 2964 01:42:57,040 --> 01:43:00,960 this operator in some expression for 2965 01:42:59,520 --> 01:43:03,840 example 2966 01:43:00,960 --> 01:43:03,840 let's see it here 2967 01:43:04,159 --> 01:43:09,360 if i increment the value of my variable 2968 01:43:06,400 --> 01:43:13,440 like this like you see in serial println 2969 01:43:09,360 --> 01:43:13,440 then we will get value of 6 2970 01:43:15,360 --> 01:43:19,679 right as you can see and the reason 2971 01:43:18,639 --> 01:43:21,760 behind this is 2972 01:43:19,679 --> 01:43:24,000 in a post increment operator the value 2973 01:43:21,760 --> 01:43:27,280 is first used in the expression 2974 01:43:24,000 --> 01:43:27,280 and then it is incremented 2975 01:43:27,360 --> 01:43:33,920 now if i 2976 01:43:30,880 --> 01:43:34,960 use a pre increment operator then we 2977 01:43:33,920 --> 01:43:39,199 will see we get 2978 01:43:34,960 --> 01:43:41,440 7. so by this we can understand 2979 01:43:39,199 --> 01:43:43,440 by pre-increment operator the value is 2980 01:43:41,440 --> 01:43:44,080 first incremented and then used in the 2981 01:43:43,440 --> 01:43:47,600 expression 2982 01:43:44,080 --> 01:43:50,159 similarly there is a decrement operator 2983 01:43:47,600 --> 01:43:50,159 if i do 2984 01:43:50,719 --> 01:43:54,719 my variable minus minus 2985 01:43:55,840 --> 01:44:00,000 will get 5 because my variable was 2986 01:43:59,040 --> 01:44:02,320 originally 6 2987 01:44:00,000 --> 01:44:03,280 so we decremented it by 1 so hence we 2988 01:44:02,320 --> 01:44:05,119 get 5. 2989 01:44:03,280 --> 01:44:07,280 i hope this concept was clear to you 2990 01:44:05,119 --> 01:44:09,119 this concept will be used multiple times 2991 01:44:07,280 --> 01:44:10,880 during our course so if you have any 2992 01:44:09,119 --> 01:44:13,040 questions you can comment down below 2993 01:44:10,880 --> 01:44:14,639 and in the next video we will look at 2994 01:44:13,040 --> 01:44:16,800 the float data type 2995 01:44:14,639 --> 01:44:19,040 so now we will look at the float data 2996 01:44:16,800 --> 01:44:19,520 type this data type is capable of 2997 01:44:19,040 --> 01:44:22,080 holding 2998 01:44:19,520 --> 01:44:24,239 decimal places as well like we saw in 2999 01:44:22,080 --> 01:44:26,639 the integer it cannot hold decimals 3000 01:44:24,239 --> 01:44:28,400 the float can hold decimals as well and 3001 01:44:26,639 --> 01:44:30,960 the default float which we use 3002 01:44:28,400 --> 01:44:32,239 in arduino programming is precise up to 3003 01:44:30,960 --> 01:44:34,159 7 decimal places 3004 01:44:32,239 --> 01:44:35,360 let me explain you in a better way like 3005 01:44:34,159 --> 01:44:37,840 for example 3006 01:44:35,360 --> 01:44:41,360 the number you see here is a real number 3007 01:44:37,840 --> 01:44:44,800 it is 863.267 3008 01:44:41,360 --> 01:44:45,119 right so in integer if we try to store 3009 01:44:44,800 --> 01:44:48,000 this 3010 01:44:45,119 --> 01:44:49,000 that would store only 863. it will just 3011 01:44:48,000 --> 01:44:52,000 ignore 3012 01:44:49,000 --> 01:44:54,719 0.267 so if you want to use 3013 01:44:52,000 --> 01:44:55,199 0.267 as well in our memory so we will 3014 01:44:54,719 --> 01:44:57,920 use 3015 01:44:55,199 --> 01:44:58,480 a float data type so how do we declare 3016 01:44:57,920 --> 01:45:01,360 that 3017 01:44:58,480 --> 01:45:02,239 we write float then space then the name 3018 01:45:01,360 --> 01:45:05,440 of that float 3019 01:45:02,239 --> 01:45:06,480 variable in our case it is value equals 3020 01:45:05,440 --> 01:45:08,719 to 3021 01:45:06,480 --> 01:45:10,000 5.6 or some other value which you want 3022 01:45:08,719 --> 01:45:13,040 then a semicolon 3023 01:45:10,000 --> 01:45:15,679 you can also start a float uninitialized 3024 01:45:13,040 --> 01:45:17,600 like we have done here so let's now see 3025 01:45:15,679 --> 01:45:19,199 the demonstration of how float is used 3026 01:45:17,600 --> 01:45:20,719 in a programming we will declare the 3027 01:45:19,199 --> 01:45:24,239 variable 3028 01:45:20,719 --> 01:45:28,000 my float variable is equal to 3029 01:45:24,239 --> 01:45:28,000 7.8 for example 3030 01:45:28,880 --> 01:45:36,239 let's see right we can see the value 3031 01:45:32,719 --> 01:45:37,840 of 7.8 now let's see what happens if we 3032 01:45:36,239 --> 01:45:41,199 try to 3033 01:45:37,840 --> 01:45:45,840 store 7.8 3034 01:45:41,199 --> 01:45:45,840 in an int variable 3035 01:45:54,400 --> 01:45:58,000 as i told you in the presentation we'll 3036 01:45:56,719 --> 01:45:59,920 get seven 3037 01:45:58,000 --> 01:46:01,440 right can you see the difference now now 3038 01:45:59,920 --> 01:46:03,600 we will just quickly see 3039 01:46:01,440 --> 01:46:04,560 the limitation which we had while using 3040 01:46:03,600 --> 01:46:06,480 int variable 3041 01:46:04,560 --> 01:46:07,679 that while dividing we could not store 3042 01:46:06,480 --> 01:46:09,760 the decimal part 3043 01:46:07,679 --> 01:46:11,199 so we will see if we can store that in 3044 01:46:09,760 --> 01:46:13,679 float variable or not 3045 01:46:11,199 --> 01:46:16,159 let's see it quickly i'll take my float 3046 01:46:13,679 --> 01:46:16,159 variable 3047 01:46:18,880 --> 01:46:25,360 and i'll divide it by 3048 01:46:22,239 --> 01:46:26,719 2 okay and we'll see the my float 3049 01:46:25,360 --> 01:46:30,400 variable then 3050 01:46:26,719 --> 01:46:30,400 let's comment this statement 3051 01:46:31,360 --> 01:46:36,960 all right 7.8 divided by 2 is 3052 01:46:34,560 --> 01:46:38,880 3.9 we can use all the operators which 3053 01:46:36,960 --> 01:46:40,800 we used in the int variable like plus 3054 01:46:38,880 --> 01:46:43,600 minus divide multiply 3055 01:46:40,800 --> 01:46:44,719 increment decrement and floats as well 3056 01:46:43,600 --> 01:46:46,239 okay 3057 01:46:44,719 --> 01:46:47,679 so you can try that on your own and 3058 01:46:46,239 --> 01:46:48,159 comment down below if you face any 3059 01:46:47,679 --> 01:46:50,880 problem 3060 01:46:48,159 --> 01:46:53,280 so now we will take a look at the bool 3061 01:46:50,880 --> 01:46:55,760 or boolean data type 3062 01:46:53,280 --> 01:46:56,719 they can be used interchangeably right 3063 01:46:55,760 --> 01:46:59,760 but we prefer 3064 01:46:56,719 --> 01:47:02,080 to use bool so the pool data type 3065 01:46:59,760 --> 01:47:03,920 holds one of the two values true or 3066 01:47:02,080 --> 01:47:06,560 false 3067 01:47:03,920 --> 01:47:07,360 that means if something is true or if 3068 01:47:06,560 --> 01:47:09,840 something is 3069 01:47:07,360 --> 01:47:10,960 false for example we can declare a 3070 01:47:09,840 --> 01:47:13,679 boolean variable 3071 01:47:10,960 --> 01:47:15,119 by writing pool then the name of the 3072 01:47:13,679 --> 01:47:18,719 boolean variable 3073 01:47:15,119 --> 01:47:22,480 in our case it is is tall equals to 3074 01:47:18,719 --> 01:47:26,639 true or false we'll take another example 3075 01:47:22,480 --> 01:47:29,040 bool is fit is equal to false semicolon 3076 01:47:26,639 --> 01:47:31,360 so this way we can declare a boolean 3077 01:47:29,040 --> 01:47:34,239 variable but i want you to note is 3078 01:47:31,360 --> 01:47:34,639 that one high or true are considered 3079 01:47:34,239 --> 01:47:37,760 same 3080 01:47:34,639 --> 01:47:40,000 by the id also 0 low 3081 01:47:37,760 --> 01:47:41,119 and false are also considered same by id 3082 01:47:40,000 --> 01:47:43,600 by id i mean 3083 01:47:41,119 --> 01:47:44,480 the arduino ide right and anything other 3084 01:47:43,600 --> 01:47:46,960 than 0 3085 01:47:44,480 --> 01:47:47,679 is also considered true by the id we'll 3086 01:47:46,960 --> 01:47:50,000 look at 3087 01:47:47,679 --> 01:47:51,199 what exactly this means in the coding 3088 01:47:50,000 --> 01:47:53,679 now let's understand 3089 01:47:51,199 --> 01:47:54,880 the boolean variable in the coding we 3090 01:47:53,679 --> 01:47:57,119 will initialize it by 3091 01:47:54,880 --> 01:47:58,719 writing bool we will then name it and 3092 01:47:57,119 --> 01:48:02,159 initialize the value of 3093 01:47:58,719 --> 01:48:05,360 say one as i told you 3094 01:48:02,159 --> 01:48:08,719 one high 3095 01:48:05,360 --> 01:48:12,080 or true all these three hold 3096 01:48:08,719 --> 01:48:15,119 the same meaning and similarly zero 3097 01:48:12,080 --> 01:48:18,080 low and false 3098 01:48:15,119 --> 01:48:19,199 all hold the same meaning if we try to 3099 01:48:18,080 --> 01:48:23,840 print the variable 3100 01:48:19,199 --> 01:48:26,960 let's see what happens it will print 3101 01:48:23,840 --> 01:48:27,280 zero right because false is zero if we 3102 01:48:26,960 --> 01:48:29,199 use 3103 01:48:27,280 --> 01:48:31,280 low then also it will print zero same 3104 01:48:29,199 --> 01:48:34,960 goes for true 3105 01:48:31,280 --> 01:48:37,119 if i use true here it will print one 3106 01:48:34,960 --> 01:48:38,800 and the other thing which i told you if 3107 01:48:37,119 --> 01:48:41,440 you use anything other than 3108 01:48:38,800 --> 01:48:43,760 0 that would evaluate to 1 let's see 3109 01:48:41,440 --> 01:48:48,000 that also for example i used 78 3110 01:48:43,760 --> 01:48:50,320 let's see what happens it still gave 1 3111 01:48:48,000 --> 01:48:51,520 okay so that means bool can either store 3112 01:48:50,320 --> 01:48:53,520 0 or 1 3113 01:48:51,520 --> 01:48:54,560 that's all and what's the purpose of 3114 01:48:53,520 --> 01:48:56,320 boolean operator 3115 01:48:54,560 --> 01:48:58,080 we check if something is true in the 3116 01:48:56,320 --> 01:49:00,080 code we'll see 3117 01:48:58,080 --> 01:49:01,360 examples while doing our experiments 3118 01:49:00,080 --> 01:49:03,040 shortly i would like to tell you 3119 01:49:01,360 --> 01:49:05,440 if we want to check some condition is 3120 01:49:03,040 --> 01:49:07,760 true or false or we can initialize our 3121 01:49:05,440 --> 01:49:10,159 condition as well if something is true 3122 01:49:07,760 --> 01:49:11,840 then only we have to do certain tasks 3123 01:49:10,159 --> 01:49:13,599 you will understand more about 3124 01:49:11,840 --> 01:49:15,599 boolean data type when we progress in 3125 01:49:13,599 --> 01:49:17,599 the course like when we study about 3126 01:49:15,599 --> 01:49:19,119 conditionals or when we study logical 3127 01:49:17,599 --> 01:49:21,199 operators or when we study 3128 01:49:19,119 --> 01:49:23,199 the comparison operators we will now 3129 01:49:21,199 --> 01:49:23,760 move on to another data type which is 3130 01:49:23,199 --> 01:49:26,719 known as 3131 01:49:23,760 --> 01:49:27,440 byte the next data type which we have is 3132 01:49:26,719 --> 01:49:29,520 byte 3133 01:49:27,440 --> 01:49:30,800 so as the name suggests it is a byte 3134 01:49:29,520 --> 01:49:34,400 long data type 3135 01:49:30,800 --> 01:49:36,560 it can store up to eight bits of data so 3136 01:49:34,400 --> 01:49:37,440 as we all know eight bits equals to one 3137 01:49:36,560 --> 01:49:39,920 byte okay 3138 01:49:37,440 --> 01:49:40,880 so a byte is just like an integer but 3139 01:49:39,920 --> 01:49:43,760 the only difference is 3140 01:49:40,880 --> 01:49:44,320 the range is 0 to 255. so if you're sure 3141 01:49:43,760 --> 01:49:46,719 that your 3142 01:49:44,320 --> 01:49:48,560 variable is not going to exceed 255 you 3143 01:49:46,719 --> 01:49:51,520 can always use a byte type 3144 01:49:48,560 --> 01:49:52,400 data type so using a byte data type will 3145 01:49:51,520 --> 01:49:54,480 save your 3146 01:49:52,400 --> 01:49:56,960 arduino memory so we will now see how to 3147 01:49:54,480 --> 01:49:59,360 declare a byte 3148 01:49:56,960 --> 01:50:00,080 we will write byte space name of the 3149 01:49:59,360 --> 01:50:01,840 variable 3150 01:50:00,080 --> 01:50:03,760 equals to and the value which we want to 3151 01:50:01,840 --> 01:50:05,199 add in that then a semicolon 3152 01:50:03,760 --> 01:50:06,880 we can also declare it without 3153 01:50:05,199 --> 01:50:07,520 initializing the variable and in that 3154 01:50:06,880 --> 01:50:10,480 case 3155 01:50:07,520 --> 01:50:11,760 the default value it will store is 0 3156 01:50:10,480 --> 01:50:16,159 just like integer 3157 01:50:11,760 --> 01:50:16,159 so let's just quickly declare our byte 3158 01:50:18,000 --> 01:50:25,840 and let's print it 3159 01:50:26,480 --> 01:50:30,000 right so now we will look at our next 3160 01:50:29,040 --> 01:50:32,960 data type 3161 01:50:30,000 --> 01:50:33,599 which is char which is a short for 3162 01:50:32,960 --> 01:50:35,679 character 3163 01:50:33,599 --> 01:50:37,040 as the name suggests it can hold a 3164 01:50:35,679 --> 01:50:38,560 single character 3165 01:50:37,040 --> 01:50:40,239 any character present on the keyboard 3166 01:50:38,560 --> 01:50:41,599 for that matter including all the 3167 01:50:40,239 --> 01:50:43,679 symbols like comma 3168 01:50:41,599 --> 01:50:45,520 question mark numbers like 1 2 3 3169 01:50:43,679 --> 01:50:47,920 characters like abc 3170 01:50:45,520 --> 01:50:50,400 small caps everything let's see how we 3171 01:50:47,920 --> 01:50:53,280 declare a character 3172 01:50:50,400 --> 01:50:54,800 we write char space name of the variable 3173 01:50:53,280 --> 01:50:56,080 equals to and the character which we 3174 01:50:54,800 --> 01:50:58,239 want to use 3175 01:50:56,080 --> 01:50:59,760 and that is enclosed in single inverted 3176 01:50:58,239 --> 01:51:01,840 commas and then 3177 01:50:59,760 --> 01:51:03,280 a semicolon we can also declare our 3178 01:51:01,840 --> 01:51:05,360 character like this 3179 01:51:03,280 --> 01:51:07,199 as we have seen it many times already 3180 01:51:05,360 --> 01:51:09,920 the thing to note about characters is 3181 01:51:07,199 --> 01:51:10,639 that it is still stored as a number what 3182 01:51:09,920 --> 01:51:13,360 i mean by that 3183 01:51:10,639 --> 01:51:14,000 is there is a full ascii table each 3184 01:51:13,360 --> 01:51:16,000 character 3185 01:51:14,000 --> 01:51:17,840 on the keyboard corresponds to a number 3186 01:51:16,000 --> 01:51:22,000 for example you can see 3187 01:51:17,840 --> 01:51:24,400 a capital a is 65 and a small a is 3188 01:51:22,000 --> 01:51:25,840 97 right similarly you can see the 3189 01:51:24,400 --> 01:51:27,360 entire table it contains 3190 01:51:25,840 --> 01:51:29,040 all the characters which are present on 3191 01:51:27,360 --> 01:51:31,280 the keyboard and each character 3192 01:51:29,040 --> 01:51:32,639 has its own number so we'll look at this 3193 01:51:31,280 --> 01:51:34,960 in a bit more detail 3194 01:51:32,639 --> 01:51:37,199 using our coding all right so we will 3195 01:51:34,960 --> 01:51:40,480 declare a character 3196 01:51:37,199 --> 01:51:45,679 care my care 3197 01:51:40,480 --> 01:51:45,679 is equal to right 3198 01:51:46,800 --> 01:51:54,880 now we will print it right 3199 01:51:50,960 --> 01:51:58,000 we get an a now if i write 65 3200 01:51:54,880 --> 01:52:00,880 which is the ascii value of capital a 3201 01:51:58,000 --> 01:52:04,080 you can refer ascii table to verify then 3202 01:52:00,880 --> 01:52:04,080 also it will print a 3203 01:52:04,320 --> 01:52:10,159 and let's have a look right it printed a 3204 01:52:08,080 --> 01:52:11,520 now still these are numbers that means 3205 01:52:10,159 --> 01:52:13,360 it should be possible 3206 01:52:11,520 --> 01:52:15,119 for us to perform some arithmetic on 3207 01:52:13,360 --> 01:52:19,840 that for example 3208 01:52:15,119 --> 01:52:22,239 if i take a here and add 1 here 3209 01:52:19,840 --> 01:52:23,760 right so what should we get we should 3210 01:52:22,239 --> 01:52:26,800 get 66 3211 01:52:23,760 --> 01:52:29,119 as expected why because the value of a 3212 01:52:26,800 --> 01:52:32,239 was 65 and it added 1 to that 3213 01:52:29,119 --> 01:52:34,480 so we get 66 right a char data type 3214 01:52:32,239 --> 01:52:36,480 occupies one byte in the memory 3215 01:52:34,480 --> 01:52:38,719 okay so i hope you understood the char 3216 01:52:36,480 --> 01:52:40,080 data type i can understand if you got 3217 01:52:38,719 --> 01:52:42,159 a bit confused with the character 3218 01:52:40,080 --> 01:52:43,199 arithmetic don't worry about that right 3219 01:52:42,159 --> 01:52:45,280 now 3220 01:52:43,199 --> 01:52:46,239 this information is enough to start our 3221 01:52:45,280 --> 01:52:47,679 projects 3222 01:52:46,239 --> 01:52:49,599 so now we have discussed all the 3223 01:52:47,679 --> 01:52:52,400 important data types like end 3224 01:52:49,599 --> 01:52:52,800 float char bool byte and you have also 3225 01:52:52,400 --> 01:52:55,119 learned 3226 01:52:52,800 --> 01:52:56,880 when to use which type of data type so 3227 01:52:55,119 --> 01:52:57,440 i'm pretty sure that you won't face any 3228 01:52:56,880 --> 01:52:59,280 issues 3229 01:52:57,440 --> 01:53:01,280 while performing your experiments 3230 01:52:59,280 --> 01:53:02,960 although there are more data types like 3231 01:53:01,280 --> 01:53:04,639 arrays and strings which are slightly 3232 01:53:02,960 --> 01:53:05,920 more complicated than data types which 3233 01:53:04,639 --> 01:53:07,679 we have already discussed 3234 01:53:05,920 --> 01:53:09,360 and they would also involve the usage of 3235 01:53:07,679 --> 01:53:10,639 loops so we will cover them after 3236 01:53:09,360 --> 01:53:12,480 discussing loops 3237 01:53:10,639 --> 01:53:14,400 as that would make it easier for you to 3238 01:53:12,480 --> 01:53:15,520 understand for now we will move on to 3239 01:53:14,400 --> 01:53:18,000 our next topic 3240 01:53:15,520 --> 01:53:19,599 which is variable scope and qualifiers 3241 01:53:18,000 --> 01:53:21,360 see you in the next video 3242 01:53:19,599 --> 01:53:23,119 now since we are familiar with the data 3243 01:53:21,360 --> 01:53:24,719 types and what variables are 3244 01:53:23,119 --> 01:53:26,719 we can easily understand what is 3245 01:53:24,719 --> 01:53:28,800 variable scope and qualifiers 3246 01:53:26,719 --> 01:53:30,960 so let's start by understanding what is 3247 01:53:28,800 --> 01:53:33,440 scope in many programming languages 3248 01:53:30,960 --> 01:53:35,360 including arduino's programming language 3249 01:53:33,440 --> 01:53:36,000 it matters where you have declared your 3250 01:53:35,360 --> 01:53:38,000 variable 3251 01:53:36,000 --> 01:53:40,320 speaking of which we have two kinds of 3252 01:53:38,000 --> 01:53:42,800 variables global variables and 3253 01:53:40,320 --> 01:53:44,159 local variables a global variable is the 3254 01:53:42,800 --> 01:53:46,320 one which can be seen by 3255 01:53:44,159 --> 01:53:48,159 every function in the program while 3256 01:53:46,320 --> 01:53:48,880 local variables are only visible to the 3257 01:53:48,159 --> 01:53:50,239 function 3258 01:53:48,880 --> 01:53:52,080 in which they are declared in the 3259 01:53:50,239 --> 01:53:54,320 arduino environment any variable 3260 01:53:52,080 --> 01:53:56,159 declared outside of a function example 3261 01:53:54,320 --> 01:53:57,360 void setup or void loop or any other 3262 01:53:56,159 --> 01:53:59,599 custom function 3263 01:53:57,360 --> 01:54:01,520 is a global variable so let's start by 3264 01:53:59,599 --> 01:54:03,840 understanding that in a proper manner 3265 01:54:01,520 --> 01:54:05,360 so what positions would qualify for 3266 01:54:03,840 --> 01:54:07,360 writing a global variable 3267 01:54:05,360 --> 01:54:08,560 the first position which we see is just 3268 01:54:07,360 --> 01:54:10,159 above white setup 3269 01:54:08,560 --> 01:54:11,920 the place where my cursor is blinking 3270 01:54:10,159 --> 01:54:14,960 right now for example i write 3271 01:54:11,920 --> 01:54:18,000 int myvariable 3272 01:54:14,960 --> 01:54:19,280 is equal to 6. so in this case my 3273 01:54:18,000 --> 01:54:22,320 variable 3274 01:54:19,280 --> 01:54:24,239 is a global variable 3275 01:54:22,320 --> 01:54:26,000 as i told the global variable is 3276 01:54:24,239 --> 01:54:28,560 accessible in all the functions 3277 01:54:26,000 --> 01:54:29,840 let's see that by printing my variable 3278 01:54:28,560 --> 01:54:33,040 in void setup 3279 01:54:29,840 --> 01:54:34,080 right it will print here as well it will 3280 01:54:33,040 --> 01:54:36,480 print 3281 01:54:34,080 --> 01:54:37,920 in void loop as well let's make an 3282 01:54:36,480 --> 01:54:39,920 identifier 3283 01:54:37,920 --> 01:54:41,719 so that we can identify in which 3284 01:54:39,920 --> 01:54:45,280 function it got printed 3285 01:54:41,719 --> 01:54:48,639 serial.println printing in 3286 01:54:45,280 --> 01:54:52,400 setup all right and let's differentiate 3287 01:54:48,639 --> 01:54:54,400 printing in blue all right 3288 01:54:52,400 --> 01:54:57,360 let's have a delay here because it will 3289 01:54:54,400 --> 01:55:00,480 print very fast otherwise 3290 01:54:57,360 --> 01:55:00,480 okay let's see that now 3291 01:55:00,719 --> 01:55:04,960 right printing in setup and printing in 3292 01:55:03,520 --> 01:55:06,320 loop 3293 01:55:04,960 --> 01:55:08,159 it is printing again and again because 3294 01:55:06,320 --> 01:55:10,400 we have written that in loop 3295 01:55:08,159 --> 01:55:12,000 as we already know loop function will 3296 01:55:10,400 --> 01:55:13,440 run until and unless we turn off the 3297 01:55:12,000 --> 01:55:15,599 arduino so that means 3298 01:55:13,440 --> 01:55:16,719 my variable could be accessed by white 3299 01:55:15,599 --> 01:55:18,639 setup as well as 3300 01:55:16,719 --> 01:55:19,760 while loop that means this is a global 3301 01:55:18,639 --> 01:55:22,800 variable 3302 01:55:19,760 --> 01:55:24,080 now we will see a local variable instead 3303 01:55:22,800 --> 01:55:26,400 of declaring it above 3304 01:55:24,080 --> 01:55:27,199 void setup let's declare it in void 3305 01:55:26,400 --> 01:55:29,199 setup 3306 01:55:27,199 --> 01:55:30,239 so now let's try to compile this we 3307 01:55:29,199 --> 01:55:32,400 should get an error 3308 01:55:30,239 --> 01:55:33,599 why because my variable was not declared 3309 01:55:32,400 --> 01:55:35,599 in the scope it is saying 3310 01:55:33,599 --> 01:55:37,119 in void loop you did not declare my 3311 01:55:35,599 --> 01:55:39,040 variable so i don't know what my 3312 01:55:37,119 --> 01:55:39,360 variable is so let's comment out this 3313 01:55:39,040 --> 01:55:41,119 line 3314 01:55:39,360 --> 01:55:43,199 now it will compile okay it compiles 3315 01:55:41,119 --> 01:55:46,480 successfully and it will just print 3316 01:55:43,199 --> 01:55:50,560 in setup once right 3317 01:55:46,480 --> 01:55:53,920 if we declare my variable 3318 01:55:50,560 --> 01:55:54,880 in void loop and just uncomment this 3319 01:55:53,920 --> 01:55:56,639 line 3320 01:55:54,880 --> 01:55:58,400 now we'll get an error in white setup 3321 01:55:56,639 --> 01:56:00,159 because it was declared in void loop but 3322 01:55:58,400 --> 01:56:02,960 it was not declared in void setup 3323 01:56:00,159 --> 01:56:04,239 you see in void setup my variable was 3324 01:56:02,960 --> 01:56:06,719 not declared in the scope 3325 01:56:04,239 --> 01:56:08,320 now let's see a consolidated example of 3326 01:56:06,719 --> 01:56:10,239 using global and local variables 3327 01:56:08,320 --> 01:56:12,800 together 3328 01:56:10,239 --> 01:56:14,320 the variable which i declare here is in 3329 01:56:12,800 --> 01:56:18,800 my global 3330 01:56:14,320 --> 01:56:22,080 variable is equal to 789 so let's 3331 01:56:18,800 --> 01:56:25,040 print it here and let's also 3332 01:56:22,080 --> 01:56:25,920 print it here okay this one is 3333 01:56:25,040 --> 01:56:27,679 accessible to 3334 01:56:25,920 --> 01:56:29,760 both white setup and while loop let's 3335 01:56:27,679 --> 01:56:32,880 declare a local variable here 3336 01:56:29,760 --> 01:56:37,119 and my local variable 3337 01:56:32,880 --> 01:56:39,119 is equal to 852. so this is a local 3338 01:56:37,119 --> 01:56:40,239 variable and it will be accessible only 3339 01:56:39,119 --> 01:56:43,840 to white setup 3340 01:56:40,239 --> 01:56:43,840 now let's try to print this 3341 01:56:44,239 --> 01:56:47,280 my local variable note that we can use 3342 01:56:46,400 --> 01:56:49,599 same names 3343 01:56:47,280 --> 01:56:51,119 if we are using a different scope for a 3344 01:56:49,599 --> 01:56:53,119 variable for example we can use 3345 01:56:51,119 --> 01:56:55,360 my local variable in void loop as well 3346 01:56:53,119 --> 01:56:59,040 and we can give it a different value 3347 01:56:55,360 --> 01:57:02,239 1 2 3 for example and let's 3348 01:56:59,040 --> 01:57:04,239 print this as well so what should be the 3349 01:57:02,239 --> 01:57:05,119 expected result when we print my global 3350 01:57:04,239 --> 01:57:07,520 variable 3351 01:57:05,119 --> 01:57:09,199 it should print 789 and when we print my 3352 01:57:07,520 --> 01:57:10,320 local variable when the code is running 3353 01:57:09,199 --> 01:57:12,480 in void setup 3354 01:57:10,320 --> 01:57:14,000 it should print 852 and when it is 3355 01:57:12,480 --> 01:57:14,800 running in while loop it should print 3356 01:57:14,000 --> 01:57:18,320 one two three 3357 01:57:14,800 --> 01:57:18,320 so let's upload this code 3358 01:57:20,800 --> 01:57:25,679 is that as expected let's see printing 3359 01:57:23,040 --> 01:57:28,239 in setup it printed my global variable 3360 01:57:25,679 --> 01:57:28,719 which is 789 and my local variable which 3361 01:57:28,239 --> 01:57:32,880 is 3362 01:57:28,719 --> 01:57:35,199 852 right now in printing in loop 3363 01:57:32,880 --> 01:57:36,239 it printed my global variable 789 and my 3364 01:57:35,199 --> 01:57:38,880 local variable which was 3365 01:57:36,239 --> 01:57:40,480 123. so i hope you are clear with the 3366 01:57:38,880 --> 01:57:42,320 scope of the variable 3367 01:57:40,480 --> 01:57:44,400 when programs start to get larger and 3368 01:57:42,320 --> 01:57:45,199 more complex local variables are useful 3369 01:57:44,400 --> 01:57:47,360 way to ensure 3370 01:57:45,199 --> 01:57:48,639 that only one function has access to its 3371 01:57:47,360 --> 01:57:50,159 own variables 3372 01:57:48,639 --> 01:57:52,320 this prevents programming errors when 3373 01:57:50,159 --> 01:57:53,840 one function modifies the variables used 3374 01:57:52,320 --> 01:57:55,599 by other functions 3375 01:57:53,840 --> 01:57:57,280 this concept will get clearer to you as 3376 01:57:55,599 --> 01:57:59,440 we progress in the course 3377 01:57:57,280 --> 01:58:00,960 so now we will look at qualifiers 3378 01:57:59,440 --> 01:58:03,440 qualifiers basically define 3379 01:58:00,960 --> 01:58:05,520 additional behavior to our variables 3380 01:58:03,440 --> 01:58:07,840 there are two main kinds of qualifiers 3381 01:58:05,520 --> 01:58:10,320 one is constant and one is static the 3382 01:58:07,840 --> 01:58:13,119 constant qualifier is declared by using 3383 01:58:10,320 --> 01:58:14,719 const keyword it is a variable qualifier 3384 01:58:13,119 --> 01:58:15,599 that modifies the behavior of the 3385 01:58:14,719 --> 01:58:18,080 variable 3386 01:58:15,599 --> 01:58:20,000 making a variable read-only this means 3387 01:58:18,080 --> 01:58:21,520 the variable can be used just as any 3388 01:58:20,000 --> 01:58:23,440 other variable of its type 3389 01:58:21,520 --> 01:58:25,199 but its value cannot be changed you will 3390 01:58:23,440 --> 01:58:27,040 get a compiler error if you try to alter 3391 01:58:25,199 --> 01:58:29,119 a value to a constant variable 3392 01:58:27,040 --> 01:58:30,719 we will just see by an example we will 3393 01:58:29,119 --> 01:58:34,000 declare our variable 3394 01:58:30,719 --> 01:58:36,880 constant int my variable 3395 01:58:34,000 --> 01:58:39,280 is equal to 5. now my variable is a 3396 01:58:36,880 --> 01:58:41,119 constant integer you cannot add anything 3397 01:58:39,280 --> 01:58:42,480 to it you cannot subtract anything to it 3398 01:58:41,119 --> 01:58:46,840 you just can't alter it 3399 01:58:42,480 --> 01:58:49,840 now let's try to alter it let's see what 3400 01:58:46,840 --> 01:58:49,840 happens 3401 01:58:50,560 --> 01:58:54,719 we got an error assignment of a read 3402 01:58:52,880 --> 01:58:56,880 only variable my variable 3403 01:58:54,719 --> 01:58:58,080 however you can use constant variables 3404 01:58:56,880 --> 01:59:03,520 for doing the math 3405 01:58:58,080 --> 01:59:06,560 for example i take another variable here 3406 01:59:03,520 --> 01:59:10,000 is equal to my variable into 3407 01:59:06,560 --> 01:59:11,760 5 right 3408 01:59:10,000 --> 01:59:13,119 since this is not possible we'll remove 3409 01:59:11,760 --> 01:59:17,840 it we'll try to 3410 01:59:13,119 --> 01:59:17,840 print the value of my second variable 3411 01:59:22,800 --> 01:59:28,639 right so can you guess what will we get 3412 01:59:26,159 --> 01:59:30,719 we got 25 right because my variable was 3413 01:59:28,639 --> 01:59:31,440 5 and we multiplied it by 5 so we got 3414 01:59:30,719 --> 01:59:33,440 25. 3415 01:59:31,440 --> 01:59:34,719 so you may wonder what purpose do 3416 01:59:33,440 --> 01:59:36,639 constant variables 3417 01:59:34,719 --> 01:59:38,400 serve in the code well we can use 3418 01:59:36,639 --> 01:59:40,719 constant variables wherever we don't 3419 01:59:38,400 --> 01:59:43,360 want our variables to change their value 3420 01:59:40,719 --> 01:59:44,960 for example there are constants like pi 3421 01:59:43,360 --> 01:59:47,280 which is 3.14 3422 01:59:44,960 --> 01:59:48,880 and we can have our arduino pins as 3423 01:59:47,280 --> 01:59:50,239 constants like if we don't want to 3424 01:59:48,880 --> 01:59:51,840 change them in the code 3425 01:59:50,239 --> 01:59:53,440 i would also like to tell you that there 3426 01:59:51,840 --> 01:59:55,440 is an alternative in c 3427 01:59:53,440 --> 01:59:56,880 plus plus language to define our 3428 01:59:55,440 --> 01:59:59,440 constant variables 3429 01:59:56,880 --> 02:00:01,599 which is hash defined as define is a 3430 01:59:59,440 --> 02:00:03,280 useful c plus plus component that allows 3431 02:00:01,599 --> 02:00:04,239 the programmer to give a name to a 3432 02:00:03,280 --> 02:00:06,719 constant value 3433 02:00:04,239 --> 02:00:08,560 before the program is compiled define 3434 02:00:06,719 --> 02:00:10,239 constants in arduino don't take up any 3435 02:00:08,560 --> 02:00:12,080 program memory space on the chip 3436 02:00:10,239 --> 02:00:13,679 the compiler will replace the references 3437 02:00:12,080 --> 02:00:15,520 to these constants with the defined 3438 02:00:13,679 --> 02:00:17,840 value at the compile time 3439 02:00:15,520 --> 02:00:19,440 so let's see this by an example we start 3440 02:00:17,840 --> 02:00:22,239 by writing hash 3441 02:00:19,440 --> 02:00:23,199 define then the name of the variable 3442 02:00:22,239 --> 02:00:27,199 which you want 3443 02:00:23,199 --> 02:00:28,639 let's say pi okay and the value of that 3444 02:00:27,199 --> 02:00:30,159 variable which you want it can be 3445 02:00:28,639 --> 02:00:32,000 anything for that matter it can be an 3446 02:00:30,159 --> 02:00:33,520 integer it can be a float it can be a 3447 02:00:32,000 --> 02:00:37,440 character 3448 02:00:33,520 --> 02:00:40,400 so let's say the value of pi is 3.14 3449 02:00:37,440 --> 02:00:41,520 right also note that we don't terminate 3450 02:00:40,400 --> 02:00:43,440 the defined lines 3451 02:00:41,520 --> 02:00:44,560 by a semicolon we just write this so 3452 02:00:43,440 --> 02:00:47,280 whenever we use 3453 02:00:44,560 --> 02:00:49,119 pi in our code the compiler will replace 3454 02:00:47,280 --> 02:00:50,800 the value which is written next to it 3455 02:00:49,119 --> 02:00:52,480 there the compiler won't care if it 3456 02:00:50,800 --> 02:00:53,840 makes any sense or not you have to make 3457 02:00:52,480 --> 02:00:56,159 sure that it makes sense 3458 02:00:53,840 --> 02:00:56,880 okay so now let's declare another 3459 02:00:56,159 --> 02:01:00,560 variable 3460 02:00:56,880 --> 02:01:03,679 of float type and let's name it area 3461 02:01:00,560 --> 02:01:07,360 of circle okay 3462 02:01:03,679 --> 02:01:12,080 and let's do the math pi into 3463 02:01:07,360 --> 02:01:14,639 r square let's say r is 5 so 3464 02:01:12,080 --> 02:01:17,040 right and now let's print the area of 3465 02:01:14,639 --> 02:01:17,040 circle 3466 02:01:18,719 --> 02:01:24,480 right let's upload it we see 3467 02:01:22,719 --> 02:01:26,000 it has automatically picked up the value 3468 02:01:24,480 --> 02:01:27,679 of pi from here and 3469 02:01:26,000 --> 02:01:29,199 it has done the math and it is giving 3470 02:01:27,679 --> 02:01:31,119 the answer to us right 3471 02:01:29,199 --> 02:01:33,280 as hash defined doesn't use any memory 3472 02:01:31,119 --> 02:01:34,960 in the arduino it is really tempting to 3473 02:01:33,280 --> 02:01:36,800 use hash define 3474 02:01:34,960 --> 02:01:38,000 but it certainly has some downsides the 3475 02:01:36,800 --> 02:01:40,639 compiler will replace 3476 02:01:38,000 --> 02:01:42,320 all the references to pi in the code and 3477 02:01:40,639 --> 02:01:44,159 you will start facing problems 3478 02:01:42,320 --> 02:01:46,719 so it is recommended that you avoid 3479 02:01:44,159 --> 02:01:48,719 using hash define so use constant int 3480 02:01:46,719 --> 02:01:50,080 in place of hash define unless you are 3481 02:01:48,719 --> 02:01:51,599 falling short of memory 3482 02:01:50,080 --> 02:01:53,599 so in the next video we'll talk about 3483 02:01:51,599 --> 02:01:55,599 the static qualifier 3484 02:01:53,599 --> 02:01:57,679 see you in the next video so we will 3485 02:01:55,599 --> 02:01:58,400 discuss about static qualifier in this 3486 02:01:57,679 --> 02:02:00,639 video 3487 02:01:58,400 --> 02:02:02,400 let me just quickly clean up this mess 3488 02:02:00,639 --> 02:02:04,480 first because it's looking so 3489 02:02:02,400 --> 02:02:07,040 confusing so just observe what's 3490 02:02:04,480 --> 02:02:11,119 happening let's declare a variable here 3491 02:02:07,040 --> 02:02:15,040 int xyz is equals to 3492 02:02:11,119 --> 02:02:20,159 zero let's increment it here and let's 3493 02:02:15,040 --> 02:02:20,159 print it let's see what happens 3494 02:02:26,159 --> 02:02:30,719 can you see that we initialized it by 3495 02:02:28,239 --> 02:02:32,400 zero we incremented by one and then we 3496 02:02:30,719 --> 02:02:33,440 printed the value so when the loop 3497 02:02:32,400 --> 02:02:35,040 started again 3498 02:02:33,440 --> 02:02:37,840 the value would be incremented to two 3499 02:02:35,040 --> 02:02:40,159 let me stop this auto scroll 3500 02:02:37,840 --> 02:02:41,280 the value will increment to two then 3501 02:02:40,159 --> 02:02:44,080 three then four and five 3502 02:02:41,280 --> 02:02:44,560 and six and then so on okay it will keep 3503 02:02:44,080 --> 02:02:47,920 running 3504 02:02:44,560 --> 02:02:50,560 until i stop it 3505 02:02:47,920 --> 02:02:52,159 so in this case we have declared xyz as 3506 02:02:50,560 --> 02:02:53,679 a global variable but i would like to 3507 02:02:52,159 --> 02:02:55,440 tell you that it is not a good practice 3508 02:02:53,679 --> 02:02:57,360 to declare many global variables 3509 02:02:55,440 --> 02:02:59,280 so we should try that we use local 3510 02:02:57,360 --> 02:03:01,119 variables as much as possible 3511 02:02:59,280 --> 02:03:04,960 so let's try to use it as a local 3512 02:03:01,119 --> 02:03:08,080 variable we will remove it from here 3513 02:03:04,960 --> 02:03:09,119 and we will declare it here right we 3514 02:03:08,080 --> 02:03:12,320 declared index y 3515 02:03:09,119 --> 02:03:14,000 equal to zero then x y z plus one 3516 02:03:12,320 --> 02:03:16,480 then we will increment it by one and 3517 02:03:14,000 --> 02:03:19,920 then we will print it okay 3518 02:03:16,480 --> 02:03:19,920 let's see what difference will it create 3519 02:03:22,719 --> 02:03:27,119 can you explain why is this happening 3520 02:03:25,520 --> 02:03:28,000 okay we initialize it by zero we 3521 02:03:27,119 --> 02:03:32,000 incremented it 3522 02:03:28,000 --> 02:03:34,080 we printed it okay and then 3523 02:03:32,000 --> 02:03:35,040 it was again initialized to zero then 3524 02:03:34,080 --> 02:03:37,440 again it was 3525 02:03:35,040 --> 02:03:38,800 incremented by one and then printed so 3526 02:03:37,440 --> 02:03:41,520 it will keep on printing one 3527 02:03:38,800 --> 02:03:42,239 unless i stop this loop so now we are in 3528 02:03:41,520 --> 02:03:44,080 a trouble 3529 02:03:42,239 --> 02:03:45,840 if we declare it in loop then it would 3530 02:03:44,080 --> 02:03:48,400 reset every time the loop is called 3531 02:03:45,840 --> 02:03:50,159 and it is recommended that we don't use 3532 02:03:48,400 --> 02:03:51,199 global variables that much so what is 3533 02:03:50,159 --> 02:03:54,840 the solution 3534 02:03:51,199 --> 02:03:56,000 the solution is that we use a static 3535 02:03:54,840 --> 02:03:58,960 qualifier 3536 02:03:56,000 --> 02:04:00,079 to do that we will just add static in 3537 02:03:58,960 --> 02:04:02,079 front of 3538 02:04:00,079 --> 02:04:04,159 our variable what this will do is this 3539 02:04:02,079 --> 02:04:06,159 will just initialize it by zero 3540 02:04:04,159 --> 02:04:07,520 and it will not reset it to zero every 3541 02:04:06,159 --> 02:04:11,840 time the loop is called 3542 02:04:07,520 --> 02:04:11,840 let's see if it solves our problem 3543 02:04:12,000 --> 02:04:16,320 yup it did solve our problem so using a 3544 02:04:14,320 --> 02:04:17,040 static data qualifier is a good way to 3545 02:04:16,320 --> 02:04:18,880 preserve 3546 02:04:17,040 --> 02:04:21,199 the data of our variables between the 3547 02:04:18,880 --> 02:04:22,480 function call i hope it was clear to you 3548 02:04:21,199 --> 02:04:24,480 please comment down if you have any 3549 02:04:22,480 --> 02:04:26,079 questions see you in the next video 3550 02:04:24,480 --> 02:04:27,520 in this video we will look at the 3551 02:04:26,079 --> 02:04:29,679 comparison operators 3552 02:04:27,520 --> 02:04:31,360 comparison operators are basically some 3553 02:04:29,679 --> 02:04:33,119 operators which would tell you if 3554 02:04:31,360 --> 02:04:34,960 something which you're trying to compare 3555 02:04:33,119 --> 02:04:36,560 is true or not they would return a 3556 02:04:34,960 --> 02:04:38,560 boolean value of either true 3557 02:04:36,560 --> 02:04:40,400 or false so we have about five or six 3558 02:04:38,560 --> 02:04:40,880 comparison operators we will just look 3559 02:04:40,400 --> 02:04:42,800 at them 3560 02:04:40,880 --> 02:04:44,719 in a moment the first operator which we 3561 02:04:42,800 --> 02:04:45,599 have is a lesson operator and is 3562 02:04:44,719 --> 02:04:47,760 represented by 3563 02:04:45,599 --> 02:04:48,880 a less than symbol then we have a 3564 02:04:47,760 --> 02:04:51,199 greater than operator 3565 02:04:48,880 --> 02:04:52,000 then we have less than equal to then we 3566 02:04:51,199 --> 02:04:54,239 have 3567 02:04:52,000 --> 02:04:55,679 greater than equal to then we have equal 3568 02:04:54,239 --> 02:04:58,639 to equal to and then 3569 02:04:55,679 --> 02:04:59,679 we have not equal right so we have a 3570 02:04:58,639 --> 02:05:01,760 total of 3571 02:04:59,679 --> 02:05:04,079 six comparison operators we will just 3572 02:05:01,760 --> 02:05:06,400 look at them what they exactly mean 3573 02:05:04,079 --> 02:05:07,920 let me comment this out first uh let's 3574 02:05:06,400 --> 02:05:11,679 have our variables 3575 02:05:07,920 --> 02:05:14,800 end variable one right 3576 02:05:11,679 --> 02:05:18,400 let's say it is seven and we have int 3577 02:05:14,800 --> 02:05:22,000 variable two and it is eight 3578 02:05:18,400 --> 02:05:25,599 let's try to compare them variable one 3579 02:05:22,000 --> 02:05:27,520 less than variable two as i told you 3580 02:05:25,599 --> 02:05:29,360 this operator returns something 3581 02:05:27,520 --> 02:05:31,760 which is true or false so what will 3582 02:05:29,360 --> 02:05:34,560 happen here is since variable one 3583 02:05:31,760 --> 02:05:35,040 is less than variable 2 right so it will 3584 02:05:34,560 --> 02:05:38,079 print 3585 02:05:35,040 --> 02:05:38,079 1. let's see 3586 02:05:40,000 --> 02:05:43,280 so now let's do one thing let us make 3587 02:05:42,159 --> 02:05:46,320 this variable 1 3588 02:05:43,280 --> 02:05:47,840 as 9. now we should get 0 because this 3589 02:05:46,320 --> 02:05:50,320 statement will become false 3590 02:05:47,840 --> 02:05:52,400 right as we expected so now can you 3591 02:05:50,320 --> 02:05:55,520 guess if i make variable 1 as 8 3592 02:05:52,400 --> 02:05:58,560 what will happen let's see 3593 02:05:55,520 --> 02:06:01,840 this should return 0 yes why because 8 3594 02:05:58,560 --> 02:06:03,679 is not less than 8 okay it is equal to 8 3595 02:06:01,840 --> 02:06:05,599 but it is not less than 8. 3596 02:06:03,679 --> 02:06:07,679 so we'll talk about this condition very 3597 02:06:05,599 --> 02:06:09,360 soon okay now we will have 3598 02:06:07,679 --> 02:06:11,920 the greater than operator let's replace 3599 02:06:09,360 --> 02:06:14,159 this right and change the variable 3600 02:06:11,920 --> 02:06:15,679 to 9 back okay so what do you think it 3601 02:06:14,159 --> 02:06:16,000 should return it should return true 3602 02:06:15,679 --> 02:06:17,920 because 3603 02:06:16,000 --> 02:06:19,520 variable 1 is greater than variable 2 of 3604 02:06:17,920 --> 02:06:20,480 course i hope you understood these two 3605 02:06:19,520 --> 02:06:23,599 operators 3606 02:06:20,480 --> 02:06:24,079 then we have less than equal to we use 3607 02:06:23,599 --> 02:06:25,920 it like 3608 02:06:24,079 --> 02:06:28,320 this a less than symbol and equal to 3609 02:06:25,920 --> 02:06:30,239 symbol this is a less than equal to 3610 02:06:28,320 --> 02:06:31,599 operator what this does is it will 3611 02:06:30,239 --> 02:06:34,239 return true 3612 02:06:31,599 --> 02:06:34,639 if the value on the left side is lesser 3613 02:06:34,239 --> 02:06:37,040 than 3614 02:06:34,639 --> 02:06:38,239 the value on the right side or it is 3615 02:06:37,040 --> 02:06:40,639 equal to the value on 3616 02:06:38,239 --> 02:06:42,000 right side you got my point so 3617 02:06:40,639 --> 02:06:43,599 previously when i made 3618 02:06:42,000 --> 02:06:45,520 variable 1 equal to eight and variable 3619 02:06:43,599 --> 02:06:48,239 two also eight it returned 3620 02:06:45,520 --> 02:06:49,520 zero but in this case it will return one 3621 02:06:48,239 --> 02:06:52,800 because eight is equal to 3622 02:06:49,520 --> 02:06:52,800 eight so let's try that 3623 02:06:53,199 --> 02:06:57,199 right so similarly a greater than equal 3624 02:06:56,639 --> 02:06:59,199 to sign 3625 02:06:57,199 --> 02:07:00,639 also works like this you can experiment 3626 02:06:59,199 --> 02:07:02,719 this on your own 3627 02:07:00,639 --> 02:07:04,800 then we'll look at the equal to equal to 3628 02:07:02,719 --> 02:07:07,360 sign equal to equal to sign means 3629 02:07:04,800 --> 02:07:08,000 it will compare if some values are equal 3630 02:07:07,360 --> 02:07:10,480 or not 3631 02:07:08,000 --> 02:07:12,320 it will return true only and only if a 3632 02:07:10,480 --> 02:07:13,920 value is exactly equal 3633 02:07:12,320 --> 02:07:16,000 in our case we will get one because our 3634 02:07:13,920 --> 02:07:19,040 value are eight and eight 3635 02:07:16,000 --> 02:07:21,920 we got one if i make it nine for example 3636 02:07:19,040 --> 02:07:21,920 we should get zero 3637 02:07:23,840 --> 02:07:27,520 then we have a not equal to operator we 3638 02:07:26,719 --> 02:07:29,679 use it like 3639 02:07:27,520 --> 02:07:30,800 we take an exclamation mark and then i 3640 02:07:29,679 --> 02:07:33,040 equal to symbol 3641 02:07:30,800 --> 02:07:35,199 this operator will tell you false only 3642 02:07:33,040 --> 02:07:38,400 if the two values are equal 3643 02:07:35,199 --> 02:07:41,360 okay in all the other cases you will get 3644 02:07:38,400 --> 02:07:43,040 a 1 not equals 2 right if some value is 3645 02:07:41,360 --> 02:07:43,280 equal to some other value it will say it 3646 02:07:43,040 --> 02:07:45,840 is 3647 02:07:43,280 --> 02:07:46,800 false because that is equal but if you 3648 02:07:45,840 --> 02:07:48,960 take any value 3649 02:07:46,800 --> 02:07:51,520 in our case for example variable 1 is 9 3650 02:07:48,960 --> 02:07:54,560 and variable 2 is 8 we should get 3651 02:07:51,520 --> 02:07:57,920 a 1 because that is true 3652 02:07:54,560 --> 02:07:59,840 right so we have covered all the 3653 02:07:57,920 --> 02:08:01,679 operators and how they work so you may 3654 02:07:59,840 --> 02:08:02,639 be wondering now what is the use of 3655 02:08:01,679 --> 02:08:04,880 these operators 3656 02:08:02,639 --> 02:08:06,880 in programming well these operators will 3657 02:08:04,880 --> 02:08:08,320 help you compare the values for example 3658 02:08:06,880 --> 02:08:10,159 you make a project in which you have to 3659 02:08:08,320 --> 02:08:12,079 compare the values of the sensors so you 3660 02:08:10,159 --> 02:08:14,480 may have to use these operators 3661 02:08:12,079 --> 02:08:15,280 right and when you use these operators 3662 02:08:14,480 --> 02:08:17,599 you will get some 3663 02:08:15,280 --> 02:08:18,800 decision making capability in your code 3664 02:08:17,599 --> 02:08:20,719 i would like you to note 3665 02:08:18,800 --> 02:08:22,719 one important thing about the equal to 3666 02:08:20,719 --> 02:08:24,320 operator many people make a mistake 3667 02:08:22,719 --> 02:08:26,239 while using the equal to operator 3668 02:08:24,320 --> 02:08:28,400 they use 1 equal to sign instead of 2 3669 02:08:26,239 --> 02:08:30,320 equal to signs while 1 equal to sign 3670 02:08:28,400 --> 02:08:32,560 is the assignment operator that means 3671 02:08:30,320 --> 02:08:34,560 you are assigning a value to a variable 3672 02:08:32,560 --> 02:08:36,960 like in this case we have assigned a 3673 02:08:34,560 --> 02:08:39,840 value of 9 to variable 1 3674 02:08:36,960 --> 02:08:40,800 we have used one equal to sign okay and 3675 02:08:39,840 --> 02:08:42,159 when we use 3676 02:08:40,800 --> 02:08:44,239 double equals to that means we are 3677 02:08:42,159 --> 02:08:46,000 trying to compare something 3678 02:08:44,239 --> 02:08:47,520 so to avoid making mistakes i really 3679 02:08:46,000 --> 02:08:49,440 recommend that you double check 3680 02:08:47,520 --> 02:08:50,960 the operator which you have used i will 3681 02:08:49,440 --> 02:08:52,560 talk about this once more 3682 02:08:50,960 --> 02:08:55,199 in the control structures when we study 3683 02:08:52,560 --> 02:08:56,960 about the if conditional block 3684 02:08:55,199 --> 02:08:58,800 and in the next video we will learn 3685 02:08:56,960 --> 02:09:00,400 about the logical operators 3686 02:08:58,800 --> 02:09:02,239 in this video we will look at logical 3687 02:09:00,400 --> 02:09:04,239 operators the concept of logical 3688 02:09:02,239 --> 02:09:04,960 operators is very simple we use logical 3689 02:09:04,239 --> 02:09:06,639 operators 3690 02:09:04,960 --> 02:09:08,239 whenever we want to take decisions in 3691 02:09:06,639 --> 02:09:10,400 the code each operand 3692 02:09:08,239 --> 02:09:12,000 is applied to some condition which may 3693 02:09:10,400 --> 02:09:13,679 be either true or false 3694 02:09:12,000 --> 02:09:15,040 we'll just see that in a moment so 3695 02:09:13,679 --> 02:09:15,679 basically there are three logical 3696 02:09:15,040 --> 02:09:18,480 operators 3697 02:09:15,679 --> 02:09:19,040 and operator or operator and a not 3698 02:09:18,480 --> 02:09:21,360 operator 3699 02:09:19,040 --> 02:09:22,719 so let's see how it works in coding so 3700 02:09:21,360 --> 02:09:25,520 the and operator 3701 02:09:22,719 --> 02:09:27,280 the and operator is represented by two 3702 02:09:25,520 --> 02:09:28,960 ampersand signs 3703 02:09:27,280 --> 02:09:30,719 these signs can you see that then we 3704 02:09:28,960 --> 02:09:31,760 have or operator and which is 3705 02:09:30,719 --> 02:09:33,520 represented by 3706 02:09:31,760 --> 02:09:34,800 two straight lines we'll find this 3707 02:09:33,520 --> 02:09:37,199 symbol just above your 3708 02:09:34,800 --> 02:09:37,920 enter key and then we have a not 3709 02:09:37,199 --> 02:09:41,360 operator 3710 02:09:37,920 --> 02:09:43,840 it is an exclamation mark that's all 3711 02:09:41,360 --> 02:09:45,760 so let's see the and operator so the and 3712 02:09:43,840 --> 02:09:46,000 operator expects that all the conditions 3713 02:09:45,760 --> 02:09:48,400 which 3714 02:09:46,000 --> 02:09:49,760 we are using in it are true in order to 3715 02:09:48,400 --> 02:09:51,599 return a true 3716 02:09:49,760 --> 02:09:53,760 these operators also return a boolean 3717 02:09:51,599 --> 02:09:56,239 value of either true or false 3718 02:09:53,760 --> 02:09:57,920 they also operate on boolean values 3719 02:09:56,239 --> 02:09:58,560 which is either true or false like i 3720 02:09:57,920 --> 02:10:01,119 told you 3721 02:09:58,560 --> 02:10:02,960 they work on some conditions please hold 3722 02:10:01,119 --> 02:10:05,599 on as i further clarify this 3723 02:10:02,960 --> 02:10:07,360 let's start with the and operator let me 3724 02:10:05,599 --> 02:10:09,199 just open the cl monitor so that we can 3725 02:10:07,360 --> 02:10:10,719 understand it side by side 3726 02:10:09,199 --> 02:10:12,960 the first thing which we have written is 3727 02:10:10,719 --> 02:10:15,520 the lessons about and operator 3728 02:10:12,960 --> 02:10:17,040 it is printed exactly as we have written 3729 02:10:15,520 --> 02:10:19,360 it 3730 02:10:17,040 --> 02:10:20,800 okay then it is true and true is true 3731 02:10:19,360 --> 02:10:23,440 and true is written like this 3732 02:10:20,800 --> 02:10:24,560 okay then we have written true which is 3733 02:10:23,440 --> 02:10:27,679 the boolean value 3734 02:10:24,560 --> 02:10:28,159 then the operator and operator and then 3735 02:10:27,679 --> 02:10:30,560 another 3736 02:10:28,159 --> 02:10:31,520 boolean value which is again true the 3737 02:10:30,560 --> 02:10:33,760 true and true 3738 02:10:31,520 --> 02:10:35,440 returns a true and both of the two 3739 02:10:33,760 --> 02:10:37,280 conditions are true 3740 02:10:35,440 --> 02:10:38,800 then the answer is true for all the 3741 02:10:37,280 --> 02:10:41,520 other conditions it is 3742 02:10:38,800 --> 02:10:42,639 false for example true and false is 3743 02:10:41,520 --> 02:10:45,040 false 3744 02:10:42,639 --> 02:10:46,320 false and true is false false and false 3745 02:10:45,040 --> 02:10:48,960 is also false 3746 02:10:46,320 --> 02:10:50,159 so whenever we use it to take decisions 3747 02:10:48,960 --> 02:10:52,239 we tell the compiler 3748 02:10:50,159 --> 02:10:53,280 you have to proceed only if both the 3749 02:10:52,239 --> 02:10:55,199 conditions are true 3750 02:10:53,280 --> 02:10:57,040 okay if they're false you don't have to 3751 02:10:55,199 --> 02:10:58,560 proceed okay i hope it is clear 3752 02:10:57,040 --> 02:11:00,560 if it is not clear don't worry we will 3753 02:10:58,560 --> 02:11:01,679 just understand while we write our main 3754 02:11:00,560 --> 02:11:03,520 programs 3755 02:11:01,679 --> 02:11:05,199 then we have printed some empty lines so 3756 02:11:03,520 --> 02:11:05,840 that we can have a space over here then 3757 02:11:05,199 --> 02:11:08,639 we will see 3758 02:11:05,840 --> 02:11:10,079 the or operator this is the or operator 3759 02:11:08,639 --> 02:11:13,280 it is printing the lessons about 3760 02:11:10,079 --> 02:11:15,119 our operator with the or operator even 3761 02:11:13,280 --> 02:11:17,520 if one condition is true 3762 02:11:15,119 --> 02:11:18,719 then the resultant will be true it will 3763 02:11:17,520 --> 02:11:21,280 be false only if 3764 02:11:18,719 --> 02:11:22,079 all the conditions are false for example 3765 02:11:21,280 --> 02:11:25,040 we can see 3766 02:11:22,079 --> 02:11:27,360 true and true is true true and false is 3767 02:11:25,040 --> 02:11:29,599 also true false and true is also true 3768 02:11:27,360 --> 02:11:31,280 false and false is false right then 3769 02:11:29,599 --> 02:11:33,119 again we have printed some lines 3770 02:11:31,280 --> 02:11:34,960 so that we can see the gap here then we 3771 02:11:33,119 --> 02:11:36,719 will see the not operator the not 3772 02:11:34,960 --> 02:11:38,800 operator basically just reverses the 3773 02:11:36,719 --> 02:11:41,119 value of the boolean for example 3774 02:11:38,800 --> 02:11:42,159 the not of true is we have used the 3775 02:11:41,119 --> 02:11:44,639 operator here 3776 02:11:42,159 --> 02:11:46,719 and the not of true is false as you can 3777 02:11:44,639 --> 02:11:47,119 see it's zero then the not of false is 3778 02:11:46,719 --> 02:11:50,000 true 3779 02:11:47,119 --> 02:11:51,280 right it has just reversed the values it 3780 02:11:50,000 --> 02:11:52,560 is very useful when we write our 3781 02:11:51,280 --> 02:11:54,719 conditional blocks 3782 02:11:52,560 --> 02:11:55,760 which we will see shortly all right so 3783 02:11:54,719 --> 02:11:57,040 let me just 3784 02:11:55,760 --> 02:11:59,199 make some changes so that you can 3785 02:11:57,040 --> 02:12:00,320 connect it with the comparison operators 3786 02:11:59,199 --> 02:12:01,840 which we used earlier 3787 02:12:00,320 --> 02:12:03,440 okay so instead of straight away writing 3788 02:12:01,840 --> 02:12:06,159 true here let's take 3789 02:12:03,440 --> 02:12:07,599 5 greater than 3 which is true right and 3790 02:12:06,159 --> 02:12:11,199 instead of writing true here 3791 02:12:07,599 --> 02:12:13,679 we can say seven is less than eight 3792 02:12:11,199 --> 02:12:15,679 okay both the conditions are true hence 3793 02:12:13,679 --> 02:12:18,960 we will also get 3794 02:12:15,679 --> 02:12:21,360 true right then also we got true 3795 02:12:18,960 --> 02:12:23,119 because both the conditions were true if 3796 02:12:21,360 --> 02:12:26,719 we make one condition false 3797 02:12:23,119 --> 02:12:29,679 let's say here 8 is less than 3798 02:12:26,719 --> 02:12:30,000 5 which is false right so true and false 3799 02:12:29,679 --> 02:12:33,360 is 3800 02:12:30,000 --> 02:12:33,360 false let's see that 3801 02:12:33,679 --> 02:12:37,760 right this is giving false we'll just 3802 02:12:36,960 --> 02:12:40,000 quickly look at 3803 02:12:37,760 --> 02:12:41,840 our condition let's say both the 3804 02:12:40,000 --> 02:12:44,800 conditions are false 3805 02:12:41,840 --> 02:12:45,920 let's make false conditions 5 is less 3806 02:12:44,800 --> 02:12:49,280 than 3807 02:12:45,920 --> 02:12:52,639 2 which is false 4 is greater than 3808 02:12:49,280 --> 02:12:54,960 9 which is also false so we should get 3809 02:12:55,679 --> 02:12:59,280 right which is this line false and false 3810 02:12:58,880 --> 02:13:01,760 is 3811 02:12:59,280 --> 02:13:03,360 0. i can understand it can be a bit 3812 02:13:01,760 --> 02:13:04,239 confusing for some people but i can 3813 02:13:03,360 --> 02:13:06,079 assure you that 3814 02:13:04,239 --> 02:13:08,159 once you start writing the codes on your 3815 02:13:06,079 --> 02:13:10,239 own you won't face any problem 3816 02:13:08,159 --> 02:13:11,520 while using these operators and even if 3817 02:13:10,239 --> 02:13:12,800 you still have some problem we are 3818 02:13:11,520 --> 02:13:14,000 always there to help you 3819 02:13:12,800 --> 02:13:16,159 you can always comment down in the 3820 02:13:14,000 --> 02:13:16,719 comment sections so see you in the next 3821 02:13:16,159 --> 02:13:18,960 video 3822 02:13:16,719 --> 02:13:20,719 we will now look at control structures 3823 02:13:18,960 --> 02:13:22,960 so basically till now we have seen 3824 02:13:20,719 --> 02:13:24,560 that the code is executed line by line 3825 02:13:22,960 --> 02:13:26,000 that means the lines of codes are 3826 02:13:24,560 --> 02:13:27,360 executed in the order 3827 02:13:26,000 --> 02:13:28,639 in which we have written them for 3828 02:13:27,360 --> 02:13:30,400 example we have written some code to 3829 02:13:28,639 --> 02:13:31,360 perform action one then we have written 3830 02:13:30,400 --> 02:13:33,280 some code to perform 3831 02:13:31,360 --> 02:13:34,800 action two then in that case the action 3832 02:13:33,280 --> 02:13:36,800 one will happen before 3833 02:13:34,800 --> 02:13:38,480 action two when the action do completes 3834 02:13:36,800 --> 02:13:40,320 then the action three will take place so 3835 02:13:38,480 --> 02:13:42,400 similarly there is a controlled flow of 3836 02:13:40,320 --> 02:13:44,159 code where we can decide which parts of 3837 02:13:42,400 --> 02:13:46,000 the code we want to execute based on 3838 02:13:44,159 --> 02:13:47,280 some conditions we start our code 3839 02:13:46,000 --> 02:13:48,719 and then there is a condition that 3840 02:13:47,280 --> 02:13:49,199 condition can be anything for that 3841 02:13:48,719 --> 02:13:51,199 matter 3842 02:13:49,199 --> 02:13:52,880 and based on that condition if it is 3843 02:13:51,199 --> 02:13:53,599 true or false we can take some other 3844 02:13:52,880 --> 02:13:56,400 actions 3845 02:13:53,599 --> 02:13:57,840 let's say we have a switch we'll check 3846 02:13:56,400 --> 02:13:58,719 if switch is pressed then we want to 3847 02:13:57,840 --> 02:14:00,320 take some action 3848 02:13:58,719 --> 02:14:01,760 if it is not pressed we want some other 3849 02:14:00,320 --> 02:14:03,440 action to take place and the flow of 3850 02:14:01,760 --> 02:14:05,199 code will depend on that condition 3851 02:14:03,440 --> 02:14:06,880 either it will go this way either it 3852 02:14:05,199 --> 02:14:08,000 will go this way and after completing 3853 02:14:06,880 --> 02:14:09,760 that task it will 3854 02:14:08,000 --> 02:14:11,199 jump back to the main code execute the 3855 02:14:09,760 --> 02:14:11,760 lines which are present in the main code 3856 02:14:11,199 --> 02:14:13,679 and then 3857 02:14:11,760 --> 02:14:15,280 it will exit so the first control 3858 02:14:13,679 --> 02:14:17,040 structure which we will study is 3859 02:14:15,280 --> 02:14:18,800 the if statement we will understand 3860 02:14:17,040 --> 02:14:20,960 about if statement and we will see how 3861 02:14:18,800 --> 02:14:21,760 to use if conditions in our code in the 3862 02:14:20,960 --> 02:14:23,920 next video 3863 02:14:21,760 --> 02:14:25,520 so let us see the if condition whenever 3864 02:14:23,920 --> 02:14:26,000 we write an if statement we write a 3865 02:14:25,520 --> 02:14:28,079 condition 3866 02:14:26,000 --> 02:14:29,440 along with that let's say we are trying 3867 02:14:28,079 --> 02:14:31,040 to use a if block 3868 02:14:29,440 --> 02:14:32,560 will take a condition which we want 3869 02:14:31,040 --> 02:14:34,400 should be true if it is true 3870 02:14:32,560 --> 02:14:35,599 then whatever we write in the if block 3871 02:14:34,400 --> 02:14:37,040 will execute and then 3872 02:14:35,599 --> 02:14:39,040 it will move on to the statement which 3873 02:14:37,040 --> 02:14:40,960 is written just after if statement okay 3874 02:14:39,040 --> 02:14:43,520 and it will execute that as well 3875 02:14:40,960 --> 02:14:44,320 and then it will exit but if in case it 3876 02:14:43,520 --> 02:14:46,560 is false 3877 02:14:44,320 --> 02:14:48,320 then it will entirely ignore whatever is 3878 02:14:46,560 --> 02:14:49,440 written inside the if block and it will 3879 02:14:48,320 --> 02:14:50,960 straight away jump to 3880 02:14:49,440 --> 02:14:52,719 the code which is written after if 3881 02:14:50,960 --> 02:14:54,320 statement it will execute that 3882 02:14:52,719 --> 02:14:56,400 and then it will exit let us quickly 3883 02:14:54,320 --> 02:14:57,920 look at the syntax of if statement 3884 02:14:56,400 --> 02:14:59,679 let's see this is our code we have 3885 02:14:57,920 --> 02:15:02,239 written some statements we write 3886 02:14:59,679 --> 02:15:03,040 if then we start a bracket we write our 3887 02:15:02,239 --> 02:15:04,960 condition 3888 02:15:03,040 --> 02:15:06,960 let's say something greater than 3889 02:15:04,960 --> 02:15:08,560 something or if something is true 3890 02:15:06,960 --> 02:15:10,960 if something is false if something is 3891 02:15:08,560 --> 02:15:12,719 not true anything for that matter i will 3892 02:15:10,960 --> 02:15:14,480 put a condition in this bracket then we 3893 02:15:12,719 --> 02:15:15,440 close the bracket and then we open up 3894 02:15:14,480 --> 02:15:16,960 the curly bracket 3895 02:15:15,440 --> 02:15:18,800 then we write all the statements which 3896 02:15:16,960 --> 02:15:20,480 we want to execute then we close the 3897 02:15:18,800 --> 02:15:22,079 bracket and then we move on to 3898 02:15:20,480 --> 02:15:24,320 write more statements in our code so 3899 02:15:22,079 --> 02:15:26,639 this is the syntax of if statement 3900 02:15:24,320 --> 02:15:27,920 so let us try this in our coding so we 3901 02:15:26,639 --> 02:15:29,920 have an example here 3902 02:15:27,920 --> 02:15:30,960 we'll write cl dot begin 9600 here so 3903 02:15:29,920 --> 02:15:32,639 that we can communicate with the 3904 02:15:30,960 --> 02:15:34,320 computer so we will write the first 3905 02:15:32,639 --> 02:15:36,239 statement serial.println 3906 02:15:34,320 --> 02:15:38,159 this line should print irrespective of 3907 02:15:36,239 --> 02:15:39,840 anything and yes this line will print 3908 02:15:38,159 --> 02:15:42,719 irrespective of anything 3909 02:15:39,840 --> 02:15:43,760 then we will write if true serial dot 3910 02:15:42,719 --> 02:15:46,960 println 3911 02:15:43,760 --> 02:15:50,239 this line should print 3912 02:15:46,960 --> 02:15:52,000 only if the condition 3913 02:15:50,239 --> 02:15:53,360 is true please note that we don't use a 3914 02:15:52,000 --> 02:15:56,400 semicolon here 3915 02:15:53,360 --> 02:16:00,079 let's write another statement 3916 02:15:56,400 --> 02:16:03,360 if false serial.print 3917 02:16:00,079 --> 02:16:06,800 ln this statement will not print 3918 02:16:03,360 --> 02:16:08,800 as the condition is false it is over 3919 02:16:06,800 --> 02:16:10,079 and then again we'll write one line 3920 02:16:08,800 --> 02:16:12,239 which should execute 3921 02:16:10,079 --> 02:16:13,520 irrespective of anything let's say this 3922 02:16:12,239 --> 02:16:15,920 only this line 3923 02:16:13,520 --> 02:16:16,639 should also print irrespective of 3924 02:16:15,920 --> 02:16:19,599 anything 3925 02:16:16,639 --> 02:16:21,920 so let's upload this code and see what 3926 02:16:19,599 --> 02:16:21,920 happens 3927 02:16:22,159 --> 02:16:25,920 so we see this line should print 3928 02:16:24,560 --> 02:16:27,360 irrespective of anything this line 3929 02:16:25,920 --> 02:16:28,719 should print only if the condition is 3930 02:16:27,360 --> 02:16:30,159 true this line should also print 3931 02:16:28,719 --> 02:16:32,160 irrespective of anything 3932 02:16:30,159 --> 02:16:34,080 did you know that when the condition was 3933 02:16:32,160 --> 02:16:36,639 false the block did not execute 3934 02:16:34,080 --> 02:16:38,000 let me do one more thing let's see a 3935 02:16:36,639 --> 02:16:40,319 block of code 3936 02:16:38,000 --> 02:16:41,519 executing let's print one more line here 3937 02:16:40,319 --> 02:16:43,519 the second line 3938 02:16:41,519 --> 02:16:45,200 right so now this line should also print 3939 02:16:43,519 --> 02:16:47,120 there 3940 02:16:45,200 --> 02:16:49,280 the second line because it was the part 3941 02:16:47,120 --> 02:16:50,399 of this if block so whatever is written 3942 02:16:49,280 --> 02:16:52,240 inside this block 3943 02:16:50,399 --> 02:16:54,240 it will execute no matter what once the 3944 02:16:52,240 --> 02:16:56,160 condition is true but of course 3945 02:16:54,240 --> 02:16:58,080 writing true and false exactly like this 3946 02:16:56,160 --> 02:16:58,479 does not make any sense right so we have 3947 02:16:58,080 --> 02:17:01,439 to 3948 02:16:58,479 --> 02:17:03,040 build our conditions let's say if 5 is 3949 02:17:01,439 --> 02:17:05,200 greater than 3 3950 02:17:03,040 --> 02:17:07,040 then this should execute we'll see the 3951 02:17:05,200 --> 02:17:07,519 same result because this evaluates to 3952 02:17:07,040 --> 02:17:09,040 true 3953 02:17:07,519 --> 02:17:10,960 right so basically we should keep in 3954 02:17:09,040 --> 02:17:13,439 mind that a boolean 3955 02:17:10,960 --> 02:17:15,359 value should come inside this okay in 3956 02:17:13,439 --> 02:17:15,840 this bracket there should be a boolean 3957 02:17:15,359 --> 02:17:17,359 value 3958 02:17:15,840 --> 02:17:19,679 then only it would be able to take some 3959 02:17:17,359 --> 02:17:21,439 decision based on that boolean value so 3960 02:17:19,679 --> 02:17:21,920 now we can complicate the condition as 3961 02:17:21,439 --> 02:17:25,200 well 3962 02:17:21,920 --> 02:17:27,200 like for example and 2 greater than 5 3963 02:17:25,200 --> 02:17:28,240 but this is false right like we saw in 3964 02:17:27,200 --> 02:17:29,920 the and operator 3965 02:17:28,240 --> 02:17:31,519 both the conditions should be true in 3966 02:17:29,920 --> 02:17:33,760 order to return true 3967 02:17:31,519 --> 02:17:35,599 right but this is true and this is false 3968 02:17:33,760 --> 02:17:37,920 so we'll now see that this block of code 3969 02:17:35,599 --> 02:17:41,280 will also not execute 3970 02:17:37,920 --> 02:17:42,719 let's see right as expected 3971 02:17:41,280 --> 02:17:44,880 this line should print irrespective of 3972 02:17:42,719 --> 02:17:47,599 anything this line will print anyway 3973 02:17:44,880 --> 02:17:49,359 this line will also print anyway so now 3974 02:17:47,599 --> 02:17:52,000 let's try to print this line 3975 02:17:49,359 --> 02:17:52,399 we'll make this condition true 2 is less 3976 02:17:52,000 --> 02:17:55,439 than 3977 02:17:52,399 --> 02:17:56,479 5 or 5 is less than 2. this condition is 3978 02:17:55,439 --> 02:17:58,160 true because 3979 02:17:56,479 --> 02:18:00,319 one of the condition is true right 2 is 3980 02:17:58,160 --> 02:18:01,040 less than 5 that is true but 5 is not 3981 02:18:00,319 --> 02:18:03,120 less than 2 3982 02:18:01,040 --> 02:18:04,960 this is false but in the or condition 3983 02:18:03,120 --> 02:18:06,080 one statement has to be true to get the 3984 02:18:04,960 --> 02:18:10,240 resultant as true 3985 02:18:06,080 --> 02:18:12,160 so this line should print now let's see 3986 02:18:10,240 --> 02:18:14,240 yep so we were able to print this line 3987 02:18:12,160 --> 02:18:16,479 because we made the condition true 3988 02:18:14,240 --> 02:18:18,240 okay so when we will be making our 3989 02:18:16,479 --> 02:18:20,000 projects what kind of conditions will we 3990 02:18:18,240 --> 02:18:21,920 use we will be using conditions like 3991 02:18:20,000 --> 02:18:23,359 the sensor value on the left hand side 3992 02:18:21,920 --> 02:18:24,319 should be greater than the sensor value 3993 02:18:23,359 --> 02:18:26,160 on the right hand side 3994 02:18:24,319 --> 02:18:27,599 then these things should happen so i 3995 02:18:26,160 --> 02:18:28,399 think you were able to relate with this 3996 02:18:27,599 --> 02:18:30,080 thing 3997 02:18:28,399 --> 02:18:31,439 okay now i will tell you another thing 3998 02:18:30,080 --> 02:18:33,599 for example i took a bool 3999 02:18:31,439 --> 02:18:35,679 many people do mistake in this so let's 4000 02:18:33,599 --> 02:18:39,439 start by taking a bool 4001 02:18:35,679 --> 02:18:40,240 my bowl is equal to false so now what i 4002 02:18:39,439 --> 02:18:43,359 want to do is 4003 02:18:40,240 --> 02:18:43,840 i want to print these lines only if my 4004 02:18:43,359 --> 02:18:46,240 bool 4005 02:18:43,840 --> 02:18:47,200 is true so i'm comparing it if it is 4006 02:18:46,240 --> 02:18:48,960 true then only 4007 02:18:47,200 --> 02:18:50,559 it should print but this is not true 4008 02:18:48,960 --> 02:18:52,800 right because the value of my bool was 4009 02:18:50,559 --> 02:18:53,439 false so that's why the resultant was 4010 02:18:52,800 --> 02:18:55,280 false 4011 02:18:53,439 --> 02:18:56,880 so hence the lines present in this if 4012 02:18:55,280 --> 02:18:59,280 block will not execute 4013 02:18:56,880 --> 02:19:03,120 now if we write false then it will 4014 02:18:59,280 --> 02:19:03,120 execute because it is actually false 4015 02:19:03,439 --> 02:19:07,760 so we can see these lines got printed so 4016 02:19:06,240 --> 02:19:08,319 now i'll talk about the mistake which 4017 02:19:07,760 --> 02:19:10,240 people do 4018 02:19:08,319 --> 02:19:11,679 what they will do is they will use one 4019 02:19:10,240 --> 02:19:13,760 equal to sign instead of 4020 02:19:11,679 --> 02:19:14,960 two signs so what will happen is the 4021 02:19:13,760 --> 02:19:18,000 compiler will assign 4022 02:19:14,960 --> 02:19:18,719 a value of true to my bool and the 4023 02:19:18,000 --> 02:19:22,000 resultant 4024 02:19:18,719 --> 02:19:25,920 value of my bool will become one okay 4025 02:19:22,000 --> 02:19:29,200 and this block of code will execute 4026 02:19:25,920 --> 02:19:30,399 right so the expression which we write 4027 02:19:29,200 --> 02:19:32,960 in the if condition 4028 02:19:30,399 --> 02:19:35,359 is executed first and then the value of 4029 02:19:32,960 --> 02:19:37,040 that thing is taken into consideration 4030 02:19:35,359 --> 02:19:39,679 if it is true or false 4031 02:19:37,040 --> 02:19:40,639 okay in our case my bool was assigned a 4032 02:19:39,679 --> 02:19:42,800 value of true 4033 02:19:40,639 --> 02:19:44,160 and then the value of my bool was used 4034 02:19:42,800 --> 02:19:46,559 please take care you use 4035 02:19:44,160 --> 02:19:47,519 double equals to if you want to compare 4036 02:19:46,559 --> 02:19:50,640 the values 4037 02:19:47,519 --> 02:19:53,359 now we can do nesting of ifs as well 4038 02:19:50,640 --> 02:19:53,920 what nesting means like this is our if 4039 02:19:53,359 --> 02:19:56,479 block 4040 02:19:53,920 --> 02:19:58,000 we can write more if blocks inside are 4041 02:19:56,479 --> 02:20:00,160 the parent if block 4042 02:19:58,000 --> 02:20:01,600 let's say we write another if if true 4043 02:20:00,160 --> 02:20:04,960 serial dot 4044 02:20:01,600 --> 02:20:07,280 print this is nested 4045 02:20:04,960 --> 02:20:08,399 if right we can write another if inside 4046 02:20:07,280 --> 02:20:11,840 that if 4047 02:20:08,399 --> 02:20:16,399 false serial.println 4048 02:20:11,840 --> 02:20:19,680 this is another line which will not 4049 02:20:16,399 --> 02:20:21,760 execute so this was nesting of if this 4050 02:20:19,680 --> 02:20:22,240 is the parent if this is a child if and 4051 02:20:21,760 --> 02:20:24,640 this is 4052 02:20:22,240 --> 02:20:25,520 a further child of this if right we can 4053 02:20:24,640 --> 02:20:27,200 see like this 4054 02:20:25,520 --> 02:20:29,600 this is the flow this bracket closes 4055 02:20:27,200 --> 02:20:32,880 here and this bracket closes here 4056 02:20:29,600 --> 02:20:33,439 for example in any case the parent if is 4057 02:20:32,880 --> 02:20:35,359 false 4058 02:20:33,439 --> 02:20:37,280 then all the child lifts will never 4059 02:20:35,359 --> 02:20:39,280 execute please keep that in mind 4060 02:20:37,280 --> 02:20:40,479 i hope you understood this point i'm 4061 02:20:39,280 --> 02:20:42,000 pretty sure that you will be able to 4062 02:20:40,479 --> 02:20:43,439 understand it in a better way when you 4063 02:20:42,000 --> 02:20:45,760 perform your experiments 4064 02:20:43,439 --> 02:20:46,800 so in the next video we'll look at the 4065 02:20:45,760 --> 02:20:48,479 else statement 4066 02:20:46,800 --> 02:20:50,560 see you in the next video now we will 4067 02:20:48,479 --> 02:20:52,240 try to understand the else statement 4068 02:20:50,560 --> 02:20:52,720 first of all let us look at the flow of 4069 02:20:52,240 --> 02:20:54,319 the code 4070 02:20:52,720 --> 02:20:56,319 we always write an else statement 4071 02:20:54,319 --> 02:20:58,000 preceded by an if statement 4072 02:20:56,319 --> 02:20:59,439 let's have a look at the flow of code 4073 02:20:58,000 --> 02:21:01,520 when we use an else block 4074 02:20:59,439 --> 02:21:03,040 there's an entry of code there is an if 4075 02:21:01,520 --> 02:21:05,600 condition if that is true 4076 02:21:03,040 --> 02:21:06,560 the body inside the if block is executed 4077 02:21:05,600 --> 02:21:08,479 the body inside 4078 02:21:06,560 --> 02:21:10,640 the else block is entirely ignored then 4079 02:21:08,479 --> 02:21:12,560 it moves on to code after if statement 4080 02:21:10,640 --> 02:21:14,000 after executing that code it would exit 4081 02:21:12,560 --> 02:21:15,200 in case if it is false it will 4082 02:21:14,000 --> 02:21:17,280 straightaway go to 4083 02:21:15,200 --> 02:21:18,880 else block and it will execute the code 4084 02:21:17,280 --> 02:21:20,160 which is present inside the else block 4085 02:21:18,880 --> 02:21:21,040 and it will ignore the code which is 4086 02:21:20,160 --> 02:21:22,880 present inside 4087 02:21:21,040 --> 02:21:24,880 the if block after executing the else 4088 02:21:22,880 --> 02:21:26,479 block it will go to the main code the 4089 02:21:24,880 --> 02:21:28,240 code which is written after the 4090 02:21:26,479 --> 02:21:30,160 if statement it will execute that and it 4091 02:21:28,240 --> 02:21:32,000 will exit before looking at the syntax 4092 02:21:30,160 --> 02:21:34,399 of else block let us compare it with 4093 02:21:32,000 --> 02:21:35,120 just the if block so this was the if 4094 02:21:34,399 --> 02:21:36,880 statement 4095 02:21:35,120 --> 02:21:38,720 in if statement if the condition was 4096 02:21:36,880 --> 02:21:40,399 true it would execute the body inside 4097 02:21:38,720 --> 02:21:40,960 the if block then it will go to the main 4098 02:21:40,399 --> 02:21:43,120 code 4099 02:21:40,960 --> 02:21:44,960 execute that and then it will exit so 4100 02:21:43,120 --> 02:21:47,439 when we use just the if condition 4101 02:21:44,960 --> 02:21:49,280 without else that means we don't define 4102 02:21:47,439 --> 02:21:50,479 what we want to happen if the condition 4103 02:21:49,280 --> 02:21:52,720 which we have specified 4104 02:21:50,479 --> 02:21:54,479 is false if it is false it will entirely 4105 02:21:52,720 --> 02:21:55,359 ignore the if body and it will jump to 4106 02:21:54,479 --> 02:21:57,359 the main code 4107 02:21:55,359 --> 02:21:59,200 but in else we define what we want to 4108 02:21:57,359 --> 02:22:00,960 happen if something is false so that we 4109 02:21:59,200 --> 02:22:02,800 write in the else block so now let us 4110 02:22:00,960 --> 02:22:04,319 look at the syntax of else block we 4111 02:22:02,800 --> 02:22:06,240 start by writing if 4112 02:22:04,319 --> 02:22:08,080 we specify the condition we open the 4113 02:22:06,240 --> 02:22:09,280 bracket we write our actions here if the 4114 02:22:08,080 --> 02:22:11,040 condition one is true 4115 02:22:09,280 --> 02:22:12,399 then we close the bracket and then we 4116 02:22:11,040 --> 02:22:14,960 write else 4117 02:22:12,399 --> 02:22:16,640 if if we have more than one conditions 4118 02:22:14,960 --> 02:22:17,680 for example if you want different sound 4119 02:22:16,640 --> 02:22:19,840 levels of an alarm 4120 02:22:17,680 --> 02:22:21,840 based on the temperature ranges for 4121 02:22:19,840 --> 02:22:22,960 example at a lower temperature an alarm 4122 02:22:21,840 --> 02:22:25,040 would ring slowly 4123 02:22:22,960 --> 02:22:27,520 and at another condition let's say 4124 02:22:25,040 --> 02:22:30,240 another range it will ring a bit louder 4125 02:22:27,520 --> 02:22:30,720 and if it exceeds something then we want 4126 02:22:30,240 --> 02:22:32,880 it to 4127 02:22:30,720 --> 02:22:34,479 ring at the maximum intensity okay so 4128 02:22:32,880 --> 02:22:36,800 these things can be controlled 4129 02:22:34,479 --> 02:22:38,880 by if and else blocks okay after writing 4130 02:22:36,800 --> 02:22:40,160 else if we write condition two if that 4131 02:22:38,880 --> 02:22:42,240 condition is true think 4132 02:22:40,160 --> 02:22:43,439 b will happen okay and then finally we 4133 02:22:42,240 --> 02:22:45,040 write an else 4134 02:22:43,439 --> 02:22:46,479 if none of the conditions is true then 4135 02:22:45,040 --> 02:22:47,920 the else block will execute 4136 02:22:46,479 --> 02:22:49,840 the thing which you need to notice here 4137 02:22:47,920 --> 02:22:50,479 is if the condition one is true it will 4138 02:22:49,840 --> 02:22:52,160 execute 4139 02:22:50,479 --> 02:22:54,560 the thing a and it will straight away 4140 02:22:52,160 --> 02:22:56,880 jump to the main code after this 4141 02:22:54,560 --> 02:22:58,960 the control won't go in else if it will 4142 02:22:56,880 --> 02:23:00,399 go in else if only if the condition one 4143 02:22:58,960 --> 02:23:01,040 was false for example the code was 4144 02:23:00,399 --> 02:23:02,960 running here 4145 02:23:01,040 --> 02:23:05,359 it found that condition one was false so 4146 02:23:02,960 --> 02:23:06,319 it will jump and check if condition 2 is 4147 02:23:05,359 --> 02:23:08,319 true or false 4148 02:23:06,319 --> 02:23:10,080 if it is true then it will do the thing 4149 02:23:08,319 --> 02:23:12,160 b if it is also false 4150 02:23:10,080 --> 02:23:14,080 then it will go to else block and do the 4151 02:23:12,160 --> 02:23:16,560 thing c we will just understand this 4152 02:23:14,080 --> 02:23:17,280 with the coding example so here we have 4153 02:23:16,560 --> 02:23:19,040 example 4154 02:23:17,280 --> 02:23:20,720 for understanding the else statement 4155 02:23:19,040 --> 02:23:24,960 let's do this we'll write if true 4156 02:23:20,720 --> 02:23:26,240 serial dot print ln my first statement 4157 02:23:24,960 --> 02:23:28,000 so you can see the compiler has 4158 02:23:26,240 --> 02:23:30,000 automatically considered this bracket 4159 02:23:28,000 --> 02:23:32,240 which was originally for void setup 4160 02:23:30,000 --> 02:23:34,080 for the if block okay we have to make 4161 02:23:32,240 --> 02:23:35,600 sure we are using our brackets correctly 4162 02:23:34,080 --> 02:23:35,920 now after closing the if block we will 4163 02:23:35,600 --> 02:23:38,960 write 4164 02:23:35,920 --> 02:23:42,319 else serial dot println my 4165 02:23:38,960 --> 02:23:43,040 else statement all right so now we will 4166 02:23:42,319 --> 02:23:44,720 close 4167 02:23:43,040 --> 02:23:46,560 the white setup bracket now let us 4168 02:23:44,720 --> 02:23:48,319 upload this code okay 4169 02:23:46,560 --> 02:23:50,479 so my first statement got printed 4170 02:23:48,319 --> 02:23:52,160 because my initial if condition was true 4171 02:23:50,479 --> 02:23:54,319 and it will ignore the else block now 4172 02:23:52,160 --> 02:23:55,760 let's make it false 4173 02:23:54,319 --> 02:23:57,359 now we will see that statement written 4174 02:23:55,760 --> 02:23:58,160 in the else block will print let's have 4175 02:23:57,359 --> 02:24:01,200 a look 4176 02:23:58,160 --> 02:24:02,720 my statement okay we can do the nesting 4177 02:24:01,200 --> 02:24:04,479 in if else statements as well 4178 02:24:02,720 --> 02:24:06,399 like we saw in the if video like i can 4179 02:24:04,479 --> 02:24:08,319 start another if here 4180 02:24:06,399 --> 02:24:10,080 if some other condition will write 4181 02:24:08,319 --> 02:24:12,000 another task here so we can use 4182 02:24:10,080 --> 02:24:14,000 endless if and else and the nesting of 4183 02:24:12,000 --> 02:24:15,439 them as well by now you must be feeling 4184 02:24:14,000 --> 02:24:16,960 a little bored by just printing the 4185 02:24:15,439 --> 02:24:18,720 statements here and there and not doing 4186 02:24:16,960 --> 02:24:19,359 any real things so in the next video i 4187 02:24:18,720 --> 02:24:22,000 will show you 4188 02:24:19,359 --> 02:24:22,640 a small simulation by using if and else 4189 02:24:22,000 --> 02:24:25,120 blocks 4190 02:24:22,640 --> 02:24:26,080 so see you in the next video so before i 4191 02:24:25,120 --> 02:24:28,560 show you that fl 4192 02:24:26,080 --> 02:24:30,319 simulation i would like to show you this 4193 02:24:28,560 --> 02:24:32,240 comic 4194 02:24:30,319 --> 02:24:35,200 just have a look at this comic for like 4195 02:24:32,240 --> 02:24:38,240 5-10 seconds 4196 02:24:35,200 --> 02:24:40,160 and if you get the joke in this comic i 4197 02:24:38,240 --> 02:24:40,800 can say that you have pretty much 4198 02:24:40,160 --> 02:24:42,960 understood 4199 02:24:40,800 --> 02:24:43,920 the concepts which we have discussed so 4200 02:24:42,960 --> 02:24:45,680 far 4201 02:24:43,920 --> 02:24:47,840 okay don't worry if you could not 4202 02:24:45,680 --> 02:24:48,720 understand this once you finish the part 4203 02:24:47,840 --> 02:24:51,439 where i'm teaching 4204 02:24:48,720 --> 02:24:53,120 about functions i'm sure you will be 4205 02:24:51,439 --> 02:24:54,800 able to understand it really well 4206 02:24:53,120 --> 02:24:57,200 so just in case if you could not 4207 02:24:54,800 --> 02:24:58,560 understand this i would say that please 4208 02:24:57,200 --> 02:25:00,720 complete that section 4209 02:24:58,560 --> 02:25:01,680 and then come back to this comic again 4210 02:25:00,720 --> 02:25:03,600 and 4211 02:25:01,680 --> 02:25:04,880 i'm pretty sure that you will have a 4212 02:25:03,600 --> 02:25:07,840 good laugh 4213 02:25:04,880 --> 02:25:10,000 okay so now let's move on to that 4214 02:25:07,840 --> 02:25:11,840 simulation i was talking about 4215 02:25:10,000 --> 02:25:14,399 so as i told you that i will show you a 4216 02:25:11,840 --> 02:25:16,000 simulation of fns blocks in the previous 4217 02:25:14,399 --> 02:25:17,680 video so i will just show you 4218 02:25:16,000 --> 02:25:19,439 that simulation on the left hand side of 4219 02:25:17,680 --> 02:25:20,800 the screen you can see a circuit diagram 4220 02:25:19,439 --> 02:25:22,479 and on the right hand side of the screen 4221 02:25:20,800 --> 02:25:24,319 you can see the code which i have used 4222 02:25:22,479 --> 02:25:25,600 to make this simulation the simulation 4223 02:25:24,319 --> 02:25:27,120 tool which you see on the left is 4224 02:25:25,600 --> 02:25:28,720 autodesk tinkercad 4225 02:25:27,120 --> 02:25:30,160 you can do a google search about it if 4226 02:25:28,720 --> 02:25:31,520 you want to know more about this i'll 4227 02:25:30,160 --> 02:25:32,800 help you in the comment section if you 4228 02:25:31,520 --> 02:25:34,479 face any problem with this 4229 02:25:32,800 --> 02:25:36,319 every one of you must have performed the 4230 02:25:34,479 --> 02:25:37,760 blink example and i have very clearly 4231 02:25:36,319 --> 02:25:40,080 explained you the functions which we 4232 02:25:37,760 --> 02:25:41,600 used in that like pin mode digital write 4233 02:25:40,080 --> 02:25:42,800 and delay so i will assume that you will 4234 02:25:41,600 --> 02:25:44,800 not face any problem 4235 02:25:42,800 --> 02:25:46,319 understanding this code so let's begin i 4236 02:25:44,800 --> 02:25:48,319 have declared temperature as the global 4237 02:25:46,319 --> 02:25:49,760 variable and initialize it with 0. in 4238 02:25:48,319 --> 02:25:52,319 the void setup i have written 4239 02:25:49,760 --> 02:25:54,080 pin number 678 as output as i want to 4240 02:25:52,319 --> 02:25:56,319 connect our led to those pins 4241 02:25:54,080 --> 02:25:58,240 so in the loop section i've started with 4242 02:25:56,319 --> 02:25:59,920 if i'm trying to tell the compiler 4243 02:25:58,240 --> 02:26:02,720 if the value of the temperature is less 4244 02:25:59,920 --> 02:26:05,840 than 50 and is also greater than 10 4245 02:26:02,720 --> 02:26:06,720 that means it lies between 10 to 50. so 4246 02:26:05,840 --> 02:26:08,640 i want to 4247 02:26:06,720 --> 02:26:10,640 perform this action please note the 4248 02:26:08,640 --> 02:26:12,479 values of 50 and 10 are not 4249 02:26:10,640 --> 02:26:14,399 inclusive as we have not used the equal 4250 02:26:12,479 --> 02:26:16,080 to sign if you want to include those 4251 02:26:14,399 --> 02:26:16,399 values you will have to use an equal to 4252 02:26:16,080 --> 02:26:18,000 sign 4253 02:26:16,399 --> 02:26:19,600 as well you must be remembering less 4254 02:26:18,000 --> 02:26:20,640 than equal to operator and greater than 4255 02:26:19,600 --> 02:26:22,160 equal to operator right 4256 02:26:20,640 --> 02:26:23,760 you can always revisit the videos if you 4257 02:26:22,160 --> 02:26:25,520 have any confusion so coming back to 4258 02:26:23,760 --> 02:26:27,439 this i've simply written the code to 4259 02:26:25,520 --> 02:26:29,439 blink the led which is connected to pin 4260 02:26:27,439 --> 02:26:31,439 number six pin number six is this one 4261 02:26:29,439 --> 02:26:33,280 that means this led is connected to pin 4262 02:26:31,439 --> 02:26:34,319 number six also note that all the leds 4263 02:26:33,280 --> 02:26:36,000 which are connected here 4264 02:26:34,319 --> 02:26:37,600 are connected to a common ground which 4265 02:26:36,000 --> 02:26:38,240 we have connected like this then we have 4266 02:26:37,600 --> 02:26:40,560 written 4267 02:26:38,240 --> 02:26:42,479 else if that means if the previous if 4268 02:26:40,560 --> 02:26:44,319 was not true then check this condition 4269 02:26:42,479 --> 02:26:46,800 if temperature is greater than 50 4270 02:26:44,319 --> 02:26:48,000 and temperature is less than 70. that 4271 02:26:46,800 --> 02:26:50,800 means the temperature range is 4272 02:26:48,000 --> 02:26:52,640 51 to 69. so if this condition is true 4273 02:26:50,800 --> 02:26:53,760 then we want to blink the led connected 4274 02:26:52,640 --> 02:26:55,680 to pin number seven 4275 02:26:53,760 --> 02:26:57,439 which is this one pin number seven this 4276 02:26:55,680 --> 02:26:58,880 and then finally we have written else if 4277 02:26:57,439 --> 02:27:01,600 none of the conditions is true 4278 02:26:58,880 --> 02:27:03,280 then do this thing which is blink the 4279 02:27:01,600 --> 02:27:05,520 led which is connected to pin number 4280 02:27:03,280 --> 02:27:07,439 eight which is this led so let's say 4281 02:27:05,520 --> 02:27:09,120 we have temperature is equal to zero 4282 02:27:07,439 --> 02:27:09,920 currently we have hard coded this 4283 02:27:09,120 --> 02:27:11,439 temperature 4284 02:27:09,920 --> 02:27:13,200 but in your projects you may have some 4285 02:27:11,439 --> 02:27:15,760 sensors like lm-35 4286 02:27:13,200 --> 02:27:17,280 or dht 11 which will return you the real 4287 02:27:15,760 --> 02:27:19,280 time temperature of your room and 4288 02:27:17,280 --> 02:27:20,960 code will act accordingly but just to 4289 02:27:19,280 --> 02:27:22,319 test these conditions will be taking 4290 02:27:20,960 --> 02:27:24,240 some arbitrary values 4291 02:27:22,319 --> 02:27:25,600 so let's see in which condition will 4292 02:27:24,240 --> 02:27:27,280 this zero fall okay 4293 02:27:25,600 --> 02:27:29,439 if temperature is less than 50 or 4294 02:27:27,280 --> 02:27:30,000 greater than 10 but it is not relying in 4295 02:27:29,439 --> 02:27:31,920 this condition 4296 02:27:30,000 --> 02:27:33,040 then it is greater than 50 and less than 4297 02:27:31,920 --> 02:27:35,439 70 4298 02:27:33,040 --> 02:27:37,359 so this is also false so ultimately the 4299 02:27:35,439 --> 02:27:38,880 else code should run so let me start the 4300 02:27:37,359 --> 02:27:40,800 simulation right you can see 4301 02:27:38,880 --> 02:27:42,479 else statement was being executed that 4302 02:27:40,800 --> 02:27:45,200 means this led is blinking so now 4303 02:27:42,479 --> 02:27:46,960 let's change the value from 0 to 52. so 4304 02:27:45,200 --> 02:27:49,200 can you guess what will happen 4305 02:27:46,960 --> 02:27:50,479 for the value of 52 okay let's see the 4306 02:27:49,200 --> 02:27:52,880 value of 52 4307 02:27:50,479 --> 02:27:54,240 is less than 50 which is false so 4308 02:27:52,880 --> 02:27:54,800 ultimately this condition will be 4309 02:27:54,240 --> 02:27:56,319 discarded 4310 02:27:54,800 --> 02:27:58,319 it will check this one then so the 4311 02:27:56,319 --> 02:28:00,399 temperature is greater than 50 yes 4312 02:27:58,319 --> 02:28:01,840 temperature is less than 70 yes so this 4313 02:28:00,399 --> 02:28:03,760 condition is true 4314 02:28:01,840 --> 02:28:05,040 so hence the led connected to pin number 4315 02:28:03,760 --> 02:28:08,319 7 should start blinking 4316 02:28:05,040 --> 02:28:09,680 so let's start the simulation so led 4317 02:28:08,319 --> 02:28:13,040 connected to pin number 7 4318 02:28:09,680 --> 02:28:14,640 has started blinking pin number seven 4319 02:28:13,040 --> 02:28:17,200 okay so let's change the temperature 4320 02:28:14,640 --> 02:28:19,040 value to 25 so now this condition will 4321 02:28:17,200 --> 02:28:21,200 get true so let's start the simulation 4322 02:28:19,040 --> 02:28:22,720 right so this led is blinking so one 4323 02:28:21,200 --> 02:28:24,560 small homework for you guys is you have 4324 02:28:22,720 --> 02:28:27,120 to comment down below what will happen 4325 02:28:24,560 --> 02:28:28,240 if i select the value of 100 we can take 4326 02:28:27,120 --> 02:28:30,479 a pause of 5 seconds 4327 02:28:28,240 --> 02:28:33,359 and just go and comment down below after 4328 02:28:30,479 --> 02:28:35,200 then come back and see the results 4329 02:28:33,359 --> 02:28:36,399 so led which is connected to pin number 4330 02:28:35,200 --> 02:28:39,120 8 is blinking 4331 02:28:36,399 --> 02:28:40,880 why so because 100 will not fall in any 4332 02:28:39,120 --> 02:28:41,680 of the conditions so the compiler will 4333 02:28:40,880 --> 02:28:43,439 execute 4334 02:28:41,680 --> 02:28:44,720 the else statement one interesting thing 4335 02:28:43,439 --> 02:28:47,040 which i want you to notice is 4336 02:28:44,720 --> 02:28:49,120 that right now we have chosen arbitrary 4337 02:28:47,040 --> 02:28:51,040 values but with the sensors you will get 4338 02:28:49,120 --> 02:28:52,479 really changing values you may get the 4339 02:28:51,040 --> 02:28:54,640 values which are changing so 4340 02:28:52,479 --> 02:28:56,319 the arduino will act in the real time 4341 02:28:54,640 --> 02:28:57,760 okay if you don't change the value and 4342 02:28:56,319 --> 02:28:59,359 the sensor changes that value 4343 02:28:57,760 --> 02:29:00,640 and we get different values from that 4344 02:28:59,359 --> 02:29:02,080 sensor then the arduino will 4345 02:29:00,640 --> 02:29:03,680 automatically check 4346 02:29:02,080 --> 02:29:05,280 which condition is true right now and it 4347 02:29:03,680 --> 02:29:07,040 will execute that statement 4348 02:29:05,280 --> 02:29:08,880 and it happens really fast so with the 4349 02:29:07,040 --> 02:29:10,319 real sensor you may see led which is 4350 02:29:08,880 --> 02:29:10,800 currently blinking may change very 4351 02:29:10,319 --> 02:29:12,240 quickly 4352 02:29:10,800 --> 02:29:14,479 for example if you light up a candle 4353 02:29:12,240 --> 02:29:15,680 near the sensor then the led which is 4354 02:29:14,479 --> 02:29:17,200 blinking may change 4355 02:29:15,680 --> 02:29:19,359 and then if you remove the candle then 4356 02:29:17,200 --> 02:29:20,960 you may see that the other led may start 4357 02:29:19,359 --> 02:29:22,000 blinking depending on the condition 4358 02:29:20,960 --> 02:29:23,760 which is currently running 4359 02:29:22,000 --> 02:29:25,280 so i hope you are clear with this if you 4360 02:29:23,760 --> 02:29:27,200 still have any questions you can always 4361 02:29:25,280 --> 02:29:27,439 comment down below or send a message to 4362 02:29:27,200 --> 02:29:29,439 us 4363 02:29:27,439 --> 02:29:31,280 so we will now take a look at loop 4364 02:29:29,439 --> 02:29:32,240 structure which is another kind of a 4365 02:29:31,280 --> 02:29:33,760 control structure 4366 02:29:32,240 --> 02:29:35,439 in this kind of control structure we 4367 02:29:33,760 --> 02:29:37,120 will basically learn how to write 4368 02:29:35,439 --> 02:29:39,120 instructions in order to repeat 4369 02:29:37,120 --> 02:29:40,960 certain tasks instead of writing code 4370 02:29:39,120 --> 02:29:41,439 again and again for doing a certain task 4371 02:29:40,960 --> 02:29:43,359 we can 4372 02:29:41,439 --> 02:29:44,560 learn how to repeat that task again and 4373 02:29:43,359 --> 02:29:46,399 again for example 4374 02:29:44,560 --> 02:29:48,080 the void loop function which we use in 4375 02:29:46,399 --> 02:29:50,080 arduino is a loop structure 4376 02:29:48,080 --> 02:29:51,359 whatever we write in that repeats on its 4377 02:29:50,080 --> 02:29:53,760 own but that is 4378 02:29:51,359 --> 02:29:54,560 a default loop structure however you may 4379 02:29:53,760 --> 02:29:57,040 need something 4380 02:29:54,560 --> 02:29:57,680 to repeat itself in a loop as well so 4381 02:29:57,040 --> 02:29:59,840 for that 4382 02:29:57,680 --> 02:30:01,920 we have loop structures basically we 4383 02:29:59,840 --> 02:30:04,560 have three kinds of loop structures 4384 02:30:01,920 --> 02:30:05,200 one is for loop the second is while loop 4385 02:30:04,560 --> 02:30:07,120 and then 4386 02:30:05,200 --> 02:30:08,960 third is do while loop we will look at 4387 02:30:07,120 --> 02:30:09,600 them one by one in their dedicated 4388 02:30:08,960 --> 02:30:11,680 videos 4389 02:30:09,600 --> 02:30:13,840 but before that let us see how it 4390 02:30:11,680 --> 02:30:15,680 exactly works so we make the entry to 4391 02:30:13,840 --> 02:30:16,160 the code then there is a condition based 4392 02:30:15,680 --> 02:30:18,399 on which 4393 02:30:16,160 --> 02:30:20,160 we take a decision if it is true then 4394 02:30:18,399 --> 02:30:22,240 the certain action which we have defined 4395 02:30:20,160 --> 02:30:24,000 will take place and then it will come 4396 02:30:22,240 --> 02:30:26,080 back and check the condition again 4397 02:30:24,000 --> 02:30:28,399 if it is still true then it will repeat 4398 02:30:26,080 --> 02:30:31,520 the action and this will go on and on 4399 02:30:28,399 --> 02:30:32,399 until this condition becomes false if it 4400 02:30:31,520 --> 02:30:34,000 becomes false 4401 02:30:32,399 --> 02:30:36,160 it will break out of that loop and 4402 02:30:34,000 --> 02:30:36,720 perform the action 2 which is written 4403 02:30:36,160 --> 02:30:39,120 after 4404 02:30:36,720 --> 02:30:39,840 the definition of loop after performing 4405 02:30:39,120 --> 02:30:42,080 that action 4406 02:30:39,840 --> 02:30:43,920 it will exit so in the next video we 4407 02:30:42,080 --> 02:30:44,880 will look at how exactly the first 4408 02:30:43,920 --> 02:30:47,760 control structure 4409 02:30:44,880 --> 02:30:48,399 which is for loop works we will see the 4410 02:30:47,760 --> 02:30:50,560 syntax 4411 02:30:48,399 --> 02:30:52,720 and we will see how it exactly works in 4412 02:30:50,560 --> 02:30:54,080 the coding so see you in the next video 4413 02:30:52,720 --> 02:30:56,000 so now let us begin with 4414 02:30:54,080 --> 02:30:57,840 the for loop this is the first loop 4415 02:30:56,000 --> 02:30:59,120 control structure which is very commonly 4416 02:30:57,840 --> 02:31:01,200 used in computer programming 4417 02:30:59,120 --> 02:31:03,280 first of all let us know about for loop 4418 02:31:01,200 --> 02:31:05,520 this is an entry controlled loop 4419 02:31:03,280 --> 02:31:07,920 what this means is the condition based 4420 02:31:05,520 --> 02:31:08,880 on which the task will be executed is 4421 02:31:07,920 --> 02:31:10,960 checked first 4422 02:31:08,880 --> 02:31:12,000 if it is true then only those statements 4423 02:31:10,960 --> 02:31:13,760 will be executed 4424 02:31:12,000 --> 02:31:15,920 and we use for loop when we know how 4425 02:31:13,760 --> 02:31:18,240 many times we need to run a loop 4426 02:31:15,920 --> 02:31:19,359 so let us see the syntax of for loop 4427 02:31:18,240 --> 02:31:22,000 first of all we write 4428 02:31:19,359 --> 02:31:23,840 4 then an open bracket then we 4429 02:31:22,000 --> 02:31:26,080 initialize some variable here 4430 02:31:23,840 --> 02:31:27,200 that variable will count how many times 4431 02:31:26,080 --> 02:31:29,439 the loop has to run 4432 02:31:27,200 --> 02:31:30,880 then we write the condition here that 4433 02:31:29,439 --> 02:31:32,720 condition can be anything 4434 02:31:30,880 --> 02:31:34,479 this condition mostly includes the 4435 02:31:32,720 --> 02:31:35,359 variable which we have initialized then 4436 02:31:34,479 --> 02:31:37,680 we update 4437 02:31:35,359 --> 02:31:38,960 the variable which we have initialized 4438 02:31:37,680 --> 02:31:41,040 we close the bracket 4439 02:31:38,960 --> 02:31:42,720 then we start a curly bracket we write 4440 02:31:41,040 --> 02:31:43,680 all the statements which you want to get 4441 02:31:42,720 --> 02:31:45,600 executed 4442 02:31:43,680 --> 02:31:47,280 then we write curly bracket let's see 4443 02:31:45,600 --> 02:31:48,960 how it is used now let's say 4444 02:31:47,280 --> 02:31:51,359 i tell you that you have to write your 4445 02:31:48,960 --> 02:31:54,240 name 10 times on the serial monitor 4446 02:31:51,359 --> 02:31:55,600 so what will you do serial dot print ln 4447 02:31:54,240 --> 02:31:58,479 let's say my name is 4448 02:31:55,600 --> 02:31:59,680 ashish so with your existing knowledge 4449 02:31:58,479 --> 02:32:01,680 you will take this line 4450 02:31:59,680 --> 02:32:03,120 you will write it 10 times and then you 4451 02:32:01,680 --> 02:32:04,640 will upload it you'll check on see that 4452 02:32:03,120 --> 02:32:06,479 monitor you can see it is getting 4453 02:32:04,640 --> 02:32:08,160 printed 10 times so now if i tell you 4454 02:32:06,479 --> 02:32:09,439 that you have to type it 100 times 4455 02:32:08,160 --> 02:32:11,359 so would you be willing to write it 4456 02:32:09,439 --> 02:32:12,880 hundred times i guess no 4457 02:32:11,359 --> 02:32:15,280 and some of you may tell that we can 4458 02:32:12,880 --> 02:32:17,120 write it in void loop instead 4459 02:32:15,280 --> 02:32:19,040 but writing that in void loop would mean 4460 02:32:17,120 --> 02:32:20,800 that it would keep printing ashish until 4461 02:32:19,040 --> 02:32:22,560 and unless you turn off your arduino 4462 02:32:20,800 --> 02:32:24,560 you won't be able to count if it has 4463 02:32:22,560 --> 02:32:26,160 printed 100 times you can sit there and 4464 02:32:24,560 --> 02:32:28,080 count that but that certainly doesn't 4465 02:32:26,160 --> 02:32:29,359 make any sense so for that a for loop 4466 02:32:28,080 --> 02:32:31,600 comes to a rescue 4467 02:32:29,359 --> 02:32:32,640 let's see how we use it we write for we 4468 02:32:31,600 --> 02:32:35,840 declare a variable 4469 02:32:32,640 --> 02:32:36,880 int i for example is equal to 0 and we 4470 02:32:35,840 --> 02:32:39,120 write a semicolon 4471 02:32:36,880 --> 02:32:41,200 then we write a condition here for 4472 02:32:39,120 --> 02:32:41,920 example how many times you wanted to run 4473 02:32:41,200 --> 02:32:44,479 let's say 4474 02:32:41,920 --> 02:32:45,040 i less than let's say we want to print 4475 02:32:44,479 --> 02:32:47,280 my name 4476 02:32:45,040 --> 02:32:48,399 10 times so let we will write 10 here 4477 02:32:47,280 --> 02:32:51,520 and we will update 4478 02:32:48,399 --> 02:32:52,960 the condition i plus plus okay we'll now 4479 02:32:51,520 --> 02:32:56,560 write serial dot 4480 02:32:52,960 --> 02:32:58,880 print ln ashish and now we'll see what 4481 02:32:56,560 --> 02:32:58,880 happens 4482 02:33:00,000 --> 02:33:04,160 right we can see the arduino printed my 4483 02:33:03,200 --> 02:33:06,720 name 10 times 4484 02:33:04,160 --> 02:33:08,640 on the screen one two three four five 4485 02:33:06,720 --> 02:33:11,120 six seven eight nine and ten 4486 02:33:08,640 --> 02:33:12,160 okay we can also add multiple statements 4487 02:33:11,120 --> 02:33:16,240 in this block 4488 02:33:12,160 --> 02:33:18,640 let's say we can write hello world 4489 02:33:16,240 --> 02:33:20,880 okay let's see what happens it will 4490 02:33:18,640 --> 02:33:22,720 write ashish hello world ashish hello 4491 02:33:20,880 --> 02:33:24,800 world yep as expected 4492 02:33:22,720 --> 02:33:26,399 it has repeated all the things 10 times 4493 02:33:24,800 --> 02:33:28,160 now what advantage do you have is 4494 02:33:26,399 --> 02:33:29,520 now if someone tells you that you have 4495 02:33:28,160 --> 02:33:31,600 to write it 20 times 4496 02:33:29,520 --> 02:33:33,600 instead of 10 times so instead of 4497 02:33:31,600 --> 02:33:36,080 copying pasting that code again 4498 02:33:33,600 --> 02:33:37,520 you can just alter 20 here now it has 4499 02:33:36,080 --> 02:33:39,920 written it 20 times 4500 02:33:37,520 --> 02:33:41,439 now for example i want to use this 4501 02:33:39,920 --> 02:33:45,840 declared integer i 4502 02:33:41,439 --> 02:33:48,240 in my code serial dot print and then 4503 02:33:45,840 --> 02:33:50,000 we can directly use this i here we can 4504 02:33:48,240 --> 02:33:53,040 also perform arithmetics on that 4505 02:33:50,000 --> 02:33:55,439 for example i can do i plus 2 i plus 5 4506 02:33:53,040 --> 02:33:56,240 i minus 5 i divided by 2 anything for 4507 02:33:55,439 --> 02:33:57,840 that matter 4508 02:33:56,240 --> 02:33:59,920 but please note that the scope of this 4509 02:33:57,840 --> 02:34:01,439 variable is just inside this block you 4510 02:33:59,920 --> 02:34:03,359 cannot use this declared variable 4511 02:34:01,439 --> 02:34:04,880 in other blocks even if you are using it 4512 02:34:03,359 --> 02:34:07,040 in some for loop or some 4513 02:34:04,880 --> 02:34:08,319 other function the scope of i will exist 4514 02:34:07,040 --> 02:34:10,399 only in this 4515 02:34:08,319 --> 02:34:11,680 block get my point let's see it will 4516 02:34:10,399 --> 02:34:15,280 print 0 to 4517 02:34:11,680 --> 02:34:18,720 19 okay 4518 02:34:15,280 --> 02:34:22,240 like 0 1 2 3 4 5 4519 02:34:18,720 --> 02:34:24,479 6 7 and 19. okay now let's 4520 02:34:22,240 --> 02:34:26,479 understand how it was working all right 4521 02:34:24,479 --> 02:34:28,840 so whenever we write a for loop 4522 02:34:26,479 --> 02:34:30,640 the first step which happens is 4523 02:34:28,840 --> 02:34:32,800 initialization this statement is 4524 02:34:30,640 --> 02:34:34,240 executed only once when the loop is 4525 02:34:32,800 --> 02:34:36,800 entered for the first time 4526 02:34:34,240 --> 02:34:37,920 and after this the second step is it 4527 02:34:36,800 --> 02:34:39,680 checks the condition 4528 02:34:37,920 --> 02:34:41,760 this statement is probably the most 4529 02:34:39,680 --> 02:34:43,439 important one it checks to verify 4530 02:34:41,760 --> 02:34:45,760 whether or not certain expression 4531 02:34:43,439 --> 02:34:47,520 evaluates to true if it is true then the 4532 02:34:45,760 --> 02:34:49,439 loop execution continues 4533 02:34:47,520 --> 02:34:51,040 then after that if the condition is true 4534 02:34:49,439 --> 02:34:52,720 it would move on to execute the 4535 02:34:51,040 --> 02:34:54,720 statements as the third step 4536 02:34:52,720 --> 02:34:55,760 after executing the statements it will 4537 02:34:54,720 --> 02:34:57,680 move on to 4538 02:34:55,760 --> 02:34:59,439 the fourth step which is updating the 4539 02:34:57,680 --> 02:35:00,640 variable it is typically used to 4540 02:34:59,439 --> 02:35:02,880 increment or decrement 4541 02:35:00,640 --> 02:35:04,640 some variable after the update the fifth 4542 02:35:02,880 --> 02:35:06,240 step is to check the condition 4543 02:35:04,640 --> 02:35:08,080 once again if that condition is true 4544 02:35:06,240 --> 02:35:09,680 again it will come back to execute the 4545 02:35:08,080 --> 02:35:12,160 statements once again then this step 4546 02:35:09,680 --> 02:35:14,080 continues again and again until this 4547 02:35:12,160 --> 02:35:15,439 condition becomes false the moment the 4548 02:35:14,080 --> 02:35:17,680 condition becomes false 4549 02:35:15,439 --> 02:35:19,120 it will come out of the loop and start 4550 02:35:17,680 --> 02:35:20,880 executing something which is written 4551 02:35:19,120 --> 02:35:22,319 after this loop now since you know this 4552 02:35:20,880 --> 02:35:24,720 let us understand the code which we 4553 02:35:22,319 --> 02:35:26,080 wrote earlier so now let us pay a closer 4554 02:35:24,720 --> 02:35:27,439 attention to everything which we have 4555 02:35:26,080 --> 02:35:30,560 written i've written for 4556 02:35:27,439 --> 02:35:31,920 end i is equal to 0 then a semicolon and 4557 02:35:30,560 --> 02:35:35,280 in the condition we have written 4558 02:35:31,920 --> 02:35:38,880 i less than 20 that means i 4559 02:35:35,280 --> 02:35:40,640 is acceptable till 19 okay 4560 02:35:38,880 --> 02:35:42,319 and then we have written i plus plus you 4561 02:35:40,640 --> 02:35:43,840 must be remembering that plus plus is 4562 02:35:42,319 --> 02:35:46,560 used to increment a variable 4563 02:35:43,840 --> 02:35:48,319 by one we have written serial.println 4564 02:35:46,560 --> 02:35:50,399 bracket ashish that means 4565 02:35:48,319 --> 02:35:52,319 when the value of i is 0 it will print 4566 02:35:50,399 --> 02:35:54,399 aashish once then it will print 4567 02:35:52,319 --> 02:35:56,640 hello world then it will print the value 4568 02:35:54,399 --> 02:35:58,319 of i itself which is 0 right now then 4569 02:35:56,640 --> 02:36:00,640 after executing this loop body 4570 02:35:58,319 --> 02:36:01,840 it will increment the value by 1 and the 4571 02:36:00,640 --> 02:36:05,439 value will become 4572 02:36:01,840 --> 02:36:07,439 1 okay when i is 1 4573 02:36:05,439 --> 02:36:09,520 it will check if i is less than 20 which 4574 02:36:07,439 --> 02:36:09,920 is true it will execute the body once 4575 02:36:09,520 --> 02:36:12,720 again 4576 02:36:09,920 --> 02:36:14,560 then the value of i will become 2 it is 4577 02:36:12,720 --> 02:36:15,680 still less than 20 then again it will 4578 02:36:14,560 --> 02:36:18,720 execute the body 4579 02:36:15,680 --> 02:36:20,240 so it will continue till 19 but after 4580 02:36:18,720 --> 02:36:23,120 executing it for the 19th 4581 02:36:20,240 --> 02:36:24,960 time and when the value becomes 20 this 4582 02:36:23,120 --> 02:36:26,880 condition will become false the moment 4583 02:36:24,960 --> 02:36:27,520 it becomes false it will not execute 4584 02:36:26,880 --> 02:36:30,000 these lines 4585 02:36:27,520 --> 02:36:31,120 and it will exit out of the loop in case 4586 02:36:30,000 --> 02:36:33,120 if we had written 4587 02:36:31,120 --> 02:36:34,840 less than equal to 20 then the condition 4588 02:36:33,120 --> 02:36:37,680 would have been true 4589 02:36:34,840 --> 02:36:40,240 but it would have actually printed it 4590 02:36:37,680 --> 02:36:41,040 for 21 times because it is starting from 4591 02:36:40,240 --> 02:36:42,560 zero 4592 02:36:41,040 --> 02:36:44,080 other thing which we can do is start it 4593 02:36:42,560 --> 02:36:46,960 from one instead of zero 4594 02:36:44,080 --> 02:36:48,640 it will be equivalent to this but 4595 02:36:46,960 --> 02:36:50,080 usually it is recommended that we start 4596 02:36:48,640 --> 02:36:52,160 from zero so after knowing this 4597 02:36:50,080 --> 02:36:53,520 really easy trick i'm really wondering 4598 02:36:52,160 --> 02:36:55,760 if you're wishing 4599 02:36:53,520 --> 02:36:57,439 that you knew this trick before when 4600 02:36:55,760 --> 02:36:58,960 your teacher gave your punishment so in 4601 02:36:57,439 --> 02:37:02,240 the next video we will look at 4602 02:36:58,960 --> 02:37:04,240 how to do nesting in for loops 4603 02:37:02,240 --> 02:37:06,000 see you in the next video so like we saw 4604 02:37:04,240 --> 02:37:08,160 next thing in fl's block we can do 4605 02:37:06,000 --> 02:37:10,160 nesting in for loops as well for example 4606 02:37:08,160 --> 02:37:13,200 if you want a printer pattern like this 4607 02:37:10,160 --> 02:37:15,600 a series of stars there are five columns 4608 02:37:13,200 --> 02:37:17,040 with five stars in each row let me just 4609 02:37:15,600 --> 02:37:18,960 comment it so that it doesn't create 4610 02:37:17,040 --> 02:37:20,240 problem in our code we can simply go 4611 02:37:18,960 --> 02:37:22,720 ahead 4612 02:37:20,240 --> 02:37:22,720 and write 4613 02:37:31,120 --> 02:37:35,359 and we'll write serial dot println and 4614 02:37:34,000 --> 02:37:37,680 we'll print five stars 4615 02:37:35,359 --> 02:37:39,520 right so let's see what happens when we 4616 02:37:37,680 --> 02:37:43,200 upload this 4617 02:37:39,520 --> 02:37:46,479 oops we forgot to add a double quote 4618 02:37:43,200 --> 02:37:46,960 so now again oh we forgot to write the 4619 02:37:46,479 --> 02:37:50,399 name of 4620 02:37:46,960 --> 02:37:53,760 variable and i let's see 4621 02:37:50,399 --> 02:37:56,000 so it printed a lot of stars but now 4622 02:37:53,760 --> 02:37:57,439 what if we want a pattern like this a 4623 02:37:56,000 --> 02:37:59,520 staircase type of pattern 4624 02:37:57,439 --> 02:38:00,479 let me comment that as well okay so how 4625 02:37:59,520 --> 02:38:02,880 will we do that 4626 02:38:00,479 --> 02:38:03,520 it's very simple we'll do nesting of for 4627 02:38:02,880 --> 02:38:06,399 loops 4628 02:38:03,520 --> 02:38:07,920 let's say for enti is equal to zero we 4629 02:38:06,399 --> 02:38:10,479 want five rows 4630 02:38:07,920 --> 02:38:12,479 okay so we will write five then i plus 4631 02:38:10,479 --> 02:38:14,880 plus then we will write another for loop 4632 02:38:12,479 --> 02:38:16,080 we will take another variable here and j 4633 02:38:14,880 --> 02:38:18,399 is equal to 4634 02:38:16,080 --> 02:38:19,680 zero and we'll write condition as j less 4635 02:38:18,399 --> 02:38:22,640 than equal to 4636 02:38:19,680 --> 02:38:24,080 i and then j plus plus okay and then 4637 02:38:22,640 --> 02:38:26,080 we'll write serial dot 4638 02:38:24,080 --> 02:38:27,680 print please don't will not write print 4639 02:38:26,080 --> 02:38:31,280 ln here because we don't want 4640 02:38:27,680 --> 02:38:34,720 it to print in next line so cl.print 4641 02:38:31,280 --> 02:38:34,720 and just a single star 4642 02:38:34,800 --> 02:38:42,319 and then once this for loops executes 4643 02:38:39,040 --> 02:38:44,960 we'll print a new line dot println so 4644 02:38:42,319 --> 02:38:47,280 let's see what happens here 4645 02:38:44,960 --> 02:38:49,359 okay we got that pattern now i'll 4646 02:38:47,280 --> 02:38:51,040 explain you how it worked actually 4647 02:38:49,359 --> 02:38:52,479 we took our first for loop we 4648 02:38:51,040 --> 02:38:55,359 initialized our integer i 4649 02:38:52,479 --> 02:38:56,000 as 0 and we gave a condition i less than 4650 02:38:55,359 --> 02:39:00,080 5 that 4651 02:38:56,000 --> 02:39:02,800 means it will not run when i exceeds 5 4652 02:39:00,080 --> 02:39:04,720 okay or becomes 5 then we wrote another 4653 02:39:02,800 --> 02:39:05,520 for loop and we took another variable j 4654 02:39:04,720 --> 02:39:08,560 is equal to 0 4655 02:39:05,520 --> 02:39:10,000 and j less than equal to i that means in 4656 02:39:08,560 --> 02:39:13,120 first iteration the value of 4657 02:39:10,000 --> 02:39:16,479 i was zero and the value of j was also 4658 02:39:13,120 --> 02:39:18,399 zero okay so here j less than equal to i 4659 02:39:16,479 --> 02:39:19,680 that means zero less than equal to zero 4660 02:39:18,399 --> 02:39:23,040 this is true and then 4661 02:39:19,680 --> 02:39:25,359 j plus plus so it will print a star okay 4662 02:39:23,040 --> 02:39:26,160 then the value of j will increase and it 4663 02:39:25,359 --> 02:39:29,439 will become 4664 02:39:26,160 --> 02:39:32,160 1 so now this statement will become 4665 02:39:29,439 --> 02:39:32,800 false because j is 1 and i is still 0 4666 02:39:32,160 --> 02:39:35,040 then it will 4667 02:39:32,800 --> 02:39:36,399 exit out of this loop and then it will 4668 02:39:35,040 --> 02:39:38,560 print a line 4669 02:39:36,399 --> 02:39:40,160 then that means after printing one star 4670 02:39:38,560 --> 02:39:42,720 it will print another line 4671 02:39:40,160 --> 02:39:44,000 okay and then it will come back to this 4672 02:39:42,720 --> 02:39:47,120 for loop now 4673 02:39:44,000 --> 02:39:49,520 the value of i is 1 is still less than 4674 02:39:47,120 --> 02:39:50,160 5 okay and then it will come into this 4675 02:39:49,520 --> 02:39:52,880 for loop 4676 02:39:50,160 --> 02:39:53,280 so now the value of j is 0 and the value 4677 02:39:52,880 --> 02:39:58,000 of i 4678 02:39:53,280 --> 02:40:01,200 is 1 okay so 0 is less than 4679 02:39:58,000 --> 02:40:04,560 equal to i it is true it will print 4680 02:40:01,200 --> 02:40:08,240 a star then again and j will become 4681 02:40:04,560 --> 02:40:09,359 1 this condition is still true because 1 4682 02:40:08,240 --> 02:40:12,080 is less than equal to 4683 02:40:09,359 --> 02:40:12,880 1 right so it will print another star 4684 02:40:12,080 --> 02:40:14,800 next to 4685 02:40:12,880 --> 02:40:18,560 the previous star so it will print 2 4686 02:40:14,800 --> 02:40:20,560 stars let us see in the serial monitor 4687 02:40:18,560 --> 02:40:21,920 right after printing this star it will 4688 02:40:20,560 --> 02:40:24,560 print this star 4689 02:40:21,920 --> 02:40:25,200 then the value of j will become 2 and 4690 02:40:24,560 --> 02:40:26,960 then 4691 02:40:25,200 --> 02:40:28,240 this condition will become false because 4692 02:40:26,960 --> 02:40:30,319 i was still 1 4693 02:40:28,240 --> 02:40:31,680 then it will exit out of that loop and 4694 02:40:30,319 --> 02:40:34,479 print another line 4695 02:40:31,680 --> 02:40:35,840 it will print another line here okay 4696 02:40:34,479 --> 02:40:38,399 then i will become 4697 02:40:35,840 --> 02:40:39,439 2 then it will go back in this loop and 4698 02:40:38,399 --> 02:40:41,680 it will execute 4699 02:40:39,439 --> 02:40:42,800 the loop three times 0 1 and 2. 4700 02:40:41,680 --> 02:40:45,200 similarly it will 4701 02:40:42,800 --> 02:40:46,319 go until and unless this condition also 4702 02:40:45,200 --> 02:40:48,240 becomes false 4703 02:40:46,319 --> 02:40:49,520 okay so i can understand it must be 4704 02:40:48,240 --> 02:40:51,279 really tricky right now 4705 02:40:49,520 --> 02:40:53,520 if you just go back and listen to what i 4706 02:40:51,279 --> 02:40:55,040 said once again you will understand that 4707 02:40:53,520 --> 02:40:57,520 and in case you don't understand you can 4708 02:40:55,040 --> 02:40:58,960 always drop a comment or message us 4709 02:40:57,520 --> 02:41:00,800 so in the next video we will look at 4710 02:40:58,960 --> 02:41:02,479 another kind of loop structure which is 4711 02:41:00,800 --> 02:41:03,279 known as a while loop see you in the 4712 02:41:02,479 --> 02:41:05,359 next video 4713 02:41:03,279 --> 02:41:07,520 in this video we will look at while loop 4714 02:41:05,359 --> 02:41:08,000 a while loop is also an entry controlled 4715 02:41:07,520 --> 02:41:09,840 loop an 4716 02:41:08,000 --> 02:41:11,120 entry control loop is a loop in which 4717 02:41:09,840 --> 02:41:13,279 the condition is checked 4718 02:41:11,120 --> 02:41:15,200 beforehand before executing the 4719 02:41:13,279 --> 02:41:16,880 statements which are written in the 4720 02:41:15,200 --> 02:41:18,319 loop body this is the same thing which i 4721 02:41:16,880 --> 02:41:20,080 told you for the for loop 4722 02:41:18,319 --> 02:41:21,520 all right but the difference between the 4723 02:41:20,080 --> 02:41:23,439 while loop and a for loop is 4724 02:41:21,520 --> 02:41:25,279 in for loop we know how many times we 4725 02:41:23,439 --> 02:41:27,120 want to run the loop but in while loop 4726 02:41:25,279 --> 02:41:28,560 we don't know how many times we want to 4727 02:41:27,120 --> 02:41:30,560 run the loop it is based 4728 02:41:28,560 --> 02:41:32,000 just on the condition if some condition 4729 02:41:30,560 --> 02:41:34,240 is true the while loop will 4730 02:41:32,000 --> 02:41:35,680 continue to run endlessly and the moment 4731 02:41:34,240 --> 02:41:38,080 the condition becomes false 4732 02:41:35,680 --> 02:41:38,960 the code control will move out of that 4733 02:41:38,080 --> 02:41:40,880 while loop 4734 02:41:38,960 --> 02:41:43,040 that condition can be based on some 4735 02:41:40,880 --> 02:41:45,840 variable or some external conditions 4736 02:41:43,040 --> 02:41:47,359 like some values given by the sensor 4737 02:41:45,840 --> 02:41:49,200 let's say we are making a robot 4738 02:41:47,359 --> 02:41:51,439 and we are using a distance sensor we 4739 02:41:49,200 --> 02:41:53,920 can use a while loop or to move forward 4740 02:41:51,439 --> 02:41:54,560 unless the distance is less than some 4741 02:41:53,920 --> 02:41:56,560 quantity 4742 02:41:54,560 --> 02:41:58,160 and we want to exit out of that by loop 4743 02:41:56,560 --> 02:42:00,479 as soon as the distance 4744 02:41:58,160 --> 02:42:02,319 gets lesser than that specified value so 4745 02:42:00,479 --> 02:42:04,640 that the robot can avoid the collision 4746 02:42:02,319 --> 02:42:06,319 from any obstacle in front of it right 4747 02:42:04,640 --> 02:42:07,439 there can be many more while loop uses 4748 02:42:06,319 --> 02:42:09,279 but we will begin with 4749 02:42:07,439 --> 02:42:10,960 the basics we will use our traditional 4750 02:42:09,279 --> 02:42:13,120 method of printing variables 4751 02:42:10,960 --> 02:42:14,479 on the serial monitor so let's see that 4752 02:42:13,120 --> 02:42:16,960 so we have our sketch here 4753 02:42:14,479 --> 02:42:17,520 let's use a while loop to print a table 4754 02:42:16,960 --> 02:42:20,000 of two 4755 02:42:17,520 --> 02:42:21,840 let's say we'll start with an integer 4756 02:42:20,000 --> 02:42:25,600 which we will use as a condition 4757 02:42:21,840 --> 02:42:28,880 int multiple is equal to one 4758 02:42:25,600 --> 02:42:32,399 let's start with 1 while multiple 4759 02:42:28,880 --> 02:42:35,920 is less than equal to 10 4760 02:42:32,399 --> 02:42:40,880 okay serial dot 4761 02:42:35,920 --> 02:42:44,319 print ln multiple 4762 02:42:40,880 --> 02:42:46,160 into two okay and let's increment the 4763 02:42:44,319 --> 02:42:48,240 multiple 4764 02:42:46,160 --> 02:42:50,319 all right let's see if we are able to 4765 02:42:48,240 --> 02:42:52,800 print the table of two 4766 02:42:50,319 --> 02:42:54,399 oops we forgot to write serial dot begin 4767 02:42:52,800 --> 02:42:56,240 always write serial dot begin 4768 02:42:54,399 --> 02:42:59,600 whenever you have to communicate with 4769 02:42:56,240 --> 02:43:03,520 the computer let's upload that again 4770 02:42:59,600 --> 02:43:05,680 right 2 4 6 8 10 12 until 20. 4771 02:43:03,520 --> 02:43:07,520 this is a table of two now let's print a 4772 02:43:05,680 --> 02:43:12,000 table of a complicated number 4773 02:43:07,520 --> 02:43:14,399 let's say 73 yep this is a table of 73 4774 02:43:12,000 --> 02:43:16,319 so now let me show you how a while loop 4775 02:43:14,399 --> 02:43:16,800 can run endlessly if the condition is 4776 02:43:16,319 --> 02:43:19,439 true 4777 02:43:16,800 --> 02:43:20,080 let us just make it true directly this 4778 02:43:19,439 --> 02:43:21,840 will become 4779 02:43:20,080 --> 02:43:23,760 an endless loop right now it will not 4780 02:43:21,840 --> 02:43:24,640 just print numbers from one to ten it it 4781 02:43:23,760 --> 02:43:26,560 will just print 4782 02:43:24,640 --> 02:43:28,160 them endlessly let's use the easy number 4783 02:43:26,560 --> 02:43:31,840 so that we can verify 4784 02:43:28,160 --> 02:43:33,760 it won't stop at all let's see 4785 02:43:31,840 --> 02:43:35,520 look at the speed it is printing all the 4786 02:43:33,760 --> 02:43:38,560 even numbers 4787 02:43:35,520 --> 02:43:39,439 can you see that let's have a look 2 4 6 4788 02:43:38,560 --> 02:43:42,080 8 10 12 4789 02:43:39,439 --> 02:43:43,760 14 16 as you know there's no upper limit 4790 02:43:42,080 --> 02:43:44,479 to the numbers so it will just go on 4791 02:43:43,760 --> 02:43:47,920 endlessly 4792 02:43:44,479 --> 02:43:50,080 until the limit of int expires 4793 02:43:47,920 --> 02:43:51,680 so i have another example to show you 4794 02:43:50,080 --> 02:43:53,600 how a statement controls 4795 02:43:51,680 --> 02:43:55,200 a while loop how it prevents the while 4796 02:43:53,600 --> 02:43:57,359 loop from running when it is false 4797 02:43:55,200 --> 02:43:59,040 and how it initiates the while loop when 4798 02:43:57,359 --> 02:44:00,800 it becomes true so in the white setup i 4799 02:43:59,040 --> 02:44:02,479 have written serial.begin 9600 to 4800 02:44:00,800 --> 02:44:03,359 initiate the communication and then i 4801 02:44:02,479 --> 02:44:05,760 have void loop 4802 02:44:03,359 --> 02:44:06,800 i have declared a static variable a test 4803 02:44:05,760 --> 02:44:08,479 variable which is 4804 02:44:06,800 --> 02:44:10,080 going to control our condition i have 4805 02:44:08,479 --> 02:44:11,600 defined it as static because 4806 02:44:10,080 --> 02:44:13,520 i don't want to reset the value of test 4807 02:44:11,600 --> 02:44:15,279 variable with each run uh if you have 4808 02:44:13,520 --> 02:44:15,840 any confusion regarding the static part 4809 02:44:15,279 --> 02:44:17,600 you can check 4810 02:44:15,840 --> 02:44:19,359 the dedicated video which we have made 4811 02:44:17,600 --> 02:44:19,920 to explain the static qualifier for a 4812 02:44:19,359 --> 02:44:22,399 data type 4813 02:44:19,920 --> 02:44:24,000 now while loop we have started the while 4814 02:44:22,399 --> 02:44:26,640 test condition greater than five 4815 02:44:24,000 --> 02:44:27,359 that means right now the test variable 4816 02:44:26,640 --> 02:44:29,840 is zero 4817 02:44:27,359 --> 02:44:31,439 as we have not initialized it so zero is 4818 02:44:29,840 --> 02:44:32,000 the default value so zero is greater 4819 02:44:31,439 --> 02:44:33,520 than 5 4820 02:44:32,000 --> 02:44:35,520 that means this is false so this 4821 02:44:33,520 --> 02:44:37,359 statement should not execute okay but 4822 02:44:35,520 --> 02:44:39,040 in the next line we have written 4823 02:44:37,359 --> 02:44:40,160 variable plus that means we want to 4824 02:44:39,040 --> 02:44:42,319 increment that variable 4825 02:44:40,160 --> 02:44:43,600 the variable value will become 1 and it 4826 02:44:42,319 --> 02:44:46,479 will print the value 4827 02:44:43,600 --> 02:44:48,240 of the test variable then we are waiting 4828 02:44:46,479 --> 02:44:49,920 for one second so that we can observe 4829 02:44:48,240 --> 02:44:51,040 the changes which are happening and then 4830 02:44:49,920 --> 02:44:53,439 again it will come here 4831 02:44:51,040 --> 02:44:55,359 it will see while test variable greater 4832 02:44:53,439 --> 02:44:56,720 than 5 that means it is still false 4833 02:44:55,359 --> 02:44:58,800 because test variable's value 4834 02:44:56,720 --> 02:45:00,160 is 1 right now and it is still false so 4835 02:44:58,800 --> 02:45:02,080 it will still not go into 4836 02:45:00,160 --> 02:45:03,920 this loop then it will become 3 then it 4837 02:45:02,080 --> 02:45:05,760 will become 4 then it will become 5 4838 02:45:03,920 --> 02:45:07,359 at 5 also this will not become true 4839 02:45:05,760 --> 02:45:07,840 because we have not used the equal to 4840 02:45:07,359 --> 02:45:10,160 sign 4841 02:45:07,840 --> 02:45:10,960 and when it becomes 6 this condition 4842 02:45:10,160 --> 02:45:13,200 will become true 4843 02:45:10,960 --> 02:45:15,680 and this will start printing let's see 4844 02:45:13,200 --> 02:45:19,359 that 4845 02:45:15,680 --> 02:45:22,160 right one two three four 4846 02:45:19,359 --> 02:45:22,720 five six and we are in the while loop 4847 02:45:22,160 --> 02:45:24,560 now 4848 02:45:22,720 --> 02:45:26,479 okay this while loop is repeating 4849 02:45:24,560 --> 02:45:27,760 endlessly because we have not specified 4850 02:45:26,479 --> 02:45:29,200 any exit condition 4851 02:45:27,760 --> 02:45:30,880 and please note while this is in while 4852 02:45:29,200 --> 02:45:31,680 loop these statements are not being 4853 02:45:30,880 --> 02:45:34,240 executed 4854 02:45:31,680 --> 02:45:36,640 the control of code is looping here only 4855 02:45:34,240 --> 02:45:38,479 since this loop is looping infinitely 4856 02:45:36,640 --> 02:45:40,080 we might want to use some break 4857 02:45:38,479 --> 02:45:42,000 conditions we will learn about 4858 02:45:40,080 --> 02:45:44,000 break and continue statements in coming 4859 02:45:42,000 --> 02:45:45,840 videos but in the next video 4860 02:45:44,000 --> 02:45:47,600 there is one more loop which is known as 4861 02:45:45,840 --> 02:45:49,439 a do while loop we'll learn about 4862 02:45:47,600 --> 02:45:51,040 do while loop in the next video we'll 4863 02:45:49,439 --> 02:45:53,279 take a look at the last 4864 02:45:51,040 --> 02:45:54,880 loop control structure which is the do 4865 02:45:53,279 --> 02:45:56,479 while loop the first thing which i want 4866 02:45:54,880 --> 02:45:56,880 to tell you about the do while loop is 4867 02:45:56,479 --> 02:45:59,200 it is 4868 02:45:56,880 --> 02:46:00,960 very very similar to the while loop it 4869 02:45:59,200 --> 02:46:02,160 works exactly like the while loop but 4870 02:46:00,960 --> 02:46:04,560 the only difference is 4871 02:46:02,160 --> 02:46:06,800 it executes at least once and that is 4872 02:46:04,560 --> 02:46:09,040 why it is the exit control loop 4873 02:46:06,800 --> 02:46:10,240 in exit control loop the statements are 4874 02:46:09,040 --> 02:46:12,000 first executed 4875 02:46:10,240 --> 02:46:13,840 and then the condition is checked while 4876 02:46:12,000 --> 02:46:15,359 in while loop first the condition was 4877 02:46:13,840 --> 02:46:16,720 checked if the condition was true then 4878 02:46:15,359 --> 02:46:18,560 the statements would execute 4879 02:46:16,720 --> 02:46:20,000 in this first the statement block will 4880 02:46:18,560 --> 02:46:20,720 execute and then it will check the 4881 02:46:20,000 --> 02:46:22,800 condition 4882 02:46:20,720 --> 02:46:24,399 if the condition is false it will exit 4883 02:46:22,800 --> 02:46:25,680 out of the loop and not execute those 4884 02:46:24,399 --> 02:46:27,680 statements further 4885 02:46:25,680 --> 02:46:29,760 and if the condition is true it will go 4886 02:46:27,680 --> 02:46:30,160 back and execute the statements once 4887 02:46:29,760 --> 02:46:31,760 again 4888 02:46:30,160 --> 02:46:33,359 if you look at the flow the first thing 4889 02:46:31,760 --> 02:46:34,640 which happens is it executes the 4890 02:46:33,359 --> 02:46:35,200 statement block then it checks the 4891 02:46:34,640 --> 02:46:36,880 condition 4892 02:46:35,200 --> 02:46:38,560 if it is true then it will go back 4893 02:46:36,880 --> 02:46:40,479 otherwise it will come out of that loop 4894 02:46:38,560 --> 02:46:42,479 a do while loop is also used when we 4895 02:46:40,479 --> 02:46:43,760 don't know how many times an action has 4896 02:46:42,479 --> 02:46:45,760 to be repeated but 4897 02:46:43,760 --> 02:46:47,040 we are sure that it should run at least 4898 02:46:45,760 --> 02:46:48,880 once in those cases 4899 02:46:47,040 --> 02:46:50,800 we use a do while loop a do while loop 4900 02:46:48,880 --> 02:46:52,960 is used where the statement has to 4901 02:46:50,800 --> 02:46:54,640 execute once otherwise we won't be able 4902 02:46:52,960 --> 02:46:56,720 to take decision for example we are 4903 02:46:54,640 --> 02:46:57,760 expecting a user to give us some input 4904 02:46:56,720 --> 02:46:59,840 and we want him to give 4905 02:46:57,760 --> 02:47:01,600 a positive integer as an input but for 4906 02:46:59,840 --> 02:47:03,279 example he is trying to give a negative 4907 02:47:01,600 --> 02:47:04,880 input so we can write a do while loop 4908 02:47:03,279 --> 02:47:05,359 while the user gives us the negative 4909 02:47:04,880 --> 02:47:07,840 input 4910 02:47:05,359 --> 02:47:09,439 keep telling him to give us the positive 4911 02:47:07,840 --> 02:47:10,479 input and the moment he gives us the 4912 02:47:09,439 --> 02:47:12,479 positive input 4913 02:47:10,479 --> 02:47:14,160 will break out of that loop okay so let 4914 02:47:12,479 --> 02:47:15,040 us see a basic example of using a 4915 02:47:14,160 --> 02:47:17,120 do-while loop 4916 02:47:15,040 --> 02:47:18,080 like we did earlier we printed a table 4917 02:47:17,120 --> 02:47:20,080 of two 4918 02:47:18,080 --> 02:47:22,399 we'll again print the table of two using 4919 02:47:20,080 --> 02:47:24,000 a do-while loop instead of a while loop 4920 02:47:22,399 --> 02:47:26,160 so let us see how we do that we have 4921 02:47:24,000 --> 02:47:27,359 initialized a variable known as multiple 4922 02:47:26,160 --> 02:47:29,760 and initialized it with 4923 02:47:27,359 --> 02:47:31,439 one okay we'll write cl dot begin to 4924 02:47:29,760 --> 02:47:34,800 start the communication with computer 4925 02:47:31,439 --> 02:47:36,640 so we'll write do then the bracket open 4926 02:47:34,800 --> 02:47:38,319 we'll write cl dot printenet multiple 4927 02:47:36,640 --> 02:47:39,920 into two then bracket close and 4928 02:47:38,319 --> 02:47:42,240 semicolon and then we will 4929 02:47:39,920 --> 02:47:43,279 increment the multiple and then we will 4930 02:47:42,240 --> 02:47:45,279 write while 4931 02:47:43,279 --> 02:47:46,880 multiple is less than equal to ten that 4932 02:47:45,279 --> 02:47:50,240 means this condition is true 4933 02:47:46,880 --> 02:47:52,080 until the multiple becomes 10 the moment 4934 02:47:50,240 --> 02:47:53,040 it becomes 11 this condition will become 4935 02:47:52,080 --> 02:47:55,120 false and this 4936 02:47:53,040 --> 02:47:56,399 statement will stop executing so we'll 4937 02:47:55,120 --> 02:47:58,560 get a table of 2 here 4938 02:47:56,399 --> 02:47:59,520 let us see what happens right so we got 4939 02:47:58,560 --> 02:48:02,640 a table of 2 4940 02:47:59,520 --> 02:48:04,720 2 4 6 8 and then so on till 20. 4941 02:48:02,640 --> 02:48:06,640 i have another example for do while loop 4942 02:48:04,720 --> 02:48:07,040 so that we can understand how exactly it 4943 02:48:06,640 --> 02:48:08,960 works 4944 02:48:07,040 --> 02:48:10,880 so in the white setup we have written cl 4945 02:48:08,960 --> 02:48:12,560 dot begin 9600 so that we can 4946 02:48:10,880 --> 02:48:14,399 communicate with the computer in while 4947 02:48:12,560 --> 02:48:16,800 loop i have initialized a static into 4948 02:48:14,399 --> 02:48:18,479 variable which is known as test variable 4949 02:48:16,800 --> 02:48:20,080 we have written do then we are writing 4950 02:48:18,479 --> 02:48:22,319 cl.println this 4951 02:48:20,080 --> 02:48:24,240 will print at least once because a do 4952 02:48:22,319 --> 02:48:26,640 while loop will execute the statements 4953 02:48:24,240 --> 02:48:27,279 at least once so ok we have written this 4954 02:48:26,640 --> 02:48:28,880 statement 4955 02:48:27,279 --> 02:48:30,399 and we have written a delay of 500 4956 02:48:28,880 --> 02:48:31,120 milliseconds so that we can observe what 4957 02:48:30,399 --> 02:48:33,200 is happening 4958 02:48:31,120 --> 02:48:34,640 otherwise you know serial monitor prints 4959 02:48:33,200 --> 02:48:35,520 things really fast so now we have 4960 02:48:34,640 --> 02:48:37,439 written while 4961 02:48:35,520 --> 02:48:39,200 test variable is greater than 5. while 4962 02:48:37,439 --> 02:48:41,760 the test variable is less than 5 4963 02:48:39,200 --> 02:48:42,720 this statement should not execute but it 4964 02:48:41,760 --> 02:48:44,720 will 4965 02:48:42,720 --> 02:48:46,319 execute at least once then we have 4966 02:48:44,720 --> 02:48:48,160 written test variable plus plus that 4967 02:48:46,319 --> 02:48:49,600 means we are incrementing the value of 4968 02:48:48,160 --> 02:48:51,040 text variable 4969 02:48:49,600 --> 02:48:52,399 here we are printing the value of test 4970 02:48:51,040 --> 02:48:54,000 variable and we have given a delay of 4971 02:48:52,399 --> 02:48:56,560 500 milliseconds so that we can 4972 02:48:54,000 --> 02:48:58,399 observe what is happening okay so now 4973 02:48:56,560 --> 02:49:00,960 when we open the serial monitor 4974 02:48:58,399 --> 02:49:02,880 what we will see is that this statement 4975 02:49:00,960 --> 02:49:04,319 will execute once then the test variable 4976 02:49:02,880 --> 02:49:06,080 will increment 4977 02:49:04,319 --> 02:49:07,600 okay and then the value of test 4978 02:49:06,080 --> 02:49:08,479 increment will print then it will go 4979 02:49:07,600 --> 02:49:09,920 back 4980 02:49:08,479 --> 02:49:11,600 into do while loop and print this 4981 02:49:09,920 --> 02:49:13,120 statement once again 4982 02:49:11,600 --> 02:49:14,960 because in do while loop it has to 4983 02:49:13,120 --> 02:49:17,120 execute once at least 4984 02:49:14,960 --> 02:49:18,960 then while it will check the condition 4985 02:49:17,120 --> 02:49:20,640 it is false then it will come back here 4986 02:49:18,960 --> 02:49:21,200 it will increment the variable and it 4987 02:49:20,640 --> 02:49:23,359 will 4988 02:49:21,200 --> 02:49:24,319 repeat till the test variable becomes 4989 02:49:23,359 --> 02:49:26,560 greater than 5 4990 02:49:24,319 --> 02:49:28,640 okay the moment it becomes greater than 4991 02:49:26,560 --> 02:49:29,439 5 so this do while loop will keep on 4992 02:49:28,640 --> 02:49:31,279 repeating 4993 02:49:29,439 --> 02:49:33,600 let's see how it happens let us upload 4994 02:49:31,279 --> 02:49:35,680 the code first 4995 02:49:33,600 --> 02:49:37,920 right this will get printed at least 4996 02:49:35,680 --> 02:49:38,560 once and this is printing again and 4997 02:49:37,920 --> 02:49:40,399 again 4998 02:49:38,560 --> 02:49:41,920 but now just see the loop control didn't 4999 02:49:40,399 --> 02:49:43,680 come out of this okay because this 5000 02:49:41,920 --> 02:49:44,080 condition is true now it will go back 5001 02:49:43,680 --> 02:49:45,840 again 5002 02:49:44,080 --> 02:49:47,359 and execute the statement these 5003 02:49:45,840 --> 02:49:47,760 statements are not being executed 5004 02:49:47,359 --> 02:49:50,160 because 5005 02:49:47,760 --> 02:49:51,120 it is still in do while loop so i hope 5006 02:49:50,160 --> 02:49:52,960 you understood this 5007 02:49:51,120 --> 02:49:54,160 do while loop so now i have a really 5008 02:49:52,960 --> 02:49:55,680 interesting illustration 5009 02:49:54,160 --> 02:49:56,960 which you can see on the screen to 5010 02:49:55,680 --> 02:49:58,560 explain the difference between a while 5011 02:49:56,960 --> 02:49:59,840 loop and a do while loop and i think it 5012 02:49:58,560 --> 02:50:01,520 is a really good example 5013 02:49:59,840 --> 02:50:03,040 to show the difference between the two 5014 02:50:01,520 --> 02:50:06,319 every one of you must have seen 5015 02:50:03,040 --> 02:50:07,600 the roadrunner show and we see this guy 5016 02:50:06,319 --> 02:50:09,359 was using the while loop 5017 02:50:07,600 --> 02:50:11,520 while this guy was using the two while 5018 02:50:09,359 --> 02:50:13,760 loop let's discuss in the comments 5019 02:50:11,520 --> 02:50:14,880 who was using these control loops in a 5020 02:50:13,760 --> 02:50:16,960 proper manner 5021 02:50:14,880 --> 02:50:19,200 if you remember i told you that we might 5022 02:50:16,960 --> 02:50:20,560 have to break out of the loops based on 5023 02:50:19,200 --> 02:50:22,479 certain conditions 5024 02:50:20,560 --> 02:50:23,680 like for example in an endless loop we 5025 02:50:22,479 --> 02:50:25,920 might need to do something 5026 02:50:23,680 --> 02:50:27,200 to stop that loop so the break keyword 5027 02:50:25,920 --> 02:50:30,000 is used to exit 5028 02:50:27,200 --> 02:50:31,680 from a loop by bypassing the normal loop 5029 02:50:30,000 --> 02:50:33,520 condition which we have specified 5030 02:50:31,680 --> 02:50:34,880 let's see how we do that so this is the 5031 02:50:33,520 --> 02:50:36,399 modified version 5032 02:50:34,880 --> 02:50:38,560 of the code which we used to print the 5033 02:50:36,399 --> 02:50:40,000 table of two okay 5034 02:50:38,560 --> 02:50:41,840 this is the regular while loop which is 5035 02:50:40,000 --> 02:50:43,359 running okay we are printing 5036 02:50:41,840 --> 02:50:45,279 a table of two here and we are 5037 02:50:43,359 --> 02:50:47,200 incrementing the multiple here 5038 02:50:45,279 --> 02:50:48,800 but now we have specified a break 5039 02:50:47,200 --> 02:50:51,920 condition okay 5040 02:50:48,800 --> 02:50:53,279 like if multiple is equal to five then 5041 02:50:51,920 --> 02:50:53,840 we will write breaking out of the loop 5042 02:50:53,279 --> 02:50:55,760 now 5043 02:50:53,840 --> 02:50:57,520 and we will break out of the loop by 5044 02:50:55,760 --> 02:51:00,160 just using this keyword 5045 02:50:57,520 --> 02:51:00,960 let's see what happens all right so we 5046 02:51:00,160 --> 02:51:04,000 printed it 5047 02:51:00,960 --> 02:51:06,080 till four two 4 6 and 8 5048 02:51:04,000 --> 02:51:07,200 and then it breaked out of loop although 5049 02:51:06,080 --> 02:51:09,920 it should have run till 5050 02:51:07,200 --> 02:51:11,520 10 it should have printed till 20. so if 5051 02:51:09,920 --> 02:51:15,120 i comment this break condition 5052 02:51:11,520 --> 02:51:17,200 and upload the code again so we got 5053 02:51:15,120 --> 02:51:19,680 the entire table so this is the basic 5054 02:51:17,200 --> 02:51:21,760 use of breaking out of the loop 5055 02:51:19,680 --> 02:51:22,880 now let's see if we are inside an 5056 02:51:21,760 --> 02:51:25,359 endless loop 5057 02:51:22,880 --> 02:51:26,000 let's say while true this is an endless 5058 02:51:25,359 --> 02:51:29,840 loop 5059 02:51:26,000 --> 02:51:32,880 we are writing serial dot println 5060 02:51:29,840 --> 02:51:35,279 endless loop okay 5061 02:51:32,880 --> 02:51:36,319 and we will increment the multiple 5062 02:51:35,279 --> 02:51:39,920 multiple 5063 02:51:36,319 --> 02:51:42,640 plus plus okay let's say 5064 02:51:39,920 --> 02:51:43,520 i want to exit after printing it 10 5065 02:51:42,640 --> 02:51:46,960 times 5066 02:51:43,520 --> 02:51:50,319 if multiple greater than 5067 02:51:46,960 --> 02:51:53,200 10. we'll just break out of it 5068 02:51:50,319 --> 02:51:53,200 let's see what happens 5069 02:51:54,960 --> 02:52:00,399 okay we forgot to close the white setup 5070 02:51:58,840 --> 02:52:03,359 bracket 5071 02:52:00,399 --> 02:52:04,240 right if we didn't use this break 5072 02:52:03,359 --> 02:52:05,920 statement 5073 02:52:04,240 --> 02:52:07,520 it would ultimately keep running 5074 02:52:05,920 --> 02:52:10,479 endlessly let's see that 5075 02:52:07,520 --> 02:52:11,920 quickly okay can you see that it's 5076 02:52:10,479 --> 02:52:14,399 printing endlessly 5077 02:52:11,920 --> 02:52:16,160 so i hope you understand we use a break 5078 02:52:14,399 --> 02:52:18,000 statement wherever we want to 5079 02:52:16,160 --> 02:52:20,319 break out of the loop so in the next 5080 02:52:18,000 --> 02:52:22,399 video we will see the continue keyword 5081 02:52:20,319 --> 02:52:24,080 and we will also compare the break and 5082 02:52:22,399 --> 02:52:26,080 continue keywords 5083 02:52:24,080 --> 02:52:27,120 like we saw in the break statement that 5084 02:52:26,080 --> 02:52:29,359 whenever we use it 5085 02:52:27,120 --> 02:52:31,279 code control instantly moves out of the 5086 02:52:29,359 --> 02:52:32,800 loop entirely discarding all the 5087 02:52:31,279 --> 02:52:34,399 remaining iterations of the loop 5088 02:52:32,800 --> 02:52:36,720 right like we were trying to print 5089 02:52:34,399 --> 02:52:38,399 numbers from 1 to 10 and when we used if 5090 02:52:36,720 --> 02:52:40,560 our variable is equal to 5 then break 5091 02:52:38,399 --> 02:52:42,960 out of the loop so it entirely skipped 6 5092 02:52:40,560 --> 02:52:45,279 7 8 9 10 but in some situations we might 5093 02:52:42,960 --> 02:52:47,439 want to use the remaining iterations 5094 02:52:45,279 --> 02:52:48,960 right so in that case the continue 5095 02:52:47,439 --> 02:52:50,960 keyword helps us with that 5096 02:52:48,960 --> 02:52:52,880 the continue statement skips the rest of 5097 02:52:50,960 --> 02:52:54,560 the current iteration of the loop and it 5098 02:52:52,880 --> 02:52:56,319 continues by checking the conditional 5099 02:52:54,560 --> 02:52:58,000 expression of the loop and proceeding 5100 02:52:56,319 --> 02:53:00,240 with the subsequent iterations 5101 02:52:58,000 --> 02:53:01,040 that means it won't skip the rest of the 5102 02:53:00,240 --> 02:53:03,120 iterations 5103 02:53:01,040 --> 02:53:05,920 let us see how it works so we have void 5104 02:53:03,120 --> 02:53:08,720 setup serial.begin 9600 as usual 5105 02:53:05,920 --> 02:53:09,439 then we are writing for loop to print 5106 02:53:08,720 --> 02:53:11,120 numbers from 5107 02:53:09,439 --> 02:53:13,040 0 to 10 right because we have 5108 02:53:11,120 --> 02:53:14,240 initialized i with 0 and we have used 5109 02:53:13,040 --> 02:53:15,840 less than equal to sign 5110 02:53:14,240 --> 02:53:18,160 so that means both the ranges are 5111 02:53:15,840 --> 02:53:19,439 inclusive so it will print 0 to 10 and 5112 02:53:18,160 --> 02:53:22,080 then we are incrementing the 5113 02:53:19,439 --> 02:53:24,560 variable now notice we have used if i is 5114 02:53:22,080 --> 02:53:25,680 equal to 5 then continue whenever we use 5115 02:53:24,560 --> 02:53:27,520 the continue keyword 5116 02:53:25,680 --> 02:53:29,359 it would straight away take us to the 5117 02:53:27,520 --> 02:53:30,720 condition pack and it would skip all the 5118 02:53:29,359 --> 02:53:33,840 statements which are written after that 5119 02:53:30,720 --> 02:53:33,840 so let us see what happens 5120 02:53:34,240 --> 02:53:40,080 so we see 0 1 2 3 4 5 is missing 5121 02:53:37,520 --> 02:53:42,080 and 6 7 8 9 and 10. so it skipped the 5122 02:53:40,080 --> 02:53:44,880 iteration in which i was equal to 5123 02:53:42,080 --> 02:53:48,800 5 right but it did not skip the rest of 5124 02:53:44,880 --> 02:53:48,800 the iteration if we had used the break 5125 02:53:50,840 --> 02:53:54,319 keyword it would have skipped the rest 5126 02:53:53,040 --> 02:53:57,520 of the iterations 5127 02:53:54,319 --> 02:53:59,439 it stopped at 4 only let me switch back 5128 02:53:57,520 --> 02:54:00,960 to continue here again and let me 5129 02:53:59,439 --> 02:54:03,120 explain the difference between 5130 02:54:00,960 --> 02:54:05,520 the break and continue statement let's 5131 02:54:03,120 --> 02:54:08,960 say we write a statement here 5132 02:54:05,520 --> 02:54:11,120 serial dot println end of our 5133 02:54:08,960 --> 02:54:12,240 for loop this is the end of our for loop 5134 02:54:11,120 --> 02:54:14,479 that means after 5135 02:54:12,240 --> 02:54:16,080 our for loop completes this statement 5136 02:54:14,479 --> 02:54:17,439 should print regardless of anything so 5137 02:54:16,080 --> 02:54:20,880 when we use continue 5138 02:54:17,439 --> 02:54:24,160 we'll see 5139 02:54:20,880 --> 02:54:25,439 the loop was going 0 1 2 3 4 and when 5140 02:54:24,160 --> 02:54:27,920 the value became 5 5141 02:54:25,439 --> 02:54:28,640 it jumped back to check the condition 5142 02:54:27,920 --> 02:54:30,720 okay 5143 02:54:28,640 --> 02:54:31,840 so in this way it had to skip this 5144 02:54:30,720 --> 02:54:33,520 statement it cannot 5145 02:54:31,840 --> 02:54:35,359 execute the statement right so when it 5146 02:54:33,520 --> 02:54:36,880 became six again then it will start 5147 02:54:35,359 --> 02:54:39,040 printing it again can you see that 5148 02:54:36,880 --> 02:54:40,160 and after completing the loop it came 5149 02:54:39,040 --> 02:54:43,120 and printed this line 5150 02:54:40,160 --> 02:54:43,120 when we use break 5151 02:54:44,479 --> 02:54:47,680 then the control will directly come here 5152 02:54:46,479 --> 02:54:48,319 whenever the break statement is 5153 02:54:47,680 --> 02:54:50,399 encountered 5154 02:54:48,319 --> 02:54:52,080 the code control goes directly out of 5155 02:54:50,399 --> 02:54:52,479 the loop can you see that after printing 5156 02:54:52,080 --> 02:54:54,880 4 5157 02:54:52,479 --> 02:54:56,399 it printed end of for loop so we may 5158 02:54:54,880 --> 02:54:58,160 have different situations to use 5159 02:54:56,399 --> 02:55:00,000 continue and break statement and we have 5160 02:54:58,160 --> 02:55:01,920 to make sure we use them correctly 5161 02:55:00,000 --> 02:55:03,040 so in the next video we will look at the 5162 02:55:01,920 --> 02:55:04,960 last keyword 5163 02:55:03,040 --> 02:55:06,160 which is return so see you in the next 5164 02:55:04,960 --> 02:55:08,240 video the 5165 02:55:06,160 --> 02:55:09,840 return keyboard the return keyword would 5166 02:55:08,240 --> 02:55:11,920 probably the easiest thing 5167 02:55:09,840 --> 02:55:13,840 to learn right now the only function of 5168 02:55:11,920 --> 02:55:14,399 the return keyword is to terminate the 5169 02:55:13,840 --> 02:55:16,160 function 5170 02:55:14,399 --> 02:55:17,840 no matter what it doesn't take any 5171 02:55:16,160 --> 02:55:20,160 conditions it doesn't take any 5172 02:55:17,840 --> 02:55:22,319 limitations or anything whenever the 5173 02:55:20,160 --> 02:55:22,960 code encounters the return keyword it 5174 02:55:22,319 --> 02:55:24,960 would just 5175 02:55:22,960 --> 02:55:26,479 terminate the function there are two 5176 02:55:24,960 --> 02:55:28,160 ways to use a return 5177 02:55:26,479 --> 02:55:29,760 we will be covering the first way to use 5178 02:55:28,160 --> 02:55:31,600 the return keyword we will cover the 5179 02:55:29,760 --> 02:55:35,040 second way in the coming videos 5180 02:55:31,600 --> 02:55:36,640 let us see how we use it in one manner 5181 02:55:35,040 --> 02:55:38,479 all right so i have this code written 5182 02:55:36,640 --> 02:55:40,160 here okay in the white loop 5183 02:55:38,479 --> 02:55:42,160 what i'm trying to do is i'm trying to 5184 02:55:40,160 --> 02:55:42,880 print line one line two line three and 5185 02:55:42,160 --> 02:55:44,560 line four 5186 02:55:42,880 --> 02:55:46,479 okay and then i have a for loop which 5187 02:55:44,560 --> 02:55:48,960 prints number from zero to 5188 02:55:46,479 --> 02:55:51,439 nine right let's see if it is working 5189 02:55:48,960 --> 02:55:51,439 properly 5190 02:55:51,520 --> 02:55:55,120 yes it is working as expected line one 5191 02:55:53,600 --> 02:55:55,680 nine two nine three nine four and zero 5192 02:55:55,120 --> 02:55:59,359 to nine 5193 02:55:55,680 --> 02:56:00,720 right so now i want that anything return 5194 02:55:59,359 --> 02:56:02,880 beyond this point 5195 02:56:00,720 --> 02:56:05,600 should not execute so i'll just write 5196 02:56:02,880 --> 02:56:07,600 return so we'll see what happens 5197 02:56:05,600 --> 02:56:09,359 it will just print line one and line two 5198 02:56:07,600 --> 02:56:10,399 it will go back here and execute this 5199 02:56:09,359 --> 02:56:12,960 lines only 5200 02:56:10,399 --> 02:56:13,600 anything written after return will not 5201 02:56:12,960 --> 02:56:15,600 execute 5202 02:56:13,600 --> 02:56:16,640 okay now you may want to remove it from 5203 02:56:15,600 --> 02:56:19,840 here 5204 02:56:16,640 --> 02:56:22,240 and use it here right let's see what 5205 02:56:19,840 --> 02:56:22,240 happens 5206 02:56:24,240 --> 02:56:27,840 it will just print zero because when the 5207 02:56:26,160 --> 02:56:29,520 value of i was zero 5208 02:56:27,840 --> 02:56:31,439 it printed zero then it encountered 5209 02:56:29,520 --> 02:56:32,080 return so it will just terminate this 5210 02:56:31,439 --> 02:56:34,000 function 5211 02:56:32,080 --> 02:56:35,840 and you see that it is not printing one 5212 02:56:34,000 --> 02:56:37,760 two three four five six seven eight nine 5213 02:56:35,840 --> 02:56:39,040 because return keyboard just terminates 5214 02:56:37,760 --> 02:56:41,040 the function 5215 02:56:39,040 --> 02:56:42,720 all right so now i will see you in the 5216 02:56:41,040 --> 02:56:43,520 next video so the next topic in our 5217 02:56:42,720 --> 02:56:45,680 course is 5218 02:56:43,520 --> 02:56:47,600 switch case like if statements switch 5219 02:56:45,680 --> 02:56:49,760 case controls the flow of programs by 5220 02:56:47,600 --> 02:56:51,120 allowing us to specify different code 5221 02:56:49,760 --> 02:56:52,000 that should be executed in various 5222 02:56:51,120 --> 02:56:53,680 conditions 5223 02:56:52,000 --> 02:56:55,359 in particular a switch statement 5224 02:56:53,680 --> 02:56:57,200 compares the value of a variable 5225 02:56:55,359 --> 02:56:58,880 to the value specified in the case 5226 02:56:57,200 --> 02:57:00,000 statements when a case statement is 5227 02:56:58,880 --> 02:57:01,840 found whose value 5228 02:57:00,000 --> 02:57:03,279 matches that of the variable then the 5229 02:57:01,840 --> 02:57:05,279 code in that case statement 5230 02:57:03,279 --> 02:57:07,120 is executed so let us see the syntax of 5231 02:57:05,279 --> 02:57:09,040 switch case first of all we write switch 5232 02:57:07,120 --> 02:57:11,040 then our open bracket then we write the 5233 02:57:09,040 --> 02:57:12,640 variable which has to be compared 5234 02:57:11,040 --> 02:57:14,240 when we close the bracket then we start 5235 02:57:12,640 --> 02:57:17,760 a curly bracket then we write 5236 02:57:14,240 --> 02:57:19,439 case space label 1 where label 1 is 5237 02:57:17,760 --> 02:57:21,359 the number which has to be compared to 5238 02:57:19,439 --> 02:57:23,520 the variable okay then we write 5239 02:57:21,359 --> 02:57:24,479 colon note that this is a colon not a 5240 02:57:23,520 --> 02:57:26,479 semicolon 5241 02:57:24,479 --> 02:57:27,840 okay then we write the statements all 5242 02:57:26,479 --> 02:57:28,560 the statements which we want to be 5243 02:57:27,840 --> 02:57:30,720 executed 5244 02:57:28,560 --> 02:57:31,840 when label1 is equal to the variable we 5245 02:57:30,720 --> 02:57:34,000 write those statements 5246 02:57:31,840 --> 02:57:35,120 in this block then we write break 5247 02:57:34,000 --> 02:57:38,000 semicolon 5248 02:57:35,120 --> 02:57:40,000 then we write case another label then 5249 02:57:38,000 --> 02:57:42,080 all the statements then we write break 5250 02:57:40,000 --> 02:57:43,520 we can write as many labels we want in 5251 02:57:42,080 --> 02:57:44,479 our code and the last statement which we 5252 02:57:43,520 --> 02:57:46,880 write is default 5253 02:57:44,479 --> 02:57:48,720 colon all the statements break when none 5254 02:57:46,880 --> 02:57:50,080 of the labels is true then the default 5255 02:57:48,720 --> 02:57:51,520 statement is executed 5256 02:57:50,080 --> 02:57:53,120 if we don't write default and none of 5257 02:57:51,520 --> 02:57:53,920 the statement is true then nothing will 5258 02:57:53,120 --> 02:57:55,600 happen 5259 02:57:53,920 --> 02:57:57,439 all right so now let us see the flow of 5260 02:57:55,600 --> 02:57:58,560 code in switch case here is the switch 5261 02:57:57,439 --> 02:58:01,200 conditional statement 5262 02:57:58,560 --> 02:58:02,640 then it will see case one if it is true 5263 02:58:01,200 --> 02:58:04,080 it will execute the statements written 5264 02:58:02,640 --> 02:58:06,399 in that block if it is false 5265 02:58:04,080 --> 02:58:07,200 it will check case 2. if it is true then 5266 02:58:06,399 --> 02:58:09,279 it will execute the 5267 02:58:07,200 --> 02:58:10,319 statement if it is false it will go to 5268 02:58:09,279 --> 02:58:13,120 case 3 5269 02:58:10,319 --> 02:58:13,760 okay and so on if none of these are true 5270 02:58:13,120 --> 02:58:16,319 it will 5271 02:58:13,760 --> 02:58:18,319 automatically jump to default and it 5272 02:58:16,319 --> 02:58:20,160 will execute the default statements 5273 02:58:18,319 --> 02:58:22,160 and after executing one of these 5274 02:58:20,160 --> 02:58:23,279 statements the flow will go on to the 5275 02:58:22,160 --> 02:58:26,000 statement which is written 5276 02:58:23,279 --> 02:58:26,479 after the switch let's see in the coding 5277 02:58:26,000 --> 02:58:27,600 right 5278 02:58:26,479 --> 02:58:29,840 and the white setup we have written 5279 02:58:27,600 --> 02:58:30,640 serial dot begin as usual then i'm 5280 02:58:29,840 --> 02:58:33,279 writing int 5281 02:58:30,640 --> 02:58:34,240 x is equal to 5 here x is the variable 5282 02:58:33,279 --> 02:58:36,479 which we want to be 5283 02:58:34,240 --> 02:58:38,240 compared okay then i'm writing switch 5284 02:58:36,479 --> 02:58:40,720 then x here because i want 5285 02:58:38,240 --> 02:58:41,279 x to be compared then i'm writing case 1 5286 02:58:40,720 --> 02:58:43,680 colon 5287 02:58:41,279 --> 02:58:45,600 serial dot println choice 1 break 5288 02:58:43,680 --> 02:58:47,040 similarly i've written 6 cases now can 5289 02:58:45,600 --> 02:58:47,680 you guess what statement will be printed 5290 02:58:47,040 --> 02:58:50,479 here since 5291 02:58:47,680 --> 02:58:51,600 x is equal to 5 my guess is choice 5 5292 02:58:50,479 --> 02:58:53,200 should be printed 5293 02:58:51,600 --> 02:58:54,720 because it is not equal to 1 it is not 5294 02:58:53,200 --> 02:58:55,040 equal to 2 it is not equal to 3 and so 5295 02:58:54,720 --> 02:58:58,640 on 5296 02:58:55,040 --> 02:58:58,640 ok so let us see what happens 5297 02:58:59,680 --> 02:59:03,359 right as expected it is printing choice 5298 02:59:02,000 --> 02:59:06,479 five now if i change 5299 02:59:03,359 --> 02:59:10,640 the value of x to let's say 5300 02:59:06,479 --> 02:59:10,640 one so now choice one will be printed 5301 02:59:10,960 --> 02:59:15,040 right now in case if we don't write 5302 02:59:14,080 --> 02:59:16,960 break here 5303 02:59:15,040 --> 02:59:18,720 the purpose of writing break here is 5304 02:59:16,960 --> 02:59:20,000 that we want to exit as soon as one 5305 02:59:18,720 --> 02:59:22,080 condition becomes true 5306 02:59:20,000 --> 02:59:24,000 let's say if we don't write break here 5307 02:59:22,080 --> 02:59:24,960 so it will continue to execute the 5308 02:59:24,000 --> 02:59:26,800 statements 5309 02:59:24,960 --> 02:59:29,279 since x is equal to 1 so now it should 5310 02:59:26,800 --> 02:59:29,920 print choice one choice two and choice 5311 02:59:29,279 --> 02:59:31,920 three 5312 02:59:29,920 --> 02:59:33,760 okay because there's another break after 5313 02:59:31,920 --> 02:59:34,880 choice three right choice one choice two 5314 02:59:33,760 --> 02:59:36,560 choice three 5315 02:59:34,880 --> 02:59:38,399 that's the purpose of break now let's 5316 02:59:36,560 --> 02:59:42,080 see one more example without break 5317 02:59:38,399 --> 02:59:44,399 let me use x is equal to 3 5318 02:59:42,080 --> 02:59:47,040 then it will start from here will not 5319 02:59:44,399 --> 02:59:50,160 use break here 5320 02:59:47,040 --> 02:59:53,200 it should print choice 3 choice 4 5321 02:59:50,160 --> 02:59:53,200 and choice 5. 5322 02:59:54,160 --> 02:59:57,680 right as expected now the important 5323 02:59:56,240 --> 02:59:59,680 thing which you need to notice is 5324 02:59:57,680 --> 03:00:01,040 the variable which we use here and the 5325 02:59:59,680 --> 03:00:03,840 labels which we use here 5326 03:00:01,040 --> 03:00:05,680 should be of int or character type if 5327 03:00:03,840 --> 03:00:06,560 you use float or if you use another 5328 03:00:05,680 --> 03:00:08,479 array type 5329 03:00:06,560 --> 03:00:10,160 it will just throw an error this switch 5330 03:00:08,479 --> 03:00:12,319 case is a really handy tool if you want 5331 03:00:10,160 --> 03:00:14,000 to write a lot of if else statements 5332 03:00:12,319 --> 03:00:15,520 instead of that you can just write case 5333 03:00:14,000 --> 03:00:17,840 1 case 2 case 3. 5334 03:00:15,520 --> 03:00:19,359 we can also specify ranges in case 5335 03:00:17,840 --> 03:00:20,960 statements and how we do that 5336 03:00:19,359 --> 03:00:22,880 let's say we want to take a range of 1 5337 03:00:20,960 --> 03:00:26,399 to 10. we'll write 1 5338 03:00:22,880 --> 03:00:30,640 we'll write three dots and then 10 5339 03:00:26,399 --> 03:00:34,800 okay then let's say 11 space 5340 03:00:30,640 --> 03:00:38,319 to 20 okay let's say 5341 03:00:34,800 --> 03:00:40,880 21 3 dots to 30 5342 03:00:38,319 --> 03:00:41,920 then we write 31 space you have to write 5343 03:00:40,880 --> 03:00:43,279 a space there okay 5344 03:00:41,920 --> 03:00:47,359 if you don't write a space you will get 5345 03:00:43,279 --> 03:00:50,080 an error so let's see these cases only 5346 03:00:47,359 --> 03:00:50,880 let me write break again okay so now let 5347 03:00:50,080 --> 03:00:53,120 us see 5348 03:00:50,880 --> 03:00:55,120 three what will happen it will write 5349 03:00:53,120 --> 03:00:58,560 choice 1 5350 03:00:55,120 --> 03:01:02,800 right now for example if i take 35 5351 03:00:58,560 --> 03:01:02,800 it should write choice 4 5352 03:01:02,880 --> 03:01:06,479 right so i guess you got an idea how 5353 03:01:05,359 --> 03:01:08,880 easy it is 5354 03:01:06,479 --> 03:01:10,000 right instead of writing if in else we 5355 03:01:08,880 --> 03:01:11,840 can use 5356 03:01:10,000 --> 03:01:13,840 switch case so i hope you understood 5357 03:01:11,840 --> 03:01:14,560 this topic so i'll see you in the next 5358 03:01:13,840 --> 03:01:17,760 video 5359 03:01:14,560 --> 03:01:20,319 so at this point we are in a position to 5360 03:01:17,760 --> 03:01:23,439 study about the two remaining data types 5361 03:01:20,319 --> 03:01:25,680 which are arrays and strings these two 5362 03:01:23,439 --> 03:01:27,600 data types are also very commonly used 5363 03:01:25,680 --> 03:01:29,439 in the projects which are made using 5364 03:01:27,600 --> 03:01:32,240 arduino 5365 03:01:29,439 --> 03:01:34,240 so in this video we will look at arrays 5366 03:01:32,240 --> 03:01:36,000 an array is a variable which can store 5367 03:01:34,240 --> 03:01:37,680 multiple values of same type 5368 03:01:36,000 --> 03:01:39,760 let's say we have a compartment of a 5369 03:01:37,680 --> 03:01:41,279 defined size which has multiple 5370 03:01:39,760 --> 03:01:43,520 containers in it 5371 03:01:41,279 --> 03:01:44,399 like this and those containers can store 5372 03:01:43,520 --> 03:01:46,640 same kind of 5373 03:01:44,399 --> 03:01:48,080 information let's see this by an example 5374 03:01:46,640 --> 03:01:50,399 to declare an array 5375 03:01:48,080 --> 03:01:52,160 we first write the type of data which we 5376 03:01:50,399 --> 03:01:54,880 are going to store in it 5377 03:01:52,160 --> 03:01:55,600 let's say int then we write the name of 5378 03:01:54,880 --> 03:01:58,479 that array 5379 03:01:55,600 --> 03:01:58,960 let's say my array okay and then we 5380 03:01:58,479 --> 03:02:01,200 write 5381 03:01:58,960 --> 03:02:02,080 a square bracket and we write a number 5382 03:02:01,200 --> 03:02:04,160 inside it 5383 03:02:02,080 --> 03:02:05,200 that number denotes the size of that 5384 03:02:04,160 --> 03:02:07,680 array 5385 03:02:05,200 --> 03:02:09,680 okay let's say five so when we write 5386 03:02:07,680 --> 03:02:11,200 this the compiler will create a space in 5387 03:02:09,680 --> 03:02:14,479 memory where you can store 5388 03:02:11,200 --> 03:02:16,640 those five integers okay now let's store 5389 03:02:14,479 --> 03:02:17,920 some values in this array to do that we 5390 03:02:16,640 --> 03:02:20,160 write equal to 5391 03:02:17,920 --> 03:02:21,359 then we write curly bracket and then we 5392 03:02:20,160 --> 03:02:22,800 will write five 5393 03:02:21,359 --> 03:02:25,040 values which we want to store in it 5394 03:02:22,800 --> 03:02:28,640 let's say one two three 5395 03:02:25,040 --> 03:02:30,880 four and five semicolon each value 5396 03:02:28,640 --> 03:02:31,680 is separated using a comma and each 5397 03:02:30,880 --> 03:02:34,880 value inside 5398 03:02:31,680 --> 03:02:37,840 an array is known as element of array 5399 03:02:34,880 --> 03:02:39,120 okay and each element has an address of 5400 03:02:37,840 --> 03:02:42,399 its own 5401 03:02:39,120 --> 03:02:45,279 that address is known as an array index 5402 03:02:42,399 --> 03:02:46,560 that index starts from zero okay let me 5403 03:02:45,279 --> 03:02:48,720 show that to you again 5404 03:02:46,560 --> 03:02:50,960 let's say we have an array of size 10 so 5405 03:02:48,720 --> 03:02:54,160 0 is the first index and 9 5406 03:02:50,960 --> 03:02:55,439 is the last index okay and the value 5407 03:02:54,160 --> 03:02:58,560 which is present at that 5408 03:02:55,439 --> 03:03:00,319 index is known as element let's see that 5409 03:02:58,560 --> 03:03:00,960 again encoding so this is the zeroth 5410 03:03:00,319 --> 03:03:04,319 element 5411 03:03:00,960 --> 03:03:06,399 and this is the fourth element okay 5412 03:03:04,319 --> 03:03:08,640 now let's try to access them how do we 5413 03:03:06,399 --> 03:03:12,640 access them serial dot 5414 03:03:08,640 --> 03:03:14,800 println my array 5415 03:03:12,640 --> 03:03:15,760 and then the value which we want to use 5416 03:03:14,800 --> 03:03:17,840 let's say 5417 03:03:15,760 --> 03:03:21,040 2 can you guess what will be printed 5418 03:03:17,840 --> 03:03:21,040 here tell me 5419 03:03:22,000 --> 03:03:28,080 0 1 and 2 so 3 should be printed 5420 03:03:26,000 --> 03:03:30,640 so 3 has been printed here for the first 5421 03:03:28,080 --> 03:03:32,960 time users it must be really confusing 5422 03:03:30,640 --> 03:03:33,680 that why it was started from 0. it is 5423 03:03:32,960 --> 03:03:36,479 very simple 5424 03:03:33,680 --> 03:03:38,800 because computer counts from 0. while 5425 03:03:36,479 --> 03:03:40,399 humans are in a habit of counting from 1 5426 03:03:38,800 --> 03:03:41,840 that's why we are finding it a little 5427 03:03:40,399 --> 03:03:43,439 confusing now let's 5428 03:03:41,840 --> 03:03:45,120 change the values which are present 5429 03:03:43,439 --> 03:03:46,640 inside this we'll take bigger and 5430 03:03:45,120 --> 03:03:49,680 complicated values 5431 03:03:46,640 --> 03:03:52,880 let's say 745 74 5432 03:03:49,680 --> 03:03:54,319 259 85 and 421 5433 03:03:52,880 --> 03:03:56,319 these are the random values which i have 5434 03:03:54,319 --> 03:03:56,880 chosen now if we try to print the second 5435 03:03:56,319 --> 03:04:00,240 element 5436 03:03:56,880 --> 03:04:01,680 it will print 259 because 259 is present 5437 03:04:00,240 --> 03:04:04,800 at 5438 03:04:01,680 --> 03:04:06,800 second index okay while zero is this one 5439 03:04:04,800 --> 03:04:08,800 first is this one second is this one 5440 03:04:06,800 --> 03:04:11,680 third is this one and fourth is 5441 03:04:08,800 --> 03:04:12,240 this one now we can alter these elements 5442 03:04:11,680 --> 03:04:14,319 as well 5443 03:04:12,240 --> 03:04:15,680 directly now let's say i want to change 5444 03:04:14,319 --> 03:04:19,200 the value which is present at 5445 03:04:15,680 --> 03:04:22,720 second index so we'll write my array 5446 03:04:19,200 --> 03:04:26,640 2 is equal to let's say 5447 03:04:22,720 --> 03:04:30,399 7 0 6 okay now the value of 259 5448 03:04:26,640 --> 03:04:33,920 will be replaced by 706 let's see 5449 03:04:30,399 --> 03:04:34,479 let's print that again now it should be 5450 03:04:33,920 --> 03:04:37,439 printing 5451 03:04:34,479 --> 03:04:38,160 706 right we can alter any value for 5452 03:04:37,439 --> 03:04:40,240 that matter 5453 03:04:38,160 --> 03:04:41,680 we can do our regular calculations on 5454 03:04:40,240 --> 03:04:45,680 array elements as well 5455 03:04:41,680 --> 03:04:48,880 let's say i have one variable in 5456 03:04:45,680 --> 03:04:50,240 my variable okay 5457 03:04:48,880 --> 03:04:51,920 now let's say i want to add some 5458 03:04:50,240 --> 03:04:52,960 elements and store that value in my 5459 03:04:51,920 --> 03:04:56,160 variable 5460 03:04:52,960 --> 03:04:59,680 i will write my array okay 0 5461 03:04:56,160 --> 03:05:04,000 plus my array 1 5462 03:04:59,680 --> 03:05:08,160 plus my array 2. 5463 03:05:04,000 --> 03:05:12,160 okay so now my variable will be holding 5464 03:05:08,160 --> 03:05:15,439 the sum of 7 45 74 and 249 5465 03:05:12,160 --> 03:05:16,640 not 249 706 because we have altered it 5466 03:05:15,439 --> 03:05:19,359 here 5467 03:05:16,640 --> 03:05:20,960 so let's try and print my variable you 5468 03:05:19,359 --> 03:05:24,080 can check on your calculators 5469 03:05:20,960 --> 03:05:27,840 if the answer is correct or not 5470 03:05:24,080 --> 03:05:31,200 so the sum of 745 74 and 706 is 5471 03:05:27,840 --> 03:05:33,200 15 25 1525 okay 5472 03:05:31,200 --> 03:05:35,040 similarly we can also do multiplication 5473 03:05:33,200 --> 03:05:36,479 subtraction division etcetera all the 5474 03:05:35,040 --> 03:05:39,120 operators can be used here 5475 03:05:36,479 --> 03:05:39,920 okay now we can also use elements of 5476 03:05:39,120 --> 03:05:42,240 these arrays 5477 03:05:39,920 --> 03:05:44,319 in for loops as well now let's use a for 5478 03:05:42,240 --> 03:05:46,880 loop to print all the elements 5479 03:05:44,319 --> 03:05:47,760 inside my array so how we will do that 5480 03:05:46,880 --> 03:05:51,359 for 5481 03:05:47,760 --> 03:05:54,479 int i is equal to 0 5482 03:05:51,359 --> 03:05:58,160 i less than 5 5483 03:05:54,479 --> 03:06:01,359 because size of my array is 5 then i 5484 03:05:58,160 --> 03:06:05,520 plus plus okay so now what will we do is 5485 03:06:01,359 --> 03:06:07,359 serial dot println my array then i 5486 03:06:05,520 --> 03:06:09,760 okay so it should print all the elements 5487 03:06:07,359 --> 03:06:12,800 which are present inside this array 5488 03:06:09,760 --> 03:06:12,800 so it is here 5489 03:06:12,840 --> 03:06:19,680 745 74 706 5490 03:06:16,319 --> 03:06:23,760 85 and 421 right you can compare them 5491 03:06:19,680 --> 03:06:24,800 here 745 74 706 because we updated the 5492 03:06:23,760 --> 03:06:28,319 value here 5493 03:06:24,800 --> 03:06:29,920 then we have 85 then we have 421 okay 5494 03:06:28,319 --> 03:06:31,840 now can you tell me what will we do if 5495 03:06:29,920 --> 03:06:35,359 you want to add 5 5496 03:06:31,840 --> 03:06:38,479 to all the elements of my array 5497 03:06:35,359 --> 03:06:40,720 okay so now let's say we'll write 5498 03:06:38,479 --> 03:06:40,720 for 5499 03:06:41,840 --> 03:06:49,359 i is equal to 0 i less than 5500 03:06:45,920 --> 03:06:52,399 5 then i plus plus will take my array 5501 03:06:49,359 --> 03:06:55,520 i is equal to 5502 03:06:52,399 --> 03:06:58,960 my array i write 5503 03:06:55,520 --> 03:07:01,600 plus 5 5504 03:06:58,960 --> 03:07:03,680 so now 5 will be added to all these 5505 03:07:01,600 --> 03:07:06,319 elements 5506 03:07:03,680 --> 03:07:09,120 so now 5 has been added so now let's 5507 03:07:06,319 --> 03:07:09,120 print this again 5508 03:07:09,359 --> 03:07:12,399 if we print this again so now we will 5509 03:07:12,080 --> 03:07:15,840 see 5510 03:07:12,399 --> 03:07:18,240 5 has been added to all the elements 5511 03:07:15,840 --> 03:07:19,040 let's see we are here it is printing 5512 03:07:18,240 --> 03:07:22,880 from here right 5513 03:07:19,040 --> 03:07:26,720 745 plus 5 is 750 74 plus 5 is 79 5514 03:07:22,880 --> 03:07:30,720 then 706 plus 5 is 7 11 5515 03:07:26,720 --> 03:07:32,560 85 plus 5 is 90 421 plus 5 is 426 5516 03:07:30,720 --> 03:07:34,240 okay this way we have added five to all 5517 03:07:32,560 --> 03:07:36,080 the elements now we can take 5518 03:07:34,240 --> 03:07:37,520 some of all the elements in the array as 5519 03:07:36,080 --> 03:07:40,640 well how will we do that 5520 03:07:37,520 --> 03:07:42,640 let's say int sum is equal to zero we 5521 03:07:40,640 --> 03:07:46,800 have initialized it by zero and for 5522 03:07:42,640 --> 03:07:50,399 int i is equal to zero 5523 03:07:46,800 --> 03:07:53,359 i less than five then i plus plus 5524 03:07:50,399 --> 03:07:54,080 okay what will we write is sum is equal 5525 03:07:53,359 --> 03:07:57,279 to 5526 03:07:54,080 --> 03:08:02,080 sum plus my array 5527 03:07:57,279 --> 03:08:06,000 i okay and after that we'll just print 5528 03:08:02,080 --> 03:08:07,600 sum right it is printing 2 0 5529 03:08:06,000 --> 03:08:10,080 5 6. so you can check on your 5530 03:08:07,600 --> 03:08:13,040 calculators if these values are 5531 03:08:10,080 --> 03:08:14,960 summing up to 2 0 5 6 but just make sure 5532 03:08:13,040 --> 03:08:18,240 you don't add these values you add 5533 03:08:14,960 --> 03:08:22,080 the new values the new value was 750 5534 03:08:18,240 --> 03:08:24,319 79 7 11 90 and 426 5535 03:08:22,080 --> 03:08:25,840 these were the new values these okay if 5536 03:08:24,319 --> 03:08:27,840 you add these values you will get 5537 03:08:25,840 --> 03:08:29,920 two zero five six so now we have learned 5538 03:08:27,840 --> 03:08:32,319 about how to use arrays 5539 03:08:29,920 --> 03:08:34,640 how to access the values in an array and 5540 03:08:32,319 --> 03:08:36,800 how to manipulate those values 5541 03:08:34,640 --> 03:08:38,319 what we saw till now in this video were 5542 03:08:36,800 --> 03:08:40,479 one-dimensional arrays 5543 03:08:38,319 --> 03:08:41,520 that means they just have one dimension 5544 03:08:40,479 --> 03:08:43,920 now there can be 5545 03:08:41,520 --> 03:08:45,600 multi-dimensional arrays as well like 5546 03:08:43,920 --> 03:08:46,240 two-dimensional arrays three-dimensional 5547 03:08:45,600 --> 03:08:49,680 arrays 5548 03:08:46,240 --> 03:08:53,120 like you can see here this pink box 5549 03:08:49,680 --> 03:08:55,359 is a two dimensional array 5550 03:08:53,120 --> 03:08:56,319 it has rows as well it has columns as 5551 03:08:55,359 --> 03:08:58,640 well 5552 03:08:56,319 --> 03:09:00,319 okay and then we have three dimensional 5553 03:08:58,640 --> 03:09:03,439 arrays as well 5554 03:09:00,319 --> 03:09:03,760 like it has depth as well it has rows it 5555 03:09:03,439 --> 03:09:06,479 has 5556 03:09:03,760 --> 03:09:08,240 columns and it has depth as well 5557 03:09:06,479 --> 03:09:10,960 multiple two dimensional arrays 5558 03:09:08,240 --> 03:09:12,319 make three dimensional arrays i just 5559 03:09:10,960 --> 03:09:14,319 give you one use case 5560 03:09:12,319 --> 03:09:16,479 where two dimensional arrays are used 5561 03:09:14,319 --> 03:09:18,640 for example we want to store 5562 03:09:16,479 --> 03:09:19,920 the pixel data image pixel data of a 5563 03:09:18,640 --> 03:09:23,439 black and white image 5564 03:09:19,920 --> 03:09:26,239 okay so we use two dimensional arrays 5565 03:09:23,439 --> 03:09:27,520 and let's say we have to store pixel uh 5566 03:09:26,239 --> 03:09:30,479 image pixel data 5567 03:09:27,520 --> 03:09:31,279 of a colored image which also has rgb 5568 03:09:30,479 --> 03:09:33,359 values 5569 03:09:31,279 --> 03:09:35,680 so we use a three dimensional array for 5570 03:09:33,359 --> 03:09:37,840 that in this video we will talk about 5571 03:09:35,680 --> 03:09:39,279 strings strings are basically a sequence 5572 03:09:37,840 --> 03:09:41,520 of characters 5573 03:09:39,279 --> 03:09:43,200 whatever we write or you can say 5574 03:09:41,520 --> 03:09:43,680 whatever messages which we write in our 5575 03:09:43,200 --> 03:09:46,239 code 5576 03:09:43,680 --> 03:09:48,000 are all strings let us see in the code 5577 03:09:46,239 --> 03:09:49,600 the easiest way to spot 5578 03:09:48,000 --> 03:09:51,279 strings is that you will find them 5579 03:09:49,600 --> 03:09:54,479 written inside double quotes 5580 03:09:51,279 --> 03:09:57,760 for example serial dot println 5581 03:09:54,479 --> 03:09:59,279 this is my string okay 5582 03:09:57,760 --> 03:10:00,640 this is my string is the message which 5583 03:09:59,279 --> 03:10:01,439 is going to be printed on the serial 5584 03:10:00,640 --> 03:10:04,720 monitor 5585 03:10:01,439 --> 03:10:07,600 but in itself this is my string is 5586 03:10:04,720 --> 03:10:08,960 a string okay now technically speaking a 5587 03:10:07,600 --> 03:10:11,439 string is nothing 5588 03:10:08,960 --> 03:10:12,399 but an array of characters and as we 5589 03:10:11,439 --> 03:10:14,080 have already studied 5590 03:10:12,399 --> 03:10:16,479 arrays it would be really easy for you 5591 03:10:14,080 --> 03:10:19,200 to understand so now to declare a string 5592 03:10:16,479 --> 03:10:20,319 we write char in the name of the string 5593 03:10:19,200 --> 03:10:22,880 which we want 5594 03:10:20,319 --> 03:10:23,520 for example i have written str 2 then as 5595 03:10:22,880 --> 03:10:25,200 we start 5596 03:10:23,520 --> 03:10:27,680 an array by a square bracket and a 5597 03:10:25,200 --> 03:10:30,720 number inside it we similarly write it 5598 03:10:27,680 --> 03:10:34,000 for string as well now example 5599 03:10:30,720 --> 03:10:34,479 i want to write ashish which has a s h i 5600 03:10:34,000 --> 03:10:37,359 s h 5601 03:10:34,479 --> 03:10:38,880 as characters in it okay and the number 5602 03:10:37,359 --> 03:10:41,760 of characters in ashish are 5603 03:10:38,880 --> 03:10:43,520 6. okay so what we will do is we'll 5604 03:10:41,760 --> 03:10:45,920 always take one additional number 5605 03:10:43,520 --> 03:10:48,160 to declare our string because an ending 5606 03:10:45,920 --> 03:10:49,680 to the string is denoted by a special 5607 03:10:48,160 --> 03:10:50,319 character which is known as a null 5608 03:10:49,680 --> 03:10:52,160 character 5609 03:10:50,319 --> 03:10:54,080 okay the compiler automatically takes 5610 03:10:52,160 --> 03:10:56,080 that into consideration when you write 5611 03:10:54,080 --> 03:10:57,439 a string or when you declare a character 5612 03:10:56,080 --> 03:10:59,680 array okay 5613 03:10:57,439 --> 03:11:01,520 in this case compiler will see okay the 5614 03:10:59,680 --> 03:11:02,239 person is trying to declare a character 5615 03:11:01,520 --> 03:11:04,800 array 5616 03:11:02,239 --> 03:11:06,560 which has these characters so it will 5617 03:11:04,800 --> 03:11:08,560 automatically add a null character at 5618 03:11:06,560 --> 03:11:10,960 the end so now when we print this line 5619 03:11:08,560 --> 03:11:12,000 it will print ash ish on the serial 5620 03:11:10,960 --> 03:11:15,840 monitor 5621 03:11:12,000 --> 03:11:17,920 okay another way is to declare 5622 03:11:15,840 --> 03:11:18,880 that null character explicitly for 5623 03:11:17,920 --> 03:11:22,160 example i will write 5624 03:11:18,880 --> 03:11:25,279 chart str3 then 7 5625 03:11:22,160 --> 03:11:26,960 is equal to ash ish and then 5626 03:11:25,279 --> 03:11:28,880 a null character this is the null 5627 03:11:26,960 --> 03:11:30,239 character which is denoted by a 5628 03:11:28,880 --> 03:11:33,120 backslash and a 0. 5629 03:11:30,239 --> 03:11:33,920 this way the compiler identifies that 5630 03:11:33,120 --> 03:11:36,479 okay 5631 03:11:33,920 --> 03:11:38,160 this string has come to an end okay so 5632 03:11:36,479 --> 03:11:38,720 it can differentiate between one or more 5633 03:11:38,160 --> 03:11:40,239 strings 5634 03:11:38,720 --> 03:11:42,720 without this character there will be 5635 03:11:40,239 --> 03:11:44,560 problems the compiler may think that 5636 03:11:42,720 --> 03:11:46,720 the another string which is coming after 5637 03:11:44,560 --> 03:11:48,319 this string is a part of that same 5638 03:11:46,720 --> 03:11:49,680 string there has to be some way 5639 03:11:48,319 --> 03:11:52,239 to differentiate between different 5640 03:11:49,680 --> 03:11:54,720 sentences okay so that's why we use 5641 03:11:52,239 --> 03:11:56,720 a null character which is backslash zero 5642 03:11:54,720 --> 03:11:59,359 another way to declare a string is 5643 03:11:56,720 --> 03:12:00,640 we write char str4 which is the name of 5644 03:11:59,359 --> 03:12:02,560 the string 5645 03:12:00,640 --> 03:12:04,319 and then we write square brackets 5646 03:12:02,560 --> 03:12:05,840 without a number inside it 5647 03:12:04,319 --> 03:12:08,479 the compiler is smart enough to 5648 03:12:05,840 --> 03:12:10,880 dynamically allot a number to this 5649 03:12:08,479 --> 03:12:11,920 bracket it will see okay the user has 5650 03:12:10,880 --> 03:12:14,800 written a string 5651 03:12:11,920 --> 03:12:15,760 which has ash ish inside that it will 5652 03:12:14,800 --> 03:12:17,920 automatically 5653 03:12:15,760 --> 03:12:20,000 allot a memory of seven to this string 5654 03:12:17,920 --> 03:12:21,680 because ashish has six characters in it 5655 03:12:20,000 --> 03:12:24,319 and including a null character it will 5656 03:12:21,680 --> 03:12:28,239 become seven okay we can also write 5657 03:12:24,319 --> 03:12:30,319 it like this str five seven ashish 5658 03:12:28,239 --> 03:12:31,359 simply in double quotes we don't have to 5659 03:12:30,319 --> 03:12:33,760 work this much 5660 03:12:31,359 --> 03:12:35,120 it is also okay if you take a larger 5661 03:12:33,760 --> 03:12:37,120 memory for a smaller string 5662 03:12:35,120 --> 03:12:39,120 but it is not okay to take a smaller 5663 03:12:37,120 --> 03:12:41,200 size string let's say five 5664 03:12:39,120 --> 03:12:43,120 for a longer okay now you will see it 5665 03:12:41,200 --> 03:12:45,120 will only print five characters 5666 03:12:43,120 --> 03:12:46,800 and then there is another way we will 5667 03:12:45,120 --> 03:12:48,239 talk about it shortly but right now let 5668 03:12:46,800 --> 03:12:50,160 me comment this out okay 5669 03:12:48,239 --> 03:12:53,600 we'll just upload this code and we will 5670 03:12:50,160 --> 03:12:56,399 see what we are getting 5671 03:12:53,600 --> 03:12:57,680 all right so this is my string then it 5672 03:12:56,399 --> 03:13:00,880 wrote ashish 5673 03:12:57,680 --> 03:13:03,439 for this ashish for this ashish 5674 03:13:00,880 --> 03:13:03,439 for this again 5675 03:13:04,000 --> 03:13:08,640 and it printed it till here okay we 5676 03:13:07,120 --> 03:13:12,319 forgot to write 5677 03:13:08,640 --> 03:13:15,840 serial dot print ln 5678 03:13:12,319 --> 03:13:15,840 for str 5679 03:13:16,800 --> 03:13:20,479 right it just skipped the last character 5680 03:13:19,520 --> 03:13:23,040 because we didn't give 5681 03:13:20,479 --> 03:13:23,600 necessary memory to it so according to 5682 03:13:23,040 --> 03:13:25,520 me 5683 03:13:23,600 --> 03:13:27,040 this is the best way to start writing 5684 03:13:25,520 --> 03:13:28,479 strings because obviously you do not 5685 03:13:27,040 --> 03:13:29,840 know how many characters your string 5686 03:13:28,479 --> 03:13:31,200 will contain and obviously you don't 5687 03:13:29,840 --> 03:13:32,960 want to spend that time 5688 03:13:31,200 --> 03:13:34,640 to count those characters right the 5689 03:13:32,960 --> 03:13:35,200 compiler is smart enough to calculate 5690 03:13:34,640 --> 03:13:39,439 the size 5691 03:13:35,200 --> 03:13:42,640 for you okay now there is another way 5692 03:13:39,439 --> 03:13:46,160 to write a string which is by using 5693 03:13:42,640 --> 03:13:49,760 a string class okay here 5694 03:13:46,160 --> 03:13:51,760 let me just comment this out this is 5695 03:13:49,760 --> 03:13:53,520 a string class we are up calling a 5696 03:13:51,760 --> 03:13:56,319 string class and we have named 5697 03:13:53,520 --> 03:13:57,359 str7 inside it and we have just written 5698 03:13:56,319 --> 03:14:00,479 whatever we want 5699 03:13:57,359 --> 03:14:01,279 inside that let's say ashish and when we 5700 03:14:00,479 --> 03:14:03,840 print this 5701 03:14:01,279 --> 03:14:05,520 it will straightaway print this ok 5702 03:14:03,840 --> 03:14:07,520 what's the benefit of using a class is 5703 03:14:05,520 --> 03:14:09,600 that it is a built-in class first of all 5704 03:14:07,520 --> 03:14:11,600 and it has a lot of functions inside it 5705 03:14:09,600 --> 03:14:13,120 and those functions can be like we can 5706 03:14:11,600 --> 03:14:15,680 compare a string 5707 03:14:13,120 --> 03:14:16,399 okay easily we're just writing string 5708 03:14:15,680 --> 03:14:18,239 name dot 5709 03:14:16,399 --> 03:14:20,479 equals if it is equals it will return 5710 03:14:18,239 --> 03:14:22,080 true and similarly there are many more 5711 03:14:20,479 --> 03:14:24,239 built-in functions inside the string 5712 03:14:22,080 --> 03:14:25,359 class for example i can tell you we can 5713 03:14:24,239 --> 03:14:27,920 print a character 5714 03:14:25,359 --> 03:14:29,359 at a particular sequence for example i 5715 03:14:27,920 --> 03:14:32,479 wrote str 5716 03:14:29,359 --> 03:14:35,600 and then serial dot println str can 5717 03:14:32,479 --> 03:14:38,000 at 0 so it will print a because 5718 03:14:35,600 --> 03:14:39,439 at 0 position a is present similarly 5719 03:14:38,000 --> 03:14:42,239 there are many more functions 5720 03:14:39,439 --> 03:14:43,840 like or starting with ending with and 5721 03:14:42,239 --> 03:14:44,560 there is a function like we can convert 5722 03:14:43,840 --> 03:14:46,880 the entire 5723 03:14:44,560 --> 03:14:47,600 string which is written in lowercase to 5724 03:14:46,880 --> 03:14:49,920 uppercase 5725 03:14:47,600 --> 03:14:51,760 and vice versa uppercase to lowercase 5726 03:14:49,920 --> 03:14:53,040 okay we can convert integers into string 5727 03:14:51,760 --> 03:14:56,080 we can convert 5728 03:14:53,040 --> 03:14:57,520 strings into integers okay so you may be 5729 03:14:56,080 --> 03:14:59,600 needing all these functions 5730 03:14:57,520 --> 03:15:00,640 while we perform our experiments strings 5731 03:14:59,600 --> 03:15:02,960 are used to contain 5732 03:15:00,640 --> 03:15:04,000 information messages or error messages 5733 03:15:02,960 --> 03:15:06,880 or any 5734 03:15:04,000 --> 03:15:07,600 logs okay we can store them inside 5735 03:15:06,880 --> 03:15:09,840 strings 5736 03:15:07,600 --> 03:15:11,920 and we can also display strings on our 5737 03:15:09,840 --> 03:15:14,880 serial monitor on the lcd display 5738 03:15:11,920 --> 03:15:15,520 or any kind of display okay we will now 5739 03:15:14,880 --> 03:15:17,600 understand 5740 03:15:15,520 --> 03:15:19,680 what are functions a function is a set 5741 03:15:17,600 --> 03:15:21,760 of statements that take inputs 5742 03:15:19,680 --> 03:15:23,120 and do some specific computation and 5743 03:15:21,760 --> 03:15:25,120 produces some output 5744 03:15:23,120 --> 03:15:26,560 the idea is to put some commonly or 5745 03:15:25,120 --> 03:15:28,560 repeatedly done tasks 5746 03:15:26,560 --> 03:15:30,160 together and make a function so that 5747 03:15:28,560 --> 03:15:32,000 instead of writing the same code again 5748 03:15:30,160 --> 03:15:32,960 and again for different inputs we can 5749 03:15:32,000 --> 03:15:34,800 call the function 5750 03:15:32,960 --> 03:15:36,800 we'll understand what i just said as we 5751 03:15:34,800 --> 03:15:37,279 progress in the video so before anything 5752 03:15:36,800 --> 03:15:40,319 else 5753 03:15:37,279 --> 03:15:41,359 let us first understand how to identify 5754 03:15:40,319 --> 03:15:42,800 a function 5755 03:15:41,359 --> 03:15:44,640 in the code whenever we see something 5756 03:15:42,800 --> 03:15:46,479 like this like void 5757 03:15:44,640 --> 03:15:48,160 name and then there are brackets then 5758 03:15:46,479 --> 03:15:49,200 there is a curly bracket then there are 5759 03:15:48,160 --> 03:15:51,200 some statements written 5760 03:15:49,200 --> 03:15:52,640 and then there is a curly bracket again 5761 03:15:51,200 --> 03:15:55,760 this is the basic structure 5762 03:15:52,640 --> 03:15:57,760 of a function okay where void is 5763 03:15:55,760 --> 03:15:59,279 the return type that means we start 5764 03:15:57,760 --> 03:16:00,960 writing a function by telling the 5765 03:15:59,279 --> 03:16:01,520 compiler the return type of that 5766 03:16:00,960 --> 03:16:04,080 function 5767 03:16:01,520 --> 03:16:04,640 where void means that function will not 5768 03:16:04,080 --> 03:16:07,279 return 5769 03:16:04,640 --> 03:16:08,160 anything now instead of white here we 5770 03:16:07,279 --> 03:16:10,800 can use 5771 03:16:08,160 --> 03:16:11,680 int boolean or float or anything for 5772 03:16:10,800 --> 03:16:13,439 that matter 5773 03:16:11,680 --> 03:16:15,520 whatever we want to return from the 5774 03:16:13,439 --> 03:16:17,359 function then we write 5775 03:16:15,520 --> 03:16:19,600 the name of the function we can name it 5776 03:16:17,359 --> 03:16:22,239 whatever we want like we saw 5777 03:16:19,600 --> 03:16:23,200 digital write or pin mode they were the 5778 03:16:22,239 --> 03:16:25,040 functions 5779 03:16:23,200 --> 03:16:26,239 and the name of that function was pin 5780 03:16:25,040 --> 03:16:28,720 mode and 5781 03:16:26,239 --> 03:16:29,520 digital write and then in the bracket we 5782 03:16:28,720 --> 03:16:32,399 write 5783 03:16:29,520 --> 03:16:33,200 parameters or some people call them 5784 03:16:32,399 --> 03:16:35,040 arguments 5785 03:16:33,200 --> 03:16:36,560 if there are no parameters or arguments 5786 03:16:35,040 --> 03:16:37,120 to the function we just keep this 5787 03:16:36,560 --> 03:16:39,439 bracket 5788 03:16:37,120 --> 03:16:41,200 empty or if there are parameters then we 5789 03:16:39,439 --> 03:16:42,720 specify those parameters how do we 5790 03:16:41,200 --> 03:16:44,239 specify the parameters we will see in 5791 03:16:42,720 --> 03:16:45,840 the next video okay 5792 03:16:44,239 --> 03:16:48,080 so i'll just basically tell you how do 5793 03:16:45,840 --> 03:16:51,200 we call a function now like this 5794 03:16:48,080 --> 03:16:51,840 in the blink example we called pin mode 5795 03:16:51,200 --> 03:16:53,920 function 5796 03:16:51,840 --> 03:16:55,680 to call a function we write the name of 5797 03:16:53,920 --> 03:16:58,800 the function along with the 5798 03:16:55,680 --> 03:17:00,960 parameters of that function in pin mode 5799 03:16:58,800 --> 03:17:02,560 led built in comma output was the 5800 03:17:00,960 --> 03:17:04,800 parameter of this function 5801 03:17:02,560 --> 03:17:06,720 right similarly we have called digital 5802 03:17:04,800 --> 03:17:07,680 right here and the parameters of that 5803 03:17:06,720 --> 03:17:10,239 digital right was 5804 03:17:07,680 --> 03:17:12,000 led built in comma i these are the two 5805 03:17:10,239 --> 03:17:14,080 parameters of digital write 5806 03:17:12,000 --> 03:17:16,160 so in the built-in libraries of arduino 5807 03:17:14,080 --> 03:17:17,439 pin mode and digital write must be 5808 03:17:16,160 --> 03:17:20,000 defined somewhere 5809 03:17:17,439 --> 03:17:21,760 that's why arduino is able to understand 5810 03:17:20,000 --> 03:17:23,600 what this exactly means 5811 03:17:21,760 --> 03:17:25,600 otherwise it won't be able to understand 5812 03:17:23,600 --> 03:17:28,160 right okay so it has made us 5813 03:17:25,600 --> 03:17:29,680 really easy that arduino guys have 5814 03:17:28,160 --> 03:17:32,479 defined this function somewhere 5815 03:17:29,680 --> 03:17:34,080 for us okay and we just have to call it 5816 03:17:32,479 --> 03:17:35,359 now let me tell you the benefits of 5817 03:17:34,080 --> 03:17:37,680 using the functions 5818 03:17:35,359 --> 03:17:39,920 the first biggest benefit of using the 5819 03:17:37,680 --> 03:17:41,120 function is it helps us to reduce the 5820 03:17:39,920 --> 03:17:42,880 code redundancy 5821 03:17:41,120 --> 03:17:44,960 what that means is for example we want 5822 03:17:42,880 --> 03:17:46,560 to do certain tasks so we may 5823 03:17:44,960 --> 03:17:48,319 write the statements again and again 5824 03:17:46,560 --> 03:17:50,160 again and again so that would make the 5825 03:17:48,319 --> 03:17:51,840 code unnecessarily bigger 5826 03:17:50,160 --> 03:17:53,920 so what we can do is we can make a 5827 03:17:51,840 --> 03:17:54,960 function and we just call that function 5828 03:17:53,920 --> 03:17:56,880 whenever we want to 5829 03:17:54,960 --> 03:17:58,399 do that task you will understand this 5830 03:17:56,880 --> 03:17:59,200 point better when we write our own 5831 03:17:58,399 --> 03:18:02,000 functions 5832 03:17:59,200 --> 03:18:03,120 then the functions make the code modular 5833 03:18:02,000 --> 03:18:04,960 and reusable 5834 03:18:03,120 --> 03:18:06,880 what that means is for example we are 5835 03:18:04,960 --> 03:18:08,399 making a robot there must be thousands 5836 03:18:06,880 --> 03:18:10,479 of lines to make the robot 5837 03:18:08,399 --> 03:18:12,239 go forward so what we can do is we can 5838 03:18:10,479 --> 03:18:13,760 make a function to make the robot go 5839 03:18:12,239 --> 03:18:14,479 forward and we can use that function 5840 03:18:13,760 --> 03:18:17,040 whenever 5841 03:18:14,479 --> 03:18:18,880 we want to make robot go forward and you 5842 03:18:17,040 --> 03:18:20,560 have written the code to make the robot 5843 03:18:18,880 --> 03:18:21,600 go forward so now you are trying to make 5844 03:18:20,560 --> 03:18:23,680 another robot 5845 03:18:21,600 --> 03:18:24,800 so you can use that same code for the 5846 03:18:23,680 --> 03:18:26,880 another robot as well 5847 03:18:24,800 --> 03:18:28,319 so that means it became modular and it 5848 03:18:26,880 --> 03:18:29,840 became reusable 5849 03:18:28,319 --> 03:18:32,000 then the other advantage of using 5850 03:18:29,840 --> 03:18:34,239 functions is edit provides abstraction 5851 03:18:32,000 --> 03:18:36,080 and aids teamwork for example you're 5852 03:18:34,239 --> 03:18:37,680 working in a team of four so one person 5853 03:18:36,080 --> 03:18:39,439 can write the code for robot to go 5854 03:18:37,680 --> 03:18:40,239 forward one person can write the code to 5855 03:18:39,439 --> 03:18:42,640 go backward 5856 03:18:40,239 --> 03:18:44,000 one person can write the code to move 5857 03:18:42,640 --> 03:18:46,319 right and left and one can 5858 03:18:44,000 --> 03:18:48,399 write the code to make the robot jump 5859 03:18:46,319 --> 03:18:51,520 okay so once these functions are written 5860 03:18:48,399 --> 03:18:53,840 so they can together be used as one code 5861 03:18:51,520 --> 03:18:55,279 all right so these are the advantages of 5862 03:18:53,840 --> 03:18:57,359 using a function 5863 03:18:55,279 --> 03:18:58,960 now in the next video we will learn how 5864 03:18:57,359 --> 03:19:00,640 to write our own functions 5865 03:18:58,960 --> 03:19:02,399 so you will understand these points in a 5866 03:19:00,640 --> 03:19:03,359 better manner so i'll see you in the 5867 03:19:02,399 --> 03:19:05,200 next video 5868 03:19:03,359 --> 03:19:07,120 so let us now create our very own 5869 03:19:05,200 --> 03:19:07,840 function we will create a customized 5870 03:19:07,120 --> 03:19:13,279 function 5871 03:19:07,840 --> 03:19:17,680 to blink the led okay so let's do this 5872 03:19:13,279 --> 03:19:22,239 after void loop we will write void 5873 03:19:17,680 --> 03:19:25,680 let's say the name of our function is my 5874 03:19:22,239 --> 03:19:27,680 blink function okay since there are no 5875 03:19:25,680 --> 03:19:32,239 parameters in this we will leave the 5876 03:19:27,680 --> 03:19:36,000 bracket empty now 5877 03:19:32,239 --> 03:19:36,000 so let us just cut this code from here 5878 03:19:36,720 --> 03:19:41,600 and paste this exactly like this in my 5879 03:19:39,680 --> 03:19:45,200 blink function 5880 03:19:41,600 --> 03:19:48,319 okay so now we have created 5881 03:19:45,200 --> 03:19:49,600 a customized blink function now let's 5882 03:19:48,319 --> 03:19:53,840 try to 5883 03:19:49,600 --> 03:19:53,840 call this function in void loop 5884 03:19:54,560 --> 03:19:56,800 right 5885 03:19:58,239 --> 03:20:01,359 this way we have called our function in 5886 03:20:00,239 --> 03:20:03,520 the void loop 5887 03:20:01,359 --> 03:20:04,560 all right so when we upload this code on 5888 03:20:03,520 --> 03:20:06,720 arduino you will see 5889 03:20:04,560 --> 03:20:07,600 exactly the same results all right so 5890 03:20:06,720 --> 03:20:09,840 let us see this 5891 03:20:07,600 --> 03:20:12,800 so let us compare both the codes with 5892 03:20:09,840 --> 03:20:15,359 the help of a simulator 5893 03:20:12,800 --> 03:20:17,439 all right so we had this code right this 5894 03:20:15,359 --> 03:20:20,560 is the same blink code 5895 03:20:17,439 --> 03:20:23,120 let's see how it is working right as 5896 03:20:20,560 --> 03:20:23,120 expected 5897 03:20:25,680 --> 03:20:29,439 the led at pin number 13 is blinking 5898 03:20:28,640 --> 03:20:31,040 right so now 5899 03:20:29,439 --> 03:20:33,600 let us replace the code which we have 5900 03:20:31,040 --> 03:20:33,600 just written 5901 03:20:34,880 --> 03:20:43,840 we will just take it as it is 5902 03:20:47,760 --> 03:20:50,000 right 5903 03:20:52,239 --> 03:20:57,840 so now let's start the simulation 5904 03:21:03,840 --> 03:21:08,720 so i hope you got my point about 5905 03:21:06,000 --> 03:21:10,399 creating our own functions 5906 03:21:08,720 --> 03:21:12,080 but now most of you must be wondering 5907 03:21:10,399 --> 03:21:14,640 what's the point of making this 5908 03:21:12,080 --> 03:21:16,479 right yeah i agree with you there is no 5909 03:21:14,640 --> 03:21:19,840 point of making a function for this 5910 03:21:16,479 --> 03:21:21,200 small task right but you will find it 5911 03:21:19,840 --> 03:21:23,840 useful 5912 03:21:21,200 --> 03:21:26,000 when you're writing really huge programs 5913 03:21:23,840 --> 03:21:27,840 or you want to customize this thing 5914 03:21:26,000 --> 03:21:30,960 i will show you a customization right 5915 03:21:27,840 --> 03:21:30,960 now all right 5916 03:21:31,040 --> 03:21:36,399 so now let's say you have more than one 5917 03:21:34,080 --> 03:21:38,399 leds which you want to blink in a row 5918 03:21:36,399 --> 03:21:39,920 okay so with your existing knowledge 5919 03:21:38,399 --> 03:21:43,439 what would you have done 5920 03:21:39,920 --> 03:21:43,439 you would have done it like this 5921 03:21:45,279 --> 03:21:50,640 so you would have repeated these lines 5922 03:21:48,160 --> 03:21:50,640 of codes 5923 03:21:51,600 --> 03:21:58,399 and just replaced the pin numbers here 5924 03:21:55,200 --> 03:22:01,040 right and then you would have declared 5925 03:21:58,399 --> 03:22:02,399 these pins as output right but now what 5926 03:22:01,040 --> 03:22:04,479 we can do is 5927 03:22:02,399 --> 03:22:07,840 we can make a customized function let us 5928 03:22:04,479 --> 03:22:07,840 do that 5929 03:22:08,960 --> 03:22:11,520 we are here 5930 03:22:17,200 --> 03:22:23,600 so let us now make a new function void 5931 03:22:21,279 --> 03:22:23,600 my 5932 03:22:25,439 --> 03:22:32,160 custom led right 5933 03:22:28,960 --> 03:22:34,720 now what we will do is we'll specify 5934 03:22:32,160 --> 03:22:35,840 a parameters in which we can tell the 5935 03:22:34,720 --> 03:22:39,760 compiler 5936 03:22:35,840 --> 03:22:43,120 led pin number so for that we will write 5937 03:22:39,760 --> 03:22:47,040 int pin number 5938 03:22:43,120 --> 03:22:50,880 okay so this function is going to accept 5939 03:22:47,040 --> 03:22:54,640 one parameter which is pin number right 5940 03:22:50,880 --> 03:22:58,560 so now let's do this 5941 03:22:54,640 --> 03:23:01,680 we have this code okay 5942 03:22:58,560 --> 03:23:02,560 so now instead of led built in we will 5943 03:23:01,680 --> 03:23:05,760 write 5944 03:23:02,560 --> 03:23:07,680 pin here okay so automatically whenever 5945 03:23:05,760 --> 03:23:09,920 we call this function 5946 03:23:07,680 --> 03:23:10,720 with the pin specified the compiler will 5947 03:23:09,920 --> 03:23:12,800 replace 5948 03:23:10,720 --> 03:23:13,920 this pin number with the specified pin 5949 03:23:12,800 --> 03:23:17,840 number okay 5950 03:23:13,920 --> 03:23:17,840 so let's do this 5951 03:23:19,439 --> 03:23:23,840 let us just confirm what pins we have 5952 03:23:21,520 --> 03:23:23,840 used 5953 03:23:24,319 --> 03:23:32,239 we have used nine seven and two 5954 03:23:28,319 --> 03:23:32,239 okay nine seven and two 5955 03:23:33,760 --> 03:23:38,880 so let us say int led one is equal to 5956 03:23:37,359 --> 03:23:42,560 nine 5957 03:23:38,880 --> 03:23:46,160 hint led two is equal to 5958 03:23:42,560 --> 03:23:50,000 seven and int led three 5959 03:23:46,160 --> 03:23:53,200 is equal to two right 5960 03:23:50,000 --> 03:23:54,399 so now we just have to declare all these 5961 03:23:53,200 --> 03:23:59,359 pins as output 5962 03:23:54,399 --> 03:24:01,520 led one okay 5963 03:23:59,359 --> 03:24:01,520 see 5964 03:24:04,720 --> 03:24:11,359 all right now we'll just replace them 5965 03:24:08,640 --> 03:24:12,239 like this since we have declared them as 5966 03:24:11,359 --> 03:24:14,880 output 5967 03:24:12,239 --> 03:24:17,439 now what will be do is we'll just take 5968 03:24:14,880 --> 03:24:17,439 this function 5969 03:24:18,479 --> 03:24:22,720 okay we'll write my custom led with pin 5970 03:24:21,600 --> 03:24:26,720 number 5971 03:24:22,720 --> 03:24:29,920 led one okay 5972 03:24:26,720 --> 03:24:33,840 then again we'll call this function with 5973 03:24:29,920 --> 03:24:35,600 led 2 right and again we'll call this 5974 03:24:33,840 --> 03:24:39,680 function 5975 03:24:35,600 --> 03:24:44,319 and we'll just pass led 3 this time 5976 03:24:39,680 --> 03:24:44,319 okay let's see if this compiles or not 5977 03:24:46,640 --> 03:24:55,200 yes it compiles successfully now let us 5978 03:24:48,560 --> 03:24:59,279 see the simulation of this code 5979 03:24:55,200 --> 03:24:59,279 right so we have this code here 5980 03:24:59,840 --> 03:25:05,520 let us start the simulation okay can you 5981 03:25:03,040 --> 03:25:05,520 see that 5982 03:25:06,840 --> 03:25:12,000 yep it's working perfectly 5983 03:25:10,319 --> 03:25:13,520 first the led one which is connected to 5984 03:25:12,000 --> 03:25:15,200 pin number nine is blinking 5985 03:25:13,520 --> 03:25:16,640 and then the led connected to pin number 5986 03:25:15,200 --> 03:25:18,399 seven is blinking then 5987 03:25:16,640 --> 03:25:21,279 the led connected to pin number two is 5988 03:25:18,399 --> 03:25:23,760 blinking so now let us see 5989 03:25:21,279 --> 03:25:25,279 one more time what exactly happened here 5990 03:25:23,760 --> 03:25:26,640 okay so with the pin mode we have 5991 03:25:25,279 --> 03:25:28,800 declared all the leds 5992 03:25:26,640 --> 03:25:30,319 led one two and three and i'm sure you 5993 03:25:28,800 --> 03:25:31,600 know how to do this we have done this 5994 03:25:30,319 --> 03:25:34,399 many times till now 5995 03:25:31,600 --> 03:25:35,680 okay so now we have created a function 5996 03:25:34,399 --> 03:25:39,279 void 5997 03:25:35,680 --> 03:25:42,399 my custom led with a parameter of pin 5998 03:25:39,279 --> 03:25:43,520 if you wanted more parameters here we'll 5999 03:25:42,399 --> 03:25:47,760 just write comma 6000 03:25:43,520 --> 03:25:47,760 and then end let's say 6001 03:25:48,399 --> 03:25:53,840 parameter 2 right 6002 03:25:51,760 --> 03:25:56,080 so this way we can specify endless 6003 03:25:53,840 --> 03:25:58,000 number of parameters in our functions 6004 03:25:56,080 --> 03:25:59,920 but since we don't need them we'll not 6005 03:25:58,000 --> 03:26:03,120 use them 6006 03:25:59,920 --> 03:26:05,680 okay then we have started to define 6007 03:26:03,120 --> 03:26:07,040 what this function will do which is it 6008 03:26:05,680 --> 03:26:09,760 will blink the led 6009 03:26:07,040 --> 03:26:12,000 okay which led will it blink the led 6010 03:26:09,760 --> 03:26:14,239 which we have passed as the parameter 6011 03:26:12,000 --> 03:26:15,680 okay because we have used pin here for 6012 03:26:14,239 --> 03:26:19,120 example if you had 6013 03:26:15,680 --> 03:26:21,200 declared number here instead of pin 6014 03:26:19,120 --> 03:26:22,239 then you would have used number here 6015 03:26:21,200 --> 03:26:24,239 instead of pin 6016 03:26:22,239 --> 03:26:25,760 got my point so now since we have 6017 03:26:24,239 --> 03:26:27,840 finished declaring our function 6018 03:26:25,760 --> 03:26:30,720 now we can use it successfully we'll 6019 03:26:27,840 --> 03:26:30,720 just take this function 6020 03:26:30,880 --> 03:26:34,720 and we will call it here with the 6021 03:26:32,479 --> 03:26:35,520 parameter so now we have called it for 6022 03:26:34,720 --> 03:26:38,239 the first time 6023 03:26:35,520 --> 03:26:39,200 with led1 now what will happen the 6024 03:26:38,239 --> 03:26:42,319 compiler will see 6025 03:26:39,200 --> 03:26:43,600 okay a function has been used which is 6026 03:26:42,319 --> 03:26:45,600 my custom led 6027 03:26:43,600 --> 03:26:46,960 with the parameter led1 so it will see 6028 03:26:45,600 --> 03:26:49,439 the value of led 1 6029 03:26:46,960 --> 03:26:51,600 which is declared as 9 okay so it will 6030 03:26:49,439 --> 03:26:54,160 call my custom led with 9 6031 03:26:51,600 --> 03:26:55,279 so the control will go to my custom led 6032 03:26:54,160 --> 03:26:58,080 with pin 9 6033 03:26:55,279 --> 03:27:00,239 and it will execute it with pin 9. once 6034 03:26:58,080 --> 03:27:02,640 it is done executing it will come back 6035 03:27:00,239 --> 03:27:03,600 it will see it has been called again 6036 03:27:02,640 --> 03:27:06,239 with another 6037 03:27:03,600 --> 03:27:07,520 parameter which is led 2 and the value 6038 03:27:06,239 --> 03:27:09,920 of led 2 is 6039 03:27:07,520 --> 03:27:11,520 7 this time so it will go back and 6040 03:27:09,920 --> 03:27:14,560 execute the function again 6041 03:27:11,520 --> 03:27:15,840 with the value of 7 all right so this is 6042 03:27:14,560 --> 03:27:18,399 the basic concept of 6043 03:27:15,840 --> 03:27:20,000 function customization okay so instead 6044 03:27:18,399 --> 03:27:20,800 of writing this code again and again 6045 03:27:20,000 --> 03:27:23,120 with changed 6046 03:27:20,800 --> 03:27:24,800 pin numbers we can just do this so i 6047 03:27:23,120 --> 03:27:26,000 think all of you can agree with what i'm 6048 03:27:24,800 --> 03:27:28,399 saying right now 6049 03:27:26,000 --> 03:27:29,279 right one more thing which needs 6050 03:27:28,399 --> 03:27:32,080 emphasis is 6051 03:27:29,279 --> 03:27:34,080 i've used void here like i told you we 6052 03:27:32,080 --> 03:27:36,960 use void whenever our function 6053 03:27:34,080 --> 03:27:38,800 is not returning us anything okay so by 6054 03:27:36,960 --> 03:27:41,600 the time you must have realized 6055 03:27:38,800 --> 03:27:42,960 void loop and void setup are two 6056 03:27:41,600 --> 03:27:44,560 functions of their own 6057 03:27:42,960 --> 03:27:46,560 they are the main functions which are 6058 03:27:44,560 --> 03:27:47,760 used by the compiler we have discussed 6059 03:27:46,560 --> 03:27:50,000 about this 6060 03:27:47,760 --> 03:27:51,439 earlier as well so now let us try to 6061 03:27:50,000 --> 03:27:54,479 make another kind of function 6062 03:27:51,439 --> 03:27:54,479 we'll open a new file 6063 03:27:55,040 --> 03:28:00,080 and we will start writing our function 6064 03:27:57,840 --> 03:28:03,200 first of all let's write serial.begin 6065 03:28:00,080 --> 03:28:04,880 this is the most crucial thing to start 6066 03:28:03,200 --> 03:28:07,120 communication with the computer 6067 03:28:04,880 --> 03:28:09,279 okay so now let us try to write a 6068 03:28:07,120 --> 03:28:11,840 function which would return us something 6069 03:28:09,279 --> 03:28:12,800 okay so let's say it will return us an 6070 03:28:11,840 --> 03:28:15,279 integer 6071 03:28:12,800 --> 03:28:16,319 so we'll write in earlier we wrote void 6072 03:28:15,279 --> 03:28:18,800 because we didn't want 6073 03:28:16,319 --> 03:28:20,399 it to return something to us if you're 6074 03:28:18,800 --> 03:28:21,920 not able to understand what returning 6075 03:28:20,399 --> 03:28:23,520 exactly means you will just see that in 6076 03:28:21,920 --> 03:28:26,479 a moment 6077 03:28:23,520 --> 03:28:27,840 so we'll write in let's say we want to 6078 03:28:26,479 --> 03:28:31,120 repeatedly calculate 6079 03:28:27,840 --> 03:28:32,720 sums of two numbers okay or let's say 6080 03:28:31,120 --> 03:28:36,960 sum of three numbers 6081 03:28:32,720 --> 03:28:36,960 so we'll write in sum 6082 03:28:37,040 --> 03:28:43,600 okay int a comma int 6083 03:28:40,560 --> 03:28:46,000 b comma int c 6084 03:28:43,600 --> 03:28:47,520 okay where a b and c are the three 6085 03:28:46,000 --> 03:28:50,160 numbers which we want to 6086 03:28:47,520 --> 03:28:51,680 take some off all right so now we will 6087 03:28:50,160 --> 03:28:54,800 write a curly bracket 6088 03:28:51,680 --> 03:28:58,399 and then we will write return a 6089 03:28:54,800 --> 03:29:00,239 plus b plus c okay 6090 03:28:58,399 --> 03:29:01,439 so whenever we call this function we'll 6091 03:29:00,239 --> 03:29:04,479 get a value of a 6092 03:29:01,439 --> 03:29:06,319 plus b plus c let's see how we get it in 6093 03:29:04,479 --> 03:29:07,200 white loop or void setup you can use 6094 03:29:06,319 --> 03:29:09,760 this function 6095 03:29:07,200 --> 03:29:10,560 anywhere you want let's say we'll use 6096 03:29:09,760 --> 03:29:14,080 this in 6097 03:29:10,560 --> 03:29:18,160 white loop okay let's say 6098 03:29:14,080 --> 03:29:22,239 we write int let's call it d 6099 03:29:18,160 --> 03:29:25,680 okay equals to sum 6100 03:29:22,239 --> 03:29:29,600 of 7 comma 8 6101 03:29:25,680 --> 03:29:29,600 comma 9 all right 6102 03:29:29,680 --> 03:29:39,200 and let's print 6103 03:29:34,479 --> 03:29:39,200 the value of d okay 6104 03:29:46,080 --> 03:29:51,120 so what should it print the sum of 7 8 6105 03:29:48,720 --> 03:29:51,120 and 9 6106 03:29:51,279 --> 03:29:55,279 which is 24 right we can use it again as 6107 03:29:54,880 --> 03:29:57,520 well 6108 03:29:55,279 --> 03:29:59,520 with the different set of values let's 6109 03:29:57,520 --> 03:30:02,000 say 6110 03:29:59,520 --> 03:30:03,359 we'll make another function int e is 6111 03:30:02,000 --> 03:30:06,720 equal to 6112 03:30:03,359 --> 03:30:10,239 sum 1 6113 03:30:06,720 --> 03:30:10,239 comma 2 comma 3 6114 03:30:10,800 --> 03:30:17,840 let's print this 6115 03:30:22,800 --> 03:30:26,880 we should get six right 6116 03:30:27,279 --> 03:30:32,239 so we're getting six 24 and 6. 6117 03:30:30,640 --> 03:30:33,840 it's repeating as we have used it in 6118 03:30:32,239 --> 03:30:35,120 while loop so you don't have to worry 6119 03:30:33,840 --> 03:30:36,720 about that 6120 03:30:35,120 --> 03:30:38,560 okay one thing which i want to tell you 6121 03:30:36,720 --> 03:30:39,680 is you can use this function like this 6122 03:30:38,560 --> 03:30:43,279 as well 6123 03:30:39,680 --> 03:30:46,960 serial dot println 6124 03:30:43,279 --> 03:30:51,920 directly in serial print sum 6125 03:30:46,960 --> 03:30:51,920 4 comma 5 comma 6 right 6126 03:30:52,479 --> 03:30:56,720 just make sure to close all the brackets 6127 03:30:55,279 --> 03:30:57,359 here we have closed the bracket of the 6128 03:30:56,720 --> 03:30:59,560 function 6129 03:30:57,359 --> 03:31:00,800 sum here we have closed the bracket of 6130 03:30:59,560 --> 03:31:03,359 serial.println 6131 03:31:00,800 --> 03:31:04,960 okay so this is called as calling 6132 03:31:03,359 --> 03:31:06,880 function inside a function 6133 03:31:04,960 --> 03:31:08,160 this is a very useful thing which we can 6134 03:31:06,880 --> 03:31:10,080 do in programming 6135 03:31:08,160 --> 03:31:13,840 but first of all let us see the result 6136 03:31:10,080 --> 03:31:13,840 if it is working or not 6137 03:31:16,720 --> 03:31:21,200 right so we are getting 15 here because 6138 03:31:19,920 --> 03:31:24,960 this function call here 6139 03:31:21,200 --> 03:31:27,359 is printing its value okay 6140 03:31:24,960 --> 03:31:29,040 now we can have more than one functions 6141 03:31:27,359 --> 03:31:30,720 in our code now let us declare another 6142 03:31:29,040 --> 03:31:34,640 function which would return 6143 03:31:30,720 --> 03:31:37,920 a boolean value let's say bool 6144 03:31:34,640 --> 03:31:40,800 um now we are making a function to check 6145 03:31:37,920 --> 03:31:41,439 if a person is tall or not based on the 6146 03:31:40,800 --> 03:31:43,840 height we 6147 03:31:41,439 --> 03:31:44,640 enter as the parameter all right so 6148 03:31:43,840 --> 03:31:48,000 let's name it 6149 03:31:44,640 --> 03:31:51,120 is tall okay 6150 03:31:48,000 --> 03:31:54,880 and int height 6151 03:31:51,120 --> 03:31:58,160 okay so this function's name is 6152 03:31:54,880 --> 03:32:02,080 install and the parameter is height 6153 03:31:58,160 --> 03:32:05,120 okay so we'll write if 6154 03:32:02,080 --> 03:32:09,120 height is greater than 6155 03:32:05,120 --> 03:32:11,359 100 return true 6156 03:32:09,120 --> 03:32:11,359 okay 6157 03:32:12,239 --> 03:32:17,920 or else return 6158 03:32:15,600 --> 03:32:18,800 false okay so this function will just 6159 03:32:17,920 --> 03:32:20,319 return true 6160 03:32:18,800 --> 03:32:23,359 if the entered height is greater than 6161 03:32:20,319 --> 03:32:23,840 100 and if it is less than 100 it will 6162 03:32:23,359 --> 03:32:27,040 say 6163 03:32:23,840 --> 03:32:27,840 false okay so now you will see how handy 6164 03:32:27,040 --> 03:32:29,279 it becomes 6165 03:32:27,840 --> 03:32:31,520 when you have to check height of 6166 03:32:29,279 --> 03:32:37,840 multiple people okay 6167 03:32:31,520 --> 03:32:37,840 so now let's call this in white loop 6168 03:32:39,279 --> 03:32:48,000 here we have while loop so let's say 6169 03:32:42,800 --> 03:32:48,000 serial dot print ln 6170 03:32:48,080 --> 03:32:56,080 is tall let's say 6171 03:32:51,640 --> 03:32:56,080 123 okay 6172 03:32:56,560 --> 03:33:02,000 now let's just comment out the print 6173 03:32:59,439 --> 03:33:05,120 statements so that they don't interfere 6174 03:33:02,000 --> 03:33:08,160 okay this function is still being used 6175 03:33:05,120 --> 03:33:10,000 in int d and e so you can say these 6176 03:33:08,160 --> 03:33:12,399 functions are working simultaneously 6177 03:33:10,000 --> 03:33:14,000 so we are just checking is tall or not 6178 03:33:12,399 --> 03:33:17,520 okay 6179 03:33:14,000 --> 03:33:18,000 let's see before i open the serial 6180 03:33:17,520 --> 03:33:21,040 pointer 6181 03:33:18,000 --> 03:33:21,040 you can guess your values 6182 03:33:21,279 --> 03:33:26,239 right it's printing one because it has 6183 03:33:23,279 --> 03:33:26,239 returned true 6184 03:33:26,479 --> 03:33:29,840 so now let us take another value which 6185 03:33:28,960 --> 03:33:34,880 is less than 6186 03:33:29,840 --> 03:33:38,319 100 serial dot println 6187 03:33:34,880 --> 03:33:38,319 is tall 6188 03:33:38,399 --> 03:33:43,840 20. so now we should get 6189 03:33:44,840 --> 03:33:47,840 false 6190 03:33:48,080 --> 03:33:51,279 so it would be printing 1 0 1 0 because 6191 03:33:50,560 --> 03:33:54,479 1 is for 6192 03:33:51,279 --> 03:33:57,680 install 123 and 0 is for 6193 03:33:54,479 --> 03:34:02,479 install 20. so let us see that 6194 03:33:57,680 --> 03:34:04,160 right 1 0 1 0 one zero one zero one zero 6195 03:34:02,479 --> 03:34:05,520 okay so if you have to check height of 6196 03:34:04,160 --> 03:34:06,960 multiple people 6197 03:34:05,520 --> 03:34:08,560 instead of writing this code again and 6198 03:34:06,960 --> 03:34:10,720 again for that specific height 6199 03:34:08,560 --> 03:34:12,319 you can just call this function and 6200 03:34:10,720 --> 03:34:14,319 enter the height so you can see how much 6201 03:34:12,319 --> 03:34:16,399 work you have reduced for yourself 6202 03:34:14,319 --> 03:34:17,359 right by writing the functions so this 6203 03:34:16,399 --> 03:34:19,279 was all about 6204 03:34:17,359 --> 03:34:21,120 writing a custom function there is no 6205 03:34:19,279 --> 03:34:23,040 upper level to the complexity of the 6206 03:34:21,120 --> 03:34:24,880 code which you write in your functions 6207 03:34:23,040 --> 03:34:26,239 you can write endless number of lines in 6208 03:34:24,880 --> 03:34:28,080 this function 6209 03:34:26,239 --> 03:34:30,000 okay like i told you in the introductory 6210 03:34:28,080 --> 03:34:31,760 video there may be a thousands of lines 6211 03:34:30,000 --> 03:34:34,960 which are responsible for making 6212 03:34:31,760 --> 03:34:37,200 robot go forward so in that case we can 6213 03:34:34,960 --> 03:34:41,359 write 6214 03:34:37,200 --> 03:34:45,200 void move 6215 03:34:41,359 --> 03:34:46,399 robot forward and we can just define our 6216 03:34:45,200 --> 03:34:50,160 parameters here 6217 03:34:46,399 --> 03:34:53,840 and we can just write our statements 6218 03:34:50,160 --> 03:34:53,840 like this right 6219 03:34:54,720 --> 03:34:59,680 and this is our function this block of 6220 03:34:57,600 --> 03:35:01,680 code won't make your robot go forward 6221 03:34:59,680 --> 03:35:02,720 i'm just giving you an example of how do 6222 03:35:01,680 --> 03:35:05,120 we write functions 6223 03:35:02,720 --> 03:35:05,840 okay so whenever we call move robot 6224 03:35:05,120 --> 03:35:07,840 forward 6225 03:35:05,840 --> 03:35:10,080 in void setup or in void loop so the 6226 03:35:07,840 --> 03:35:12,800 compiler will take this function 6227 03:35:10,080 --> 03:35:14,319 and it will execute that alright so in 6228 03:35:12,800 --> 03:35:15,040 the next video we will take a deeper 6229 03:35:14,319 --> 03:35:16,880 look at 6230 03:35:15,040 --> 03:35:18,800 some of the inbuilt functions which the 6231 03:35:16,880 --> 03:35:20,880 arduino makers have made for us 6232 03:35:18,800 --> 03:35:22,160 so see you in the next video now in this 6233 03:35:20,880 --> 03:35:24,479 video we will talk about 6234 03:35:22,160 --> 03:35:26,319 digital input and output what that means 6235 03:35:24,479 --> 03:35:27,680 is we'll take a closer look at 6236 03:35:26,319 --> 03:35:29,840 the functions which are made by the 6237 03:35:27,680 --> 03:35:32,560 arduino makers to read or write 6238 03:35:29,840 --> 03:35:34,720 any sort of digital data all right that 6239 03:35:32,560 --> 03:35:37,120 data can be some sort of input given by 6240 03:35:34,720 --> 03:35:39,520 external sensors and it can be some sort 6241 03:35:37,120 --> 03:35:42,080 of output data which is given by arduino 6242 03:35:39,520 --> 03:35:43,760 to other peripherals or components right 6243 03:35:42,080 --> 03:35:45,200 so there are basically two functions 6244 03:35:43,760 --> 03:35:47,120 which are digital read 6245 03:35:45,200 --> 03:35:48,720 and digital right so let's take a look 6246 03:35:47,120 --> 03:35:50,239 at digital right 6247 03:35:48,720 --> 03:35:51,760 digital right is a function which we 6248 03:35:50,239 --> 03:35:53,680 have seen multiple times 6249 03:35:51,760 --> 03:35:55,439 before as well so can you recall what it 6250 03:35:53,680 --> 03:35:58,080 used to do it used to 6251 03:35:55,439 --> 03:35:58,960 write a state of low or high to a 6252 03:35:58,080 --> 03:36:01,279 digital pin 6253 03:35:58,960 --> 03:36:03,439 so we'll see digitalwrite is a function 6254 03:36:01,279 --> 03:36:04,000 where digitalwrite is the name of that 6255 03:36:03,439 --> 03:36:06,239 function 6256 03:36:04,000 --> 03:36:07,200 all right and it has two parameters 6257 03:36:06,239 --> 03:36:09,439 which are pin 6258 03:36:07,200 --> 03:36:10,880 and state where pin is the pin number 6259 03:36:09,439 --> 03:36:13,040 which we want to manipulate 6260 03:36:10,880 --> 03:36:14,239 and the state is the value of either 6261 03:36:13,040 --> 03:36:16,000 high or low 6262 03:36:14,239 --> 03:36:17,760 where high means five volts and low 6263 03:36:16,000 --> 03:36:19,920 means zero volts okay 6264 03:36:17,760 --> 03:36:21,279 just make sure whenever we use digital 6265 03:36:19,920 --> 03:36:23,760 write we have to declare 6266 03:36:21,279 --> 03:36:25,359 that pin as output using pin mode all 6267 03:36:23,760 --> 03:36:25,840 right and i have told you this earlier 6268 03:36:25,359 --> 03:36:29,279 as well 6269 03:36:25,840 --> 03:36:31,920 right next we will see digital read 6270 03:36:29,279 --> 03:36:33,120 as the name suggests it will read the 6271 03:36:31,920 --> 03:36:35,200 state of that pin 6272 03:36:33,120 --> 03:36:36,640 okay so here digital read is the name of 6273 03:36:35,200 --> 03:36:38,800 the function which we are calling 6274 03:36:36,640 --> 03:36:40,960 and pin number is the parameter which we 6275 03:36:38,800 --> 03:36:42,000 pass into it to read the state of that 6276 03:36:40,960 --> 03:36:44,479 particular pin 6277 03:36:42,000 --> 03:36:46,640 okay if it is high or low so we will now 6278 03:36:44,479 --> 03:36:48,399 see a combined example of using digital 6279 03:36:46,640 --> 03:36:50,560 read and digital write and how will we 6280 03:36:48,399 --> 03:36:53,359 do that we will turn on one led 6281 03:36:50,560 --> 03:36:54,640 if a switch is pressed okay so let's see 6282 03:36:53,359 --> 03:36:56,399 how we do that 6283 03:36:54,640 --> 03:36:58,479 so i have the circuit diagram here in 6284 03:36:56,399 --> 03:37:00,160 which i have used a regular led 6285 03:36:58,479 --> 03:37:02,000 with a resistance in series which you 6286 03:37:00,160 --> 03:37:03,920 can see and here i have used 6287 03:37:02,000 --> 03:37:05,439 a push button switch so before we move 6288 03:37:03,920 --> 03:37:07,359 further let us first look at 6289 03:37:05,439 --> 03:37:09,120 what a push button switch looks like 6290 03:37:07,359 --> 03:37:10,720 from inside then only you will be able 6291 03:37:09,120 --> 03:37:12,720 to understand it in a better manner 6292 03:37:10,720 --> 03:37:14,720 so here is a push button switch all 6293 03:37:12,720 --> 03:37:16,399 right which has four terminals out of 6294 03:37:14,720 --> 03:37:18,080 which these two terminals are internally 6295 03:37:16,399 --> 03:37:19,520 connected and these two terminals are 6296 03:37:18,080 --> 03:37:22,319 internally connected as well 6297 03:37:19,520 --> 03:37:23,359 okay so when we press the switch these 6298 03:37:22,319 --> 03:37:25,040 two terminals 6299 03:37:23,359 --> 03:37:26,640 get interconnected and these two 6300 03:37:25,040 --> 03:37:28,000 terminals get interconnected when it is 6301 03:37:26,640 --> 03:37:29,920 not pressed these two are 6302 03:37:28,000 --> 03:37:31,200 not interconnected okay so let's get 6303 03:37:29,920 --> 03:37:33,279 back to our example 6304 03:37:31,200 --> 03:37:35,120 okay so the code is we have started with 6305 03:37:33,279 --> 03:37:36,720 int button is equal to seven 6306 03:37:35,120 --> 03:37:38,560 as we want to read the state of that 6307 03:37:36,720 --> 03:37:40,560 button on a digital pin number 6308 03:37:38,560 --> 03:37:42,399 seven all right in white setup i have 6309 03:37:40,560 --> 03:37:44,160 declared pin mode led built in which is 6310 03:37:42,399 --> 03:37:46,319 the led connected to pin number 13 6311 03:37:44,160 --> 03:37:47,520 as output and using pin mode we have 6312 03:37:46,319 --> 03:37:49,760 declared the button as 6313 03:37:47,520 --> 03:37:51,920 input because button will be telling its 6314 03:37:49,760 --> 03:37:52,479 state to the arduino hence it is used as 6315 03:37:51,920 --> 03:37:55,279 input 6316 03:37:52,479 --> 03:37:56,439 okay serial dot begin 9600 as usual then 6317 03:37:55,279 --> 03:37:57,760 in void loop i have written 6318 03:37:56,439 --> 03:38:00,880 serial.println 6319 03:37:57,760 --> 03:38:02,720 digital read and bracket button so here 6320 03:38:00,880 --> 03:38:03,279 i am asking it to print the state of the 6321 03:38:02,720 --> 03:38:05,040 button 6322 03:38:03,279 --> 03:38:06,800 either it is pressed or not in the 6323 03:38:05,040 --> 03:38:08,800 circuit which we have used we will get 6324 03:38:06,800 --> 03:38:11,200 one on pressing the switch and we will 6325 03:38:08,800 --> 03:38:13,200 get zero when we do not press the switch 6326 03:38:11,200 --> 03:38:15,040 all right so let us see that works when 6327 03:38:13,200 --> 03:38:17,120 i'm pressing the switch 6328 03:38:15,040 --> 03:38:18,960 i'm getting one here when i'm releasing 6329 03:38:17,120 --> 03:38:20,720 the switch i'm getting zero here 6330 03:38:18,960 --> 03:38:22,479 look at the serial monitor here right 6331 03:38:20,720 --> 03:38:23,040 now i'm not pressing it so it's saying 6332 03:38:22,479 --> 03:38:25,040 zero 6333 03:38:23,040 --> 03:38:26,560 when i'm pressing it it's saying one 6334 03:38:25,040 --> 03:38:28,319 okay so most of you must have also 6335 03:38:26,560 --> 03:38:29,279 noticed the led which is connected on 6336 03:38:28,319 --> 03:38:31,199 pin number 13. 6337 03:38:29,279 --> 03:38:32,960 when i'm pressing the switch the led is 6338 03:38:31,199 --> 03:38:33,920 getting turned on and when i'm releasing 6339 03:38:32,960 --> 03:38:36,880 the switch 6340 03:38:33,920 --> 03:38:38,399 oops it's not getting turned off why 6341 03:38:36,880 --> 03:38:39,600 we'll see that in the moment probably 6342 03:38:38,399 --> 03:38:41,920 there is some error in the 6343 03:38:39,600 --> 03:38:43,760 code i've done this intentionally so 6344 03:38:41,920 --> 03:38:45,840 that you can pay attention to that 6345 03:38:43,760 --> 03:38:47,680 okay so here i have written if digital 6346 03:38:45,840 --> 03:38:50,000 read button is equal to high 6347 03:38:47,680 --> 03:38:51,199 then digital write led built in to high 6348 03:38:50,000 --> 03:38:53,840 when i press the switch 6349 03:38:51,199 --> 03:38:55,279 write a high state on pin number 13 but 6350 03:38:53,840 --> 03:38:57,040 i have not written what to do 6351 03:38:55,279 --> 03:38:58,960 if the button is not pressed so let us 6352 03:38:57,040 --> 03:39:03,120 do that now we will write 6353 03:38:58,960 --> 03:39:06,399 else digital right 6354 03:39:03,120 --> 03:39:10,479 led built in low 6355 03:39:06,399 --> 03:39:12,239 okay so now let us start this again 6356 03:39:10,479 --> 03:39:13,840 there was an error the closing bracket 6357 03:39:12,239 --> 03:39:17,600 to void loop was missing 6358 03:39:13,840 --> 03:39:19,840 so let us start it again all right 6359 03:39:17,600 --> 03:39:21,040 so when i press it the led turns on and 6360 03:39:19,840 --> 03:39:23,439 when i release it 6361 03:39:21,040 --> 03:39:24,160 the led turns off okay so you guys must 6362 03:39:23,439 --> 03:39:25,920 be wondering 6363 03:39:24,160 --> 03:39:27,600 what's the point of doing this we can 6364 03:39:25,920 --> 03:39:29,439 use a simple series connection 6365 03:39:27,600 --> 03:39:31,520 and we can turn on the led why are we 6366 03:39:29,439 --> 03:39:32,160 using arduino in that i absolutely agree 6367 03:39:31,520 --> 03:39:34,080 with you 6368 03:39:32,160 --> 03:39:35,760 you can do that very easily using a 6369 03:39:34,080 --> 03:39:36,640 series connection but what you have 6370 03:39:35,760 --> 03:39:38,239 learned here is 6371 03:39:36,640 --> 03:39:40,640 you have learned how to use the 6372 03:39:38,239 --> 03:39:41,040 functions like digital read and digital 6373 03:39:40,640 --> 03:39:42,560 write 6374 03:39:41,040 --> 03:39:44,319 you will be able to implement this 6375 03:39:42,560 --> 03:39:46,080 learning in further projects 6376 03:39:44,319 --> 03:39:47,840 the experiments which you do all right 6377 03:39:46,080 --> 03:39:49,439 so now let me just quickly explain you 6378 03:39:47,840 --> 03:39:50,880 the circuit which we have made here as 6379 03:39:49,439 --> 03:39:53,359 most of you must be facing 6380 03:39:50,880 --> 03:39:54,000 difficulty in that all right so here is 6381 03:39:53,359 --> 03:39:55,680 the switch 6382 03:39:54,000 --> 03:39:57,439 i showed you the diagram previously 6383 03:39:55,680 --> 03:39:58,399 right so these two terminals are 6384 03:39:57,439 --> 03:40:00,160 interconnected 6385 03:39:58,399 --> 03:40:01,840 automatically when i press the switch 6386 03:40:00,160 --> 03:40:02,640 this terminal will get connected to this 6387 03:40:01,840 --> 03:40:04,800 terminal 6388 03:40:02,640 --> 03:40:06,160 okay so i have taken a wire and 6389 03:40:04,800 --> 03:40:08,960 connected one terminal 6390 03:40:06,160 --> 03:40:09,520 to 5 volts okay and then i have taken a 6391 03:40:08,960 --> 03:40:11,920 resistor 6392 03:40:09,520 --> 03:40:13,600 and i have connected it to ground so 6393 03:40:11,920 --> 03:40:15,279 here we have made a series connection of 6394 03:40:13,600 --> 03:40:17,840 a switch and a resistor 6395 03:40:15,279 --> 03:40:19,199 like this and from this point as all 6396 03:40:17,840 --> 03:40:20,239 these points are interconnected we can 6397 03:40:19,199 --> 03:40:21,840 connect them anywhere 6398 03:40:20,239 --> 03:40:23,920 so at this point we're reading the 6399 03:40:21,840 --> 03:40:27,040 voltage which is present between 6400 03:40:23,920 --> 03:40:28,960 this and this point okay so as we want 6401 03:40:27,040 --> 03:40:30,880 to read the state we have connected it 6402 03:40:28,960 --> 03:40:32,000 to the pin number seven so when we press 6403 03:40:30,880 --> 03:40:34,319 the switch this 6404 03:40:32,000 --> 03:40:36,479 line will get connected to this line and 6405 03:40:34,319 --> 03:40:39,040 entire 5 volts will drop across 6406 03:40:36,479 --> 03:40:40,319 this resistance okay so hence the 6407 03:40:39,040 --> 03:40:41,680 arduino will read it as 6408 03:40:40,319 --> 03:40:44,399 high state and when the switch is 6409 03:40:41,680 --> 03:40:46,479 released this point will be connected to 6410 03:40:44,399 --> 03:40:47,840 ground via resistor so it will be read 6411 03:40:46,479 --> 03:40:50,399 as low 6412 03:40:47,840 --> 03:40:51,040 okay so i hope you understood the basic 6413 03:40:50,399 --> 03:40:54,080 idea 6414 03:40:51,040 --> 03:40:56,000 let me try to clarify it even more 6415 03:40:54,080 --> 03:40:57,760 so this is the equivalent circuit of the 6416 03:40:56,000 --> 03:41:00,080 circuit which you saw earlier 6417 03:40:57,760 --> 03:41:01,199 okay you can consider arduino's 5v pin 6418 03:41:00,080 --> 03:41:03,359 connected to 6419 03:41:01,199 --> 03:41:05,040 this switch this is a push button switch 6420 03:41:03,359 --> 03:41:05,600 right similarly these terminals are 6421 03:41:05,040 --> 03:41:07,680 connected 6422 03:41:05,600 --> 03:41:09,600 and when we press the switch these two 6423 03:41:07,680 --> 03:41:11,359 terminals will get interconnected 6424 03:41:09,600 --> 03:41:13,120 okay so in the series we have used a 6425 03:41:11,359 --> 03:41:14,319 resistance and we have connected one 6426 03:41:13,120 --> 03:41:17,359 point of that resistor 6427 03:41:14,319 --> 03:41:19,920 to ground okay and we are trying to read 6428 03:41:17,359 --> 03:41:21,439 voltage from this point can you see that 6429 03:41:19,920 --> 03:41:24,880 we have connected this point 6430 03:41:21,439 --> 03:41:26,720 to arduino's pin number seven all right 6431 03:41:24,880 --> 03:41:28,239 so this way we are able to read the 6432 03:41:26,720 --> 03:41:30,160 state of a switch 6433 03:41:28,239 --> 03:41:31,760 now what advantages can you have after 6434 03:41:30,160 --> 03:41:33,760 reading a state of a switch 6435 03:41:31,760 --> 03:41:34,960 you can trigger multiple actions like 6436 03:41:33,760 --> 03:41:37,279 running a motor 6437 03:41:34,960 --> 03:41:38,800 or sending some message right you can do 6438 03:41:37,279 --> 03:41:40,720 anything for that matter 6439 03:41:38,800 --> 03:41:42,880 so now you have learned about digital 6440 03:41:40,720 --> 03:41:45,040 input and output and in the next video 6441 03:41:42,880 --> 03:41:46,960 we'll look at other functions like 6442 03:41:45,040 --> 03:41:48,720 analog read and analog write 6443 03:41:46,960 --> 03:41:50,640 so see you in the next video in the 6444 03:41:48,720 --> 03:41:52,800 digital input output video we saw that 6445 03:41:50,640 --> 03:41:54,640 we can use a function called as digital 6446 03:41:52,800 --> 03:41:56,880 read to read the state of a pin 6447 03:41:54,640 --> 03:41:59,040 if it is high or if it is low that means 6448 03:41:56,880 --> 03:42:01,840 we can just read the binary situation 6449 03:41:59,040 --> 03:42:02,960 if it is on or either of that's all but 6450 03:42:01,840 --> 03:42:05,199 while making our projects 6451 03:42:02,960 --> 03:42:06,479 we may have situations in which we have 6452 03:42:05,199 --> 03:42:09,199 to read 6453 03:42:06,479 --> 03:42:10,880 not just those discrete values we may 6454 03:42:09,199 --> 03:42:12,160 also have to read the continuous 6455 03:42:10,880 --> 03:42:14,720 voltages so for that 6456 03:42:12,160 --> 03:42:15,680 we have analog read this function can be 6457 03:42:14,720 --> 03:42:18,800 used only on 6458 03:42:15,680 --> 03:42:21,359 the analog pins which are numbered a0 to 6459 03:42:18,800 --> 03:42:22,800 a5 right before seeing how it works 6460 03:42:21,359 --> 03:42:25,359 we'll have a basic idea of 6461 03:42:22,800 --> 03:42:27,359 analog information in the environment so 6462 03:42:25,359 --> 03:42:29,600 just look at this flowchart we have 6463 03:42:27,359 --> 03:42:31,520 the real world which is our environment 6464 03:42:29,600 --> 03:42:32,880 at the top we have some sensor 6465 03:42:31,520 --> 03:42:35,279 which is converting that physical 6466 03:42:32,880 --> 03:42:36,880 parameter into an analog signal 6467 03:42:35,279 --> 03:42:38,800 that physical parameter can be 6468 03:42:36,880 --> 03:42:41,120 temperature some distance 6469 03:42:38,800 --> 03:42:42,319 or humidity or anything for that matter 6470 03:42:41,120 --> 03:42:44,960 that analog signal 6471 03:42:42,319 --> 03:42:45,359 is then converted into digital signals 6472 03:42:44,960 --> 03:42:47,680 by 6473 03:42:45,359 --> 03:42:48,880 an analog to digital converter arduino 6474 03:42:47,680 --> 03:42:51,040 has a built-in 6475 03:42:48,880 --> 03:42:52,000 10 bit adc the short for analog to 6476 03:42:51,040 --> 03:42:54,239 digital converter is 6477 03:42:52,000 --> 03:42:56,080 adc so whenever i say adc you can 6478 03:42:54,239 --> 03:42:58,080 understand that i am saying analog to 6479 03:42:56,080 --> 03:42:59,199 digital converter so that digital signal 6480 03:42:58,080 --> 03:43:01,680 which is converted from 6481 03:42:59,199 --> 03:43:02,640 analog signal that is used by arduino to 6482 03:43:01,680 --> 03:43:04,319 make decisions 6483 03:43:02,640 --> 03:43:06,560 our arduino board is capable of 6484 03:43:04,319 --> 03:43:09,279 measuring voltage between 0 to 6485 03:43:06,560 --> 03:43:10,880 5 volts and this is the conversion scale 6486 03:43:09,279 --> 03:43:11,600 what i mean by that is since the 6487 03:43:10,880 --> 03:43:14,800 resolution 6488 03:43:11,600 --> 03:43:18,560 of adc on the arduino board is 10 bits 6489 03:43:14,800 --> 03:43:20,960 it can hold up to 1023 values okay 6490 03:43:18,560 --> 03:43:23,359 so if we compare that if the arduino 6491 03:43:20,960 --> 03:43:24,160 reads 0 volts so the corresponding adc 6492 03:43:23,359 --> 03:43:26,800 value will be 6493 03:43:24,160 --> 03:43:30,160 0 and if it reads 5 volts the 6494 03:43:26,800 --> 03:43:32,640 corresponding adc value will be 1023 6495 03:43:30,160 --> 03:43:34,000 and we can use unitary method to find 6496 03:43:32,640 --> 03:43:37,040 out values in between for 6497 03:43:34,000 --> 03:43:37,920 example you can tell me what will 3.3 6498 03:43:37,040 --> 03:43:39,760 volts 6499 03:43:37,920 --> 03:43:41,040 mean i hope i don't have to explain you 6500 03:43:39,760 --> 03:43:42,960 the unitary method right 6501 03:43:41,040 --> 03:43:45,120 this is the scale if zero volt means 6502 03:43:42,960 --> 03:43:46,479 zero and five volt means one zero two 6503 03:43:45,120 --> 03:43:48,960 three so one volt will mean 6504 03:43:46,479 --> 03:43:50,399 one zero two three divided by five so if 6505 03:43:48,960 --> 03:43:51,359 you know the value of one volt you can 6506 03:43:50,399 --> 03:43:53,120 find out value of 6507 03:43:51,359 --> 03:43:54,800 any voltage so now many of you must be 6508 03:43:53,120 --> 03:43:56,640 wondering from where this value of one 6509 03:43:54,800 --> 03:43:58,319 zero two three came from so i'll quickly 6510 03:43:56,640 --> 03:43:58,800 explain it to you we have a cupboard 6511 03:43:58,319 --> 03:44:01,600 here 6512 03:43:58,800 --> 03:44:03,439 which contains ten boxes and each box 6513 03:44:01,600 --> 03:44:03,920 can contain a value of either zero or 6514 03:44:03,439 --> 03:44:06,319 either 6515 03:44:03,920 --> 03:44:07,199 one okay so this is the cupboard and 6516 03:44:06,319 --> 03:44:09,680 these are the 6517 03:44:07,199 --> 03:44:11,439 boxes individual boxes to find the value 6518 03:44:09,680 --> 03:44:13,439 of the cupboard we take the value of 6519 03:44:11,439 --> 03:44:15,840 each box and we multiply it with the 6520 03:44:13,439 --> 03:44:16,960 multiplier the multiplier is this 2 to 6521 03:44:15,840 --> 03:44:20,080 the power 0 is 6522 03:44:16,960 --> 03:44:20,479 1 2 to the power 1 is 2 2 to the power 2 6523 03:44:20,080 --> 03:44:23,520 is 6524 03:44:20,479 --> 03:44:26,080 4 and similarly 2 to the power 9 is 6525 03:44:23,520 --> 03:44:26,640 512. so when we have values of all the 6526 03:44:26,080 --> 03:44:28,560 boxes 6527 03:44:26,640 --> 03:44:29,760 we take sum of all those values and we 6528 03:44:28,560 --> 03:44:31,520 get the value of that 6529 03:44:29,760 --> 03:44:33,600 entire cupboard so the maximum value 6530 03:44:31,520 --> 03:44:35,840 which can be held by a cupboard in which 6531 03:44:33,600 --> 03:44:38,720 all the boxes contain a value of one 6532 03:44:35,840 --> 03:44:40,160 will be one zero two three how this box 6533 03:44:38,720 --> 03:44:42,080 will evaluate to one 6534 03:44:40,160 --> 03:44:43,279 why because two to the power zero is one 6535 03:44:42,080 --> 03:44:46,880 and one multiplied by 6536 03:44:43,279 --> 03:44:47,359 1 is 1 okay so now the 2 to the power 1 6537 03:44:46,880 --> 03:44:50,239 is 6538 03:44:47,359 --> 03:44:51,279 2 and we multiply 1 by this so we get 2. 6539 03:44:50,239 --> 03:44:53,520 so we will be summing 6540 03:44:51,279 --> 03:44:54,960 all the values from here to here like 5 6541 03:44:53,520 --> 03:44:58,479 12 256 6542 03:44:54,960 --> 03:45:02,160 128 64 32 16 6543 03:44:58,479 --> 03:45:04,319 8 4 2 and 1 when you sum all these 6544 03:45:02,160 --> 03:45:05,760 values you will get 1 0 2 3 you can try 6545 03:45:04,319 --> 03:45:07,760 it on your calculator right now 6546 03:45:05,760 --> 03:45:09,760 so now let's take a look at analog read 6547 03:45:07,760 --> 03:45:11,040 function this function is simply used by 6548 03:45:09,760 --> 03:45:13,359 calling analog read 6549 03:45:11,040 --> 03:45:14,880 with the parameter of pin number where 6550 03:45:13,359 --> 03:45:16,880 pin number is a0 to 6551 03:45:14,880 --> 03:45:18,479 a5 so whenever you call this analog read 6552 03:45:16,880 --> 03:45:19,279 function it will return you the value at 6553 03:45:18,479 --> 03:45:21,520 red on that 6554 03:45:19,279 --> 03:45:22,319 pin so let's see how we use that so now 6555 03:45:21,520 --> 03:45:24,960 i have used 6556 03:45:22,319 --> 03:45:26,960 two one kilo ohm resistances in series 6557 03:45:24,960 --> 03:45:27,680 can you see that so now i have connected 6558 03:45:26,960 --> 03:45:29,600 it to 6559 03:45:27,680 --> 03:45:31,040 5 volts this point is connected to 5 6560 03:45:29,600 --> 03:45:33,439 volts and this point is 6561 03:45:31,040 --> 03:45:34,239 connected to ground so you can imagine a 6562 03:45:33,439 --> 03:45:37,040 series circuit 6563 03:45:34,239 --> 03:45:38,399 so now i want to read voltage across 6564 03:45:37,040 --> 03:45:39,439 this resistance since both the 6565 03:45:38,399 --> 03:45:42,000 resistances are equal 6566 03:45:39,439 --> 03:45:42,880 the 5 volt will split equally on both 6567 03:45:42,000 --> 03:45:45,600 the resistances 6568 03:45:42,880 --> 03:45:47,120 so we should be getting 2.5 volts let us 6569 03:45:45,600 --> 03:45:48,160 see that so in the code we have written 6570 03:45:47,120 --> 03:45:50,160 serial.begin 6571 03:45:48,160 --> 03:45:52,239 to start communication with the computer 6572 03:45:50,160 --> 03:45:55,199 and then we have written serial.println 6573 03:45:52,239 --> 03:45:56,800 bracket analog read a0 that means i want 6574 03:45:55,199 --> 03:45:59,120 to read the voltage 6575 03:45:56,800 --> 03:46:00,399 which is given at a0 so let's try this 6576 03:45:59,120 --> 03:46:04,000 code so we are getting 6577 03:46:00,399 --> 03:46:05,439 511 which is nearly 2.5 volts 6578 03:46:04,000 --> 03:46:07,279 we saw in that scale right so let's 6579 03:46:05,439 --> 03:46:08,000 change the resistance and see what value 6580 03:46:07,279 --> 03:46:11,520 do we get now 6581 03:46:08,000 --> 03:46:13,600 let's make this value as 2 kilo ohms 6582 03:46:11,520 --> 03:46:15,199 right so we got a change in value more 6583 03:46:13,600 --> 03:46:16,319 the value of resistance more the voltage 6584 03:46:15,199 --> 03:46:17,840 will drop across it 6585 03:46:16,319 --> 03:46:19,920 we can see the value of voltage across 6586 03:46:17,840 --> 03:46:21,120 this resistance is increasing if we make 6587 03:46:19,920 --> 03:46:23,439 it too high 6588 03:46:21,120 --> 03:46:25,040 it will increase it will also change if 6589 03:46:23,439 --> 03:46:26,880 we change the value of this resistance 6590 03:46:25,040 --> 03:46:28,399 let's say we make it 10. so now 6591 03:46:26,880 --> 03:46:30,720 the voltage across this resistance will 6592 03:46:28,399 --> 03:46:32,399 drop and hence we get a lower value 6593 03:46:30,720 --> 03:46:34,160 now let's see this with a light 6594 03:46:32,399 --> 03:46:35,680 dependent resistor this is a special 6595 03:46:34,160 --> 03:46:38,000 kind of resistance which changes 6596 03:46:35,680 --> 03:46:39,359 its resistance when light falls on it in 6597 03:46:38,000 --> 03:46:40,960 most of the light dependent resistance 6598 03:46:39,359 --> 03:46:43,439 the resistance will decrease 6599 03:46:40,960 --> 03:46:44,640 if the light on it increases okay so 6600 03:46:43,439 --> 03:46:48,000 let's try this 6601 03:46:44,640 --> 03:46:51,040 replace this resistance with 6602 03:46:48,000 --> 03:46:54,319 a light dependent resistor okay we'll 6603 03:46:51,040 --> 03:46:54,319 connect this in series 6604 03:46:56,560 --> 03:47:04,720 we'll take it here all right and we take 6605 03:46:59,760 --> 03:47:06,640 this wire now you see 6606 03:47:04,720 --> 03:47:08,479 this bar will represent the amount of 6607 03:47:06,640 --> 03:47:09,120 light falling on it right i can control 6608 03:47:08,479 --> 03:47:12,800 it like this 6609 03:47:09,120 --> 03:47:15,680 so right now here it is total darkness 6610 03:47:12,800 --> 03:47:17,040 and here it is very bright okay so when 6611 03:47:15,680 --> 03:47:18,960 it is dark the resistance of this 6612 03:47:17,040 --> 03:47:20,800 component is very high 6613 03:47:18,960 --> 03:47:22,479 okay so the voltage which drops across 6614 03:47:20,800 --> 03:47:24,560 this resistance will be very low 6615 03:47:22,479 --> 03:47:26,640 you can see the value is very low right 6616 03:47:24,560 --> 03:47:28,160 as soon as i increase the light on it 6617 03:47:26,640 --> 03:47:30,000 you will see the value in the serial 6618 03:47:28,160 --> 03:47:31,520 pointer is increasing 6619 03:47:30,000 --> 03:47:33,439 can you see that because the resistance 6620 03:47:31,520 --> 03:47:35,279 of this component is getting lower and 6621 03:47:33,439 --> 03:47:36,560 and more voltage is dropping across the 6622 03:47:35,279 --> 03:47:38,960 resistance 6623 03:47:36,560 --> 03:47:40,800 okay now this is the principle of analog 6624 03:47:38,960 --> 03:47:42,800 read now you can see how we can read the 6625 03:47:40,800 --> 03:47:45,199 value of analog sensors using 6626 03:47:42,800 --> 03:47:46,640 analog read all right so in the next 6627 03:47:45,199 --> 03:47:47,920 video we will look at the another 6628 03:47:46,640 --> 03:47:50,000 function which is known as 6629 03:47:47,920 --> 03:47:52,319 analog right so see you in the next 6630 03:47:50,000 --> 03:47:54,160 video in this video we'll take a look at 6631 03:47:52,319 --> 03:47:56,000 analog write function which is another 6632 03:47:54,160 --> 03:47:58,399 important built-in function 6633 03:47:56,000 --> 03:48:00,160 of arduino all right so to begin with 6634 03:47:58,399 --> 03:48:02,239 analog write i would firstly like to 6635 03:48:00,160 --> 03:48:05,279 tell you that it has no relation with 6636 03:48:02,239 --> 03:48:07,359 the analog pins or analog read function 6637 03:48:05,279 --> 03:48:09,520 it is absolutely a different thing what 6638 03:48:07,359 --> 03:48:11,920 exactly it is we will see 6639 03:48:09,520 --> 03:48:13,439 shortly so to use analog write function 6640 03:48:11,920 --> 03:48:15,760 we write analog write 6641 03:48:13,439 --> 03:48:16,800 bracket pin number on which we want to 6642 03:48:15,760 --> 03:48:18,800 use analog write 6643 03:48:16,800 --> 03:48:20,960 and then we specify a value which ranges 6644 03:48:18,800 --> 03:48:23,680 from 0 to 255. 6645 03:48:20,960 --> 03:48:24,239 we close the bracket and use a semicolon 6646 03:48:23,680 --> 03:48:25,520 right 6647 03:48:24,239 --> 03:48:27,520 the important thing which we need to 6648 03:48:25,520 --> 03:48:28,160 note is the pin numbers which we can use 6649 03:48:27,520 --> 03:48:31,359 here 6650 03:48:28,160 --> 03:48:34,560 are specific which are pin number 3 5 6651 03:48:31,359 --> 03:48:37,439 6 9 10 and 11 only okay 6652 03:48:34,560 --> 03:48:38,479 while all of these pins except pin 6653 03:48:37,439 --> 03:48:41,199 number five and six 6654 03:48:38,479 --> 03:48:43,279 support a frequency of 490 hertz and pin 6655 03:48:41,199 --> 03:48:43,600 number five and six support a frequency 6656 03:48:43,279 --> 03:48:45,760 of 6657 03:48:43,600 --> 03:48:46,960 980hz we don't need to worry about this 6658 03:48:45,760 --> 03:48:49,040 frequency right now 6659 03:48:46,960 --> 03:48:50,160 i'll explain as we progress so before we 6660 03:48:49,040 --> 03:48:52,239 dig deeper into this 6661 03:48:50,160 --> 03:48:53,199 we need to understand a few terms like 6662 03:48:52,239 --> 03:48:55,199 pwm 6663 03:48:53,199 --> 03:48:57,520 pulse width and frequency and even 6664 03:48:55,199 --> 03:48:59,359 before that we need to know what exactly 6665 03:48:57,520 --> 03:49:01,359 this analog write function does 6666 03:48:59,359 --> 03:49:03,199 the analog write function generates a 6667 03:49:01,359 --> 03:49:06,000 square wave of a specified 6668 03:49:03,199 --> 03:49:08,239 duty cycle on that specified pin the 6669 03:49:06,000 --> 03:49:10,560 major purpose of using analog write is 6670 03:49:08,239 --> 03:49:12,720 to control the brightness of led or to 6671 03:49:10,560 --> 03:49:14,239 control the speed of a motor 6672 03:49:12,720 --> 03:49:16,319 right the first thing which we need to 6673 03:49:14,239 --> 03:49:17,920 see now is a square wave what a square 6674 03:49:16,319 --> 03:49:19,840 wave is on the screen you can see 6675 03:49:17,920 --> 03:49:21,199 a square wave is coming this is a square 6676 03:49:19,840 --> 03:49:23,199 wave okay 6677 03:49:21,199 --> 03:49:25,120 although this is a varying square wave 6678 03:49:23,199 --> 03:49:27,439 now a square wave is nothing 6679 03:49:25,120 --> 03:49:28,640 but a signal which has only two discrete 6680 03:49:27,439 --> 03:49:31,680 values either on 6681 03:49:28,640 --> 03:49:33,760 or off as you can see here it is on 6682 03:49:31,680 --> 03:49:35,040 and here it is off and the time for 6683 03:49:33,760 --> 03:49:37,279 which it is on 6684 03:49:35,040 --> 03:49:39,279 and off is varying you can see here 6685 03:49:37,279 --> 03:49:40,960 right i can understand it must be 6686 03:49:39,279 --> 03:49:43,040 little difficult to comprehend but 6687 03:49:40,960 --> 03:49:43,760 please stick with me okay so the next 6688 03:49:43,040 --> 03:49:46,000 term is 6689 03:49:43,760 --> 03:49:47,199 pulse width the amount of time for which 6690 03:49:46,000 --> 03:49:49,920 a signal is on 6691 03:49:47,199 --> 03:49:50,560 is known as pulse width for example in 6692 03:49:49,920 --> 03:49:52,560 this wave 6693 03:49:50,560 --> 03:49:54,479 this is the pulse width denoted by this 6694 03:49:52,560 --> 03:49:56,399 arrow in this portion 6695 03:49:54,479 --> 03:49:57,760 this is the pulse width denoted by this 6696 03:49:56,399 --> 03:50:00,319 arrow in this portion 6697 03:49:57,760 --> 03:50:00,960 this is the pulse width noted by this 6698 03:50:00,319 --> 03:50:04,319 arrow 6699 03:50:00,960 --> 03:50:06,640 all right the next term is duty cycle 6700 03:50:04,319 --> 03:50:08,160 duty cycle is the fraction of period for 6701 03:50:06,640 --> 03:50:10,720 which the signal was 6702 03:50:08,160 --> 03:50:12,239 on right so we have five sections here 6703 03:50:10,720 --> 03:50:13,680 with zero percent duty cycle twenty five 6704 03:50:12,239 --> 03:50:15,600 percent due to cycle fifty percent duty 6705 03:50:13,680 --> 03:50:17,760 cycle seventy five percent duty cycle 6706 03:50:15,600 --> 03:50:18,640 and hundred percent duty cycle okay so 6707 03:50:17,760 --> 03:50:21,600 in this section 6708 03:50:18,640 --> 03:50:22,319 the voltage for entire time was zero 6709 03:50:21,600 --> 03:50:24,720 okay 6710 03:50:22,319 --> 03:50:25,439 so that means the duty cycle is zero 6711 03:50:24,720 --> 03:50:28,399 percent 6712 03:50:25,439 --> 03:50:29,199 in this section we have about one fourth 6713 03:50:28,399 --> 03:50:31,279 of the time 6714 03:50:29,199 --> 03:50:32,319 as on you can see that right for the one 6715 03:50:31,279 --> 03:50:34,720 fourth time it is on 6716 03:50:32,319 --> 03:50:36,160 and three fourth time it is off so that 6717 03:50:34,720 --> 03:50:39,760 means the duty cycle is 6718 03:50:36,160 --> 03:50:42,800 25 in this section we have about 6719 03:50:39,760 --> 03:50:43,680 half of the time as on time and half of 6720 03:50:42,800 --> 03:50:47,279 the time as of 6721 03:50:43,680 --> 03:50:50,399 time so here the duty cycle is 50 6722 03:50:47,279 --> 03:50:53,680 similarly here the on time is 3 4 6723 03:50:50,399 --> 03:50:55,439 hence the duty cycle is 75 and here 6724 03:50:53,680 --> 03:50:57,279 for the entire duration of time the 6725 03:50:55,439 --> 03:51:00,319 voltage was on hence 6726 03:50:57,279 --> 03:51:02,960 the duty cycle was 100 okay now 6727 03:51:00,319 --> 03:51:04,319 if we look in terms of arduino when we 6728 03:51:02,960 --> 03:51:06,479 call analog write 6729 03:51:04,319 --> 03:51:07,520 with a value of 0 it will give us 0 6730 03:51:06,479 --> 03:51:10,000 percent duty cycle 6731 03:51:07,520 --> 03:51:10,720 that means the signal will be off for 6732 03:51:10,000 --> 03:51:12,800 the whole time 6733 03:51:10,720 --> 03:51:15,439 if you write analog write 64 then it 6734 03:51:12,800 --> 03:51:17,439 will give us a duty cycle of 25 percent 6735 03:51:15,439 --> 03:51:20,160 if you write 191 it will give a value of 6736 03:51:17,439 --> 03:51:21,840 75 percent and 255 will give us a duty 6737 03:51:20,160 --> 03:51:24,479 cycle of 100 6738 03:51:21,840 --> 03:51:25,199 okay so now to summarize pulse width 6739 03:51:24,479 --> 03:51:27,760 modulation 6740 03:51:25,199 --> 03:51:28,399 or pwm is a technique for getting analog 6741 03:51:27,760 --> 03:51:30,720 results 6742 03:51:28,399 --> 03:51:32,560 with digital means digital control is 6743 03:51:30,720 --> 03:51:33,040 used to create a square wave which is a 6744 03:51:32,560 --> 03:51:36,080 signal 6745 03:51:33,040 --> 03:51:36,640 switch between on and off all right and 6746 03:51:36,080 --> 03:51:39,279 this 6747 03:51:36,640 --> 03:51:40,880 on and off cycle takes place really fast 6748 03:51:39,279 --> 03:51:41,840 and this on off pattern can simulate 6749 03:51:40,880 --> 03:51:44,319 voltages in between 6750 03:51:41,840 --> 03:51:46,479 full on and full off by changing the 6751 03:51:44,319 --> 03:51:49,439 portion of the time the signal spends 6752 03:51:46,479 --> 03:51:50,960 on versus the time that signal spins off 6753 03:51:49,439 --> 03:51:52,080 all right so next thing which we need to 6754 03:51:50,960 --> 03:51:55,680 look at 6755 03:51:52,080 --> 03:51:58,399 is the pwm frequency okay 6756 03:51:55,680 --> 03:51:59,279 let's see this is a wave which has a 6757 03:51:58,399 --> 03:52:01,520 duty cycle of 6758 03:51:59,279 --> 03:52:02,399 50 that means half of the time the 6759 03:52:01,520 --> 03:52:04,319 signal is on 6760 03:52:02,399 --> 03:52:05,840 and half of the time signal is off 6761 03:52:04,319 --> 03:52:07,520 changing the frequency of the signal 6762 03:52:05,840 --> 03:52:09,840 will not change the duty cycle of the 6763 03:52:07,520 --> 03:52:12,560 signal okay so let's say 6764 03:52:09,840 --> 03:52:14,800 we have a signal of 50 duty cycle here 6765 03:52:12,560 --> 03:52:16,800 and if we make the frequency to 400 6766 03:52:14,800 --> 03:52:18,319 so the waves will become closer that 6767 03:52:16,800 --> 03:52:20,880 means now it will turn 6768 03:52:18,319 --> 03:52:22,479 on two times and turn off two times 6769 03:52:20,880 --> 03:52:26,720 right you can see here 6770 03:52:22,479 --> 03:52:28,239 on and off earlier it was on one time 6771 03:52:26,720 --> 03:52:30,560 and off one time 6772 03:52:28,239 --> 03:52:32,399 okay but you see the duty cycle is still 6773 03:52:30,560 --> 03:52:34,000 50 you're getting my point so you see 6774 03:52:32,399 --> 03:52:34,880 the duty cycle of the signal has not 6775 03:52:34,000 --> 03:52:36,640 changed 6776 03:52:34,880 --> 03:52:39,279 because it was still on for the half of 6777 03:52:36,640 --> 03:52:42,000 the time and off for half of the time 6778 03:52:39,279 --> 03:52:43,120 even if i make it 600 it is still on for 6779 03:52:42,000 --> 03:52:45,760 the half of the time 6780 03:52:43,120 --> 03:52:47,600 and off for half of the time okay so i 6781 03:52:45,760 --> 03:52:48,960 hope it was clear to you and if in case 6782 03:52:47,600 --> 03:52:51,760 it was not clear to you 6783 03:52:48,960 --> 03:52:53,600 we'll take an example and blink the led 6784 03:52:51,760 --> 03:52:55,520 and change the brightness of the led 6785 03:52:53,600 --> 03:52:57,520 all right and we will also monitor it 6786 03:52:55,520 --> 03:52:58,239 along with a digital oscilloscope an 6787 03:52:57,520 --> 03:53:00,080 oscilloscope 6788 03:52:58,239 --> 03:53:01,920 is nothing but it is a device which is 6789 03:53:00,080 --> 03:53:03,600 used to analyze the signals okay so 6790 03:53:01,920 --> 03:53:05,359 let's see that so here what we have done 6791 03:53:03,600 --> 03:53:07,520 is we have taken an led 6792 03:53:05,359 --> 03:53:08,880 on pin number 10 and correspondingly we 6793 03:53:07,520 --> 03:53:10,880 have connected these wires to an 6794 03:53:08,880 --> 03:53:11,359 oscilloscope to see the signal so let us 6795 03:53:10,880 --> 03:53:13,279 see the 6796 03:53:11,359 --> 03:53:14,640 code first so you must have noticed that 6797 03:53:13,279 --> 03:53:15,120 we have not written anything in void 6798 03:53:14,640 --> 03:53:16,880 setup 6799 03:53:15,120 --> 03:53:18,800 and we don't have to use pin mode 6800 03:53:16,880 --> 03:53:19,359 whenever we want to use analog write 6801 03:53:18,800 --> 03:53:21,760 function 6802 03:53:19,359 --> 03:53:22,880 okay so now in void loop i have written 6803 03:53:21,760 --> 03:53:26,239 analog write 6804 03:53:22,880 --> 03:53:28,160 pin number 10 and a value of 50 6805 03:53:26,239 --> 03:53:30,560 okay and then i have given a delay of 6806 03:53:28,160 --> 03:53:33,359 one second then analog write 10 with the 6807 03:53:30,560 --> 03:53:36,479 value of 100 then 150 then 200 and 255 6808 03:53:33,359 --> 03:53:38,479 here we will get a duty cycle of 100 6809 03:53:36,479 --> 03:53:40,000 okay so now let's see how it looks like 6810 03:53:38,479 --> 03:53:41,279 pay attention to the wave which is 6811 03:53:40,000 --> 03:53:43,040 coming on the oscilloscope 6812 03:53:41,279 --> 03:53:44,720 and also note the brightness of this led 6813 03:53:43,040 --> 03:53:50,080 i'm starting the simulation 6814 03:53:44,720 --> 03:53:51,279 let's see can you see that the 6815 03:53:50,080 --> 03:53:53,439 brightness of led 6816 03:53:51,279 --> 03:53:55,600 is increasing gradually as the code 6817 03:53:53,439 --> 03:53:58,080 progresses and it gets backs to 50 6818 03:53:55,600 --> 03:53:59,760 and then it again increases also note 6819 03:53:58,080 --> 03:54:01,359 the pulses which are coming in the 6820 03:53:59,760 --> 03:54:02,720 oscilloscope so now we will see an 6821 03:54:01,359 --> 03:54:04,479 example in which we are changing the 6822 03:54:02,720 --> 03:54:06,880 brightness of led in steps of 6823 03:54:04,479 --> 03:54:07,600 five we will also look at the pwm wave 6824 03:54:06,880 --> 03:54:09,040 simultaneous 6825 03:54:07,600 --> 03:54:10,560 let's look at the code first we have 6826 03:54:09,040 --> 03:54:12,160 defined an led pin which is connected on 6827 03:54:10,560 --> 03:54:13,040 pin number ten in white setup we don't 6828 03:54:12,160 --> 03:54:14,960 have to do anything 6829 03:54:13,040 --> 03:54:16,960 in void loop we have written four which 6830 03:54:14,960 --> 03:54:17,439 is a for loop and we have defined a fade 6831 03:54:16,960 --> 03:54:19,920 value 6832 03:54:17,439 --> 03:54:21,040 in fade value is equal to 0 and you have 6833 03:54:19,920 --> 03:54:22,720 to do this till 6834 03:54:21,040 --> 03:54:24,319 the fade value is less than or equal to 6835 03:54:22,720 --> 03:54:25,760 255 okay 6836 03:54:24,319 --> 03:54:27,359 and then we are incrementing the value 6837 03:54:25,760 --> 03:54:29,520 of fade value by 6838 03:54:27,359 --> 03:54:31,279 5. this is an another compound operator 6839 03:54:29,520 --> 03:54:34,479 you can say it is similar to writing 6840 03:54:31,279 --> 03:54:37,520 fade value is equal to fade 6841 03:54:34,479 --> 03:54:39,439 value plus 5 all right 6842 03:54:37,520 --> 03:54:41,439 so now we have written analog write and 6843 03:54:39,439 --> 03:54:42,319 we have written led pin here which is 6844 03:54:41,439 --> 03:54:45,359 pin number 10 6845 03:54:42,319 --> 03:54:47,520 with the fade value okay 6846 03:54:45,359 --> 03:54:48,960 so how it will go it will write zero 6847 03:54:47,520 --> 03:54:50,720 here then after the delay of 30 6848 03:54:48,960 --> 03:54:52,640 milliseconds it will write five year 6849 03:54:50,720 --> 03:54:54,960 then after a delay of 30 milliseconds it 6850 03:54:52,640 --> 03:54:57,840 will write 10 here then 15 and 20 6851 03:54:54,960 --> 03:54:58,720 and 25 and so on till 255. once this 6852 03:54:57,840 --> 03:55:00,960 value 6853 03:54:58,720 --> 03:55:02,720 becomes 260 you know in the last 6854 03:55:00,960 --> 03:55:04,640 iteration the value will become 260 6855 03:55:02,720 --> 03:55:06,319 so this condition will become false and 6856 03:55:04,640 --> 03:55:06,880 it will exit this for loop and come 6857 03:55:06,319 --> 03:55:08,800 inside 6858 03:55:06,880 --> 03:55:11,120 this for loop in this for loop we have 6859 03:55:08,800 --> 03:55:12,560 used fade value starting from 255 6860 03:55:11,120 --> 03:55:14,560 and we have written a condition fade 6861 03:55:12,560 --> 03:55:17,359 value greater than equal to zero 6862 03:55:14,560 --> 03:55:19,040 that means you have to do this till the 6863 03:55:17,359 --> 03:55:22,000 value is greater than 6864 03:55:19,040 --> 03:55:24,080 or equal to zero okay then we have to 6865 03:55:22,000 --> 03:55:26,160 use fade value minus equal to five 6866 03:55:24,080 --> 03:55:29,680 and this is similar to writing yes you 6867 03:55:26,160 --> 03:55:32,720 guys did right it is similar to writing 6868 03:55:29,680 --> 03:55:35,680 okay so now it will start 6869 03:55:32,720 --> 03:55:38,800 at 255. after a delay of 30 milliseconds 6870 03:55:35,680 --> 03:55:41,600 it will write 250 and 245 then 240 6871 03:55:38,800 --> 03:55:42,160 and 235 and so on till 0. in the last 6872 03:55:41,600 --> 03:55:44,160 iteration 6873 03:55:42,160 --> 03:55:46,720 when the value is 0 the value will 6874 03:55:44,160 --> 03:55:49,199 become -5 and the condition will become 6875 03:55:46,720 --> 03:55:50,000 false so this loop will exit and it will 6876 03:55:49,199 --> 03:55:52,000 come back 6877 03:55:50,000 --> 03:55:54,399 into this for loop and this will repeat 6878 03:55:52,000 --> 03:55:56,640 endlessly till we turn off the arduino 6879 03:55:54,399 --> 03:55:58,160 let's start the simulation note the 6880 03:55:56,640 --> 03:55:59,359 brightness of the led and note the 6881 03:55:58,160 --> 03:56:00,800 signal which is coming in the 6882 03:55:59,359 --> 03:56:05,920 oscilloscope 6883 03:56:00,800 --> 03:56:08,080 let's see okay 6884 03:56:05,920 --> 03:56:09,439 it's interesting right the brightness of 6885 03:56:08,080 --> 03:56:12,640 leds increasing 6886 03:56:09,439 --> 03:56:13,920 from 0 to 55 and the pulse width is 6887 03:56:12,640 --> 03:56:17,199 changing when it is 0 6888 03:56:13,920 --> 03:56:19,040 you can see it is entirely off and when 6889 03:56:17,199 --> 03:56:20,239 the duty cycle becomes 100 it becomes 6890 03:56:19,040 --> 03:56:22,080 entirely on 6891 03:56:20,239 --> 03:56:23,439 the pulse width is changing here so i 6892 03:56:22,080 --> 03:56:24,399 hope you have understood this really 6893 03:56:23,439 --> 03:56:25,840 well 6894 03:56:24,399 --> 03:56:27,920 the last topic which we need to learn 6895 03:56:25,840 --> 03:56:30,800 about before starting our experiments 6896 03:56:27,920 --> 03:56:32,640 is the arduino libraries so libraries 6897 03:56:30,800 --> 03:56:33,600 are a collection of code that makes it 6898 03:56:32,640 --> 03:56:35,520 easier for you 6899 03:56:33,600 --> 03:56:36,960 to connect to a sensor display or a 6900 03:56:35,520 --> 03:56:38,880 module for example 6901 03:56:36,960 --> 03:56:40,319 there is a built-in library to control a 6902 03:56:38,880 --> 03:56:42,239 liquid crystal display 6903 03:56:40,319 --> 03:56:43,680 that library makes it easier for us to 6904 03:56:42,239 --> 03:56:46,239 talk to that display 6905 03:56:43,680 --> 03:56:48,000 right for example you can see that 6906 03:56:46,239 --> 03:56:49,279 library will control what character will 6907 03:56:48,000 --> 03:56:50,800 come at what position 6908 03:56:49,279 --> 03:56:52,479 apart from this library there are many 6909 03:56:50,800 --> 03:56:53,680 more libraries which are available for 6910 03:56:52,479 --> 03:56:56,160 download on internet 6911 03:56:53,680 --> 03:56:57,199 and there are also built-in libraries 6912 03:56:56,160 --> 03:56:59,040 for example 6913 03:56:57,199 --> 03:57:01,680 the built-in libraries are these 6914 03:56:59,040 --> 03:57:04,399 libraries which are already present in 6915 03:57:01,680 --> 03:57:04,800 arduino id i'll just name a few like ap 6916 03:57:04,399 --> 03:57:06,960 rom 6917 03:57:04,800 --> 03:57:08,080 is used to read and write elements from 6918 03:57:06,960 --> 03:57:10,960 the permanent storage 6919 03:57:08,080 --> 03:57:13,120 a gsm library is used to connect gsm or 6920 03:57:10,960 --> 03:57:14,399 gprs network with the gsm shield 6921 03:57:13,120 --> 03:57:16,239 the liquid crystal library which you 6922 03:57:14,399 --> 03:57:17,600 just saw controls the liquid crystal 6923 03:57:16,239 --> 03:57:18,560 display which is used for reading and 6924 03:57:17,600 --> 03:57:20,880 writing data on 6925 03:57:18,560 --> 03:57:22,800 sd cards a server library will be used 6926 03:57:20,880 --> 03:57:24,319 to control server motors similarly there 6927 03:57:22,800 --> 03:57:25,279 are many more libraries which are 6928 03:57:24,319 --> 03:57:27,279 already there on 6929 03:57:25,279 --> 03:57:28,960 arduino the code which is written inside 6930 03:57:27,279 --> 03:57:30,080 those libraries can be written by 6931 03:57:28,960 --> 03:57:32,160 someone else 6932 03:57:30,080 --> 03:57:33,600 or you can write the code on your own as 6933 03:57:32,160 --> 03:57:34,000 well once we have the library in our 6934 03:57:33,600 --> 03:57:36,239 arduino 6935 03:57:34,000 --> 03:57:37,199 id it's very simple to use that library 6936 03:57:36,239 --> 03:57:39,359 i'll just show you how 6937 03:57:37,199 --> 03:57:41,600 so this is our code let's say we have to 6938 03:57:39,359 --> 03:57:43,439 use liquid crystal library so we will 6939 03:57:41,600 --> 03:57:46,640 write hash 6940 03:57:43,439 --> 03:57:50,160 include liquid crystal dot 6941 03:57:46,640 --> 03:57:51,680 h okay whenever we use this library 6942 03:57:50,160 --> 03:57:53,040 we'll be able to use the functions which 6943 03:57:51,680 --> 03:57:54,000 are written inside the liquid crystal 6944 03:57:53,040 --> 03:57:57,439 library 6945 03:57:54,000 --> 03:57:59,840 okay similarly if we have to include 6946 03:57:57,439 --> 03:58:00,800 another library for sd cards we'll write 6947 03:57:59,840 --> 03:58:03,680 sd dot 6948 03:58:00,800 --> 03:58:04,800 h okay this will include the sd library 6949 03:58:03,680 --> 03:58:06,399 in our code 6950 03:58:04,800 --> 03:58:08,560 we'll be able to use all the functions 6951 03:58:06,399 --> 03:58:09,920 which are written in sd library 6952 03:58:08,560 --> 03:58:11,120 i would also like to tell you that the 6953 03:58:09,920 --> 03:58:12,080 functions which we were using like 6954 03:58:11,120 --> 03:58:14,000 digital write 6955 03:58:12,080 --> 03:58:15,359 were also declared in some library i 6956 03:58:14,000 --> 03:58:17,040 will just show you 6957 03:58:15,359 --> 03:58:18,880 how it was written so there's a built-in 6958 03:58:17,040 --> 03:58:21,359 code which is written inside 6959 03:58:18,880 --> 03:58:23,120 wiring underscore digital dot c which is 6960 03:58:21,359 --> 03:58:24,960 located at this location 6961 03:58:23,120 --> 03:58:26,640 see program files arduino hardware 6962 03:58:24,960 --> 03:58:29,279 arduino avr course 6963 03:58:26,640 --> 03:58:30,560 arduino and then finally the file now if 6964 03:58:29,279 --> 03:58:32,880 we see the declaration of 6965 03:58:30,560 --> 03:58:35,120 digitalwrite we will see that this is 6966 03:58:32,880 --> 03:58:36,160 how a digital write function is declared 6967 03:58:35,120 --> 03:58:39,359 in that library 6968 03:58:36,160 --> 03:58:42,960 okay you just see that void digitalwrite 6969 03:58:39,359 --> 03:58:45,520 pin number and value okay where pin is 6970 03:58:42,960 --> 03:58:47,439 the pin number and value is high or low 6971 03:58:45,520 --> 03:58:48,880 it accepts two arguments right we sorted 6972 03:58:47,439 --> 03:58:51,520 while calling this function 6973 03:58:48,880 --> 03:58:53,359 so this is how the digital write is 6974 03:58:51,520 --> 03:58:55,840 called we'll not get into 6975 03:58:53,359 --> 03:58:58,080 details of this function as it may be 6976 03:58:55,840 --> 03:58:59,840 very complicated for you to understand 6977 03:58:58,080 --> 03:59:01,600 okay similarly digital read has been 6978 03:58:59,840 --> 03:59:02,319 declared here this is a declaration of 6979 03:59:01,600 --> 03:59:06,560 digital read 6980 03:59:02,319 --> 03:59:08,720 similarly pin mode is also declared 6981 03:59:06,560 --> 03:59:09,600 right so i hope you were clear with 6982 03:59:08,720 --> 03:59:11,760 libraries 6983 03:59:09,600 --> 03:59:14,080 and i hope you understand how using 6984 03:59:11,760 --> 03:59:16,640 libraries saves a lot of our time 6985 03:59:14,080 --> 03:59:17,600 okay so in the next video we will see 6986 03:59:16,640 --> 03:59:20,319 how to add 6987 03:59:17,600 --> 03:59:21,279 additional libraries in our arduino ide 6988 03:59:20,319 --> 03:59:23,439 so see you in the 6989 03:59:21,279 --> 03:59:25,520 next video so now let's see how do we 6990 03:59:23,439 --> 03:59:28,000 install external libraries in our 6991 03:59:25,520 --> 03:59:28,800 arduino ide there are basically two 6992 03:59:28,000 --> 03:59:31,040 methods 6993 03:59:28,800 --> 03:59:32,080 one is through the library manager and 6994 03:59:31,040 --> 03:59:34,960 one is through 6995 03:59:32,080 --> 03:59:35,840 adding external zip files okay let's 6996 03:59:34,960 --> 03:59:38,840 look at 6997 03:59:35,840 --> 03:59:40,319 the library manager first we will go to 6998 03:59:38,840 --> 03:59:44,720 sketch 6999 03:59:40,319 --> 03:59:46,960 include libraries then manage libraries 7000 03:59:44,720 --> 03:59:48,000 it will open the library manager this is 7001 03:59:46,960 --> 03:59:50,319 the library manager 7002 03:59:48,000 --> 03:59:51,439 it will update all the libraries which 7003 03:59:50,319 --> 03:59:53,359 are already there 7004 03:59:51,439 --> 03:59:55,600 in their database and it will show us 7005 03:59:53,359 --> 03:59:57,120 the list of available libraries for us 7006 03:59:55,600 --> 03:59:58,640 you can see there are a lot of libraries 7007 03:59:57,120 --> 04:00:01,040 already there 7008 03:59:58,640 --> 04:00:02,000 right these are all the libraries which 7009 04:00:01,040 --> 04:00:05,359 are present 7010 04:00:02,000 --> 04:00:07,359 in their database right now so let's say 7011 04:00:05,359 --> 04:00:09,840 we need a library for dht 11 7012 04:00:07,359 --> 04:00:11,279 which is a sensor which captures 7013 04:00:09,840 --> 04:00:12,560 temperature and humidity of our 7014 04:00:11,279 --> 04:00:15,279 environment 7015 04:00:12,560 --> 04:00:16,800 so we will write dht11 here and it will 7016 04:00:15,279 --> 04:00:18,800 search all the libraries 7017 04:00:16,800 --> 04:00:20,080 which are available for dht 11 by 7018 04:00:18,800 --> 04:00:21,840 different authors 7019 04:00:20,080 --> 04:00:24,160 so let's say this is a very reliable 7020 04:00:21,840 --> 04:00:27,199 library by adafruit 7021 04:00:24,160 --> 04:00:29,359 which i've already installed okay so 7022 04:00:27,199 --> 04:00:31,199 just in case you have not installed it 7023 04:00:29,359 --> 04:00:33,120 already you will get 7024 04:00:31,199 --> 04:00:35,439 install here you can select the version 7025 04:00:33,120 --> 04:00:37,680 here which version you want to install 7026 04:00:35,439 --> 04:00:38,880 usually this is the latest one and then 7027 04:00:37,680 --> 04:00:40,800 you just click on install 7028 04:00:38,880 --> 04:00:42,160 and it will install the library in your 7029 04:00:40,800 --> 04:00:44,720 id okay 7030 04:00:42,160 --> 04:00:45,600 once it is installed we can use it in a 7031 04:00:44,720 --> 04:00:48,880 regular manner 7032 04:00:45,600 --> 04:00:48,880 hash include 7033 04:00:49,279 --> 04:00:56,880 dht dot h 7034 04:00:54,080 --> 04:00:58,479 okay if this dht library was not 7035 04:00:56,880 --> 04:01:00,880 installed in my id 7036 04:00:58,479 --> 04:01:01,760 it would not appear in this orange color 7037 04:01:00,880 --> 04:01:04,720 okay 7038 04:01:01,760 --> 04:01:05,680 let's take an arbitrary name include 7039 04:01:04,720 --> 04:01:07,680 ashish dot 7040 04:01:05,680 --> 04:01:09,760 h since there is no library named ashi 7041 04:01:07,680 --> 04:01:11,600 so this ashish is not coming in 7042 04:01:09,760 --> 04:01:13,760 orange color although this is not a very 7043 04:01:11,600 --> 04:01:16,399 hard and fast rule you might not get 7044 04:01:13,760 --> 04:01:17,199 orange color in some libraries but it is 7045 04:01:16,399 --> 04:01:19,520 a really 7046 04:01:17,199 --> 04:01:20,560 good indication that you're working in a 7047 04:01:19,520 --> 04:01:23,120 right direction 7048 04:01:20,560 --> 04:01:24,239 okay so now let us look at the other way 7049 04:01:23,120 --> 04:01:26,479 which is adding them 7050 04:01:24,239 --> 04:01:27,520 manually let's say again we want a 7051 04:01:26,479 --> 04:01:31,840 library 7052 04:01:27,520 --> 04:01:35,920 for our dht11 sensor we will write dht 7053 04:01:31,840 --> 04:01:38,960 11 library 7054 04:01:35,920 --> 04:01:41,520 for arduino usually 7055 04:01:38,960 --> 04:01:43,279 libraries are available on github you 7056 04:01:41,520 --> 04:01:44,080 may also find zip files on some other 7057 04:01:43,279 --> 04:01:46,160 websites 7058 04:01:44,080 --> 04:01:47,439 but github is usually preferred as you 7059 04:01:46,160 --> 04:01:49,680 would get the latest version of the 7060 04:01:47,439 --> 04:01:51,680 library from there so again adafruit has 7061 04:01:49,680 --> 04:01:54,800 hosted their library on github 7062 04:01:51,680 --> 04:01:56,880 so let's click on that and then we'll go 7063 04:01:54,800 --> 04:02:00,560 to clone or download 7064 04:01:56,880 --> 04:02:02,479 we'll click download zip 7065 04:02:00,560 --> 04:02:04,800 and it will start downloading it you 7066 04:02:02,479 --> 04:02:07,760 have to see where you have downloaded it 7067 04:02:04,800 --> 04:02:08,319 you have to go to sketch include library 7068 04:02:07,760 --> 04:02:11,279 then add 7069 04:02:08,319 --> 04:02:11,760 dot zip library in my case i downloaded 7070 04:02:11,279 --> 04:02:14,319 it 7071 04:02:11,760 --> 04:02:14,800 in my h drive so it is here we'll click 7072 04:02:14,319 --> 04:02:17,199 on this 7073 04:02:14,800 --> 04:02:18,640 and just click on open in my case it was 7074 04:02:17,199 --> 04:02:20,319 already installed so it gave me a 7075 04:02:18,640 --> 04:02:22,239 warning a library name dht sensor 7076 04:02:20,319 --> 04:02:24,560 library master already exists 7077 04:02:22,239 --> 04:02:26,319 okay but in your case it will say the 7078 04:02:24,560 --> 04:02:28,000 library has been successfully installed 7079 04:02:26,319 --> 04:02:29,840 so these are the basic two ways in which 7080 04:02:28,000 --> 04:02:31,840 we add libraries 7081 04:02:29,840 --> 04:02:33,840 at this point i can really say that you 7082 04:02:31,840 --> 04:02:36,239 have reached a milestone 7083 04:02:33,840 --> 04:02:37,840 and you are in a position to dig deeper 7084 04:02:36,239 --> 04:02:38,960 as you have so many tools under your 7085 04:02:37,840 --> 04:02:40,399 belt now 7086 04:02:38,960 --> 04:02:42,080 we have covered the foundations of 7087 04:02:40,399 --> 04:02:43,840 electronics then we covered 7088 04:02:42,080 --> 04:02:45,760 what is an arduino board and then we 7089 04:02:43,840 --> 04:02:46,960 discussed what is inside arduino 7090 04:02:45,760 --> 04:02:48,880 we covered the difference between the 7091 04:02:46,960 --> 04:02:51,760 microcontroller and microprocessor 7092 04:02:48,880 --> 04:02:53,040 then we saw the arduino ide how it works 7093 04:02:51,760 --> 04:02:55,120 and how we use it 7094 04:02:53,040 --> 04:02:56,880 we also saw an online simulator which 7095 04:02:55,120 --> 04:02:57,760 can be used if someone doesn't have an 7096 04:02:56,880 --> 04:03:00,640 arduino right now 7097 04:02:57,760 --> 04:03:01,520 then we saw how to use a breadboard then 7098 04:03:00,640 --> 04:03:04,800 some topics like 7099 04:03:01,520 --> 04:03:05,520 input output analog digital etc and then 7100 04:03:04,800 --> 04:03:07,920 we started 7101 04:03:05,520 --> 04:03:09,359 arduino programming and i tried to cover 7102 04:03:07,920 --> 04:03:10,000 all the essential topics which are 7103 04:03:09,359 --> 04:03:12,880 required 7104 04:03:10,000 --> 04:03:14,720 for you to start your own projects from 7105 04:03:12,880 --> 04:03:17,760 this point you can try making 7106 04:03:14,720 --> 04:03:18,080 various led patterns you can try to work 7107 04:03:17,760 --> 04:03:19,760 with 7108 04:03:18,080 --> 04:03:23,040 a seven segment display which can be 7109 04:03:19,760 --> 04:03:24,800 used to display different digits on it 7110 04:03:23,040 --> 04:03:26,080 then you can try to interface sensors 7111 04:03:24,800 --> 04:03:28,399 like ultrasonic sensor 7112 04:03:26,080 --> 04:03:30,000 or ir sensor and try to read their 7113 04:03:28,399 --> 04:03:32,080 values using the built-in functions 7114 04:03:30,000 --> 04:03:33,840 which we have studied already 7115 04:03:32,080 --> 04:03:35,439 then you can try to control the motion 7116 04:03:33,840 --> 04:03:37,359 and speed of a dc motor 7117 04:03:35,439 --> 04:03:39,199 then i recommend you to try using a 7118 04:03:37,359 --> 04:03:40,960 servo motor after this 7119 04:03:39,199 --> 04:03:42,640 you will be in a position to make robots 7120 04:03:40,960 --> 04:03:45,439 like a line falling reward 7121 04:03:42,640 --> 04:03:47,199 a robot which is capable of following 7122 04:03:45,439 --> 04:03:50,080 light lines over a dark background 7123 04:03:47,199 --> 04:03:50,080 or vice versa 7124 04:03:50,319 --> 04:03:53,439 you can also make obstacle of winning 7125 04:03:51,840 --> 04:03:55,359 robots 7126 04:03:53,439 --> 04:03:57,040 then you can make remote control cars 7127 04:03:55,359 --> 04:03:57,600 like this and once you get comfortable 7128 04:03:57,040 --> 04:03:59,359 with this 7129 04:03:57,600 --> 04:04:01,680 you can also make complicated robots 7130 04:03:59,359 --> 04:04:04,319 like a hexa port 7131 04:04:01,680 --> 04:04:04,960 like this which has several servo motors 7132 04:04:04,319 --> 04:04:07,439 used in it 7133 04:04:04,960 --> 04:04:08,880 right which is moving forward you can 7134 04:04:07,439 --> 04:04:09,680 also check out some posts at my 7135 04:04:08,880 --> 04:04:12,000 instagram 7136 04:04:09,680 --> 04:04:13,760 ashish underscore things and check out 7137 04:04:12,000 --> 04:04:15,520 some of my other projects as well 7138 04:04:13,760 --> 04:04:18,000 so i hope that you found this course 7139 04:04:15,520 --> 04:04:18,880 really useful to begin your journey with 7140 04:04:18,000 --> 04:04:20,640 arduino 7141 04:04:18,880 --> 04:04:23,760 thank you so much for your time and have 7142 04:04:20,640 --> 04:04:23,760 a nice day ahead 501390

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.