Pages: 1 2 [3] 4 5   Go Down
Author Topic: PWM Servo via IR  (Read 3221 times)
0 Members and 1 Guest are viewing this topic.
Buffalo, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is what I meant:
Code:
PanServoPos = PanServoMovement +  PanServoPos
PanServo.write(PanServoPos);

When the button is pressed, you change PanServoPos, then tell the servo to move to that position.

Okay, thank you for clearing that up for me.
This is what I have than:

Code:
#include <Servo.h>
#include <IRremote.h>
#include <IRremoteInt.h>


Servo PanServo;
int PanServoPos= (90);
int PanServoMovement = 15;  //how many degrees per move

int irReceiver = 2;
int IROutput = 10;

IRrecv irrecv(irReceiver);
decode_results results;

void setup() {
  pinMode (IROutput, OUTPUT);
  PanServo.attach(10);
  PanServo.write(90);
 
  irrecv.enableIRIn();
}
   
void loop() {
 

  if (irrecv.decode(&results))  {
    if (results.value == 0x20DFC03F){
  PanServoPos = PanServoMovement + PanServoPos;
  PanServo.write(PanServoMovement);
    }
     if (results.value == 0x20DF40BF) {
      PanServoPos = PanServoMovement - PanServoPos;
      PanServo.write(PanServoMovement);
   
    }     
  }
  irrecv.resume();
}
   

I also noticed that you changed PanServo.write(PanServoMovement);  to   PanServo.write(PanServoPos);
So, I have tried that as well and I still have no movement on the command of the button.
Logged

