Ardriuno Code for servos to open a flap
- or -
Post a project like this3159
$$
- Posted:
- Proposals: 5
- Remote
- #869826
- Awarded
Description
Experience Level: Intermediate
Hello I am controlling two servos to open up a flap and need the servos to switch of after they have moved as the servos hum, so looking to disconnect the power supply with a relay and reconnect it when the switch position changes.
This is the servo code that I am using with the relay times Shown with explanation mark Example: !!!(FOR 10 SECONDS TO ALLOW SERVOS TO MOVE)!!!
#include
int button1 = 12; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;
Servo servo2;
void setup()
{
pinMode(button1, INPUT);
servo1.attach(6);
servo2.attach(7);
digitalWrite(4, HIGH); //enable pullups to make pin high
}
void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{!!!TURN RELAY ON!!! !!!(FOR 10 SECONDS TO ALLOW SERVOS TO MOVE)!!!
servo1.write(160);
servo2.write(30);
TURN RELAY OFF !!!(AND STAY OFF UNTIL BUTTON 1 CHANGES)!!!
}
else {
!!!(TURN RELAY ON (FOR 10 SECONDS TO ALLOW SERVOS TO MOVE )!!!
servo1.write(30 );
servo2.write(160);
!!!(TURN RELAY OFF (AND STAY OFF UNTIL BUTTON 1 CHANGES)!!!
}
}
I can pay by paypal or by any means that suites you.
Many Thanks
Chris Garner
This is the servo code that I am using with the relay times Shown with explanation mark Example: !!!(FOR 10 SECONDS TO ALLOW SERVOS TO MOVE)!!!
#include
int button1 = 12; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;
Servo servo2;
void setup()
{
pinMode(button1, INPUT);
servo1.attach(6);
servo2.attach(7);
digitalWrite(4, HIGH); //enable pullups to make pin high
}
void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{!!!TURN RELAY ON!!! !!!(FOR 10 SECONDS TO ALLOW SERVOS TO MOVE)!!!
servo1.write(160);
servo2.write(30);
TURN RELAY OFF !!!(AND STAY OFF UNTIL BUTTON 1 CHANGES)!!!
}
else {
!!!(TURN RELAY ON (FOR 10 SECONDS TO ALLOW SERVOS TO MOVE )!!!
servo1.write(30 );
servo2.write(160);
!!!(TURN RELAY OFF (AND STAY OFF UNTIL BUTTON 1 CHANGES)!!!
}
}
I can pay by paypal or by any means that suites you.
Many Thanks
Chris Garner
Chris G.
100% (13)Projects Completed
7
Freelancers worked with
7
Projects awarded
88%
Last project
29 Nov 2020
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies