# How do I make an oscillating servo with arduino UNO?

I am working with Ardunio UNO in class. I was assigned a prject to make an oscillating servo that rotates 180° I have no code and no circut. I must use a motor too. My teacher said that it is possible with the circut from project 9 but I have been searching for solutions and this is my final attempt. Help is appreciated.

Google can help you with using an Arduino and a servo.

This is the first hit that came up for me.

Define what “oscillating servo that rotates 180°” means exactly.

And while you're at it,

larryd:
Define what....

rschafer1:
project 9

is too.

rschafer1:
I have been searching for solutions

You are unlikely to find solutions; you will find examples to ponder and tweak, but ultimately you have to design a solution.

Show what you've done so far, and say how it works / doesn't work for you.

I have tried to look at "Sweep" I was not able to complete my task. What i mean by 180 degrees is that it just has to rotate 180 degrees constantly with a toggle button. All I really need is the code, sweep does not have a toggle switch. Thank you for trying to help though.

You mean that when you press the button, if it's at 0 it must go to 180, or if it's at 180 it must go to 0?

Have you seen the examples in the ide (file, examples)? There's one there that shows how to read a button... do you have that sorted?

rschafer1:
I have tried to look at "Sweep" I was not able to complete my task. What i mean by 180 degrees is that it just has to rotate 180 degrees constantly with a toggle button. All I really need is the code, sweep does not have a toggle switch. Thank you for trying to help though.

That still doesn't make much sense. When a servo has rotated 180 degrees that's as far as it can go. It can't keep doing 180 degree moves, it can only go back. So is the actual movement in Sweep correct e.g. 0 to 180, back to 0 then to 180 over and over again? If not try to explain just the servo movement.

Once that's done you need to say exactly what effect the "toggle switch" should have on this movement.

Steve

So I have done some research and this code works, I just need to make a toggle button, when I press the button, it turns off but when we release, it constinues.
Code here:
#include <Servo.h>

Servo servo;
int angle = 10;
int switchstate = 1;
void setup() {
servo.attach(8);
servo.write(angle);
}

void loop()
{
if (switchstate = 1);
// scan from 0 to 180 degrees
for(angle = 10; angle < 180; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 10; angle–)
{
servo.write(angle);
delay(15);
}
}
Board is in the attatchment. Thanks!