Introduction: Satisfying OCD

Done By Joel Ng from Singapore Polytechnic studying in the course of Diploma in Computer Engineering (DCPE) and my supervisor Mr Teo Shin Jen, i got the parts and know how from him.

BACKGROUND

I always have a tendency to check if i have left the lights on or left the air conditioner on after i have left my house or my office. There was once I left for the airport early but when I reached, I suddenly felt like I left the air condition on. In the end i headed back home just to check if I had switched it off.

My OCD is a project where by i have an android application that can switch off the lights or the air condition from anywhere that has internet(practically anywhere thanks to the availability of data plans).

Step 1: Software

Picture of Software

For this project, I'll be using the official android IDE, Android Studios to code the android application, http://developer.android.com/sdk/index.html , and I'll be using the Arduino IDE to program and upload the program to the ESP-01, https://www.arduino.cc/en/Main/Software. To get the ESP8266 "board" in the board manager, go to File>Preferences, under settings tab, copy and paste "http://arduino.esp8266.com/stable/package_esp8266com_index.json" into the Additional Boards Manager URLs then go to tools>board>boards manager then key in "ESP8266" into the search and download the result by ESP8266 community.

Step 2: Hardware

Picture of Hardware

1.ESP-01(ESP8266)
2.Android phone
3.Servo(I'm using MG90)
4.USB to UART(I'm using CP2102)
5.3v3 power supply(I'm using ywrobot PSU)

CP2102 -- -- ESP-01 -- -- ywrobot PSU
RX -- -- TX
TX -- -- RX
-- -- VCC -- -- 3V3 (Do not use 3V3 from CP2102)
GND -- -- GND - CH_PD -- -- GND

RST connected to a push button at normal high. RST is active low meaning when set to Ground, it'll activate.
GPIO0 set to VCC for normal mode meaning it'll run the program that was uploaded and set to GND to run in Programming mode to upload a program. always reset when changing the GPIO0 to change the chip mode.

Sometimes the ESP-01 takes up too much power so i have attached a 220uF Capacitor to the power supply.

If using an external supply, always connect the GND of the external supply to all the GND of the working circuit. Always have a common ground.

The ywrobot board is supplied by a DC barrel plug. input voltage ranging around 6V-12V. Using the little connectors on the power rails to select which voltage output you want.(3V3 or 5V, use 3V3 in our case)

The Servo has 3 connections, VCC, GND and Control.
Servo -- -- ESP-01 -- -- ywrobot PSU
VCC -- -- -- -- 5V(use the second power rail or use an external 5V)
GND -- -- GND -- -- GND
Control -- -- GPIO2

Extra knowledge on Servo

A Servo's position is determined by the control input. The control has a 50ms duration for the input. During this 50ms, the first 2 ms determines the position. 1ms is the position on the left and 2ms is the position on the right.
If coding the control line without the Servo class(like using other micro controllers without a Servo class) Remember to add the additional delay behind the 1-2ms to fill up the 50ms.

Step 3: Android Studio Programming

The full source code can be found at https://github.com/joelngpd25/MyOCD .

First create a new android studios project. File>New>New project(if you are already on an opened project) or click start a new android studio project if u haven't opened a project. Application Name: MY OCD(or anything you want)
Company domain: (Anything you want)>Phone and tablet i chose API15 as it suits most phones around.> blank activity. The blank activity can be left as default.

Copy the code in Main activity to yours and also the content_main.xml.
Under AndroidManifest.xml, make sure to add '' just above the
Extra knowledge
Android studio's coding policy is that networking codes should be done under a different thread so using AsynTask.execute does the networking in the background.

Step 4: ESP-01 Programming

Step 5: PORT Forwarding

Picture of PORT Forwarding

In order to access the ESP from outside the LAN, port forwarding from the router is required.
What is port forwarding? It is the forwarding of connection from outside the router to inside the router using a port number. For example, I'll use port 80. On my router, i set port 80 to forward to the ip address of my ESP-01 when connected. Then on my android app, i just type in my public ip(Can be found by googling, whatsmyip) and the port which was set to be 80. Search up on port forwarding for more detailed information.

To get to the interface of port forwarding, type in the ip address of your default gateway in your web browser to access the http interface of your router(find the default gateway by window+r then type cmd then press "ok". Key in "ipconfig" into the command prompt and look for Default Gateway).

Comments

wold630 (author)2016-02-19

Great idea! I always think I left the garage door open!

JoelN11 (author)wold6302016-02-19

Thanks! Oh yes that feeling!

About This Instructable

572views

7favorites

License:

Bio: Singapore Polytechnic student studying in the course of computer engineering. Coding to improve way of life.
More by JoelN11:WiFi Tank(Esp8266/01 Variant)Satisfying OCD
Add instructable to: