Pages: [1]   Go Down
Author Topic: Making a servo motor function using a switch  (Read 638 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Tesla Member
***
Karma: 143
Posts: 9599
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Simple servo button test code.

Code:
//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);
  servo1.attach(7);
  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)
  {
    servo1.write(170);
  }   
 
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
 
  /*else {
    servo1.write(90);
  }*/
}
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: