Shiv Kumar
Published

Pan-Tilt Controller Using Particle Photon and Bluetooth

A pan-tilt controller locally controlled by a Photon and remotely via Bluetooth, physical potentiometers and another Photon.

IntermediateProtip2 hours1,397
Pan-Tilt Controller Using Particle Photon and Bluetooth

Things used in this project

Hardware components

Photon
Particle Photon
×2
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×2
HiTech HS-5685MH Servo
×2

Story

Read more

Schematics

The Pan-Tilt Remote Controller

Showing the entire circuit board with Photon, HC-05 and 18650 Battery

The Pan-Tilt Remote Controller - Front View

Showing the two Potentiometers on the front panel

The Pan-Tilt Remote Controller - Closeup View

The Pan-Tilt Remote Controller - Showing wiring on the perma breadboard

Pan-Tilt Controller - Photon

D0 and D1 pins of the Photon connected to the Pan and Tilt Servos. The RX pin from the HC-05 is connected to the TX pin of the Photon and the TX pin of the HC-05 is connected to the RX pin of the Photon

Pan-Tilt Controller - Showing the Photon board and the Power supply board

The HC-05 is mounted on the Power supply board (I already had this board from my earlier (Phone based inclinometer) project, and since the Photon takes up the entire board, I decided to mount the HC-05 here and wire it from this board to the Photon. The Orange and green wires are the RX and TX pins respectively of the HC-05 module

Code

Pan-Tilt Remote controller

C/C++
#define panReadPin A0
#define tiltReadPin A1

unsigned long panTiltReadInterval = 30;
unsigned long panTiltReadLastTime;

USARTSerial& buletoothSerial = Serial1;

void setup() {
    buletoothSerial.begin(9600);
}

void loop() {
    
    unsigned long elapsedMillis = millis();
    
     if (elapsedMillis - panTiltReadLastTime >= panTiltReadInterval)
     {
        panTiltReadLastTime = elapsedMillis;
    
        int panValueRead = analogRead(panReadPin);
        int tiltValueRead = analogRead(tiltReadPin);
  
        if (buletoothSerial.available())
        {  
              Serial.write(buletoothSerial.read());
        }

        unsigned int panValue = map(panValueRead, 0, 4095, 800, 2255);
        unsigned int tiltValue = map(tiltValueRead, 0, 4095, 755, 2240);

        buletoothSerial.print(panValue);
        buletoothSerial.write(',');
        buletoothSerial.print(tiltValue);
        buletoothSerial.write('|');
     }
}

Pan-Tilt Controller

C/C++
#define bufferSize 1024
#define panServoPin D0
#define tiltServoPin D1
#define panServoMin 800
#define panServoMax 2255
#define tiltServoMin 755
#define tiltServoMax 2240


byte buffer[bufferSize];
const char delimiters[3] = ",|";
int bytesRead;

USARTSerial& buletoothSerial = Serial1;
Servo panServo;
Servo tiltServo;


void setup() {
    buletoothSerial.begin(9600);
    panServo.attach(panServoPin);
    tiltServo.attach(tiltServoPin);
    
    // Center the Servos
    panServo.writeMicroseconds(1528);
    tiltServo.writeMicroseconds(1498);
}

void loop() {
    
    while (buletoothSerial.available() > 0) {
        byte byt = buffer[bytesRead] = buletoothSerial.read();
        buffer[bytesRead] = byt;
        bytesRead++;
        
        if (byt == 124)
        {
            char* tempPayload = (char*)malloc(bytesRead + 1);
            memcpy(tempPayload, buffer, bytesRead);
            tempPayload[bytesRead] = NULL;
            bytesRead = 0;
            
            double panValue = strtod(strtok(tempPayload, delimiters), NULL);
            double tiltValue = strtod(strtok(NULL, delimiters), NULL);
            free(tempPayload);
            
            panValue = constrain(panValue, panServoMin, panServoMax);
            tiltValue = constrain(tiltValue, tiltServoMin, tiltServoMax);
            panServo.writeMicroseconds(panValue);
            tiltServo.writeMicroseconds(tiltValue);
        }
        
        Particle.process();
    }
}

Credits

Shiv Kumar

Shiv Kumar

1 project • 3 followers
Studied Electronics Engineering. Developed and manufactured a bunch of Automotive electronic aftermarket kits. Now a Software Engineer

Comments

Add projectSign up / Login