Introduction: Rotating Phone Mount

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com).

Want to make a rotating phone mount so you can view contents of your phone in portrait or landscape orientation without having to hold it? Then, look no further.

To create this project, you will need:

- Arduino Microcontroller and IDE

- USB Cable to upload code

- Breadboard

- Jumper Wires

- LCD Display

- Servo

- Column that can attach to the servo

- IR Remote

- IR Receiver

- 10k ohm resistor

- Kenu Airframe+ Phone Clip (or something to hold the phone in place)

- 9 V Battery for portable power or just USB powered Arduino

Step 1: Build the IR Receiver Circuit

First, jump GND and +5V from the Arduino to the power rails on your breadboard. Then, jump your 10k ohm resistor from the +5V power rail to the output pin of your IR receiver phototransistor. Next, use a jumper wire to connect to pin 11 on the Arduino from the output pin of the IR receiver. Then, use two jumper wires to send ground and +5V to the respective pins on the IR receiver. The RC filter pictured in the schematic above is not necessary. Lastly, I did not make the schematic shown in this step, and the source for it is present in the picture.

Step 2: Connect the Servo, Column, and Phone Holder

Now, use two jumper wires to jump from ground and +5V of the breadboard power rails into the brown and red wires of the servo, respectively. Then, use one jumper wire to attach pin 9 on the Arduino to the orange wire of the servo.

Then, attach a column to the head of the servo as shown in the second picture.

Finally, attach something to hold the phone to the column, like the Kenu Airframe+, as shown in the third picture.

Step 3: Connect the LCD Display for Servo Readout

Jump ground and +5V from your breadboard power rails to the respective pins on the LCD Display. Also, jump the SDA and SCL pins from the LCD onto the Ardiuno. The Arduino's SDA and SCL pins can be identified from the back of the Arduino board and are the two pins above AREF and Ground above pin 13. The SCL pin is the highest one. This allows the LCD display to read out the current servo position.

Step 4: Use the Code and Libraries Attached to Program the Arduino

Download the RotatingMountCode.zip file. Install the Arduino IDE and unzip the downloaded file into Documents\Arduino. Make sure you copy the contents of my sketches and libraries folder into your sketches and libraries folder. Open the ServoIRandLCD sketch and upload it to your Arduino.

See later steps for code explanation.

Step 5: Connect Desired Power Source to Arduino and Use the Remote to Rotate the Mount!

Either leave the Arduino plugged into your computer or unplug it from your computer and use a 9V battery to provide DC power to the Arduino. Finally, use a cheap IR remote to control the servo and therefore the orientation of the phone mount!

The number 1 on the remote should set the servo position to 0 degrees, number 2 to 90 degrees, and number 3 to 180 degrees. Meanwhile the + and - buttons on the remote should increment or decrement the servo's angle by 1 degree, respectively.

Note: If you use a different IR Remote than the one pictured here, it is possible the IR codes corresponding to various buttons changed. If so, modify the ServoIRandLCD sketch to use those IR codes instead.

Step 6: Read This for Source Code Explanation

The source code for the Arduino sketch can be found below or in the previously attached .zip file. The required libraries can only be found in the previously attached .zip file in step 4.

The first thing the code does is include the necessary libraries needed to run all the functions in the sketch. Next, it declares pin 9 on the Arduino to be the PWM-enabled signal pin for the servo. It also makes pin 11 on the Arduino the pin used for the IR receiver. Next, it declares an integer variable used to keep track of the servo's position in degrees and sets it to 0 degrees, initially. Then, it instantiates the required objects for an IRrecv object, a servo object, and myDisplay LCD object (that is also configured in the same line) so these objects can be used later on.

Next, in the setup function, the serial port is started at 9600 bits/sec so the serial monitor can be used to keep track of the servo's position if desired. It also attaches the myservo object to pin 9, starts the IR receiver, and initializes the LCD display.

In the main loop function, the body of which is only executed if an IR transmission is received from the IR receiver, the IR receiver decodes the signal sent to it from the IR remote using the decode(&results) function and then if statements determine what to set the servo to depending on the IR value received. The write function is used to set the servo to its appropriate degrees, and the read function is used to find the current angle of the servo and increment or decrement it as necessary.

Finally, the current angle of the servo is sent to both the serial monitor and LCD display using the myservo.read() function, and the main loops iterates indefinitely.

Source Code:

#include //Arduino standard library
#include //IR library #include "Wire.h" //Wire.h for LCD (sometimes needed) #include "LiquidCrystal_I2C.h" //LCD library

#define servopin 9 //this defines pin 9 as the pin used for the servo control lead (orange)

int RECV_PIN = 11; //IR photo-transistor sends output to pin 11

int currentAngle = 0; //declare currentAngle integer variable and set to 0

IRrecv irrecv(RECV_PIN); //instantiate a IR receiver object decode_results results; //instantiate a decode_results object. This object is separate from the IR receiver.

Servo myservo; //instantiate a Servo object named 'myservo' //a maximum of eight servo objects can be created

LiquidCrystal_I2C myDisplay(0x27, 16, 2); //instantiate LCD object and set up config

void setup() {

Serial.begin(9600); //start serial port

myservo.attach(servopin); //attaches the servo on pin 9 to the servo object

irrecv.enableIRIn(); //start the receiver

myDisplay.init(); //initialize LCD

myDisplay.backlight(); //turn on LCD backlight

}

void loop() {

if (irrecv.decode(&results)) //if transmission received...

{ Serial.print("IR value received: ");

Serial.println(results.value); //display value received

//interpret the received commands... if (results.value == 16724175) //1 { //left myservo.write(0); }

if (results.value == 16718055) //2 { //middle myservo.write(90); }

if (results.value == 16743045) //3 { //right myservo.write(180); }

if (results.value == 16754775) //+ { //increment currentAngle = myservo.read(); myservo.write(currentAngle + 1); } if (results.value == 16769055) //- { //decrement currentAngle = myservo.read(); myservo.write(currentAngle - 1); } }

irrecv.resume(); //Receive the next value

//Serial monitor print Serial.print("Current servo position: ");

Serial.println(myservo.read()); //this retrieves the servo position and sends it to the serial monitor

//LCD print myDisplay.clear();

myDisplay.print("Servo deg.: ");

myDisplay.print(myservo.read());

delay(200); //delay to make servo actuation stable

}

Step 7: Watch My Youtube Video for Help

View my unlisted YouTube video which fully discusses and demonstrates the project if you have any questions!