I am working on a project that includes an Arduino, a 4 button key fob, and a servo motor. Although i have 4 buttons i only need to use the A,B,C buttons. I am trying to make it so each button have a certain task. For “A” i want it to move 45 degrees, “B” i want it to go to 90 degrees, and “C” return back to 0. Any advise would be helpful.
Post details of your keyfob and the corresponding receiver.
Post your program and tell us what it actually does and what it should do that is different.
You question is a bit like "I want to paint my girlfriend's (or boyfriend's) portrait, please advise"
The keyfob is a 4-Button RF Remote Control - 315MHz and a simple RF M4 receiver from adafruit. Right now
my codes are below but i tried to put in another input but it wouldn’t let me. This code allows me to press the A and D button so when pressing A it allows it to move forward and for D allows it to go backwards. I need help adding another button B. Each would move at different positions so i would like A to move at 45 degrees and B move at 90 degrees and C will move back to 0 degrees.
studentdo:
This code allows me to press the A and D button so when pressing A it allows it to move forward and for D allows it to go backwards. I need help adding another button B.
I don’t see button A or D or B in that code so how am I supposed to know how to help?
Post a link to the datasheet for your keyfob and receiver.
And please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum
#include <Servo.h>
int A = 8; // button A input
int D = 7; // button D input
int B = 4; // button B input
int servoPin = 9;
int angle = 90;
int change = 15; // this value determines how much the angle changes each time through the loop
Servo myservo;
void setup(){
pinMode(A, INPUT); // initialize pins
pinMode(D, INPUT);
pinMode(B, INPUT);
digitalWrite(A, HIGH); // set internal pull up resistors
digitalWrite(D, HIGH);
digitalWrite(B, HIGH);
myservo.attach(servoPin);
}
void loop(){
if( digitalRead(A) == LOW) {
// here if increment switch pressed
angle = angle + change;
}
if( digitalRead(D) == LOW) {
// here if decrement switch pressed
angle = angle - change;
}
if( digitalRead(B) == LOW) {
// here if decrement switch pressed
angle = angle + change;
}
angle = constrain(angle, 0, 180); // limit value of angle
myservo.write(angle);
delay(20);
}
I do not have access to the keyfob and receiver datasheet. I can’t seem to get my input button B to work. It works fine with A and D button inputs. Also, how can I make the angles precise and stop the servo motor from locking up so I don’t have to keep resetting it?