Go Down

Topic: Making a servo motor function using a switch (Read 920 times) previous topic - next topic


Can you please help me to make a code using if statements that will enable the servo motor to run if the sensor input becomes 1.


Which part are you stuck with. Use the Servo Sweep example as a basis. Add a digitalRead() to see if your switch is on.


Simple servo button test code.

Code: [Select]

//zoomkat servo button test 12-29-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high

void loop()
  press1 = digitalRead(button1);
  if (press1 == LOW)
  press2 = digitalRead(button2);
  if (press2 == LOW)
  /*else {
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131