Servo Motor, that has to turn 20 degrees every 5 seconds

hello guys I cant realise my little project can somone help me out,

i try to make a servo that, When I push button 1, a servo motor must every 5 seconds move 20 degrees, when I push a second button, button 2 the servo motor has to stop immidatly

Can somone help me out pls?

Your post was MOVED to its current location as it is more suitable.

What made you think that it had anything to do with Avrdude ?

@louis123456789
start with the example 02. Digital / Debounce

instead of the LED - move your servo.

If you struggle - show your code.

First, have you found a servo that can continually turn another 20 degrees forever if you don't push button 2? Servos generally only have a limited range of movement, typically 120-180 degrees in total.

Steve

Hi, @louis123456789
Welcome to the forum.

Can you please tell us your electronics, programming, arduino, hardware experience?

Have you written any code?

If you Google;

arduino servo tutorial

There are many how to examples to show you how to use a servo with an Arduino.

What Arduino do you have?
What servo do you have?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

OKey so I work with an arduio uno, and yes my servo only can turn 180degrees.

this is my code atm
but I cant figure out how I Shoudl put in my Push buttons. This is what I already found on thinercad, but then I tried my own code but this wont work.

#include <Servo.h>

int pos = 0;

Servo servo_9;

void setup()
{
servo_9.attach(9, 500, 2500);

}

void loop()
{

for (pos =0; pos <= 180; pos += 1) {
/
servo_9.write(pos);

delay(15);


}
for (pos = 180; pos >= 0; pos -= 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(pos);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
}

This is my own code

#include <Servo.h>
Servo servo;

int pos = 10;
int dk1 = A1;
int dk2 = A2;
int drukken =0;
int led1 = 13;

bool dk1status;
bool dk1statuslast;
bool dk2status;
bool dk2statuslast;

void setup()
{
Serial.begin(9600);
servo.attach(9);
pinMode(dk1, INPUT);
pinMode(led1, OUTPUT);

}

void loop(){

dk1status = digitalRead(dk1);
dk2status = digitalRead(dk2);
if (dk1status == LOW && pos <=180){
drukken = drukken +1;
Serial.println(drukken);
pos = map(drukken,0,29,20,180);
servo.write(pos);
delay(5);
}
else if (dk2status == LOW){
digitalWrite(led1, HIGH);
}

}

Hi,
Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.
Your code will be posted in a scrolling window.
Also before posting your code, press [ CTRL ] [ T ], this will format your code and make it easier to read.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

#include <Servo.h>

int pos = 0;

Servo servo_9;

void setup()
{
servo_9.attach(9, 500, 2500);

}

void loop()
{

for (pos =0; pos <= 180; pos += 1) {
/
servo_9.write(pos);
}
for (pos = 180; pos >= 0; pos -= 1) {
// tell servo to go to position in variable 'pos'
servo_9.write(pos);
// wait 15 ms for servo to reach the position
delay(15); // Wait for 15 millisecond(s)
}
}

This is my own code

#include <Servo.h>
Servo servo;

int pos = 10;
int dk1 = A1;
int dk2 = A2;
int drukken =0;
int led1 = 13;

bool dk1status;
bool dk1statuslast;
bool dk2status;
bool dk2statuslast;

void setup()
{
Serial.begin(9600);
servo.attach(9);
pinMode(dk1, INPUT);
pinMode(led1, OUTPUT);

}

void loop(){

dk1status = digitalRead(dk1);
dk2status = digitalRead(dk2);
if (dk1status == LOW && pos <=180){
drukken = drukken +1;
Serial.println(drukken);
pos = map(drukken,0,29,20,180);
servo.write(pos);
delay(5);
}
else if (dk2status == LOW){
digitalWrite(led1, HIGH);
}

}

Like this ? or i am still doing things wrong?

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to [url=https://forum.arduino.cc/index.php?topic=710766.0]Learn How To Use The Forum[/url].

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Hi,
This is your code;

#include <Servo.h>
Servo servo;

int pos = 10;
int dk1 = A1;
int dk2 = A2;
int drukken = 0;
int led1 = 13;

bool dk1status;
bool dk1statuslast;
bool dk2status;
bool dk2statuslast;

void setup()
{
  Serial.begin(9600);
  servo.attach(9);
  pinMode(dk1, INPUT);
  pinMode(led1, OUTPUT);
}

void loop()
{
  dk1status = digitalRead(dk1);
  dk2status = digitalRead(dk2);
  if (dk1status == LOW && pos <= 180)
  {
    drukken = drukken + 1;
    Serial.println(drukken);
    pos = map(drukken, 0, 29, 20, 180);
    servo.write(pos);
    delay(5);
  }
  else if (dk2status == LOW)
  {
    digitalWrite(led1, HIGH);
  }
}

Tom... :grinning: :+1: :coffee: :australia:

Hi,
How have you got your buttons wired?
Can you please post a schematic?
You only have one pinMode input declaration.

 pinMode(dk1, INPUT);

You also need;

 pinMode(dk2, INPUT);

Tom.. :grinning: :+1: :coffee: :australia:

Why all the fiddling with drukken and map()? Why not just pos = pos + 20? And delay(5) isn't 5 seconds. Also it won't repeat the move unless you keep dk1 pressed.

Steve

1 Like

yes, but i cant find how I should do it like u say what u say i try to put in my code but i dont know how I should do it

use the keyboard :nerd_face:

@noiasca @paulpaulson @UKHeliBob @TomGeorge @slipstick

please tell me what is so hard to write down this hint?

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

I do this with a hotstring programmed with Autohotkey

a hotstring-definition in autohotkey looks like this

:R:TheHotString::Text that shall be typed automatically by autohotkey

my personal hotstring for the text above is "postcode"

:R:postcode::You should post code by using code-tags`rThere is an automatic function for doing this in the Arduino-IDE`rjust three steps`r1) press Ctrl-T for autoformatting your code`r2) do a rightclick with the mouse and choose "copy for forum"`r3) paste clipboard into write-window of a posting`r`r

whenever I write the character-sequence "postcode"
The character-sequence p-o-s-t-c-o-d-e gets replaced by the text above

This means by typing 8 characters the above text is inserted in the posting
explaining the most comfortable way to get newcomers to post their entire sketch.

What are your arguments that justify to describe the other methods which prove beeing unsuccessfull again and again?

https://www.autohotkey.com/download

it does not count if you argue I use linux/mac. I'm 101% sure linux and mac have something with an equal functionality. (linux and iOs are very smart operation-systems aren't they? And for linux/mac there exists very smart software doesn't it?)

best regards Stefan

What is so hard for users to understand about the message users get when they post code without code tags ?

New users are also taken automatically to the forum topic explaining how to get the most out of the forum by using it correctly when they first log in. Do they take any notice ?

As to automating the insertion of standard messages

you need to type 7 characters ? What a waste !
All it takes for me to post one of my standard replies is a single click on a keypad attached to an Arduino Leonardo running a sketch that I wrote and mods also have access to canned replies that cover many situations

If you have tried then post the code that you tried and we can go from there. There's nothing in any code you posted that shows you're taking any notice of the help people are trying to give you.

Also it would help if you answered some of the many questions you have been asked.

Steve

Please tell me why you think it's a good idea that loads of us should all post identical "hints" that don't make any attempt to answer the OPs problem?

Steve