- Sun Feb 09, 2014 11:49 pm
#168270
Here is the newest code
I was thinking that the receiver/transmitter was the problem since its so sporadic in lighting the LEDs, but why wouldn't the servo rotate if I connected one of the arduino input pins (either 4 or 5) to a 5v source (not from the arduino but a USB breadboard kit that I bought from here)? If the pins get a 5v source, shouldn't the servo rotate? The one time it did work the serial monitor did show it move from 0 to 90, but I didn't look so see what it said when I got it to rotate back to 0 from 90, I was excited it was working and wasn't paying attention, and now it does absolutely nothing, other than create a humming servo.
Is there another small RF transmitter/receiver combo that would do what I am looking for? Maybe its the current ones I'm using, like you mentioned in an earlier post. I need it to be as small as possible because this will be going into a costume helmet and they don't provide a lot of extra room.
I was planning on running the servo off of an Adafruit trinket, but its looking like that isn't going to work so I may have to use an arduino nano or micro. I think the code will work, I just need to figure out if its the code, my input wire connections, or the receiver/transmitter combo.
Code: Select all
I got excited because it worked the second time it tried it, but then nothing. The serial monitor shows nothing, so I was thinking that it wasn't getting a signal from the rf transmitter. I connected the transmitter to a couple LEDs, and they worked (but I think I need new batteries in the key fob). When I upload the code the servo starts humming and doesn't stop, so I don't know what's going on with that. I am not sure how the 10k resistors should get connected to the inputs of the arduino; rf output to resistor to arduino, or resistor to ground and arduino with the rf input in series with that. I didn't know how it should get hooked up with the resistors so I connected an input pin to a 5v source and nothing, no rotation and nothing on the serial monitor. I tried that with both input pins and neither did anything. The servo works because I can load the sweep example leaving the servo input the same as with my code (pin 9) and it works fine, so the servo is not the problem. #include <Servo.h>
int button1 = 4;
int press1 = 0;
int button2 = 5;
int press2 = 0;
Servo servo1;
int pos = 0;
void setup()
{
pinMode(button1, INPUT);
pinMode(button2, INPUT);
servo1.attach(9);
Serial.begin(9600);
servo1.write(10);
}
void loop()
{
if ( (digitalRead(button1) == HIGH) && (pos == 10) )
{
for (pos = 10; pos < 100; pos +=1)
{
servo1.write(pos);
Serial.println(pos);
delay(15);
}
}
if ( (digitalRead(button2) == HIGH) && (pos == 100) )
{
for (pos = 100; pos > 10; pos -=1)
{
servo1.write(pos);
Serial.println(pos);
delay(15);
}
}
}
I was thinking that the receiver/transmitter was the problem since its so sporadic in lighting the LEDs, but why wouldn't the servo rotate if I connected one of the arduino input pins (either 4 or 5) to a 5v source (not from the arduino but a USB breadboard kit that I bought from here)? If the pins get a 5v source, shouldn't the servo rotate? The one time it did work the serial monitor did show it move from 0 to 90, but I didn't look so see what it said when I got it to rotate back to 0 from 90, I was excited it was working and wasn't paying attention, and now it does absolutely nothing, other than create a humming servo.
Is there another small RF transmitter/receiver combo that would do what I am looking for? Maybe its the current ones I'm using, like you mentioned in an earlier post. I need it to be as small as possible because this will be going into a costume helmet and they don't provide a lot of extra room.
I was planning on running the servo off of an Adafruit trinket, but its looking like that isn't going to work so I may have to use an arduino nano or micro. I think the code will work, I just need to figure out if its the code, my input wire connections, or the receiver/transmitter combo.