Skip to content

jeevan9s/homectrl-sys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

homectrl

Smart home controller powered by ESP32 and Next.js

Contents

Overview

I designed homectrl as a modular home automation controller to smooth out the moving-in process into my first apartment.

The system's main functions include irrigation (plant-watering) and motorized shading (controlled blinds) which are managed via WiFi, utilizing a web-app interface and Alexa for monitoring and control. The controller's firmware was coded in C++ with Arduino, and the board was designed with KiCad.

Built With

  • Arduino
  • Espressif
  • Next.js
  • TailwindCSS

Architecture

System

The left column represents the overall workflow, with the ESP32 as the central controller connecting to irrigation (top right) and shading (bottom right) modules. Communication is handled over WiFi, using SinricPro for Alexa voice control. the Next.js dashboard interfaces with the ESP32 via Websockets for real-time monitoring and control.

Firmware

Controller was written in C++/Arduino and UI was written with Next.js.

Code workflow consists of initialization & setup, event handlers, control functions, MQTT subscribing/publishing/receiving. Module-specific setup and loop functions are called in the main program.

An example of a control function:

checkAutoWatering()
// these functions utilize handlers and are called directly in their module's main loop.

void checkAutoWatering() {
    if (!autoMode) return; 

    uint8_t soilPct = irrigationGetMoisturePct();
    Serial.print("auto watering? "); Serial.println(autoMode);
    Serial.print("soil %: "); Serial.println(soilPct);

    if (!pumpOn && soilPct < autoThreshold && millis() - lastAutoWaterMs > IRRIG_COOLDOWN_MS) {
        pumpOnHandler(false);
        lastAutoWaterMs = millis();
    }

    if (pumpOn && millis() - lastWaterStartMs > IRRIG_MIN_ON_MS && autoMode) {
        pumpOffHandler();
    }
}

A snippet from the main loop:

loop()
// this loop brings together all individual loops to handle communication, process commands, update sensors, and run module control functions in real time.

void loop() {
  wifiLoop(); 
  mqttLoop(); 
  sinricLoop();        
  irrigationLoop();     
  shadingLoop();     
}

Hardware

The controller's hardware consists of a PCB built around an ESP32 Devkit, including an A4988 stepper motor driver and NEMA 17 stepper motor for shading, a relay module for DC pump control, power management components such as a buck converter and decoupling capacitors, and signal devices like LEDs.

The board is also split up into several modules:

Power The controller receives a 12V-2A input from an AC adapter via barrel jack. This power is bulk filtered and stepped down to 5V to supply low-voltage components (via LM2596 buck converter). The 12V line also powers the stepper motor driver's VMOT pin and an external connection.
Shading Module The shading module utilizes a stepper motor (NEMA 17) for actuation, which is controlled by an A4988 driver. A screw block terminal is placed between the stepper motor and the driver for reliable connection.
Irrigation Module The irrigation module consists of a DC pump controlled by a relay module. Soil moisture is recorded with a capacitive sensor. All connections are secured with screw terminals.
Signal & Indicators Each module has a respective LED for status and action indication. Two separate LEDs are used to indicate WiFi connection and system status.

Prerequisites / Installation

Prerequisites

  • Hardware: ESP32 Devkit, stepper motors, relay modules, DC pump, sensors, LEDs, PCB component (see BOM)
  • Software: Arduino IDE (with Espressif ESP32 board support)
  • Libraries: PubSubClient, SinricPro, WebSockets, and any other dependencies listed in firmware
  • Node.js: v18+ (for Next.js dashboard)
  • Package Manager: npm or yarn

Installation

  1. Clone the repository:
git clone https://github.com/jeevan9s/homectrl.git
cd homectrl

Contact

email    LinkedIn

About

modular home automation controller with a web-based dashboard.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published