ESP32 Arduino Library

Control Your Smart Home
with YaranaSmartHome

A powerful ESP32 relay controller library that lets you manage 4 or 8 relays securely through the Yarana Smart Home app. Simple setup, safe GPIO handling, and complete control at your fingertips.

01

What You Can Do

YaranaSmartHome turns your ESP32 into a professional relay controller compatible with the Yarana Smart Home ecosystem.

πŸ”Œ

4 or 8 Relay Control

Manage up to 8 relays from a single ESP32. Perfect for home automation projects of any scale.

πŸ“±

Mobile App Control

Control your relays from anywhere using the Yarana Smart Home Android app. Simple and intuitive.

πŸ›‘οΈ

Safe GPIO Handling

Built-in protection prevents you from using unsafe pins. GPIO2 is automatically reserved for status LED.

⚑

Quick Setup

Get running in minutes with straightforward configuration. Just define your relay pins and you're ready.

πŸ”„

Factory Reset

Hold the boot button for 5 seconds to reset and reconfigure your device whenever needed.

πŸ“Š

Live Status

View real-time relay states, WiFi signal strength, and device health directly in the app.

02

Installation

Install the library through the Arduino Library Manager or by importing the ZIP package.

βœ“
Recommended: Arduino Library Manager

The easiest way to install and keep your library updated automatically.

Method 1: Arduino Library Manager

  1. Open Arduino IDE Launch the Arduino IDE on your computer.
  2. Go to Library Manager Navigate to Sketch β†’ Include Library β†’ Manage Libraries…
  3. Search for YaranaSmartHome Type YaranaSmartHome in the search box and press Enter.
  4. Install the library Click Install on the YaranaSmartHome library by Yarana Web Tech.
  5. Restart Arduino IDE Close and reopen Arduino IDE to load the library properly.
  6. Open the example Go to File β†’ Examples β†’ YaranaSmartHome β†’ YaranaBasic to start.

Method 2: ZIP Import

  1. Download the library Get the latest version from the Yarana Web Tech website.
  2. Open Arduino IDE Go to Sketch β†’ Include Library β†’ Add .ZIP Library…
  3. Select the ZIP file Choose the downloaded YaranaSmartHome-x.x.x.zip file.
  4. Install and restart Wait for confirmation, then restart Arduino IDE if needed.
03

Required Libraries

Before using YaranaSmartHome, install these dependencies from the Arduino Library Manager:

Library Minimum Version Purpose
ArduinoJson v6.21.0 or later Handles JSON data for relay commands and status messages
PubSubClient v2.8.0 or later Connects to the Yarana cloud for remote control
NimBLE-Arduino v2.0.0 or later Enables Bluetooth Low Energy for app setup
β„Ή
Install dependencies first

Install all three libraries before compiling your sketch to avoid errors.

04

Your First Project

Setting up YaranaSmartHome is straightforward. Define your relay pins, configure the basics, and you're ready to control your devices.

// Include the library
#include <YaranaSmartHome.h>

// Create the library instance
YaranaSmartHome yarana;

void setup() {
  Serial.begin(115200);

  // Configure your device
  YaranaConfig config;
  config.relayCount = 4;  // Use 4 or 8 relays

  // Set relay pins (use safe pins only)
  YARANA_SET_RELAY_PIN(config, 0, 32);
  YARANA_SET_RELAY_PIN(config, 1, 26);
  YARANA_SET_RELAY_PIN(config, 2, 27);
  YARANA_SET_RELAY_PIN(config, 3, 14);

  // Activate active-low mode (for most relay modules)
  config.relayActiveLow = true;

  // Initialize the library
  yarana.begin(config);
}

void loop() {
  // Keep the library running
  yarana.loop();
}
βœ“
Pro Tip

Always use YARANA_SET_RELAY_PIN() instead of directly modifying relayPins[]. This prevents you from accidentally using GPIO2, which is reserved for the status LED.

05

Relay Configuration

Choose your relay module type and configure the pins accordingly. We provide safe pin assignments for both 4-channel and 8-channel setups.

4-Channel Relay Module

YaranaConfig config;
config.relayCount = 4;
YARANA_SET_RELAY_PIN(config, 0, 32);  // Relay 1 β†’ GPIO32
YARANA_SET_RELAY_PIN(config, 1, 26);  // Relay 2 β†’ GPIO26
YARANA_SET_RELAY_PIN(config, 2, 27);  // Relay 3 β†’ GPIO27
YARANA_SET_RELAY_PIN(config, 3, 14);  // Relay 4 β†’ GPIO14
RelayESP32 PinModule Pin
Relay 1GPIO32IN1
Relay 2GPIO26IN2
Relay 3GPIO27IN3
Relay 4GPIO14IN4
PowerGNDGND
Power5V (external)VCC

8-Channel Relay Module

