Open Source Smart Power Plug

From Microduino Wiki
Jump to: navigation, search

Outline

  • Project: Microduino Open Source Smart Power Plug
  • Objective: To use a phone to control the power-on or off of a plug.
  • Difficulty: Low
  • Time-consuming: 2-hour
  • Maker:
  • Introduction:

The Smart Power Plug is consisted of the control module and the circuit part. Users can use a phone to connect the Bluetooth module (Microduino-BT ) and send instructions or receive the status of the circuit. The core control module (Microduino-Core) can analyze the data and control the circuit via the relay.

123.png

Bill of Materials

  • Microduino Equipment
Module Number Function
Microduino-Core 1 Core board
Microduino-USBTTL 1 Program download
Microduino-BT 1 Bluetooth communication
  • Other Equipment
Module Number Function
Bottom case + circuit board 1
Shell 1
Long screw 1 Fixate the bottom case and the shell
Short screw 1 Fixate the bottom case and the circuit board
M3 screw driver 1

Principle of the Experiment

1Chazuotheory.jpg
  • Principle of the circuit control

The Smart Power Plug can be divided into two parts, voltage conversion and delay control. Let first introduce the voltage conversion. Since the common used voltage at home is 220V and the Microduino-Core works under 5V DC voltage, this part can be treated as a voltage converter, just like a phone power supply plug that can change the voltage. The other part is the relay control. The relay is when the input voltage changes and reaches to the specified requirements, which can make the controlled amount of a predetermined step change in the electrical output circuit. It has an interactive relationship between the controlling system (also known as the input loop) and the controlled system (also known as the output circuit). It is generally used in automatic control circuit, which is actually an "automatic switch" using a small current to control the operation of a large current. Therefore, it plays the automatic regulation, security protection, transformation circuit and so on in the circuit. Since the Microduino-Core control pin's output voltage is very small and it cannot charge appliance directly, It need to control through the relay to indirectly control the household power supply.

  • Wireless Communication Principle

Here we adopt Microduino-BT module since it shields the bottom protocol. Bluetooth protocol will not be classified here and you just need to make sure the default serial port connection method of the Bluetooth is (D2,D3), which can refer to the picture below.

Microduino-BT-2Big1.jpg
  • Main Component

Microduino-BT

Document

Debugging

  • Program Download

Stack the Microduino-Core and Microduino-USBTTL together, and then upload the pre-written program from Microduino-USBTTL to Microduino-Core with a USB cable. Please be noted to upload the program before stacking all modules.

Download1.jpg

Open Arduino IDE and then click【File】→【Open】. (If you don't have the Arduino IDE on your computer, you can refer to installation method below. )

Bleopen.jpg

Find "MicroduinoBluControlOutlet.ino" in the popup dialog, double click it and open.

Bluecontrol.jpg

Click the icon "√" on the top left to compile and the Tool, choose the right board card (Microduino-Core Atmega328P@16M,5V) and the port number (COMX). After that, please click "→" and download the program to the development board.

Chooseboard.jpg
  • Buildup

Fixate the circuit board on the bottom case with three 4mm screws.

Chazuo1.jpg

Stack the Microduino-BT and the Microduino-Core, then insert them into the base board of the Smart Plug.

Chazuo2.jpg

Insert the shell into the bottom case and fixate it with 8mm long screws. By here, the buildup of the Smart Plug part is completed.

Chazuo3.jpg

Plug in the Smart Plug into the socket, connect the phone charger and press down the button. You can see the indicator goes on, which means the phone starts charging. As the picture shown below" ①Switch button ②Power-on indicator ③Power-on and off indicator of the Smart Plug

Chazuo4.jpg
  • Phone APP

Scan the two-dimension code with your phone, download the Bluetooth APP and open it.

Chazuo2d.jpg

Click SCAN, search Bluetooth devices around you, find and click Microduino.

Chazuoandroid1.jpg

Wait for 1-2s until you see "Ready" on the screen, then you can start to operate the Smart Plug.

Chazuoandroid2.jpg

Click the button switch in the middle of the screen and you can control the power-on and off of the Plug, which can also be controlled by the key on the Plug. The phone APP can realize synchronous opening or closing.

Chazuoandroid3.jpg

Notes

  • Be careful about the safe use of the electricity. Please make sure all installation is operated under power-off status.
  • If adopting Serial10 connection method in the Bluetooth schematic, please download stack the Microduino-BT when burning program with Microduino-Core and Microduino-USBTTL or it'll cause serial conflict. Here is the right thing to do: After burning the program, please pull off the Microduino-USBTTL, then stack the BT module and the Core module on the base board of the Plug.

Program Description

  • Main Program Part
void loop() 
{ 
    // Read the serial port if there is data received. It needs conversion every time the serial port transmits a character.
    while (my_Serial.available() > 0) 
    { 
 
        tmp += char(my_Serial.read()); 
        delay(2); 
    } 
    //Judge the status if the content from the serial port is not empty
    if (tmp.length() > 0) 
    { 
        if(tmp == "on")      //If receives "on" 
        { 
            Serial.println("power on");  //Serial display: Power on  
            digitalWrite(outletPin, HIGH); //Get the switch indicator lightened 
            swith = true; 
        } 
        else if(tmp == "off")  //If receives "off"
        { 
            digitalWrite(outletPin, LOW); //Turn off the switch indicator 
            Serial.println("power off");//Serial display: Power off 
            swith = false; 
        } 
        tmp = ""; 
    } 
 
    if(key_get(Button_Pin, 0)) //Used in physical button every time the key is pressed down and get loosened  
    { 
        delay(300); 
        swith = !swith; //Convert the switch status 
    } 
 
    if(change != swith) //If the switch status changes  
    { 
        change = swith; //Record the switch status for the current operation with "Change" 
        if(swith)   //If the status is "on" 
        { 
            digitalWrite(outletPin, HIGH); //Lighten the indicator 
            my_Serial.println("ON");     //Notice the BT module to start the Smart Plug 
        } 
        else 
        { 
            digitalWrite(outletPin, LOW);  //Close the indicator 
            my_Serial.println("OFF");     //Notice the BT module to close the Smart Plug 
        } 
    } 
}

Video