Bob
Published © GPL3+

Control a Mini Pan-Tilt Camera Mount with Your Phone

This is a simple project to control a mini camera mount with your phone over WiFi.

IntermediateProtip2 hours41
Control a Mini Pan-Tilt Camera Mount with Your Phone

Things used in this project

Hardware components

Mini-Pan-Tilt-Camera-Mount with servos by Ximimark
×1
4 channel logic level converter
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Male Jumper Wires
×1
SparkFun break away header pins, long
×1
Capacitor 1000 µF
Capacitor 1000 µF
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Schematics

blink-joystick-breadboard

Fritzing breadboard to help setup project

Code

interactive_servo.ino

C/C++
Use this program to send commands to a servo from the Arduino Serial Monitor
/*****************************************************************************
* Program Name: interactiveServo
* Author: Bob
* 
* Move a servo interactively with the Arduino IDE Serial Monitor
* 
* based upon  BARRAGAN <http://barraganstudio.com>
* and Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Sweep
* 
* ----------------------------------------------------------------------------
* Change History
* Date         Ver    Description
* ----------   ----   --------------------------------------------------------
* 02/25/2019   V1.0   Initial development
*****************************************************************************/
#include <Servo.h>

int    servoPIN = 12; //servo signal pin
int    servoPos = 90; //initial servo position
String inString = ""; //string to hold incomming command
Servo  servo;         //create servo object to control the servo



/*********************************************************************
 *  setup()
 *  Called once at power on
 ********************************************************************/
void setup() {
  servo.attach(servoPIN); // attaches the servo pin to the servo object
  servo.write(servoPos);  // set servo to initial position
  
  Serial.begin(115200);
  Serial.println("");
  Serial.println("-----------------------------------------------------------------------");
  Serial.println("- Welcome to Interactive Servo");
  Serial.println("- Open the serial monitor and ensure the Line Ending option (at bottom");
  Serial.println("- of the monitor window) is set to NewLine. To move the servo, enter a ");
  Serial.println("- number from 0 to 180(at top of monitor window)and press ENTER/SEND");
  Serial.println("-----------------------------------------------------------------------");
  Serial.print("Servo at "); Serial.print(servoPos); Serial.println(".\tNew position?");
}



/*********************************************************************
 *  loop()
 *  Main processing loop. Called after setup()
 ********************************************************************/
void loop() {
  
  /*wait till we get a command from serial monitor*/
  while(Serial.available()) {
    char inChar = Serial.read();
    if(inChar == '\n')  {
      int num = inString.toInt();
      inString = "";

      /*if valid number move servo*/
      if((num >= 0) && (num <= 180)) {
        for(int i = servoPos; i != num; i += (servoPos < num? 1 : -1)) {
          servo.write(i); delay(15); //move servo +/- 1 degree every 15 msec
        }
        servoPos = num; //update servo position
        Serial.print("Servo at "); Serial.print(servoPos); Serial.println(".\tNew position?");
      }
      else { Serial.print(num); Serial.println(" not valid.  Must be between 0 and 180"); }
    }

    /*add char to string if string not too long and valid digit*/
    else {
      if(inString.length() > 2) continue;
      if(isDigit(inChar)) inString += inChar;
    }
  }
}

blynk_joystick.ino

C/C++
Use this program with the Blynk app on your phone to control the pan tilt camera mount.
/*****************************************************************************
* Program Name: blink-joystick
* Author: Bob
* 
* Use the joystick widget in the Blynk app to conrol the mini pan tilt
* camera mount from your phone
* 
* ----------------------------------------------------------------------------
* Change History
* Date         Ver    Description
* ----------   ----   --------------------------------------------------------
* 04/07/2019   V1.0   Initial development
*****************************************************************************/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "wifiname";
char pass[] = "wifipassword";
char auth[] = "Blynk auth key";


Servo pan;        // create servo object to control the yaw servo
Servo tilt;       // create servo object to control the pitch servo
int panPos  = 90; // initial/current pan servo position
int tiltPos = 90; //initial/current tilt servo position




/*********************************************************************
 *  Get phone app joystick position (pan)
 *  Move pan servo
 ********************************************************************/
BLYNK_WRITE(V0) // V0 is the number of Virtual Pin  for pan servo
{
  int num = param.asInt();
  if((num < 0) && (num > 180)) return; //make sure number is valid
  Serial.print("V0 = ");Serial.println(num);
  
  for(int i = panPos; i != num; i += (panPos < num? 1 : -1)) {
    pan.write(i);       //move servo +/- 1 degree every 15 msec
    delay(15); yield(); //use yied to allow background tasks to run
  }
  panPos = num;         //update servo position
}



/*********************************************************************
 *  Get phone app joystick position (tilt)
 *  Move tilt servo
 ********************************************************************/
BLYNK_WRITE(V1) // V1 is the number of Virtual Pin  for tilt servo
{
  int num = param.asInt();
  if((num < 0) && (num > 180)) return; //make sure number is valid
  Serial.print("V1 = ");Serial.println(num);

  for(int i = tiltPos; i != num; i += (tiltPos < num? 1 : -1)) {
    tilt.write(i);      //move servo +/- 1 degree every 15 msec
    delay(15); yield(); //use yied to allow background tasks to run
  }
  tiltPos = num;        //update servo position
}



/*********************************************************************
 *  setup()
 *  run once at power on
 ********************************************************************/
void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);

  pan.attach(12);   // attaches the servo on pin 12 to the servo object
  tilt.attach(13);  // attaches the servo on pin 13 to the servo object
}



/*********************************************************************
 *  loop()
 *  Main loop ... run blynk
 ********************************************************************/
void loop()
{
  Blynk.run();
}

Credits

Bob

Bob

1 project • 0 followers
Hobbiest

Comments

Add projectSign up / Login