Skip to content

Instantly share code, notes, and snippets.

@ulitiy
Created August 25, 2016 19:30
Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save ulitiy/5c319f65c419dfa1af7ca2dcdebab3ce to your computer and use it in GitHub Desktop.
Save ulitiy/5c319f65c419dfa1af7ca2dcdebab3ce to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo myservo;
const int servoPin = 9;
const int buttonPin = 12;
const int ledPin = 13;
void setup() {
myservo.attach(servoPin);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
myservo.write(180);
delay(1000);
myservo.detach();
}
void loop() {
int buttonVal = digitalRead(buttonPin);
if(buttonVal == LOW) {
myservo.attach(servoPin);
myservo.write(30);
delay(575);
myservo.write(180);
delay(1500);
myservo.detach();
delay(5000);
}
delay(13);
}
@MU-ciber
Copy link

Why did he use in the if Statment LOW and not HIGH

@ulitiy
Copy link
Author

ulitiy commented May 29, 2022

Why did he use in the if Statment LOW and not HIGH

arduino has internal pull up resistor, it's activated on line 12. It doesn't have pull down resistors.

@agullapa
Copy link

Hi, Thank you for the program. It is super helpful and easy to understand. I am trying to create this for my dog. I feed him twice a day. I don't want him to keep pressing and keep getting food. How can i change the program so that after morning feed (~8AM), it does not dispense food till 5 PM?

@ulitiy
Copy link
Author

ulitiy commented Sep 28, 2023

Hi, Thank you for the program. It is super helpful and easy to understand. I am trying to create this for my dog. I feed him twice a day. I don't want him to keep pressing and keep getting food. How can i change the program so that after morning feed (~8AM), it does not dispense food till 5 PM?

https://gist.github.com/ulitiy/25d675591af73f347926b7a4e6921797

Have a look at this

@Mamin0679
Copy link

that code is suit for sg90 servo?

@ulitiy
Copy link
Author

ulitiy commented Nov 29, 2023

that code is suit for sg90 servo?

Yes but it's weak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment