Control mini DC motor using Tilt switch
Control mini DC motor using Tilt switch

Unlock smart detection with EzloPi!

Control mini DC motor using Tilt switch

The EzloPi smart devices provide automation through simple, customizable use with our open-source EzloPi platform, making daily life easier and improving human-machine interactions.

Before moving into this example, it is very important to know about the device registration, provisioning and converting the ESP32 device into an EzloPi device along with knowledge of Web Flasher, MiOS Mobile Application for Android/iOS and the MiOS Web Application.

1. About this example

The following project aims to interface the KY-20 tilt switch module with the EzloPi device to detect orientation changes. The KY-20 module is a simple tilt sensor which reacts to tilt movements. The EzloPi device reads the digital signal from the KY-20 module and executes predefined actions which the user has set based on the tilt status. This project setup can be used for applications like motion detection, angle or tilt detection in robotic arms, security systems, and automatic device shutdowns in case of abnormal tilts. The project involves wiring the components, configuring the EzloPi device to interpret the tilt sensor's output, handle the sensor’s data and trigger appropriate responses.

2. Project Demonstration Video

Welcome to the project demonstration video section. The following video showcases the key aspects of Control mini DC motor using Tilt switch, providing a visual walkthrough of its implementation.

3. Circuit Diagram & Interface

The following components are required for interfacing with the EzloPi device:

  • ESP32 as an EzloPi smart device.
  • KY-020 Tilt switch module.
  • Single Channel Relay Module
  • DC Motor
  • DC Power Source

The wiring diagram of ESP32 30 pin is represented as follows:

The following connections are made in order to complete the circuit setup.

From ESP32 to KY-020:

ESP32 KY-020
VCC Vin
GND GND
D15 S (Signal)

From ESP32 to the Single Channel Relay module:

ESP32 Relay Module
3V3 (VCC)
GND (GND)
D4 S (Signal)

From Relay Module to DC Motor & Power Supply:

Relay Module Power Supply
NO Positive terminal
NC Negative terminal & 2nd terminal of Motor
COM 1st terminal of Motor

4. Interfacing the Tilt Switch Module & DC Motor using the EzloPi Web Flasher

1. Set up your device/hardware by visiting config.ezlopi.com

  1. Log in using the credentials which you just set earlier while signing up.
  1. Now, click on the Connect Device button and a pop-up window will appear.
  1. Now, select COM Port to which your ESP32 device is connected. In our case, the COM3 port is used.

Click Connect

  1. If you are new to this and it's your first time configuring, select Create new Device ID. Enter Wifi SSID and Wifi Password.
  2. In the Device Configuration, tab click on Digital Input.
  1. A Digital Input window will open for inputting the following parameters:
  • Set a Device name of your choosing. In our case, we have set it to the Tilt Switch Module.
  • Set INPUT GPIO to 15.
  • Set Device Subtype to Digital In Switch / Button / Key.
  • Set Resistor to PULL DOWN.
  • Then Click Apply Button.
  1. In the Device Configuration, tab click on Digital Output.
  1. A Digital Output window will open for inputting the following parameters:
  • Set a Device name of your choosing. In our case, we set it to the DC Motor.
  • Set INPUT GPIO to 4.
  • Set Device Subtype to Relay.
  • Set Resistor to PULL UP.
  • Then Click Apply Button.
  • After clicking the apply button you can see a table of your setting in the device configuration tab.
  • Press the Flash Device button.
  1. A window will appear on the bottom right side of the screen displaying “Please press BOOT button while flashing begins.”
  1. Hold the BOOT button down until the next window appears on the bottom right side of the screen which says “Installation prepared. Please release the boot button now.”
  1. Release the BOOT button from your ESP32 when this pop-up on the bottom right window appears.
  1. After some time, a popup will appear saying Device Flashed Successfully! This means that your device has been set up successfully.

5. MiOS Web Dashboard

  1. After configuring the controller with the EzloPi web flasher, head to ezlogic.mios.com
  1. Use the same credential to log in that you used for configuring the controller with the web flasher.
  1. Now, on the MiOS web dashboard, you will see the tiles of your connected devices as shown above labeled as Tilt Switch Module and DC Motor. Currently, no tilting or changes in orientation is detected by the sensor therefore both tilt sensor and DC Motor tiles show the “OFF” message.

MeshBots:

  1. On the left side of the screen under Automation, click on MeshBots.
  2. On meshbot screen, click on Create new MeshBot button present on the top right corner of the screen.
  3. After clicking on Create new MeshBot, you will see this now under Automation MeshBot click on EzloPi.
  1. On the next screen you will see that we can create a name of our choosing, in this case we write it as Test002.
  1. In the trigger tab you can set the TRIGGER for your device and in the ACTION tab you can set the action to be performed based on the trigger which you have created.
  1. Set these things in TRIGGER section:
  • Set Node Type to Device.
  • Set the Node to Tilt Switch Module.
  • Set the Capability to Switch.
  • Set the value to True.
  1. Set these values in the TRUE part of the ACTION section.
  • Set Node type to Device.
  • Set Controllable to DC Motor.
  • Set Capability to switch.
  • Set value to true.
  1. Set these values in the FALSE part of the ACTION section.
  • Set Node type to Device.
  • Set Controllable to DC Motor.
  • Set Capability to switch.
  • Set value to false.
  • After clicking the apply button you can see a table of your setting in the Current configuration tab.
  1. After clicking the save button you can see this screen on the top right corner of the screen.
  1. Now as seen above, it shows that when the Tilt Switch module gets triggered ON then the DC Motor also gets turned ON because of the rules we have set in the meshbot.

6. MiOS App

You can download the MIOS Android app from the Google Play Store and Apple App Store.

Google PlayApple App Store

  1. After downloading the app, proceed to install the application and open it.
  1. Using the MIOS mobile application, create a new Ezlo Cloud account using the sign-up option. If you already have an account, you may proceed to log in.
  1. After successfully logging in, you will be able to see the number of controllers connected such as a lamp, fan, or any other device in the MiOS app. Tap on any controller of your desired ID:
  1. You will be able to see the status of your controller whether it is online or offline. Access the device dashboard, and tap the device. The following view of the dashboard will appear:
  1. As shown above on the MiOS mobile dashboard, you can see the tiles of your connected devices as shown above labeled as Tilt Switch Module and DC Motor. Currently, no tilting or changes in orientation is detected by the sensor therefore both tilt sensor and DC Motor tiles show the “OFF” message.
  1. Now as seen above, it shows that when the Tilt Switch module gets triggered ON then the DC Motor also gets turned ON because of the rules we have set in the meshbot.
Buy Components

eZlopie Products A single-channel 5V relay module $00.00

eZlopie Products Momentary switch $00.00

eZlopie Products Level Shifter Module (BSS138) $00.00

eZlopie Products ESP32
$00.00

eZlopie Products AC Lamp and Holder
$00.00