Go Down

Topic: PWM Servo via IR (Read 4 times) previous topic - next topic

Peter9DO

I think I'm making some headway.... Still working on it though. I'll update later.
What if Burt Reynolds, really changed his name to Turd Ferguson?

JimboZA

Well I just got home after a loooooong day (and week).... gna help my daughter re-assemble her Magician chassis which is a total load of crap cos the motor holes don't line up and 3 of the 4 motor wires have snapped off.
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Peter9DO

#57
Jun 29, 2012, 04:57 pm Last Edit: Jun 29, 2012, 05:26 pm by Peter9DO Reason: 1
NICE! You know they don't make anything like they used to! lol! Good luck with that!!! I'm still plugging away over here, I think I might have figured this out... I'll post on it once I finish up what I'm doing to see if it will work. I'm crossing my fingers, praying to god, Buddha and Tom Cruse that this will work!

So, I got the Serial.print to read the "Are you here yet" and the directional IR signals!!!!! The servo however is not moving yet, but I'm getting there!

Code: [Select]
#include <IRremote.h>
#include <IRremoteInt.h>
#include <Servo.h>


Servo triggerservo;
Servo PanServo;

               
int pos = 0;    
int button = 7;   //<---- Nothing in pin (DO NOT USE PIN 7)
 
const int irReceiverPin = 2;
int Saftey =5;
int RelayTrig = 4;
int RelayLaser = 3;

int PanServoVal;
int PanServoMovement = (15);
int PanServoPos = (0);

IRrecv irrecv(irReceiverPin);
decode_results results;


void setup()
{
 triggerservo.attach(9);  
 PanServo.attach(10);
 
pinMode(pos, OUTPUT);
pinMode(button, INPUT);
digitalWrite (button, LOW);

pinMode (Saftey, OUTPUT);
pinMode(RelayTrig, OUTPUT);
pinMode(RelayLaser, OUTPUT);
irrecv.enableIRIn();

Serial.begin(9600);
Serial.print("!!STARTED!!");

PanServo.write(PanServoVal);
}

int on = 0;
unsigned long last = millis();


void loop()
{
 
   if (digitalRead(button) == LOW)

 for(pos = 0; pos < 90; pos += 90)   //
 {                                  
   triggerservo.write(pos);              
               
 }
 if (digitalRead(button) == HIGH)
 
 for(pos=90; pos>=0; pos-=90)    
 {                                
    triggerservo.write(pos);              
                               
                         
 }
{
 if (irrecv.decode(&results)) {    
   if (results.value == 0x20DFC23D) { //Menu Button: pulls/releases trigger only if saftey is off (LED on when released).
     if (millis() - last > 250) {
       on = !on;
       digitalWrite(RelayTrig, on ? HIGH : LOW);
               Serial.print(" TRIGGER ACTION ");
       
     }
     last = millis();
   }    
 }
 
 if (irrecv.decode(&results)) {    
   if (results.value == 0x20DF10EF) { //Power Button: Turns on/off the saftey on the trigger
     if (millis() - last > 250) {
       on = !on;
       digitalWrite(Saftey, on ? HIGH : LOW);
       Serial.print(" SAFTEY ACTION ");
     }
     last = millis();
   }    
 
 }
{
 if (irrecv.decode(&results)) {
   if (results.value == 0x20DF906F) { //Mute Button: Turns on/off the targeting laser.
   if (millis() - last > 250) {
       on = !on;
       digitalWrite(RelayLaser, on ? HIGH : LOW);
       Serial.print(" LASER ACTION ");
    }
     last = millis();
   }    
    if (irrecv.decode(&results))  {
 Serial.print("Are you here yet");
 
   if (results.value == 0x20DFC03F){
    PanServoVal = PanServoMovement + PanServoPos;
    PanServo.write(PanServoVal);
 Serial.print("20DFC03F WORKING (LEFT)");

   }
    if (results.value == 0x20DF40BF) {
     PanServoVal = PanServoMovement - PanServoPos;
     PanServo.write(PanServoVal);
 Serial.print("20DF40BF WORKING (RIGHT)");

 
   }    
   irrecv.resume();
}
}
 }
}
}


In the sketch above the "Are you here yet" is in there but I have taken that out because it is working and that line is coming up every time I hit a button. I found it to be annoying so I took it out...
What if Burt Reynolds, really changed his name to Turd Ferguson?

Peter9DO

I took a look at the signal going to the servo with my o-scope and AWOL is 100% correct, I got a ton of noise on there. Now, when I reset the Arduino or I load the sketch it moves to the 120 degree position. then if I hit either directional buttons it will move to the 90 degree position. After that, I get no response from the servo. I don't know if this is from my poor code writing skills or the noise. I figure I can hook up an LM7805 with some caps to filter it out, however I don't know if that will do anything if it's because of my code as AWOL has claimed above.
What if Burt Reynolds, really changed his name to Turd Ferguson?

Peter9DO

Well, I figured out why the PanServo was not working. It wasn't getting enough power. I hooked it up to an external power supply and it works just fine now. But, with the "if" statements that I have it's going all the way to one side with a single press of a button and then all the way to the other side with the other button, single pressed. I'm going to try and get the math down right on it so it will move 15 degrees every time I hit a button and maybe I will go nuts and program a swing in there along with a stop.
What if Burt Reynolds, really changed his name to Turd Ferguson?

Go Up