This video is incredible! I was wanting to learn how to do exactly this for months now and this video helped me out so much, thank you!
@johnlake63212 жыл бұрын
This is exactly what I needed to control the cueing and auto lift for my new turntable build. Thank you.
@Dilpreet_Singh59113 жыл бұрын
Thanks sir I really appreciate that clear explanation.Your channel should get more attention!!!!!!
@CodeWithConner3 жыл бұрын
I appreciate that! Hopefully someday it will :)
@carlhenry5153 жыл бұрын
This explanation was perfect. I was even able to modify the loop function to incorporate 3 buttons, and also create a loop that moves the Servo to a specified angle, thanks for your help! Here's the code I wrote under the loop function: void loop() { int button1State = digitalRead(button1); int button2State = digitalRead(button2); int button3State = digitalRead(button3); if(button1State == HIGH && servoPosition = 0) { myservo.write(servoPosition); servoPosition = 0; delay(100); } else if(button3State == HIGH && servoPosition >=0) { myservo.write(servoPosition); servoPosition = 180; delay(100); } } The only problem I have with this is that regardless of which button you press first, you have to press the second button that sets it back to angle '0' right after, otherwise the Arduino won't move the servo anywhere. Will have to play around with the if and else if statements a little more, none the less, great lesson!
@CodeWithConner3 жыл бұрын
Nicely done! With your code the way it is. Once you press button3 you’re stuck at 180 until you press button1. As the other two buttons have if statement conditions that can’t run at a position of 180. I hope that helps a bit. Keep it up :)
@julietamolina42722 жыл бұрын
You just saved my semester with this code, literally. Thank you so much
@joescopo89333 ай бұрын
Can you do pinMode INPUT_PULLUP for the buttons instead of using resistors?
@MarcSundermeyer5 ай бұрын
I am trying to find a configuration and code that only uses one button. On press it rotates, but on release it returns to the home position.
@tazcurrier21933 жыл бұрын
OK, i HAVE BEEN ABLE TO DO THIS, HOWEVER, WHAT IF i WANT TO HOLD THE SERVO, IN EACH POSITION? SAY, i PUSH THE LEFT BUTTON, AND, THE SERVO MOVES TO 60 DEGREES, STOPS, AND HOLDS POSITION, UNTIL COMMANDED TO MOVE, BY THE RIGHT BUTTON? SAME THING WITH THE RIGHT BUTTON. I WANT IT TO MOVE TO 160 DEGREES POSITION, STOP AND HOLD THERE, UNTIL COMMANDED TO MOVE. HOW WOULD YOU CODE THAT? THANKS!!!
@jameshank55816 ай бұрын
Hey is it possible to duplicate the code in order to control multiple servos with multiple buttons?
@kenzodesandrokusuma36493 жыл бұрын
Amazing tutorial!!! when I want to make a project I search on youtube do the wiring and code it, but sometimes some videos have a link to copy the code, but I love this one that doesn't need to copy paste a code, and its easy what mistake I made and it was a short coding so it's simple for me! (but sometimes when the video has a link in the desc for me it means that the code is too long). But amazing simple project for beginners
@DatFunnyPerson6 ай бұрын
Why do we need resitors? And do those kind of buttons always need voltage, ground and a pin? Even if I use it on a Ada fruit soundboard for example?
@malcolmrobinson20553 жыл бұрын
Conor , I would like to use a PCA9865 , have you any videos on how this would work rather than a direct feed form ardiuno board ...i want to move the servo to preset positions depending on a feed from a toggle switch ..
@CodeWithConner3 жыл бұрын
So I haven't done a project video with a servo breakout board like this, but they are awesome. This site has a ton of good info on setting one up though: learn.adafruit.com/16-channel-pwm-servo-driver?view=all
@marklaslett96132 жыл бұрын
Really loved your video. Great teaching style. I understand the coding. Have typed in code, checked and checked, but when I compile, after : else if(button2State == HIGH) && servoPosition >=0 //else if we are over 0 button 2 is on" get "expected ";" before "{" token. Can't see the error!. Frustrating
@CodeWithConner2 жыл бұрын
Can you paste the whole if/else if blocks of code here or email them to me codewithconner@gmail.com
@marklaslett96132 жыл бұрын
@@CodeWithConner here it is if(buttonState == HIGH) && servoPosition =0 //else if we are over 0 button 2 is on { Servo1.write(servoPosition); //write current position servoPosition--; //subtract 1 to position delay(5); //delay 5 ms }
@kataramanN162 жыл бұрын
Can you please tell me the code for when i pressed the two buttons together then the servo goes to 0 ??? i loved the tutorial from your video...keep up the good work!!!
@CodeWithConner2 жыл бұрын
Email codewithconner@gmail.com and I can send you solution code.
@B16Dominoes2 жыл бұрын
Thanks for the tutorial. I subscribed
@timberhoff Жыл бұрын
deserves a subscription!!
@nicedaymovie94111 ай бұрын
Hello, I would like to build a similar circuit for a model car (mechanical transmission). It should be operated with 2 buttons (up/down). Each time you press the button, the servo should adjust by 10 degrees (or another defined number of degrees). Neutral = 0 position 1st gear = one down Neutral = on up 2nd gear = one up 3rd gear = one up 4th gear = one up The entire transmission should then be switched up (UP) and down (down) using 2 buttons. It would be great if the “UP” button also had the function if you switched it to its 0 position (neutral) for 3 seconds. I would be very grateful if you could help me with this. Thank you. Greetings Hans
@ninodeceuster21462 жыл бұрын
hey hey, I used your code and it works perfect! but I want my servo to turn slower. How do you have to change this code so that the servo will turn slower, because it is going quite fast now?
@CodeWithConner2 жыл бұрын
The easiest way would be to just increase the length of the delay inside the if/else statement in your loop function where you increment/decrement the servoposition variable.
@Rchee3 жыл бұрын
can i use this without a resistor
@CodeWithConner3 жыл бұрын
You COULD but you'll likely get erratic button behavior. Read this for a bit more insight: create.arduino.cc/projecthub/muhammad-aqib/arduino-button-tutorial-using-arduino-digitalread-function-08adb5
@michaelauth89363 жыл бұрын
How would the code be different if I wanted to press a button and the servo rotates so that I don't have to keep holding the button?
@CodeWithConner3 жыл бұрын
Basically, in the code below, where we increment servoposition by 1, you would instead send it all the way to position 180. Or if you want it to sweep the other way in the else statement, send it to 0. We were iterating by sending it one degree at a time. Be sure to increase the delay if you do this otherwise you'll get a LOT of HIGH reads on the button before you actually let go of it. if(buttonState == HIGH && servoPosition
@n70tonka8 ай бұрын
tried to compile sketch and this is coming up Compilation error: 'Servo1write' was not declared in this scope i have tried fixing it with no luck . help please.
@samarsamir14892 ай бұрын
mines did not work i did the same coding same curcuit please help
@jomfawad92556 ай бұрын
is it possible to make servo move in loop fron 0 to 180 and when i click button the servo stops at its current position? or not possible without position feedback? thank you
@christianpatterson13 жыл бұрын
What software do you use for your wiring diagrams?
@CodeWithConner3 жыл бұрын
Most of them I do with tinkercad circuits. But some I had to use fritzing.
@ananta88373 жыл бұрын
So, what if I want to use 3 buttons with 0, 45, 90 degrees each button, sorry if my question seems lazy to try, just curious and currently I don't have an arduino
@CodeWithConner3 жыл бұрын
This would be pretty straight forward. When a buttons read value is high, set the servo to the desired angle. Repeat for multiple buttons.
@ananta88373 жыл бұрын
@@CodeWithConner thanks for the answer man, appreciate it 🔥
@dragoOgnjenovic5 ай бұрын
Your teaching is great, but I have 0 skills (too old) for writing a code. I can develop the application and hardware, but not write the code. I really wish I can! I am wondering if you can help me with very short Arduino code for Servo motor?
@Rchee3 жыл бұрын
hey ive got a question... Great video btw: I want to control my servo so when i press a buttondown it rotates 180*. But then when i stop pressing it, it goes back to 0*. i tried altering your code but i cant figure it out
@CodeWithConner3 жыл бұрын
Shoot me an email: codewithconner@gmail.com with your code and I'll see if I can help
@yamanidemabildo97243 жыл бұрын
hello sir Conner... i have followed the code you have written and i modified some of it for the application of my project.. I've built a pingpong robot and i planned to use a servo motor on the panning. i want to control the servo with 6 buttons each have different angles to perform on the servo. The first time i uploaded the code to my arduino it worked very well, but later i have encountered a problem.. when i turned on the arduino the program will automatically run, executing the program on either of the buttons. please note that the buttons are not yet pressed.. please help me sir...
@CodeWithConner3 жыл бұрын
Shoot me an email to codewithconner@gmail.com with your code and I can have a look for you. No promises but I'll try and help.
@Toxicblackmambahs3 жыл бұрын
Very good tutorial, instant subbed.
@CodeWithConner3 жыл бұрын
Awesome. Glad to have you :)
@danshah_kz64203 жыл бұрын
Hello sir , my question is .. when servo move to 1°-180° and i want it delay for 5s .. after that automove back to 180°-1° .. each button has a same instruction but the different is value of angle movement servo.. so how the code sir? Please reply n help me to solve this problem. Tq
@CodeWithConner3 жыл бұрын
If the only difference between the button is the speed of the movement, basically the first if statement would do a full sweep from 0 - 180, delay 5, then sweep back to 0. The "sweep" would be a for loop that changes the servo angle and writes it however many times you want. The finer/smaller the angle adjustment each time the slower/smoother the movement will be.
@bretandrews85222 жыл бұрын
Code didn't work for me. #include int buttonPin = 4; int button2Pin = 7; int servoPin = 3; Servo Servo1; int servoPosition = 0; void setup() { // put your setup code here, to run once: Servo1.attach(servopin); Servo1.write(servoPosition); } void loop() { // put your main code here, to run repeatedly: int buttonState = digitalRead(buttonPin); int button2State = digitalRead(button2Pin); Error massage says ServoPin was not declared in this scope
@CodeWithConner2 жыл бұрын
When you declared servoPin you used a capital P but when you access it later you used a lower case p. That’s why it can’t find it.
@desmondclyde6835 Жыл бұрын
I have an issue with my circuit and im hoping you could help. I have two servos connected to a button and i want the servos to start at zero to move to 45 degrees when button is pushed (not held), and when the button is pressed again, servos move back to 0. where in my code is it incorrect ? #include int buttonPin =2; int servoPin =3; int servo2Pin =5; Servo servo1; Servo servo2; int servoPosition =0; int servoIncrement =4.5; void setup() { servo1.attach(servoPin); servo2.attach(servo2Pin); servo1.write(servoPosition); servo2.write(servoPosition); } void loop() { int buttonState =digitalRead(buttonPin); if (buttonState==HIGH&&servoPosition=0) {servoPosition-=servoIncrement; servo1.write(0); servo2.write(0); delay(10); } }
@tothemoon93043 жыл бұрын
How to write many angles settings for each buttons? Plss help
@RiCARdo_Racing3 жыл бұрын
Nice tutorial Keep up!
@akanbaki68063 жыл бұрын
Hello guys , i have a great problem and i Hope you would help me please. I want to pilot a servo moteur with a signal input 5 volt like your button system ( in réality i want to pilote the servo with a signal of a VHF REMOTE CONTROL whose work on 12 volt and reduct to 5 volt with a convert to control in finely an excavator machine....when i push on a button of the VHF REMOTE control , i want it's do the same like your button program.... Which modification on your programme i 'll have to do for it's work . Thanks you for your compréhension , and i live in France ...maybe i'm lucky if you speak french .thanks you .
@CodeWithConner3 жыл бұрын
I'm not sure about the VHF remote input source, but in theory as long as you can determine when the button you want is being pressed on the remote, you can then put that into an if statement and within the statement, set the angle change for the servo motor. Essentially replacing the buttonread == HIGH from the button version with whatever input check there is for your remote.
@tazcurrier21933 жыл бұрын
EVEN BETTER... HAVE A SPDT SWITCH, AND USE THE SWITCH TO DETERMINE THE DIRECTION OF THE SERVO, AND A PUSH BUTTON, TO TELL IT TO MOVE TO THAT POSITION, WHEN COMMANDED. HOW WOULD YOU DO THAT? i HAVE TRIED SEVERAL WAYS, AND CANNOT GET IT TO STAY IN EITHER POSITION. IT JUST CYCLES BACK AND FORTH, NEVER STOPS... I AM FRUSTRATED. I LEARN BETTER WHEN SHOWN HOW TO DO SOMETHING, AND THEN I CAN APPLY IT, TO OTHER SITUATIONS THAT I AM WORKING WITH AT A LATER DATE. THANKS AGAIN!!!
@CodeWithConner2 жыл бұрын
So really the idea here is that whatever is in your loop() function directly will just keep happening over and over again. The key to all of this is the if statements in the loop function. There are a couple reasons this can get messed up, for example depending on how you are detecting your button state. Even though we might think we aren't holding a button down, the Arduino will recognize it several thousand times in a second potentially. Having a delay built in anytime it detects a button push helps prevent it re-running the code more than once per button press. But, if you have no motor movement in your main loop() function, but an if statement for a button that just moves it a certain amount in a certain direction and doesn't do any kind of looping or incremental change this should be doable. something like: if(buttonstate==HIGH){Servo1.write(120); delay(1000);} would just move the motor to 120 and do nothing else.
@whitewolf87443 жыл бұрын
do you have a copy of the code to post for this?
@CodeWithConner3 жыл бұрын
Send me an email. codewithconner@gmail.com and I'll send it to you.
@olaf13433 жыл бұрын
hey can you send me the code :)
@kenansofuyev42953 жыл бұрын
Thank You!
@umitaktan9233 ай бұрын
THANKS
@steameducation81182 жыл бұрын
omg thank u very much
@CodeWithConner2 жыл бұрын
Glad it helped
@frenchtoast_493 ай бұрын
doesnt work
@mohamedaboshady1062 жыл бұрын
The word (Servo1) didn't activate durring writing the code broo !!
@QuqRose Жыл бұрын
i eally don't know where is the mistakemaking thnk why wouldn't you JUST POST THE CODE!!! #include int buttonPin = 4; int button2Pin = 7; int servoPin = 3 Servo ; int ServoPosition = 0; void setup() { Servo1.attach(servoPin); Servo1.write (servoPosition); Serial. begin (9600); } void loop() { int burtonState = digitalRead(buttonPin); int button2State = digitalRead(button2Pin); if(buttonState == HIGH && servoPosition
@CodeWithConner Жыл бұрын
Feel free to share if you want. I don’t post the code because I think there is better learning in following along and in the act of typing out the code and the brackets and all of it yourself. To each their own.