Thank you!
Just was thinking... if the servos are rated for 4.8v dc and i use 2 of them does that mean my external power should be 4.8v x 2 = 9.6v ( a 9 v battery)?
No, still 4.8V.... look at the pic I posted earlier and you'll see the motors are in parallel on the power supply. It's the current that's the kicker: if you have 3 servos which might each pull an amp at once, then you need a 3A supply.
Thanks.
Ok new question Could you please look at the following code and tell me how I would have to modify it to turn a servo motor in the following manner:
button A moves servo 90 deg to the right
button B moves servo to neutral position
button C moved servo 90 deg to the left
Thanks!
*
2.source: www.electroschematics.com
3.You'll need to change the led pins and the codes
4.accordingly to your configuration and IR remote
5.*/
#include <IRremote.h>
int RECV_PIN = 3; // the pin where you connect the output pin of TSOP4838
/*int itsONled[] = {0,0,0,0};
/* the initial state of LEDs is OFF (zero)
the first zero must remain zero but you can
change the others to 1's if you want a certain
led to light when the board is powered */
#define code1 16796749 // code received from button A
#define code2 16811141 // code received from button B
#define code3 16778245 // code received from button C
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600); // you can comment this line
irrecv.enableIRIn(); // Start the receiver
pinMode(servo1, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
if(itsONled[1] == 1) { // if first led is on then
digitalWrite(led1, LOW); // turn it off when button is pressed
itsONled[1] = 0; // and set its state as off
} else { // else if first led is off
digitalWrite(led1, HIGH); // turn it on when the button is pressed
itsONled[1] = 1; // and set its state as on
}
break;
case code2:
if(itsONled[2] == 1) {
digitalWrite(led2, LOW);
itsONled[2] = 0;
} else {
digitalWrite(led2, HIGH);
itsONled[2] = 1;
}
break;
case code3:
if(itsONled[3] == 1) {
digitalWrite(led3, LOW);
itsONled[3] = 0;
} else {
digitalWrite(led3, HIGH);
itsONled[3] = 1;
}
break;
}
Serial.println(value); // you can comment this line
irrecv.resume(); // Receive the next value
}
}
Assuming 90 left is a servo position of 0 degrees, neutral (if by that you mean centred?) is 90, and 90 right is 180. (Well the 0 and 180 as left and right is subjective I guess, depends which way you're facing....)
In each respective "case" of the "switch" you just need a servo.write() with the correct value, probably with a (dreaded ) delay() to give it time to get there.
switch(value) {
case code1:
servo.write(90); //or 0 or 180
delay(50); // or whatever
break;
Thanks I will give it a try and let you know.
According to your profile it's 3.30am where you are..... 5.30 here, that's early enough for me.
Now, is it enough to connect that 3-pin IR receiver to read the codes from a TV IR remote control?
Will I just see the codes when pressing the buttons?
I'll need the library, won't I?
rva1945:
Now, is it enough to connect that 3-pin IR receiver to read the codes from a TV IR remote control?Will I just see the codes when pressing the buttons?
I'll need the library, won't I?
You could make a form of LUT of the codes in the form of "on time, off time, on time" etc.
OR you could look up the manufacturer's protocols:
For example, Sony's IR protocols...
Sony IR Protocol
A useful Sparkfun tutorial:
https://learn.sparkfun.com/tutorials/ir-communication
So seems as if I need just the IR receiver and the library. The tutorial says" IR Keychain Remote or any IR remote that uses 38kHz modulation", or a "common IR control". So I can use the library with ANY TV remote control? Aren't those libraries specific for an brand, like SONY?
Thanks