LESSON 16: Controlling a Servo with Arduino

  Рет қаралды 244,510

Paul McWhorter

Paul McWhorter

Күн бұрын

Пікірлер: 223
@lanterrefanterre9600
@lanterrefanterre9600 3 жыл бұрын
Mr. McWhorter, let me tell you that you got me hooked ....... Fortunately, not to pin 9, but to your tutorials. They are great and easy to follow. You are a very good teacher. Would you please allow me to tell the guys who are too lazy (or too stù-pi-do) to follow your well explained math, that there is a 'map()-function' in Arduino. This 'map() function' re-maps any number from one range to another. The syntax of the 'map() function' is map(value, fromLow, fromHigh, toLow, toHigh). That is, a value of 'fromLow' would get mapped to 'toLow', a value of 'fromHigh' to 'toHigh', and values in between to values in between. To follow your example at 41:35: pos = map(potReading, 0, 1023, 15, 170). The only thing to keep in mind is, that the 'map() function' uses integer math so it will not generate fractions, when the math might indicate that it should do so. Fractional remainders are truncated, and are not rounded or averaged.
@josgrootaers1881
@josgrootaers1881 10 жыл бұрын
Sir McWhorter, thank you for this series of lessons. For me, they are by far the best Arduino tutorials i have seen so far. You are an excellent teacher. You explain things in a very clear and understandable way. You learned me a lot. I'm looking forward to see the whole series. Thank you, with greetings from Belguim.
@rbmnewton
@rbmnewton 5 жыл бұрын
Am on Christmas Long vacation now.... Spending the days in completing Paul's Arduino Tutorial... Life never had been more worthwhile in recent past ....completed Lesson 16 ,will complete the rest hopefully by first week of Jan'19...
@robsemuthu7802
@robsemuthu7802 4 жыл бұрын
Your channel is a best teaching Arduino channel. I wish you to stay safe. I wish you to get all the power of god to do new video's. T.D.Semuthu. Sri Lanka.
@akshithaashok9957
@akshithaashok9957 4 жыл бұрын
sir ,you are the greatest teacher of arduino in the world.i have tried so many tutorials but i didnt understand any of them,i have aldready watched 20 of your classes ,but dont have the materials for lesson 20 to 28 .looking forward to get the materials and start again from lesson 20 .thank you for such a good tutorial
@supersantahibiki7087
@supersantahibiki7087 7 жыл бұрын
WOW, after watching this video, i have to re-declare that "this world needs you paul!" it's has everythings i ever needed about sevors in this one amazing video!
@paulmcwhorter
@paulmcwhorter 7 жыл бұрын
Thanks for the kind words!
@sivaramarajusiv7826
@sivaramarajusiv7826 3 жыл бұрын
I like the passion of Paul for teaching.
@Casberu
@Casberu 9 жыл бұрын
Here are one more encouraging words! By far the most systematic and clear tutorial I have ever found in youtube, thanks, Paul! Will keep track on your channel.
@paulmcwhorter
@paulmcwhorter 9 жыл бұрын
Casber U Thanks!
@hughpatterson1480
@hughpatterson1480 2 жыл бұрын
That was a fantastic lesson. It's all in the details! As always, I agree that the math is crucial to understanding how to create real world projects. I am so glad you mentioned the quality of the servos that come with the kits because I've seen students spends days trying to correct their circuits and code when it's simply a bad or cheap servo. Thanks again Paul.
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Well said!
@rdoetjes
@rdoetjes 10 жыл бұрын
Dear Paul, you are a great teacher. I liked what you discussed at the end where your students need to think of an application for their newly acquired skills. I am an (software) engineer for 20 years and I have (and still am) working with some really gifted people even though I have gone freelance for the past 6.5 years. But I am a weird sort of engineer because I am also an artist (musician, mentalist/hypnotist and video producer). It was always through these fields of interest that I found applications for my engineering and computing knowledge. Most my engineering colleagues are great engineers (some probably better than I am) but they never think out of the box. When a problem arises that is not directly solved with their "trivial" knowledge they go like: "How do we do that? We can't do this or this or that?" Because I am no expert but a true alrounder I combine different pieces of knowledge from different fields to come up with solutions that are.. if I say so myself... unique. Especially in the magic arts when I consult magicians I have a bias for electronics because they are small hands of and can do marvelous things especially in combination with some sneaky magic methods. I adhere to Carl Sagan's saying that any sufficiently advanced technology will look like magic. The tech I use is mainly off the shelf but in the context that it is applied it is very sufficiently advanced.
@sureshchaudhari77
@sureshchaudhari77 7 жыл бұрын
neven built single circuit in life but you can teach anyone nicely thanks sir
@iamishu1
@iamishu1 5 жыл бұрын
Sir I made a project which feeds my fish when I say "Alexa , feed my fish " and the servo moves little bit and fish pellets falls down and servo goes back to its initial position where the pellets won't fall ..(I can also feed my fish from the webpage from any device too) Your tutorial helped me in understanding this very easily ...thank you so much and lots of respect...😊
@paulmcwhorter
@paulmcwhorter 10 жыл бұрын
@Jo Gro . . . thanks for the kind and encouraging words!
@abhisekgupta_
@abhisekgupta_ 6 жыл бұрын
Paul McWhorter Sir, why didn't we put pinMode(potPin, INPUT)???
@syedfariduddin8044
@syedfariduddin8044 4 жыл бұрын
@@abhisekgupta_ It should have been set as input, don't know how it worked.
@LHommeDeParfum
@LHommeDeParfum 4 жыл бұрын
Thanks for the clear information especially when you explain what the code you are writing is actually doing. Great video.
@dahlendo7513
@dahlendo7513 7 жыл бұрын
Sir, you are the best. Can you please make video on stepper motors. And please make more videos, we like your videos.
@russelj79513
@russelj79513 8 жыл бұрын
Hello Paul. Many thanks for your time, effort and thoroughness put into your presentations. They really are top class.
@MARKBASEBALL25
@MARKBASEBALL25 9 жыл бұрын
Thank you for taking the time to teach in a simple manner.
@hkhatri12
@hkhatri12 6 жыл бұрын
came through this 4years after it was made and still it is one of the best tutorial thanks for making it _/\_
@sameershaik6830
@sameershaik6830 8 жыл бұрын
I wanted to comment some praisals from heart for this fantastic work in teaching, but now i would just want to notify u that "I NEVER SAW COMMENTS LIST FULL OF APPLAUSE "like "i see for every session of ur series".no more words :D Thanx Sir.
@erygion
@erygion 5 жыл бұрын
Great lesson Mr. Mcwhorter. I've gone through basics but this is in depth and it really helps in mastering the craft. Those equations are very handy, sadly I used to just "wing it" but not anymore! Thank you sir, you're an excellent teacher. 💡♾💡
@michaelcostello6991
@michaelcostello6991 4 жыл бұрын
Excellent demo and code. Would be nice if you did an electronic course specifically linked to or related to your micro controllers courses. I mean designing basic electronic circuits and interfacing with arduino etc etc. Not sure exactly whats needed. But some real world applications like you currently do so well. Thank you.
@halservices
@halservices Жыл бұрын
Write a program in Arduino to do the following: 1. Add an LED that increases brightness as the servo angle approaches 0 degrees and dims as the angle approaches 180 degrees. he LED should be dark at 180 degrees and full brightness at 0 and fade evenly over the values in between. 2. Rotate the servo 90 degrees if the output voltage from LDR is greater than 20 V. 3. Use a for Loop to find the Sum of 100 Random Numbers. Then find the Average. The Sum and Average should be written to the Serial Monitor 4. Using the 4 LEDs, write a sketch where the LEDs operate in 2 different modes. 1 where all LEDs are off except for the one that is ON, the other mode is where all are On except for the one that is OFF. Let the user set the speed by serial and mode by using the button.
@utubefrog09
@utubefrog09 7 жыл бұрын
You are an amazing teacher, I wish the professors in my university was half, heck a quarter as good. I am really hoping you would make some other set of videos on other programming languages, that would be great(hint, hint). Anyways, thanks a world for what you're doing.
@Telboy-fv8ke
@Telboy-fv8ke 4 жыл бұрын
Excellent video as always, I have same problem as Shaun Somaru below, When entering a value it moves to point then returns right away???
@radhakrishna.kalluri7192
@radhakrishna.kalluri7192 2 жыл бұрын
Great lecture professor....
@Steven-jf4cs
@Steven-jf4cs 6 жыл бұрын
Sir, outstanding series! May I make a recommendation of a tutorial please? At minute 3:44 you discussed attaching an external power source to the Servo (or anything else needing controlled) and retaining the Arduino as control (white line). Could you create a tutorial(s) that demonstrates how to control a large motor? e.g., 120v vacuum cleaner motor or blender motor, etc... Either way - thanks for not only this series but all the fine work you've put out for you students whether in class room or not.
@lindascoon4652
@lindascoon4652 5 жыл бұрын
36:04 what happens in math class stays in math class 😄. Thank you so much for your videos.
@RishabhSingh99
@RishabhSingh99 7 жыл бұрын
amazing tutorials... by far its the best and most recommended tutorial series for Arduino Beginners. Step by Step basics explained in best details. Thank You Sir for providing such great material, internet needs guys like you to avail info to students and make self-learning from internet easier. i would request to add few videos on Using 9DOF Gyroscope Accelerometer, taking inputs from them and few other switches/controllers. also can you suggest, how to develop independent software for Microcontroller related projects, such as if i want to get a Visual Feedback from Gyroscope and Accelerometer marking the positions in Coordinate Space, or getting the EMG shield visual feedback. (basically how to make Graphical User Interface software for my projects)
@paulmcwhorter
@paulmcwhorter 7 жыл бұрын
Making a visual display from raw data from 9-axis sensor is a pretty hard job. Look at the Pololu 9-axis. They have software that runs on V-Python that will do the visualization. I have never made a series on this topic because the math gets really hard, and I sort of understand it, but not well enough to explain to someone.
@halservices
@halservices Жыл бұрын
Write a program in Arduino to do the following: 1. Add an LED that increases brightness as the servo angle approaches 0 degrees and dims as the angle approaches 180 degrees. he LED should be dark at 180 degrees and full brightness at 0 and fade evenly over the values in between
@McGavel1
@McGavel1 8 жыл бұрын
Cool stuff - thanks again for sharing the info. Got the potentiometer to dynamically adjust the servo as I turn it back and forth through the range I found for the servo. It turned out that my SG90 can go 0-180, so that was cool. I'm gonna get some pulleys and play around and also see about powering it with solar since I've been learning about solar power lately. Thanks again - peace.
@stephenvowles1326
@stephenvowles1326 8 жыл бұрын
Koolamundo!!! Used this to set up two servos on a webcam to control pan and tilt. Thanx Next is a plant waterer that uses sensor and servo to open a valve.
@shaunsomaru9520
@shaunsomaru9520 5 жыл бұрын
Sir , thank you for the clear explanation in the tutorial. i have a problem though. When i insert a value in the serial monitor , for example 45, the servo will move to that position and then move back to zero , It would not stay in the position that i insert. how do i change that? i have typed out your code exactly.
@Telboy-fv8ke
@Telboy-fv8ke 4 жыл бұрын
I have same problem, Did you sort it?
@alexmachado3176
@alexmachado3176 5 жыл бұрын
Looking for some help please. Using and Arduino, servo and a momentary switch, I want to control the servo by pressing momentary (button or magnetic switch) and having the servo travel certain amount of degrees. For example press once 20deg, press again 80deg and back and forth every press in that same angle of rotation. I have not been able to find a tutorial on this so any guidance would be much appreciated.
@bilboechtste
@bilboechtste 5 жыл бұрын
insanely useful video! thanks
@kevchef
@kevchef 3 жыл бұрын
this is a great lesson in coding for me, I'm starting off tinkering with Arduino boards. I have a question - The main bit of code : "pos = (155./1023.)*potReading +15" why did you not just put "0.15151515" instead of "(155./1023)" wouldn't - letting it know the calculated value - save on some processing time, memory and resources? Rather than giving the processor an extra job to do? or is there a reason why you wrote the code that way to make it more efficient?
@Ed.R
@Ed.R 8 жыл бұрын
Thanks for the great lesson. I'm using this setup to electronically shift the NuVinci hub on my bicycle. Will be watching a few more of your videos. I want to automate the shifting by getting the Arduino to monitor crank and wheel rpm.
@TheProCactus
@TheProCactus 8 жыл бұрын
+Ed R (Oran) This is also something I would like. I have been thinking of the concept for a few years now. I never have built anything towards it though. I just spent more than a few hours wondering how it would react and how would it interface to humans and non-humans :D. And what kinds of behaviors would make it seem intelligent. I would love to do the logic for it. But building it, I NEED to know and understand a bit more than logic.
@Ed.R
@Ed.R 8 жыл бұрын
+TheProCactus I'm thinking about keeping it reasonably simple. What I'm aiming for is to turn the potentiometer from a ratio selector, which it currently is, to a pedal rpm selector. The Arduino needs to monitor the crank rpm and if its higher than desired increase the gear ratio, if lower decrease ratio. Making it work in real life situations is going to be a little more complicated. I've got all the mechanics worked out I just need to understand how to write Arduino code and logic it will understand.
@TheProCactus
@TheProCactus 8 жыл бұрын
Ed R Id like it to be fully automatic. Id have 3 or 4 different automatic modes. They all pretty much involve knowing the torque in the chain. ha, I just rememberd a while back I saw an electric derailer. It wasent automatic, it had buttons. But anyway, Good luck with it
@locothenos9658
@locothenos9658 8 жыл бұрын
By far the best Arduino To servo connection lesson I've seen on KZbin! Can I use your lessons as foot notes for my projects? Great work and all the best! Take care!
@rkprashanth
@rkprashanth 3 жыл бұрын
Sir, in the last of the video, while connecting the potentiometer, you calculated the equation of line. Instead of calculating, can we use the map command directly to control the servo by potentiometer?
@HammockerSam
@HammockerSam 7 жыл бұрын
Very helpful. I appreciate your work
@joescopo8933
@joescopo8933 Жыл бұрын
Is there no need for a "pinMode" in the void setup for the potentiometer?
@briangraham910
@briangraham910 Жыл бұрын
Why do you use a library object for a servo but not, for example, the color sensor from the previous lesson?
@evyta37
@evyta37 8 жыл бұрын
Seriously Paul , you are an amazing teacher. I just got at the college to learn some arduino and I was feeling dissapointed because the classes there are not clear at all.Watching your videos give me alot of help. I dont know if you please can give me and idea about the four display seven segments and how do they work with arduino. Especially working with arraya is a part that confuse me a little bit. I will really appreciate your help.
@zainarabi8978
@zainarabi8978 4 жыл бұрын
I'm trying to do the programming for just setting the servo motor to a certain degrees and have had to restart the program several times but it just keeps going back to its original spot after i move it
@Nosvenicar
@Nosvenicar 4 жыл бұрын
I'm a bit late to the game, and I've been enjoying your videos. Was just curious if the map () function would be appropriate instead of calculating the slope by hand? int potReading = analogRead(potPin); pos = map(potReading, 0, 1023, 15, 170);
@webslinger2011
@webslinger2011 4 жыл бұрын
Works also.
@gerardvanderheide76
@gerardvanderheide76 7 жыл бұрын
Great Paul..........as a newbie its very nice tutorial. What about connecting rtc and lcd to set times to start multiple loops?
@e6530C
@e6530C 4 жыл бұрын
Great Videos, But, I went to your site and Lesson 16 didn't have schematic or the Code, Please Advise, Thanks
@akhilareddy4860
@akhilareddy4860 6 жыл бұрын
Sir, why pinMode (potPin ,INPUT) was not included in void setup( )?
@joeymonstaman
@joeymonstaman 5 жыл бұрын
That's a good point. However, it seems like it worked without it. I guess there's either no point, or he did something else to substitute for that.
@petercorbett1610
@petercorbett1610 8 жыл бұрын
Hi Paul, once again great teaching a pleasure too follow. I have two servo's SG90 - one is marked Digital and the other Analog , which one should i use fro this lesson, and what is the difference? Thank you Peter
@ciceromaia
@ciceromaia 7 жыл бұрын
Hello Paul McWhorter, how do I record the positions of the servo, to reproduce later, I really liked his explanation, so I came to this doubt, grateful for the attention.
@richardstiers9010
@richardstiers9010 3 жыл бұрын
Paul for some reason my upload will not get past 'while' in the coding is does not turn orange an an error message says it expects something before it...as a result cannot load.??
@stefanb.933
@stefanb.933 8 жыл бұрын
Hello. I want to make an project and i cant handle it. I am interested in the code at the 30:30 of the video. In the code i have this command: if(digitalRead(8)==HIGH) { for (pos = 0; pos = 0; pos -= 1) { myservo.write(pos); delay(2); }} There in the moment when the command is "HIGH", the servo make the movement permanent ..i am interested that at the command "HIGH", that the servo to make the move only once how long the statement "HIGH" is during...,after if the command its again "HIGH",again to make only once the move, not permanent.Thanks
@ruben4739
@ruben4739 9 жыл бұрын
Great tuturials! Keep up the good work!
@TRfromTO
@TRfromTO 7 жыл бұрын
Great series Paul. Got a question re Arduino UNO. I'm working with a Hobbico Command CS-61 servo ... trying to establish the range. All works well except that within seconds of responding correctly to various angle inputs, it reverts back to approx. zero. Every time. The voltage at pin 9 drops too. I expected that once established, the pin 9 voltage would stay until new command. No improvement with battery power. Any thoughts?
@sivaramarajusiv7826
@sivaramarajusiv7826 3 жыл бұрын
I think Serial.available(), function is not for waiting until the serial port is ready. But it is far more likely that the WHILE will empty the buffer even though only part of the data has arrived.
@tensor131
@tensor131 5 жыл бұрын
Hi Paul .. another great video, thank you. I am a newbie - this is the first time I have ever touched a servo!! Can you advise me, please, on an issue I have, which I have googled and got nowhere. My SMRAZA starter kit has an SG90 servo .. looks identical to yours. I ran the test the range sketch and it accepts 0 to 180 without any jitter, BUT 180 looks more like 170 (maybe less, I do not have a protractor to hand being on hols!!). It's not that it is going over range; write(170) puts it in a position and write(180) rotates it further (no jitter) so this seems to be either an accuracy issue or somewhere in the code (library?) there is a scaling factor that I need to set. If I write anything over 180 there is no further rotation (and no jitter .. it seems like it simply cuts off at 180?). Any ideas please?
@vishalkrishnan1644
@vishalkrishnan1644 4 жыл бұрын
I hav a doubt why didn't you use that pinmode to declare potentiometer as an input?
@ahmedhafez5859
@ahmedhafez5859 8 жыл бұрын
hi Mr : Paul McWhorter i need to ask you why we don't define the Potentiometer pin as pinMode(INPUT);
@treelight1707
@treelight1707 6 жыл бұрын
If you haven't figured it out yet. I think the analog pins are always input.
@astro_1859
@astro_1859 6 жыл бұрын
Ahmed Hafez it because whenever you want to do something on input like potentiometer you have to input so analogwrite is needed And on output you have write digitalwrite
@CiscoSaeed
@CiscoSaeed 6 жыл бұрын
it's written on the board Analog IN, the Digital could be input or output.
@amineyouyou5935
@amineyouyou5935 4 жыл бұрын
why you didnt write pinMode( potpin.INPUT); in void setup() in this programme sir ????
@TheProgramwizard
@TheProgramwizard 7 жыл бұрын
Sir I have a problem with the servo project where you made it go up and down continuosly. I tried it myself and wrote the for loop and uploaded it so I think the code is fine but the servo completes one loop and the after that the arduino gets disconnected from my PC automatically saying that board at COM3 is not available
@aakash512
@aakash512 7 жыл бұрын
hi Paul I have a problem using servo library with virtualwire can you suggest a solution
@DataWiseDiscoveries
@DataWiseDiscoveries 5 жыл бұрын
And it worked finally, thanks for this video
@pronobroy8389
@pronobroy8389 8 жыл бұрын
Sir I have MG996R servo so what would be the correct way to connect that with Arduino?
@christmasdreams1
@christmasdreams1 8 жыл бұрын
Any chance you have plans to discuss controlling the speed of rotation of servos without using a "for loop" ? I always try to incorporate acceleration and deceleration in my movements and using for loops with those features is very tedious and cumbersome. Perhaps the answer lies in Object Oriented Programming ?
@Firas95k
@Firas95k 8 жыл бұрын
I really appreciate your work thank you very much
@faizurrahman2399
@faizurrahman2399 5 жыл бұрын
Hello sir! I make a humanoid leg using servo and for rotation i use for loop. But my problem is that when i connected lipo with servos, they move abnormally for 1-2 second after that they go to their programmed position and if they already in programmed positon after on the lipo they move from their position for a few second. How can i fix this?
@yangyuan3288
@yangyuan3288 5 жыл бұрын
I really like your tutorials and I also want to build a website in China and teach students who are interested in arduino just like your website techboy , and I am wondering how you build your website ,can you give me some advices.hope you can reply me.
@saptangshumanna9919
@saptangshumanna9919 7 жыл бұрын
How to do it if I don't want to use the library. And I wanted to know that in the program 1 you have already assigned pos to 0. Why?? After that you assign the value to it given by the user.
@HalfwayAerial
@HalfwayAerial 5 жыл бұрын
I followed your code exactly up to the 24 minute mark. when I tell my servo to go to a position it moves to the position for about a second and then returns to 0. How do I get it to hold the position?
@lawrencemao6519
@lawrencemao6519 7 жыл бұрын
Does this tutorial apply to continuous rotation servos? I ran the code and inputed 45 like you did, but it just circled around.
@naboulsikhalid7763
@naboulsikhalid7763 8 жыл бұрын
perfect traing from generous Man. Mr McWohorter
@rtdave6982
@rtdave6982 7 жыл бұрын
Great work Paul! Is there a way to see the servo library code?
@rocket6786
@rocket6786 7 жыл бұрын
you can view it by exploring the arduino folder!
@multitech1719
@multitech1719 6 жыл бұрын
Hello Sir, Pls how do i use the servo in a robotic arm movement or control. What other component do i need?Thanks in advance.
@YourLifeWasting
@YourLifeWasting 5 жыл бұрын
I had a neat idea while using the potentiometer and the servo what if while you turn the potentiometer the RGBLED turns different colors as well
@-thesmartboard8984
@-thesmartboard8984 5 жыл бұрын
I am going to buy a Servo Motor For RC Robot Helicopter is it suitable for this project ?
@preritpradeep
@preritpradeep 9 жыл бұрын
sir McWhorter,thnx for the tutorial.Learned a lot from it. However,cant we use the map function provided by arduino,to map the range of values of potentiometer and the range of our servo motor?
@paulmcwhorter
@paulmcwhorter 9 жыл бұрын
Prerit Jain I am trying to teach students to recognize and use the math they have learned in Math class. Yes, the map function will work, but I am trying to get them to use their math skills.
@preritpradeep
@preritpradeep 9 жыл бұрын
Okay Thank you sir :)
@tlaim
@tlaim 7 жыл бұрын
Hello, i realize this is an old video, but i've watched most of the others and learned quite a bit. I noticed on this code sample you didn't declare A0 as an input, but we did with the Pot lesson, is there any reason why? I tried it both ways and it didn't seem to matter. I know if i don't declare an output the arduino acts weird so i'm curious.
@UnoVato
@UnoVato 7 жыл бұрын
Chris Ortiz I read somewhere on the arduino page that the pins are set as inputs by default.
@aayushlakkad9241
@aayushlakkad9241 4 жыл бұрын
Sir, How do I control 2 servos in a single program? I tried making 2 servo objects and defined positions for both of them! but it didn't work out. It just moves a single servo not both!
@boowonder888
@boowonder888 5 жыл бұрын
I put in the code and it works but my servo returns to its start position everytime after i input "pos". Strange cause there is no code telling it to do that. Anyone know why that is? In the vid the pointer just stays at "pos".
@TheProCactus
@TheProCactus 8 жыл бұрын
G'Day. This is the first video I watched from you, Ill will be watching more. I like the slow pace, I can do other things while watching a series of connected concepts made real. I do however have some very slight criticism. The damn mouse pointer. Is there some way you can make the pointer disappear. Its a pet hate of mine to have a mouse cursor over any text or video. Myself is in a habit of pushing the mouse to the right side, Even sometimes I forget when I fullscreen a video and get in bed. Get comfy and there is a giant white triangle covering someones face. LOL Cheers. I look forward to watching more.
@dezzodarling
@dezzodarling 8 жыл бұрын
How do you control the speed of rotation ? I have read in the forum that there is a new library ? "delay" only tells it the interval between each step, not the speed of rotation! Thanks
@alejandroperez5368
@alejandroperez5368 6 жыл бұрын
You didn't watch the video... you can increase the speed by shortening the count-up of the for loop.
@mlutteral
@mlutteral 8 жыл бұрын
you could use the map() function to map the output of the potentiometer, something like map(0,1023,15,170);
@Lukabrazi69
@Lukabrazi69 5 жыл бұрын
I actually did that way. Much easier and less math :) here's the code. It also shows the degree to which Servo is turned on the screen. #include //Loading the servo library int pos=0; // Declare and initialize the pos variable. int servoPin = 9; //Servo pin hookup place int servoDelay = 10; int potReading; // Declare variable for potentiometer reading int potPin=A0; // Connect potentiometer to pin A0 Servo myPointer; // Create a servo object called myPointer void setup() { // put your setup code here, to run once: Serial.begin(9600); myPointer.attach(servoPin); } void loop() { potReading = analogRead(potPin); //Read potentiometer potReading = map(potReading, 0, 1023, 0, 180); //convert potentiometer reading to 0-180 degrees for Servo pos = potReading; // Calculate position myPointer.write(pos); // Write position to servo Serial.println(potReading); // Display the degree of turn }
@mechatronicsevolution1624
@mechatronicsevolution1624 5 жыл бұрын
With the new arduino ide 1.8.9...my serial.available() isn't working properly in the loop... It gives me the option to input a value... Turns the Servo motor then reads the serial message again, bypasses the serial.available() ==0 and takes value of pos as 0...Servo back to initial position.... Then I'm given again the input message and I can input value for pos again because serial.available works this time... I'm not sure what's wrong... Can you please retry this sketch with the new arduino ide?
@paulmcwhorter
@paulmcwhorter 5 жыл бұрын
Make sure your serial monitor is set to no line ending
@mechatronicsevolution1624
@mechatronicsevolution1624 5 жыл бұрын
@@paulmcwhorter thank you very much sir
@boowonder888
@boowonder888 5 жыл бұрын
After watching this vid many times, I know that the servo is supposed to return. But stii see no coding for the returning. Can you put the signal pin of the pot in a digital pin instead of Ao?
@tbinarab
@tbinarab 7 жыл бұрын
Thanks u make it easy and very cleared thanks again
@GK-ud8dv
@GK-ud8dv 3 жыл бұрын
When I try to run this code I get a function definition is not allowed here before "{" token .. I have contrl-T'd a million times and tried every possible combination of brackets ... HELP !!
@saidoungaide804
@saidoungaide804 5 жыл бұрын
Dear Paul, thank you for these great videos, I am learning a bunch. I have been experiencing some issues when uploading the data into the Arduino, I hope you could help me fix this soon. I can't move on while the error is still there. This is the error: Sketch uses 3214 bytes (9%) of program storage space. Maximum is 32256 bytes. Global variables use 267 bytes (13%) of dynamic memory, leaving 1781 bytes for local variables. Maximum is 2048 bytes. Thank you!
@BalajiAddankiVidEd
@BalajiAddankiVidEd 7 жыл бұрын
Sir, can you please tell me how to know, what are the things in those lib files and how they are useful?????
@RetroRobotRadio
@RetroRobotRadio 8 жыл бұрын
How about connecting the servo to a piece of paper that shades a photoresistor. So the brighter the light becomes, it sends the signal to pull the shades. If it becomes too dark, it opens the shades.
@bubunmazumder
@bubunmazumder 8 жыл бұрын
You are on this project?
@mcvoid4971
@mcvoid4971 4 жыл бұрын
please make a video on how to hook it up
@kankannx5072
@kankannx5072 7 жыл бұрын
Hi Paul will you make a lesson about Gyro control
@ernminpeck
@ernminpeck 6 жыл бұрын
If I am using a digital servo is there a difference in the code?
@bhargavpatel1357
@bhargavpatel1357 5 жыл бұрын
In this program (Last modified program at-43:00 minutes) u can't define Input PinMode for Potentiometer in VOID SETUP () but program still working without any error How it's possible
@mechatronicsevolution1624
@mechatronicsevolution1624 5 жыл бұрын
Hey there, are you using the 1.8.9 arduino ide?... If yes, is your serial.available working fine?
@sundaramahalingamv4297
@sundaramahalingamv4297 5 жыл бұрын
Dear Sir, I have faced a problem in Servo position control, Plz find the below code #include //Load the servo Library int pos = 0; // variable to store the servo position int servoPin= 9; //Servo is hooked to pin 9 int servoDelay=25; // 25 millisecond delay after each servo write Servo myPointer; //Create your servo object. I call mine 'myPointer' void setup() { Serial.begin(9600); myPointer.attach(servoPin); // attaches the servo myPointer to pin servoPin, which should be pin 9 } void loop() { Serial.println("Where would you like to position the Servo?"); //prompt user for position while (Serial.available()==0) {//wait for user input } //Serial.print(pos); pos=Serial.parseInt(); //read user input into pos Serial.println(pos); { myPointer.write(pos); //set servo position to pos delay(servoDelay); // waits 25ms for the servo to reach the position } //Serial.flush (); } in above code even after i give serial flush - the servo returns to the 0 degree position - it's not stop in intended angle position that is the loop will break another one time & returns the servo to zero poition the output: Where would you like to position the Servo? 180 Where would you like to position the Servo? 0 Where would you like to position the Servo?
@steveng9911
@steveng9911 5 жыл бұрын
got same problem if i find out all let u knw
@RobertJessup
@RobertJessup 4 жыл бұрын
set no Line End on the serial monitor
@burakayan3360
@burakayan3360 4 жыл бұрын
my servo doesn't stop at point where i want him to stay. it makes an angle but then it turns back to initial position. which is 0 .
@siaulanh
@siaulanh 2 ай бұрын
if your servo keep going back, on the serial monitor change "new line" to "no line ending".
@Hamzakhan1o
@Hamzakhan1o 4 жыл бұрын
i cant find this lesson on toptechboy.com
@91722854
@91722854 7 жыл бұрын
are there any ways to tweak cheap servo to go full 180 degree range like an expensive one?
@paulmcwhorter
@paulmcwhorter 7 жыл бұрын
No cheap servos are going to be jittery and not have good range. Worth the investment to get a good servo.
@gvet47
@gvet47 5 жыл бұрын
@@paulmcwhorter I have purchased cheap servos for RCPlanes and when tested every one has always turned 180 and returned . Was your supply voltage lower than it should be as that can do that.
@davidhristu6742
@davidhristu6742 6 жыл бұрын
Hey, everyone I need help, I tried doing the same thing will a Arduino Nano and a Hi-tec HS-402X and every time after I upload the program, the servo just rotates continuously in a clockwise direction until it hits the physical maximum the servo can go and then just gets jammed in there until I power off the servo. Can someone please explain why this happens and how to fix it? I`m doing it exactly like in the video. I have also researched how to fix the problem with "writeMircoseconds" command but it does the same thing. Paul, if you could reply to this I would really appreciate it and I can provide you more details if needed Thank you
@yamrajoli3834
@yamrajoli3834 4 жыл бұрын
hlo sir I want to make the baby cradle, so i have no idear how to write a code can you explain it
@OliveRC-Addict
@OliveRC-Addict 7 жыл бұрын
thanks for this lesson
LESSON 17: Measure Speed of Sound with Arduino and Ultrasonic Sensor
27:03
Mastering Servo Control: PCA9685 PWM Driver with Arduino Tutorial and Demo
7:50
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 14 МЛН
Walking on LEGO Be Like... #shorts #mingweirocks
00:41
mingweirocks
Рет қаралды 6 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 53 МЛН
Человек паук уже не тот
00:32
Miracle
Рет қаралды 3,9 МЛН
Electronic Basics #25: Servos and how to use them
5:55
GreatScott!
Рет қаралды 953 М.
Positional vs Continuous Rotation Servo Motors
6:48
Science Buddies
Рет қаралды 89 М.
Using Servo Motors with Arduino
43:06
DroneBot Workshop
Рет қаралды 1,4 МЛН
Arduino Basics - Lesson 12 - Using buttons to control a Servo motor
12:04
Smooth control of servo motors and drive
18:17
Sam Wane
Рет қаралды 9 М.
How to Control a 12V Motor with Arduino: Easy Wiring & Code Examples
44:13
I Made The Ultimate Cheating Device
9:39
ChromaLock
Рет қаралды 1,4 МЛН
Basic Arduino Servo Control for Model Railroads
19:55
DIY and Digital Railroad
Рет қаралды 15 М.
Big Stepper Motors with Arduino
29:43
DroneBot Workshop
Рет қаралды 1,2 МЛН
How to test Servo motor with 3 channel Cheap Servo Tester
7:53
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 14 МЛН