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.
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.
Installation
Install the library through the Arduino Library Manager or by importing the ZIP package.
The easiest way to install and keep your library updated automatically.
Method 1: Arduino Library Manager
- Open Arduino IDE Launch the Arduino IDE on your computer.
-
Go to Library Manager
Navigate to
Sketch β Include Library β Manage Librariesβ¦ - Search for YaranaSmartHome Type YaranaSmartHome in the search box and press Enter.
- Install the library Click Install on the YaranaSmartHome library by Yarana Web Tech.
- Restart Arduino IDE Close and reopen Arduino IDE to load the library properly.
-
Open the example
Go to
File β Examples β YaranaSmartHome β YaranaBasicto start.
Method 2: ZIP Import
- Download the library Get the latest version from the Yarana Web Tech website.
-
Open Arduino IDE
Go to
Sketch β Include Library β Add .ZIP Libraryβ¦ -
Select the ZIP file
Choose the downloaded
YaranaSmartHome-x.x.x.zipfile. - Install and restart Wait for confirmation, then restart Arduino IDE if needed.
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 all three libraries before compiling your sketch to avoid errors.
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(); }
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.
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
| Relay | ESP32 Pin | Module Pin |
|---|---|---|
| Relay 1 | GPIO32 | IN1 |
| Relay 2 | GPIO26 | IN2 |
| Relay 3 | GPIO27 | IN3 |
| Relay 4 | GPIO14 | IN4 |
| Power | GND | GND |
| Power | 5V (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
| Relay | ESP32 Pin | Module Pin |
|---|---|---|
| Relay 1 | GPIO32 | IN1 |
| Relay 2 | GPIO26 | IN2 |
| Relay 3 | GPIO27 | IN3 |
| Relay 4 | GPIO14 | IN4 |
| Relay 5 | GPIO25 | IN5 |
| Relay 6 | GPIO33 | IN6 |
| Relay 7 | GPIO16 | IN7 |
| Relay 8 | GPIO17 | IN8 |
| Power | GND | GND |
| Power | 5V (external) | VCC |
Pin Safety Guide
Not all ESP32 GPIO pins are safe to use with relays. The library protects you from common mistakes.
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.
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 Type | Pins to Avoid | Reason |
|---|---|---|
| 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. |
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.
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.
The app sends all necessary configuration (WiFi, connection settings) to your ESP32 via Bluetooth. You don't need to hardcode anything in your sketch.
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.
Control your relays from anywhere in the world through the Yarana cloud. No need to be on the same WiFi network.
Quick API Reference
The library is designed to be simple. You only need to know a few key functions.
Essential Functions
| Function | Purpose |
|---|---|
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
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.
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 β