0% found this document useful (0 votes)
15 views5 pages

Group 37

This document describes a DIY tilt/pan holder created by a student team at Ain Shams University. It provides a parts list and code for controlling two servo motors with an Mbed Frdm KL25Z microcontroller board. The code uses signals from potentiometers to map joystick positions to servo positions, allowing the holder to tilt and pan according to joystick input. It includes functions to move the servos up/down and left/right in steps, ensuring smooth motion.

Uploaded by

amraladdin94
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Group 37

This document describes a DIY tilt/pan holder created by a student team at Ain Shams University. It provides a parts list and code for controlling two servo motors with an Mbed Frdm KL25Z microcontroller board. The code uses signals from potentiometers to map joystick positions to servo positions, allowing the holder to tilt and pan according to joystick input. It includes functions to move the servos up/down and left/right in steps, ensuring smooth motion.

Uploaded by

amraladdin94
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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