I am new in the world of arduino. I have a project to finish but i don't know anything about programming.I have an arduino uno, a servo motor , a four button rf transmitter (315mhz) and a rf receiver (315mhz).I want from someone to help me with the code to do the following.
As i push the A button of the transmitter i want from the servo to move 45 degrees in 2 seconds and then the power will go off.
As i push the B button i want from the servo to move to the start position at 0 degrees (also in a time of 2 seconds and then the power will go off.
Do you have a link to the tx and rx?
I'm guessing you have these adafruit units?
They're dead simple: all that happens when you press a key on the transmitter, the corresponding pin on the receiver does something. You need to understand exactly what that "something" is, based on which of the 3 models of receiver you have: momentary, toggle or latch.
All you need to do is hook the receiver's pins to Arduino digital i/o and read them with digitalRead().
The fact that the pins are controlled by radio is totally irrelevant as far as the Arduino is concerned. Their video here just has leds on the receiver.
Thanks for the immediate reply. You are right ,I have the above adafruits products.The receiver is a momentary model.That means that I 'll keep pushing the button A until the servo makes the move I want. Am I right?.Let's say that I'll attach the servo to pin 9. Then, where could I attach the 4 pins of the receiver?How could be a code for this thought?
Basic servo button code. You have several other parts to work out, such as the communication between the arduinos. Have you worked out the communication part between the arduinos?
//zoomkat servo button test 12-29-2011
// Powering a servo from the arduino usually *DOES NOT WORK*.
#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);
}
}
Why are you asking me about the communication between arduinos?I have only one arduino. I will send the signal with the four button keyfob. I tried your code but the result was a noise from the servo as he is moving 1 degree left and 1 degree right constantly. I know that it is not right to power servo from the arduino but i haven't any other power supply for now.I tried to move the servo with potentiometer and it worked. But i can't move the servo with the 4 button rf keyfob
geoptic:
Why are you asking me about the communication between arduinos?I have only one arduino. I will send the signal with the four button keyfob. I tried your code but the result was a noise from the servo as he is moving 1 degree left and 1 degree right constantly. I know that it is not right to power servo from the arduino but i haven't any other power supply for now.I tried to move the servo with potentiometer and it worked. But i can't move the servo with the 4 button rf keyfob
After looking at that type of tx/rx, you might only need an NPN transistor to act as a switch for the arduino on the receiving end.
You could do it as you said, and move the servo in one direction as long as button A is pressed and in the other direction with B. But then you're unlikely to be able accurately to get it to stop at the right point I'd say.
So what you need is to have code that says "aha, button A has become pressed" (as distinct from is pressed). When it sees that A has become pressed it initiates a sweep type of code to go where it needs to go, with small delays between the steps probably, so that it takes the 2 seconds- if that's important.
To do what I said there, have a look at this example- just ignore the part that increments the counter.
If your pin has changed, and is high now, that means it just got pressed so do something.
Essentially, your receiver takes the place of the switch in the schematic of the example. You would need to pull the pin low as shown, to ensure you don't get any false highs.
I'm going to my supplier today and I see he has these in stock, so I'm going to get a receiver and keyfob to play....