Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stepper based PTZ turntable with IR
#1
Code:
/* AshleyStepperIR_asDone  Function: PTZ turntable to move small indoor antenna to desired position from the comfort of
*  a chair using an IR remote and small stepper motor
*/

#include "Stepper.h"
#include "IRremote.h"

/*-----This code now does a jog on each Right or Left button press from the JVC RM-RK50 8 button remote
 * added the "Sound" button with code to find the Home position at extreme CW position which closes Limit02  
 * confirmed that limit switches work -when limit is reached, can't continue unless motor jogged in opposite direction
 * i_am_home LED will only light when at extreme CW Home position Limit02 HIGH reading
 * Limit01 and Limit02 are H21A1 Phototransistor Optical Interrupter placed at 0 and 270 degrees on turntable
 * using a JVC remote salvaged from automotive radio
 * special thanks ( Merci!) to Yvan at Brainy Bits brainy-bits.com/blogs/tutorials for the limit switch and the 28BYJ-48 code...it sure helped!
 * Code and project dedicated to Ashley D. - starting the journey with Arduino!
 */

/*----- Variables, Pins -----*/
#define STEPS  32                                          // Number of steps per revolution of Internal shaft of 28BYJ-48 5 vdc stepper motor
int  Steps2Take;                                           // 2048 = 1 Revolution of stepper motor
int receiver = 6;                                          // Signal Pin of IR receiver 1838B to Arduino Digital Pin 6
int val = 0;                                               // store the value read from Limit02 switch during goHome function
#define Limit01 2                                          // Pin 2 input connected to CCW Limit switch out HIGH when reaches extreme CCW
#define Limit02 4                                          // Pin 4 input connected to CW Limit switch HIGH when reaches extreme CW
#define i_am_home 3                                        // Pin 3 output to show when CCW limit switch is HIGH

/*-----( Declare objects )-----*/
                                                           // Setup of proper sequencing for Motor Driver Pins
                                                           // In1, In2, In3, In4 in the sequence 1-3-2-4

Stepper small_stepper(STEPS, 8, 10, 9, 11);                // ULN2003 stepper driver board 8-in1, 9-in2, 10-in3, 11-in4
IRrecv irrecv(receiver);                                   // create instance of 'irrecv'
decode_results results;                                    // create instance of 'decode_results'

void setup()
{
  delay(250);    
  Serial.begin(9600);                                      // Start the serial monitor
  delay(250);  
  irrecv.enableIRIn();                                     // Start the IR receiver module model 1838B
  pinMode(Limit01, INPUT);                                 // Pin 2 CCW LIMIT high when covered
  pinMode(Limit02, INPUT);                                 // Pin 4 CW LIMIT high when covered
  pinMode(i_am_home, OUTPUT);                              // HIGH when CW limit 02 pin 4 reaches this point
  digitalWrite(i_am_home, HIGH);                           // start with home pin 3 LED ON
  delay(2000);
  digitalWrite(i_am_home, LOW);                            // end set up  with home pin 4 LED OFF
                       
}

void goHome(){
  val = digitalRead(Limit02);                              // read the input pin to see if Limit02 and store in val
    digitalWrite(Limit02, val);                            // checks the Limit02 switch to see if it is CLOSED (HIGH)  

    if (val == HIGH){
      digitalWrite(i_am_home, HIGH);                       // ON as long as table is at Home position
      delay(5);
      Serial.println("I am HOME!");                        // Serial output to indicate Home position is reached
      delay(5);
      return;                                              // return to loop and wait for IR signal to cange table position
     }
      else{
      digitalWrite(i_am_home, LOW);                        // OFF as long as not at home position
      small_stepper.setSpeed(400);                         // Max seems to be 700
      Steps2Take = 32;                                     // 2048 steps per full rotation / 32 steps x 64 pulses for 1 full motor rotation
      small_stepper.step(Steps2Take);                      // move motor 32 steps CCW
      delay(5);
      goHome();                                            // keep testing to see when Limit02 is HIGH and stop    
      delay(5);
    }
 
}

void loop()
{
if (irrecv.decode(&results))                                // have we received an IR signal?

  {
    switch(results.value)                                   // check switch case to see what IR button was pressed

    {

      case 0x00F1C9:                                        // LEFT  button pressed ( <R ) on JVC RM-RK50 remote
                      if (digitalRead(Limit01)) {}          // check if limit switch at extreme CCW position is activated HIGH
    
                        else {                              // if limit switch is not activated, move motor clockwise

                      small_stepper.setSpeed(400);          // Max seems to be 700
                      Steps2Take  =  -32;                   // Rotate CW
                      small_stepper.step(Steps2Take);       // -32 steps works nice , but this can be reduced to 16 if required
                      digitalWrite(i_am_home, LOW);         // OFF as long as not at home position
                      delay(10);
                        }
                      break;

      case 0x00F149:                                        // RIGHT  button pressed ( F> ) on JVC RM-RK50 remote
                      if (digitalRead(Limit02)) {}          // check if limit switch at extreme CW position is activated HIGH also Home Position
    
                        else {                              //  if limit switch is not activated, move motor counter clockwise

                      small_stepper.setSpeed(400);          // Max seems to be 700
                      Steps2Take  =  32;                    // Rotate CCW
                      small_stepper.step(Steps2Take);       // 32 steps works nice , but this can be reduced to 16 if required
                      digitalWrite(i_am_home, LOW);         // OFF as long as not at home position
                      delay(10);
                        }  
                      break;

    case 0x00F1B1:                                          // Sound button pressed upper right of remote selects goHome function
                        {
                        goHome();                           // find Home position and light i_am_home LED pin 3
                        }
                      break;
                    
    }
    irrecv.resume();                                        // receive the next value from the IR remote
   }


Hi Guys,
Here is a project my daughter wanted to make as a 1st Arduino project.
-she is taking some basic Arduino programming classes, and wanted to make a device to position a small indoor antenna.
-I wanted to offer assistance with the hardware and some of the coding so this is what we come up with.
-I am at a point where the electronics can be built into the salvaged PTZ housing.
-note that only the Pan function is required, so the Tilt mechanism is removed.
-I opted for using the UN2003 with the 28BYJ-48 5 vdc stepper... low torque, but sufficient in this case.
-my first time posting code and I am not sure if it is done correctly.
-this was a nice experience ( as are all projects really) as i want to keep it as simple as possible.
I am looking forward to the "real world test" on my next visit.
Bob D


Attached Files Thumbnail(s)
   
Image(s)
   
Reply
#2
Bob, awesome project for a kid, thumbs up !
Reply
#3
Hi Roman,
She is actually 26...but always wanting to learn. I would say she is a lot like me.
Bob D
Reply
#4
Ooops, my mistake

What I really wanted to say is that this is very nice non-trivial 1st Arduino project Smile
Reply
#5
Hi Roman,
I agree that practical projects are the best for teaching. Following through to a working product is also something that can lead to unexpected re-designs when things don't work quite as we thought they would.
Bob D
Reply
#6
Hi guys,
Here are the pictures of the as done turntable. The rest is up to my daughter to put together. She is going to work on adding two set points to the program as well for practice.
Now...on to the next project!
Bob D


Attached Files Thumbnail(s)
       
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)