You are on page 1of 5

Page |1

AIN SHAMS UNIVERSITY


FACULTY OF ENGINEERING
Mechatronics Engineering

DIY Tilt/Pan Holder


Team #37
Student name ASU ID
Amr Osama Mostafa 1700920
Amr Aladdin Ismail Omari 16T0200
Ahmed Osama Abd El-Samie 1700025

---------------------------------------------------------------------------------------------------------------------------

1|Page
You can get the components needed for this Tilt/Pan
Holder from the links below:
• Frdm KL25Z ………………. Future-e
• Servo Pan / Tilt Bracket Platform………. ram-shop
• 2x Servo motors……………. Future-e
• Jumper Wires…………………. Future-e

Mbed Frdm KL25Z Code


#include "mbed.h"

// C++ code

//

#include "Servo.h"

Servo myservo(PTC13); // create servo object to control a servo

2|Page
Servo myservo2(PTC14);

int xPosition = 0;

int yPosition = 0;

int SW_state = 0;

int mapX = 0;

int mapY = 0;

int lastx = 0;

int lasty = 110;

int pos = 0; // variable to store the servo position

int triger = 1;

int triger2 = 1;

DigitalIn VRx(PTC10);

DigitalIn VRy(PTC11);

DigitalIn SW(PTC12);

void upup (int angele)

if(triger2 == 1) {

for (pos = lasty; pos <= lasty+angele; pos += 10) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

myservo2.write(pos);

if(pos == 120+angele) {

triger2 = 0;

wait(100); // waits 15ms for the servo to reach the position

float map(float in, float inMin, float inMax, float outMin, float outMax) {

// check it's within the range

if (inMin<inMax) {

if (in <= inMin)

return outMin;

if (in >= inMax)

return outMax;

3|Page
} else { // cope with input range being backwards.

if (in >= inMin)

return outMin;

if (in <= inMax)

return outMax;

// calculate how far into the range we are

float scale = (in-inMin)/(inMax-inMin);

// calculate the output.

return outMin + scale*(outMax-outMin);

void down (int angele)

if(triger == 1) {

for (pos = lastx; pos <= angele; pos += 10) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

myservo.write(pos);

if(pos == angele) {

triger = 0;

wait(100); // waits 15ms for the servo to reach the position

int main() {

while(1){

xPosition = VRx;

yPosition = VRy;

SW_state = SW;

mapX = map(xPosition, 0, 1023, -315, 291);

mapY = map(yPosition, 0, 1023, -180, 180);

if(abs(lastx - mapX) > 40) {

triger = 1;

down(mapX);

4|Page
lastx = mapX;

wait(100);

if(abs(lasty - mapY) > 20) {

triger2 = 1;

upup(mapY);

lasty = mapY;

wait(100);

if(SW_state == 0) {

triger = 1;

lastx = 0;

down(0);

triger2 = 1;

lasty = 50;

upup(50);

Reference
https://colourtvservicebbsr.blogspot.com/2019/04/diy-
arduino-gimbal-self-stabilizing.html

5|Page

You might also like