D1 Mini Switch Control: Automating Your Home with a PHP Server

Introduction

Are you tired of manually controlling your home appliances? Do you want to automate your home and have full control over your devices? In this blog post, we will explore an exciting project called D1 Mini Switch Control. By using a D1 Mini microcontroller, an Android smartphone, and a PHP server, you can easily control various home appliances such as lighting, ventilation, and heating, etc. This project is not only cost-effective but also offers a great level of convenience. Let's dive into the details and learn how to set up this system.

Requirements

To get started with the D1 Mini Switch Control project, you will need the following components:

  • A power supply - 5VDC, 1 Amp
  • A micro USB port
  • A D1 Mini microcontroller
  • 3 switches
  • An Android smartphone
  • Various cables

The System Diagram

Before we delve into the setup process, let's take a look at the system diagram. The diagram showcases the main components of the D1 Mini Switch Control project. It consists of a power button, a bell indicator, and three relays or switches. These switches can be turned on or off based on the instructions programmed into the microcontroller. The project can be controlled either via Wi-Fi or through physical buttons on the D1 Mini microcontroller. The Android smartphone plays a crucial role in hosting the PHP server and the web page used to control the inputs and outputs of the D1 Mini.

Project Applications

The D1 Mini Switch Control project offers a wide range of applications. It can be used for automating an irrigation system, where you can control electrovalves to water your plants automatically. These electrovalves can either be purchased or repurposed from old washing machines. Additionally, you can utilize this project to control other home equipment such as lighting, ventilation, and heating systems. The PHP server installed on an old Android smartphone acts as the central control unit, providing a user-friendly interface to manage the D1 Mini and its connected devices.

The PHP Server Setup

To get started with the D1 Mini Switch Control project, you need to set up the PHP server on your Android smartphone. The server installation is simple and does not require MySQL. Once installed, the PHP server creates a folder structure, including subfolders for configuration, logging, and public files. The "Public" folder is where all the necessary files reside, including the index.php file, which serves as the initial login page, and the automatic file responsible for controlling the D1 Mini.

Assembling the System

After setting up the PHP server, it's time to assemble the D1 Mini Switch Control system. The system consists of the D1 Mini microcontroller, the bell indicator, and the three relays or switches. These components are connected to one another using the provided cables. The D1 Mini microcontroller is then connected to a computer via a USB port. The solenoid valve, used for demonstration purposes, can be replaced with a used washing machine valve or a single solenoid valve depending on your requirements.

Programming the D1 Mini

To program the D1 Mini microcontroller, you will need the Arduino IDE. The control program for the D1 Mini is written in the Arduino IDE and offers various functionalities. It can send notifications to your Gmail account and even update the D1 Mini firmware over the air (OTA). The program utilizes several libraries, including libraries for Gmail, OTA firmware updates, EEPROM, Wi-Fi, and UDP. These libraries facilitate communication between the PHP server and the D1 Mini microcontroller.

Configuring the Program

Before uploading the program to the D1 Mini microcontroller, you need to make sure that you have selected the correct board in the Arduino IDE. Choose "Lolin D1 Mini R2" or "Mini" as the board depending on your model. Additionally, verify that the correct port is selected in the Arduino IDE. Once all the configurations are in place, check for any errors in the program. If there are no errors, proceed with uploading the program to the microcontroller.

Installing the Firmware

To install the firmware on the D1 Mini microcontroller, you need to put the microcontroller in programming mode. This can be done by connecting a wire between the Ground pin and Pin D3. After entering programming mode, click the "Send" button in the Arduino IDE to upload the program to the microcontroller. Once the program is uploaded, remove the wire and press the "Reset" button on the microcontroller. This will restart the microcontroller with the new firmware.

Verifying the System

After the restart, you can verify that the D1 Mini Switch Control system is working correctly. The system should be connected to the smartphone via Wi-Fi, and the PHP server should be up and running. The D1 Mini microcontroller will communicate with the PHP server and receive instructions from it. The system includes red LEDs to indicate the operation of the switches. A green LED turns on when the system is active. You will receive email notifications when the system turns on or off based on the programmed instructions.

Using the Control Menu

To access the control menu for the D1 Mini Switch Control system, open a web browser and enter the internal IP address of the PHP server followed by port 8080. This will display the login menu where you can log in to access the control menu. The control menu allows you to change the password and user settings. It also provides options to turn the system on or off. If there is a power outage, the system will automatically restart in the off position for security reasons. You will receive email notifications when the system restarts.

Additional Features

The D1 Mini Switch Control system offers several additional features to enhance its functionality. For example, you can configure the switches to work only on even days, allowing for a more flexible scheduling system. Each switch can be programmed to work during specific time periods, such as morning, noon, and night. This allows for precise control of your home appliances. Additionally, the system supports firmware updates over the air (OTA), which can be enabled by activating the "Serveron" option.

Conclusion

The D1 Mini Switch Control project provides an easy and affordable solution for automating your home appliances. By utilizing a D1 Mini microcontroller, an Android smartphone with a PHP server, and a web page interface, you can have complete control over your home devices. Whether you want to automate your irrigation system or control your home lighting, this project offers endless possibilities. If you're interested in replicating this project, feel free to leave a comment, and we'll provide you with the necessary files. Don't forget to subscribe to our channel and share this project with your friends.

Buy components in Amazon

Buy components in AliExpress

Comentários