So today we will be building a project in which we will be communicating with arduino and python. In the previous video, we received data from the ir sensor of the arduino, but this time i am using a potentiometer. So by using the potentiometer i am going to adjust the volume of the computer. So lets start so. Im gon na continue with the code from the previous video, so here first lets. Do the connections because well have to change the connections of the rv. So friends, as you can see, ive turned on my camera, so first we will connect the vcc pin of the potentiometer to the vcc part of the arduino, okay yeah, then the gnd to the candy and then well connect the middle pin to it. So thats our connections lets come back to the code, oops Music, im gon na close, my camera app and now here now we are back in the code, so lets go to the arduino code, okay and rather than printing serial.printing, we will have to just print whatever We get from the potentiometer, so lets copy this same thing, ctrl c and then well create a new new sketch ctrl, a ctrl v done so now we dont need all of this code. Lets remove all of this. Just a second well have to remove here, backspace and now here we will see the potentiometer sensor, thats too big, so ill, say, pot sensor. Then we will say inch okay for end what sensor data, what and search data equals analog.

Oh guys, i forgot that the pin of the potentiometer, the middle one should always connect, should always be connected to an analog, pin. So sorry about that guys. Lets connect it to a0 and well change this to um a 0 0 analog read actually removing that a. I dont know if this makes a difference: okay partner equals zero in pawns area, then print um, serial dot, print Music sensor data sensor data guys. I forgot a second over here yeah and we change this to pot sensors port sensor. Okay, i think thats right lets run this save it as arduino python, see and uploading. None upload lets come to python and lets run this so friends before we run this. I have a suggestion, uh that i missed in the last previous video. We could say arduino data called cell dot, realign dot d code, so why we are using decoder is, as you can see here, theres like bytes and slack slash, r, slash, and if you want to remove all of this, you can just say dot decode and lets Run this now, it will be complete clean yeah, as you can see its coming from 1000 im gon na decrease this its decreasing. I think its from 100 to 1000, so guys um first lets stop this, and now, as we got our potential value, well, convert this to our volume value so well have to put some a few if statements like if our denote data is, is okay thats? What the data is, if greater than 100 100, like that um like yeah 10, well, adjust it to 10 and if its like in the one two like that.

Well, do like one thing like that. So 10 is like what it will set the volume to one and so on and so forth. Something like that. So how will we adjust the volume we install a package called biker? Oh yeah, so lets first copy. All of this oops ill control see this. You can see it will, if you create a bunch of airs its okay now lets install biker and then now all the errors are gone now lets remove this ctrl x and well paste it above space and yeah. This is what we need. This is all for. The setup part lets we dont need to remove this, but we dont need it to get mute. So lets see what this part and we need the volume lens. I dont think so. I dont want volume change, but we need volume, dot, uh, set master volume level. Now i dont know about this package that much i just got to know it now. So lets start, i believe, is 160 minus 65, something like that is 0 65.25. I cant remember so. Okay lets try running this. You cant get it to be accurate. Okay, lets do one thing, guys well say: if its greater than greater than 100 and lesser than 105, like 110 yeah lets, say that lesser than 100, then it will execute it str and it lets do this inch. Okay lets see arduino arduino data equals end and arduino data whats wrong, im friends – i i think well have to remove this time because its already in and theres no point in making it again.

Let me change this by to 200. Okay, oh i dont understand what to do lets. I think it will be the same, oh good, nice and why its not working is its already ive already set it to 100. Why should it be 100? I decrease the volume uh, so lets run this again somethings wrong again come on, but it was just working now lets try it again: oh it turned 200 guys. Did you notice that so yeah? Okay, as you can see, im putting here at least thats working lets see: okay, so on whats, the problem, its greater than 100 and lesser than 200 lets try it. Then why is it even though its about one thats one thing lets say and is lesser than then well do this? Why is it okay? I understand decrease this and it should not work. Yeah thats right its in physics as you as you can see it just increase the wall. You freeze it and change this now. Nothing happens and yeah Music. Now it wont uh Music, 100 yeah. It changed super. So this is how well do it guys? We will do like this for every single you know, volume so well be changing the volume by you know 10, so that will be good, so first ill search in google uh for all the volumes. Okay for zero uh lets do zero. We dont want zero Music whats, the volume or 10 in python Music Music.

I dont know how we can so guys um. As you can see, i just adjusted the code for it to work now like this uh. It took me a lot of time for to think of this idea, so now i want to show it to you. First lets come here: yeah and lets run it its okay. Now lets put this here now im gon na, as you can see it automatically came there. It kept the you know, potentiometer more than hundred, if one in arduino data and len of arduino data equals three, so its making sure that it is more than hundred or two in arduino data and len arduino data equals equals three, and i need one data dot Count equals equals 2, so its making sure that its lesser than 200 first, it will check the uh. How many digits are there and, if theres a two and then it will check how many zeros? If there are two zeros, then only it will do if its 201, it wont, do it so im gon na increase this completely yeah guys and lets see if this does it again, but i think its constantly changing and coming back to 100 yeah nothings changing its Right guys, as you can see, nothing is changing now, im gon na decrease it decrease yeah. As you can see, i just solved the problem and we just copy paste this 10 times, so it will become like from 100 and you know so on and so forth.

So friends in this video, i only wanted to show this part uh and the rest of the part uh.