An Automatic Phone Charger



Introduction: An Automatic Phone Charger

"This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida ("

The idea behind this project was to create a device that could charge a phone, and then unplug it when the phone reaches 100%. This would stop issues of over charging.

Step 1: Plastic Components

There were some components that were used that were 3D printed. These components comprised a base, a holder for the charger, a rack and pinion gear set (a normal gear and a linear piece that changes the rotation to linear movement), and a base for everything to operate on. These components will be explained in the following paragraphs. In order of appearence

Charger Holder

The purpose of this is to hold the phone charger, or at least give it a better and level base to be upon.


The base has rings for the phone holder as well as a track for the gear set.

Phone Holder

Holds the phone, obviously

Phone Arm

Moves and holds the phone

Rack and Pinion Gear Set

Used to move the phone charger back and forth

Step 2: Break Down of Non 3D Printed Components

These are the components that were either purchased for the project or already owned. For some of the parts I linked to them/similar items on amazon, but feel free to acquire them anywhere.

Micro Servo:

Standard 0-180 Servo:

HC-05 Bluetooth Serial Module:

Phone and Phone Charger



Box or bin for base

Touch Sensor:

Step 3: Electronics

The circuit for this project may require some though, mainly because of the HC-05 module. Many of the modules of this type are rate for roughly 3.3V to 6V, which is with in the operating range of the Arduino. But, for serial communication the Rx pin sometimes works better with only 3.3V. As seen in the above diagram the two servos are hooked up to the Vin pin on the Arduino. This extra voltage can be supplied by anything, I used a 9 volt battery. The touch sensor was plugged into the 5V on the Arduino. This was because all of the components had trouble running off of the same voltage. The touch sensor is attached to pin 2 so it can be used as a pin interrupt. Then the bluetooth module is connected to the the Rx and Tx pins for serial communication. Between the Rx pin on the module and Tx on the Arduino is a 2 kilo ohm resistor with a 1 kilo ohm connecting to ground. This helps to regulate the voltage going in.

Step 4: Assembly

The assembly is quite simple.

  1. with some super glue mount your servos in their positions, one for the gear by the cutout on the base and one near where the base of the phone is.
  2. Attach the touch sensor to the phone holder, so it can know when the phone is there.
  3. Then attach the gear and arm to their respective servos
  4. Make sure wires do not interfere with other components as you fill your electronics in

Step 5: Code

There are three sets of code that will be presented, one code for the Arduino, that was created in the Arduino IDE and two codes that were made in Android Studio. The Android apps are the same except for one is the full app that tracks battery life and one does not. The second one is for testing purposes.

Arduino Code

The main point of this code is to operate the touch sensor and motors, it receives a command from the phone and acts upon it.

#include  //calls the servo library so we can control the two servos<br>Servo servo1;
Servo servo2;//creates two servo objects for each servo motor
int a=0;//tracking variable for testing
int q=0;//a variable that allows there to be a delay before to pluggin process begins
char c;//variable that contains the serial message from the phone
void setup() {
  attachInterrupt(digitalPinToInterrupt(2), AH, FALLING);// attaches a falling interrupt to know exactly when the touch sensor sees when the phone is being out on
  servo2.attach(9);// initializes the two servos
  Serial.begin(9600);// begins the serial communication at a rate similar to that of the bluetooth module
  servo2.write(20);//auto sets the servos to a starting position
void loop() {
  if (Serial.available()){// this checks if there is anything coming in from the phone over the serial pins Tx and Rx;//reads what is coming in from
    if (c=='t'){//if the serial device reads a t then that means that the phone is fully charged, the unplugging process begins
      servo2.write(120);//unplugs the charger
      delay(5000);//waits to make sure there is time for the removal
      servo1.write(110);//moves the phone into an upright position to signal 
      attachInterrupt(digitalPinToInterrupt(2), AH, FALLING);//reattaches the interrupt  
  if (q==1){//if the condition for pluggin in is ture then commence with attaching the charger
  servo2.write(0);//moves servo into position
  q=0;//resets condition
void AH(){
    servo1.write(180);// drops the phone platform into the charging position
    q=1;//starts the condtition to continue the process
    detachInterrupt (digitalPinToInterrupt(2));//detaches the interrupt, so that there wont be any issues with the interrupt starting when it shouldn't

Android App

Here I will only display the proper app but the test code file will also be given, the only difference will be the removal of the runnable and getBattery class. The serial code mentioned is the one that is standard for phones connecting to devices like the module.

package com.example.daniel.make;<br>
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.Handler;
import android.os.Bundle;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import java.util.Set;
import java.util.UUID;
public class MainActivity extends AppCompatActivity {
    // creating necessary objects
    Handler handler;//helps with the loop
    Runnable runnable;//runs continuously
    BluetoothAdapter mBluetoothAdapter;
    BluetoothSocket mmSocket;
    BluetoothDevice mmDevice;
    OutputStream mmOutputStream;
    volatile boolean stopWorker;
    private OutputStream outputStream;
    private final String DEVICE_NAME="HC-05";
    private final UUID PORT_UUID=UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
    private BluetoothAdapter device;
    private BluetoothSocket socket;
    protected void onCreate(Bundle savedInstanceState) {//is a set of instructions that run when the app is created
        super.onCreate(savedInstanceState);//displya creation
        runnable = new Runnable() {
            public void run() {//runs repeatedly
                int level = (int) getBattery();// gets the current battery level
                if (level==100){//if the battery level reaches 100%
                    try {
                        getBT();//connects to the bluetooth module
                        openBT();//opens it
                        sendData();//sends the necessary data
                        closeBT();//closes the object
                    catch (IOException ex) { }
                handler.postDelayed(runnable, 5000);//a delay
        handler = new Handler();
    public float getBattery() {
        Intent batteryIntent= registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));// creates the action that connects to the battery
        int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);//gets the bettery level
        int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);//gets the scale of the battery
        if (level == -1 || scale == -1) {//in case of misstep
            return 50.0f;
        float batt = (level/(float)scale)*100.0f;//gets the proper scale
        return batt;//returns the level
    void getBT(){//gets the possible bluetooth connections
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();//gets the adapter
        if(!mBluetoothAdapter.isEnabled()) {//makes sure the phone ahs blue tooth on
            Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);//requests it to be turned on if not
            startActivityForResult(enableBluetooth, 0);
        Set pairedDevices = mBluetoothAdapter.getBondedDevices();//gets the list of bonded bluetooth
        if(pairedDevices.size() > 0) {//makes sure there are some devices
            for(BluetoothDevice device : pairedDevices) {//loops through the devices
                if(device.getName().equals("HC-05")) {//checks if its the proper one
                    mmDevice = device;//saves it
    void openBT() throws IOException {
        UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard //SerialPortService ID
        mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);//connects to the device with the proper id
        mmOutputStream = mmSocket.getOutputStream();//starts the ability to send data to the arduino module
    void sendData() throws IOException {//class that sends the t to the arduino
    void closeBT() throws IOException {//closes all of the connections to the arduino
        stopWorker = true;

Step 6: Files

Thank you for reading, attached are the files that were used in this project

Be the First to Share


    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • For the Home Contest

      For the Home Contest
    • Make It Bridge

      Make It Bridge