YaranaConfig config;
config.relayCount = 8;
YARANA_SET_RELAY_PIN(config, 0, 32);  // Relay 1 β†’ GPIO32
YARANA_SET_RELAY_PIN(config, 1, 26);  // Relay 2 β†’ GPIO26
YARANA_SET_RELAY_PIN(config, 2, 27);  // Relay 3 β†’ GPIO27
YARANA_SET_RELAY_PIN(config, 3, 14);  // Relay 4 β†’ GPIO14
YARANA_SET_RELAY_PIN(config, 4, 25);  // Relay 5 β†’ GPIO25
YARANA_SET_RELAY_PIN(config, 5, 33);  // Relay 6 β†’ GPIO33
YARANA_SET_RELAY_PIN(config, 6, 16);  // Relay 7 β†’ GPIO16
YARANA_SET_RELAY_PIN(config, 7, 17);  // Relay 8 β†’ GPIO17
RelayESP32 PinModule Pin
Relay 1GPIO32IN1
Relay 2GPIO26IN2
Relay 3GPIO27IN3
Relay 4GPIO14IN4
Relay 5GPIO25IN5
Relay 6GPIO33IN6
Relay 7GPIO16IN7
Relay 8GPIO17IN8
PowerGNDGND
Power5V (external)VCC
06

Pin Safety Guide

Not all ESP32 GPIO pins are safe to use with relays. The library protects you from common mistakes.

⚠
GPIO2 is Reserved

GPIO2 is used by the status LED. If you try to use it as a relay pin, the library will give you a compile-time error. This is intentional β€” use safe pins like GPIO32, 26, 27, 14 instead.

●
Status LED Patterns

GPIO2 fast blink means setup/offline, double blink means WiFi is connected but MQTT is offline, slow heartbeat means WiFi + MQTT are online, and a short pulse means the Android app is connected over BLE. Hold the BOOT button on GPIO0 for 5 seconds to clear saved WiFi/MQTT credentials and return to BLE provisioning mode.

Pin TypePins to AvoidReason
Status LED GPIO2 Reserved for onboard LED. Cannot be used as relay.
Strapping Pins GPIO0, GPIO12, GPIO15 Used during boot. External loads can prevent ESP32 from starting.
Flash Pins GPIO6-11 Connected to SPI flash. Never use these.
Input Only GPIO34-39 Cannot drive outputs. Input pins only.
βœ“
Safe Relay Pins

Use these pins for your relays: GPIO32, 26, 27, 14, 25, 33, 16, 17. These are tested and safe for both 4-channel and 8-channel relay modules.

07

Connect to the App

The Yarana Smart Home app makes setup effortless. No complex coding or network configuration needed.

πŸ“²

1. Power Up

Connect your ESP32 to power. It will start advertising as YARANA_XXXXXX.

πŸ“±

2. Open the App

Launch the Yarana Smart Home app and tap "Add Device" to scan for nearby devices.

βš™οΈ

3. Configure

Select your WiFi network and enter credentials. The app handles everything automatically.

βœ…

4. Start Controlling

Once connected, you can control your relays from anywhere using the app.

β„Ή
First Time Setup

The app sends all necessary configuration (WiFi, connection settings) to your ESP32 via Bluetooth. You don't need to hardcode anything in your sketch.

08

Control Your Relays

Once set up, you have complete control over your relays through the app. The library handles all the communication in the background.

What You Can Do

πŸ”›

Turn Relay On/Off

Switch individual relays on or off with a single tap in the app.

πŸ”ƒ

Turn All Relays Off

Quickly turn off all relays at once with one button.

πŸ“Š

View Status

See real-time relay states, WiFi signal, and device health.

πŸ”„

Reset Device

Factory reset your device from the app to reconfigure it.

βœ“
Works from Anywhere

Control your relays from anywhere in the world through the Yarana cloud. No need to be on the same WiFi network.

09

Quick API Reference

The library is designed to be simple. You only need to know a few key functions.

Essential Functions

FunctionPurpose
yarana.begin(config) Initialize the library with your relay configuration
yarana.loop() Keep the library running (call this continuously)
yarana.setRelay(index, state) Turn a specific relay on (1) or off (0)
yarana.relayState(index) Check if a relay is currently on or off

Helper Macro

// Always use this macro to set relay pins safely
YARANA_SET_RELAY_PIN(config, relay_number, gpio_pin);

// Example:
YARANA_SET_RELAY_PIN(config, 0, 32);  // Safe
YARANA_SET_RELAY_PIN(config, 1, 2);   // Error: GPIO2 is reserved
!
Configuration Options

The library handles most settings automatically. You only need to set relayCount and assign relay pins. Everything else (WiFi, MQTT, connection details) is managed through the app.

AM

Abhishek Maurya

Founder, Yarana Web Tech | IoT Educator

Passionate about making IoT and ESP32 development accessible to everyone. Creator of the YaranaSmartHome library and host of the Yarana IoT Guru YouTube channel, where I teach IoT concepts in Hindi through practical tutorials and hands-on projects.

10

Get Help & Learn

Need help or want to learn more about IoT and ESP32? Here are the best resources:

πŸ“Ί

YouTube Channel

Watch step-by-step tutorials on the Yarana IoT Guru channel. Learn IoT, ESP32, and home automation in Hindi.

Subscribe β†’
🌐

Yarana Web Tech

Visit our website for more projects, services, and IoT solutions. We specialize in ESP32, Arduino, and custom IoT development.

Visit Website β†’
πŸ’‘

Need Custom Help?

Looking for custom IoT solutions, firmware development, or consulting? Reach out through our website.

Get in Touch β†’