What if Burt Reynolds, really changed his name to Turd Ferguson?

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24430
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at your servo writes.
What value are you writing?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Buffalo, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AWOL, are you trying to confuse me even more than I am (if that's even possible at this point). You had to throw in a little shorthand!!! lol!!! Thanks buddy! hahaha!
Logged

What if Burt Reynolds, really changed his name to Turd Ferguson?

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24430
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apart from the servo write in setup, you're always writing 15 to the servo.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Buffalo, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apart from the servo write in setup, you're always writing 15 to the servo.

I thought that's how I would be able to move the servo 15 degreesor millis every time I hit the button. I'm just tring to use 2 buttons on a remote to move the servo in either direction. I clearly do not have the knowladge to do this and there is nothing similar online that I have found to use for a clear referance.
Logged

What if Burt Reynolds, really changed his name to Turd Ferguson?

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24430
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You update PanServoPos, the write PanServoMovement.
That's going to result in a static servo, because the latter is always 15.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you want to do is this (not proper code):

new = old + change
move to new


What you're doing is:

new = old + change
move to change


So it stays at the degree position of change, not moving to new.
Logged

Retired from Arduino.
PMs are set to ignore all.

Buffalo, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you want to do is this (not proper code):

new = old + change
move to new


What you're doing is:

new = old + change
move to change


So it stays at the degree position of change, not moving to new.


Thanks Jimbo!!!! I see what you're saying now that you put it like that.
I don't know if you can tell due to the amount of changes I did to it, but I have stated this sketch off of the one you gave me, it really did help me piece together this sketch a lot! Thanks again! I will post the sketch with the changes on it soon.
Logged

What if Burt Reynolds, really changed his name to Turd Ferguson?

Buffalo, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <Servo.h>
#include <IRremote.h>
#include <IRremoteInt.h>


Servo PanServo;
int PanServoPos= (90);
int PanServoMovement = 15;  //how many degrees per move

int irReceiver = 2;
int IROutput = 10;

IRrecv irrecv(irReceiver);
decode_results results;

void setup() {
  pinMode (IROutput, OUTPUT);
  PanServo.attach(10);
  PanServo.write(0);
 
  irrecv.enableIRIn();
}
   
void loop() {
 

  if (irrecv.decode(&results))  {
    if (results.value == 0x20DFC03F){
  PanServoPos = PanServoMovement + PanServoPos;
  PanServo.write(PanServoPos);
    }
     if (results.value == 0x20DF40BF) {
      PanServoPos = PanServoMovement - PanServoPos;
      PanServo.write(PanServoPos);
   
    }     
  }
  irrecv.resume();
}

This is what I have, this thing is still not working though.

AWOL, At this point I will take the static... As long as there is some kind of movement. I think I might have to look into putting a PrintIn on this sketch as WildBill has mentioned so I can see what's going on.
Logged

What if Burt Reynolds, really changed his name to Turd Ferguson?

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, putting some prints to the monitor will be a big help.... like in the "if" you got to when a particular key was pressed, if the servo's not moving, well you don't know if the "if" worked in the first place. So put in a line inside the "if" that sends something to the monitor along the lines of "ok, key <whatever its code is> was pressed" then at least you know you're inside the "if" and it didn't fly over it.  Or blink an led, anything that lets you know you got into the "if".

EDIT: There are a bunch of those printing lines in my original sketch, just put them back and change the message. Don't forget the Serial.begin(9600); at the top.

Also reload the sketch with a different value in the PanServo.write(0); inside setup()... make sure the servo is in fact obeying any commands at all!
« Last Edit: June 28, 2012, 11:41:50 pm by JimboZA » Logged

Retired from Arduino.
PMs are set to ignore all.

Buffalo, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had did that earlier with putting a different value in and it works with no problem. If you don't mind I'm going to put together the PrintIn, if you could please look it over for me. I have not done anything so far with that function. I'm going to look for a tutorial real quick and work off of that. 
Logged

What if Burt Reynolds, really changed his name to Turd Ferguson?

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are a bunch of those printing lines in my original sketch, just put them back and change the message. Don't forget the Serial.begin(9600); at the top.
Logged

Retired from Arduino.
PMs are set to ignore all.

Buffalo, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, okay! Thanks!
Logged

What if Burt Reynolds, really changed his name to Turd Ferguson?

Buffalo, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <Servo.h>
#include <IRremote.h>
#include <IRremoteInt.h>


Servo PanServo;
int PanServoPos = (90);
int PanServoMovement = (15);  //how many degrees per move

int irReceiver = 2;
int IROutput = 10;

IRrecv irrecv(irReceiver);
decode_results results;

void setup() {
  pinMode (IROutput, OUTPUT);
  PanServo.attach(10);
  PanServo.write(0);
  Serial.begin(9600);
 
  irrecv.enableIRIn();
}
   
void loop() {
 

  if (irrecv.decode(&results))  {
    if (results.value == 0x20DFC03F){
     PanServoPos = PanServoMovement + PanServoPos;
     PanServo.write(PanServoPos);
  Serial.print(PanServoMovement);
  Serial.print("20DFC03F WORKING (LEFT)");
  Serial.println(PanServoPos);
    }
     if (results.value == 0x20DF40BF) {
      PanServoPos = PanServoMovement - PanServoPos;
      PanServo.write(PanServoPos);
  Serial.print(PanServoMovement);
  Serial.print("20DF40BF WORKING (RIGHT)");
  Serial.println(PanServoPos);
   
    }     
  }
  irrecv.resume();
}

I'm not getting anything on the Serial Monitor. Not sure if I set up the Serial.print wrong, or if this is why it's not working.
Logged

What if Burt Reynolds, really changed his name to Turd Ferguson?

Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Put a serial print in the setup too, to say "started" or something, and a few more in loop(), maybe above the "if" so you know it got there.... anywhere where you need a marker that you got to that point.

Did you switch the monitor on in the Arduino ide? (Control + shift + M or the icon top right of ide screen.)

As a matter of interest, how do you know the codes that your keys generate?- did you use that dump sketch or whatever it's called to put them up on the monitor?
Logged

Retired from Arduino.
PMs are set to ignore all.

Pages: 1 2 [3] 4 5   Go Up
Jump to: