Jump to content

How can I make a servo rotate 90 degrees?

Go to solution Solved by linuxChips2600,

Try -

 

Lemme know if you have any more questions after this


Also https://www.arduino.cc/reference/en/

Btw I do not believe that you have to worry about integer overflow for the delay (unless the wait is longer than ~9 hours) as long as the arduino supports 16-bit integers for unsigned long data type

To preface this, I'm a total newbie with Arduino and OOP in general. My current project is an automatic pet feeder, and I just need to make an SG90 mini-servo rotate 90 degrees and back, and repeat that action every 6 hours. No idea how to do this, any help would be great.

Link to comment
Share on other sites

Link to post
Share on other sites

Try -

 

Lemme know if you have any more questions after this


Also https://www.arduino.cc/reference/en/

Btw I do not believe that you have to worry about integer overflow for the delay (unless the wait is longer than ~9 hours) as long as the arduino supports 16-bit integers for unsigned long data type

Edited by linuxChips2600
added note about int overflow
Link to comment
Share on other sites

Link to post
Share on other sites

Another option would be to use some infrared sensor and infrared led to detect when 90 degree rotation is done.

Make a disc around the servo, cut holes in the disc, put infrared led on one side and infrared sensor on other side, when the disc is rotated enough, hole opens in the disc and infrared led hits the infrared sensor and therefore your arduino detects that and can stop the servo.

Or rather a regular motor, because now you don't need a servo to count the degrees of rotation, you stop when

 

image.png.2ebc0c085bd4b21b4f0be90ef1dab5e0.png

 

Another option would be to use a couple of those limit switches ... put a raised notch on the  disc which presses on the switch when the disc rotates enough... as soon as the switch is pressed, you stop the motor.

example of such switch :

 

SS0750301F040P1A

an extra benefit of this is that if you use two such limit switches, you know the position when you  power up your device because one such switch would be closed and the other open ... or you can program your device at boot to spin motor one direction until limit switch is hit.

If there's some power loss, you can easily just spin motor one direction until the limits are hit (can do same with infrared led and sensor i guess) but with a servo it may be a bit more difficult - you don't know how many degrees to turn to fully close or open if the power was lost somewhere in the middle.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×