Makers Smart Home Kit: 10 Practical ESP8266 Projects for Smart Home Automation

Makers Smart Home Kit

Makers Smart Home Kit: 10 Practical ESP8266 Projects for Smart Home Automation

Contents List
  1. Introduction
  2. What Is the Makers Smart Home Kit?
  3. Why Use ESP8266 for Smart Home Projects?
  4. Main Components of the Kit
  5. ESP8266 NodeMCU and Pin Planning
  6. Project 01 — Automatic Night Light
  7. Project 02 — Motion Activated Light
  8. Project 03 — Door Open Alarm
  9. Project 04 — Security Motion Alarm
  10. Project 05 — Automatic Fan Controller
  11. Project 06 — Electronic Door Lock
  12. Project 07 — Password Door Lock
  13. Project 08 — Smart Room Controller
  14. Project 09 — Home Security System
  15. Project 10 — Complete Smart Home
  16. Programming and Wi-Fi Connectivity
  17. Safety and Design Considerations
  18. Frequently Asked Questions
  19. Conclusion

Time reading is 20min.

1. Introduction

Smart home technology combines sensors, controllers, actuators, and wireless communication to automate everyday tasks and monitor the home environment.

The Makers Smart Home Kit is designed as a practical learning platform based on the ESP8266 NodeMCU 30-Pin with CP2102 Micro USB. Instead of providing components for only one experiment, the kit allows beginners, hobbyists, and engineers to build a series of progressively more advanced smart-home projects using the same main controller.

The projects start with simple circuits such as an automatic night light and gradually introduce motion detection, alarms, temperature-based control, servo-operated locks, password protection, multiple sensors, relays, displays, and Wi-Fi connectivity.

The ESP8266 is particularly relevant to this type of project because it combines a microcontroller with 2.4 GHz Wi-Fi and interfaces such as GPIO, UART, SPI, I²C, PWM, and ADC. Espressif lists home appliances, home automation, smart lights, smart plugs, sensor networks, and security-related applications among ESP8266EX applications.

This makes the kit useful not only for learning individual electronic components, but also for understanding how a complete IoT-based automation system is designed.

 What You Will Learn?

By completing the ten projects, the learner can gradually understand:

  • Digital and analog sensors
  • GPIO input and output
  • Automatic lighting
  • Motion detection
  • Door and window monitoring
  • Buzzer-based alarms
  • Temperature-based control
  • Relay operation
  • Servo motor control
  • Keypad input
  • LCD/OLED displays
  • Sensor combination and automation logic
  • Wi-Fi communication
  • Basic IoT concepts
  • Complete smart-home system architecture

2. What Is the Makers Smart Home Kit?

The Makers Smart Home Kit is a reusable electronics development platform centered around an ESP8266 NodeMCU development board.

The basic idea is simple:   Sense → Process → Decide → Act → Communicate

  • A sensor first detects a physical condition. The ESP8266 processes the information and applies the programmed logic.
  • It then controls an output such as an LED, buzzer, relay, servo, or display.
  • When Wi-Fi is included, the ESP8266 can also communicate with a local network or an Internet-based service.

For example:   PIR Sensor → ESP8266 → Relay → Light

  • The PIR detects movement, the ESP8266 decides whether the light should be switched on, and the relay controls the low-voltage load.
  • This same principle can be expanded into a complete smart-home system.

3. Why Use ESP8266 for Smart Home Projects?

Built-In Wi-Fi
  • One of the main advantages of the ESP8266 is that Wi-Fi is integrated into the SoC rather than requiring a separate Wi-Fi shield.
  • The ESP8266EX supports IEEE 802.11 b/g/n operation in the 2.4 GHz band and can operate as a station or access point.
  • For a smart-home learning kit, this means the same controller can be used for both local electronics experiments and network-connected projects.
Multiple Digital Interfaces
  • The ESP8266 provides GPIO pins that can be used for switches, PIR sensors, LEDs, buzzers, relay modules, servo control, and other digital devices.
  • It also supports interfaces including I²C, SPI, UART, and PWM.
Analog Input
  • The ESP8266 has one user-accessible ADC channel.
  • This is important when planning the kit because an LDR or another analog sensor can use A0, but the design should not depend on many simultaneous analog inputs.
  • For this reason, the Makers Smart Home Kit should favor digital sensors and I²C devices where possible.

Suitable for Learning IoT

The ESP8266 Arduino Core provides support for Arduino-style programming and libraries for Wi-Fi, I²C, SPI, interrupts, digital I/O, and analog input.

This gives beginners a relatively straightforward path from:

Blinking an LED

to:  Building a Wi-Fi-connected smart-home controller.

4. Main Components of the Kit

A practical version of the Makers Smart Home Kit can contain the following components.

Component Suggested Quantity Main Use
ESP8266 NodeMCU 30-Pin CP2102 1 Main controller
Breadboard 1 Prototyping
Jumper wires Set Connections
LEDs Several Indicators and lighting
Resistors Assorted LED/LDR circuits
LDR 1–2 Light detection
PIR sensor 1 Motion detection
Reed switch 1 Door/window detection
Magnetic magnet 1 Reed switch activation
Buzzer 1 Alarm indication
DHT22 1 Temperature/humidity sensing
Relay module 1 Low-voltage load control
DC fan 1 Fan-control project
SG90 servo 1 Electronic lock
4×4 keypad 1 Password entry
I²C LCD 1 Text/status display
0.96-inch SSD1306 OLED Optional Compact graphical display
Push buttons Several Manual control
5V regulated supply 1 Powering the kit
USB cable 1 Programming/power

The DHT22 is a digital temperature/humidity sensor containing a humidity sensing element, thermistor, and internal conversion electronics, making it convenient for beginner microcontroller projects.

5. ESP8266 NodeMCU and Pin Planning

  • Good pin planning is particularly important with ESP8266 because not every GPIO should be treated as an unrestricted general-purpose pin.
  • The ESP8266 uses GPIO0, GPIO2, and GPIO15 during startup to select its boot mode.
  • Consequently, connecting sensors or modules to these pins without considering their startup states can cause boot problems.
  • A practical arrangement for the Makers kit can therefore reserve the pins carefully.

Suggested Pin Assignment
Function NodeMCU Pin ESP8266 GPIO
OLED/LCD SDA D2 GPIO4
OLED/LCD SCL D1 GPIO5
DHT22 D5 GPIO14
PIR D6 GPIO12
Reed Switch D7 GPIO13
Buzzer D0 GPIO16
Relay D3/GPIO0* GPIO0
Servo D4/GPIO2* GPIO2
LDR A0 ADC
Keypad Several available GPIOs —

* D3/GPIO0 and D4/GPIO2 require additional care because they are boot-strapping pins.

  • For a production kit, the exact pin allocation should be validated against the specific NodeMCU board and the attached module’s startup behavior.
  • GPIO0, GPIO2, and GPIO15 participate in ESP8266 boot-mode selection.
  • For the final hardware design, it is preferable to reserve the boot-sensitive pins or isolate them appropriately rather than treating them like ordinary GPIOs.
I²C Display

An I²C display is especially useful because it requires only the two I²C signal lines plus power and ground.

For an I²C OLED:

  • ESP8266 SDA → OLED SDA
  • ESP8266 SCL → OLED SCL
  • 3.3 V → OLED VCC
  • GND → OLED GND

I²C OLED modules such as SSD1306-based displays are commonly used with microcontrollers through their SDA and SCL connections.

6. Project 01 — Automatic Night Light

The first project introduces one of the simplest smart-home concepts: automatically controlling a light according to the surrounding brightness.

Components
  • ESP8266 NodeMCU
  • LDR
  • Resistor
  • LED
  • Breadboard
  • Jumper wires
How It Works?
  • The LDR changes its resistance according to the amount of light falling on it.
  • A voltage-divider circuit converts this resistance change into a voltage that can be measured by the ESP8266 ADC.

The basic operation is:

  • Light detected → LED OFF
  • Darkness detected → LED ON

The software continuously reads A0 and compares the measured value with a programmed threshold.

Why This Project Is Important
  • This simple circuit introduces the relationship between:  Physical condition → Sensor → Microcontroller → Decision → Output
  • The same concept is used in larger lighting-control systems.
Important ESP8266 Consideration

Because the ESP8266 has only one user ADC channel, the LDR should normally be treated as the primary analog sensor in this kit.

Connections
Component ESP8266
LDR voltage divider output A0
LED anode through resistor D6 / GPIO12
LED cathode GND
LDR circuit 3.3 V / GND
Arduino IDE Code
const int LDR_PIN = A0;
const int LED_PIN = D6;

// Adjust this value after testing your LDR circuit.
const int LIGHT_THRESHOLD = 500;

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

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);

  Serial.println("Automatic Night Light");
}

void loop() {
  int lightValue = analogRead(LDR_PIN);

  Serial.print("LDR Value: ");
  Serial.println(lightValue);

  // Adjust this comparison according to your voltage-divider orientation.
  if (lightValue < LIGHT_THRESHOLD) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }

  delay(200);
}
Programming Explanation

The ESP8266 reads the LDR through its single analog input, A0.

The program compares the reading with LIGHT_THRESHOLD.

When the measured value indicates darkness, the LED is switched on.

The threshold is not universal. It should be calibrated experimentally with the actual LDR and resistor used in the kit.

7. Project 02 — Motion Activated Light

The second project replaces the light sensor with a motion sensor.

Components
  • ESP8266 NodeMCU
  • PIR motion sensor
  • LED
  • Resistor
How It Works?
  • A PIR sensor detects changes in infrared radiation associated with moving people or objects.
  • The ESP8266 reads the PIR’s digital output.
  • When motion is detected:  PIR → ESP8266 → LED ON
  • After a programmed delay:  LED → OFF
Example Logic
Start
  ↓
Read PIR
  ↓
Motion detected?
  ├── No → Keep LED OFF
  └── Yes
       ↓
     LED ON
       ↓
    Wait period
       ↓
     LED OFF

This project introduces timers and event-based automation.

Connections
Component ESP8266
PIR OUT D5 / GPIO14
PIR VCC 5 V or module-rated supply
PIR GND GND
LED D6 / GPIO12
LED resistor Series with LED
Arduino IDE Code
const int PIR_PIN = D5;
const int LED_PIN = D6;

const unsigned long LIGHT_ON_TIME = 10000; // 10 seconds

unsigned long motionTime = 0;
bool lightOn = false;

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

  pinMode(PIR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(LED_PIN, LOW);

  Serial.println("Motion Activated Light");
}

void loop() {
  int motionState = digitalRead(PIR_PIN);

  if (motionState == HIGH) {
    digitalWrite(LED_PIN, HIGH);

    lightOn = true;
    motionTime = millis();

    Serial.println("Motion detected");
  }

  if (lightOn && (millis() - motionTime >= LIGHT_ON_TIME)) {
    digitalWrite(LED_PIN, LOW);
    lightOn = false;

    Serial.println("Light OFF");
  }
}
Programming Explanation
  • The PIR output is read as a digital signal.
  • When the PIR becomes HIGH, the ESP8266 turns the LED on and records the current millis() value.
  • Using millis() instead of delay() allows the ESP8266 to continue executing other tasks while the light timer is running.

8. Project 03 — Door Open Alarm

This project demonstrates how a smart-home system can monitor a door or window.

Components
  • ESP8266 NodeMCU
  • Magnetic reed switch
  • Magnet
  • Buzzer
  • Optional LED
How It Works?
  • The reed switch changes state when the magnet moves close to or away from it.
  • The magnet is attached to the moving door while the reed switch is fixed to the door frame.
  • When the door opens:  Magnet moves away → Reed switch changes state → ESP8266 detects opening → Buzzer activates
Practical Application

The same principle can be used for:

  • Doors
  • Windows
  • Cabinets
  • Drawers
  • Storage boxes

This makes the project a useful introduction to basic intrusion detection.

Connections
Component ESP8266
Reed switch D7 / GPIO13
Reed switch other terminal GND
Buzzer D0 / GPIO16
Buzzer GND GND

The example uses the ESP8266’s internal pull-up resistor.

Arduino IDE Code
const int REED_PIN = D7;
const int BUZZER_PIN = D0;

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

  pinMode(REED_PIN, INPUT_PULLUP);
  pinMode(BUZZER_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);

  Serial.println("Door Open Alarm");
}

void loop() {

  int doorState = digitalRead(REED_PIN);

  // LOW = door closed
  // HIGH = door open
  if (doorState == HIGH) {

    digitalWrite(BUZZER_PIN, HIGH);

    Serial.println("WARNING: Door Open");
  }
  else {

    digitalWrite(BUZZER_PIN, LOW);

    Serial.println("Door Closed");
  }

  delay(100);
}
Important
  • The actual logic depends on how the reed switch is physically installed.
  • If your reed switch behaves in the opposite direction, simply reverse the HIGH and LOW conditions.

9. Project 04 — Security Motion Alarm

The fourth project changes the output from a simple indicator to an alarm.

Components
  • ESP8266 NodeMCU
  • PIR sensor
  • Buzzer
  • LED
Operation
  • The PIR monitors the protected area.
  • When movement is detected:  PIR → ESP8266 → Buzzer + LED
  • The software can keep the alarm active for a predetermined period.
  • A push button can also be added as an alarm-reset input.
What the Learner Understands?
  • This project introduces the idea that a sensor does not directly control the final device.
  • Instead:   Sensor → Controller → Decision → Actuator
  • The ESP8266 provides the decision-making layer.
Connections
Component ESP8266
PIR OUT D5 / GPIO14
Buzzer D0 / GPIO16
LED D6 / GPIO12
Arduino IDE Code
const int PIR_PIN = D5;
const int BUZZER_PIN = D0;
const int LED_PIN = D6;

const unsigned long ALARM_TIME = 10000; // 10 seconds

bool alarmActive = false;
unsigned long alarmStartTime = 0;

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

  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);

  Serial.println("Security Motion Alarm");
}

void loop() {

  int motion = digitalRead(PIR_PIN);

  if (motion == HIGH && !alarmActive) {

    alarmActive = true;
    alarmStartTime = millis();

    Serial.println("MOTION DETECTED!");
  }

  if (alarmActive) {

    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED_PIN, HIGH);

    if (millis() - alarmStartTime >= ALARM_TIME) {

      digitalWrite(BUZZER_PIN, LOW);
      digitalWrite(LED_PIN, LOW);

      alarmActive = false;

      Serial.println("Alarm Reset");
    }
  }
}
Programming Concept

The important new concept is the system state:

NORMAL
   ↓
Motion detected
   ↓
ALARM ACTIVE
   ↓
Timeout
   ↓
NORMAL

10. Project 05 — Automatic Fan Controller

This project introduces temperature-based automation.

Components
  • ESP8266 NodeMCU
  • DHT22 temperature/humidity sensor
  • Relay module
  • Low-voltage DC fan

The DHT22 provides digital temperature and humidity information to the ESP8266.

How It Works?

The ESP8266 reads the room temperature periodically.

For example:

  • Temperature < 28°C → Fan OFF
  • Temperature ≥ 30°C → Fan ON

Using two different thresholds creates hysteresis and helps prevent rapid relay switching around a single threshold.

Why Use a Relay?
  • The ESP8266 GPIO should not be used to power a fan directly.
  • The relay provides an electrically controlled switching interface between the controller and the load.
  • For a beginner-oriented kit, a low-voltage DC fan is preferable to a mains-powered fan.
  • For this project I recommend using a DHT22 and a low-voltage DC fan controlled through a relay module.
Required Library
  • Install:  DHT sensor library by Adafruit
  • and its dependency:  Adafruit Unified Sensor
Connections
Component ESP8266
DHT22 DATA D5 / GPIO14
DHT22 VCC 3.3 V
DHT22 GND GND
Relay IN D6 / GPIO12
Arduino IDE Code
#include <DHT.h>

#define DHT_PIN D5
#define DHT_TYPE DHT22

const int RELAY_PIN = D6;

const float FAN_ON_TEMP = 30.0;
const float FAN_OFF_TEMP = 28.0;

DHT dht(DHT_PIN, DHT_TYPE);

bool fanState = false;

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

  dht.begin();

  pinMode(RELAY_PIN, OUTPUT);

  // Change these if your relay is active HIGH.
  digitalWrite(RELAY_PIN, HIGH);

  Serial.println("Automatic Fan Controller");
}

void loop() {

  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  if (isnan(temperature) || isnan(humidity)) {

    Serial.println("DHT22 reading failed");
    delay(2000);

    return;
  }

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" C");

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");

  // Hysteresis control
  if (!fanState && temperature >= FAN_ON_TEMP) {

    fanState = true;

    digitalWrite(RELAY_PIN, LOW);

    Serial.println("Fan ON");
  }

  if (fanState && temperature <= FAN_OFF_TEMP) {

    fanState = false;

    digitalWrite(RELAY_PIN, HIGH);

    Serial.println("Fan OFF");
  }

  delay(2000);
}
Why Two Temperatures?

Using:

  • Fan ON = 30°C
  • Fan OFF = 28°C

prevents the relay from rapidly switching when the temperature is hovering around 30°C.

This is called hysteresis.

11. Project 06 — Electronic Door Lock

This project introduces servo motor control.

Components
  • ESP8266 NodeMCU
  • Push button
  • SG90 servo
  • LED
  • Optional buzzer
How It Works?
  • The push button acts as a simple authorization input.
  • For example:  Button pressed → ESP8266 verifies input → Servo moves to unlock position
  • After a delay:  Servo returns to locked position
  • The servo therefore represents a small electronic locking mechanism.
Learning Objective

This project teaches:

  • Digital input
  • Servo control
  • Timing
  • State changes
  • Simple access-control logic
Connections
Component ESP8266
Push button D7 / GPIO13
Servo signal D4 / GPIO2
Servo power External suitable supply
Servo GND Common GND
Required Library

The ESP8266 Arduino core includes the Servo functionality.

Arduino IDE Code
#include <Servo.h>

const int BUTTON_PIN = D7;
const int SERVO_PIN = D4;

const int LOCK_POSITION = 0;
const int UNLOCK_POSITION = 90;

Servo doorServo;

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

  pinMode(BUTTON_PIN, INPUT_PULLUP);

  doorServo.attach(SERVO_PIN);

  doorServo.write(LOCK_POSITION);

  Serial.println("Electronic Door Lock");
}

void loop() {

  int buttonState = digitalRead(BUTTON_PIN);

  if (buttonState == LOW) {

    Serial.println("Unlocking...");

    doorServo.write(UNLOCK_POSITION);

    delay(3000);

    Serial.println("Locking...");

    doorServo.write(LOCK_POSITION);

    // Prevent repeated triggering
    delay(500);
  }
}
Important Servo Power Note
  • Do not assume the ESP8266 board’s 3.3 V pin should power the servo.
  • A small servo can create significant current transients.
  • Use an appropriate external supply for the servo and connect its GND to the ESP8266 GND.

12. Project 07 — Password Door Lock

The next step is to replace the simple push button with a keypad.

Components
  • ESP8266 NodeMCU
  • 4×4 keypad
  • SG90 servo
  • I²C LCD
  • Buzzer
Basic Operation
  • The LCD displays:   Enter Password
  • The user enters a sequence through the keypad.
  • The ESP8266 compares the entered sequence with the programmed password.
Correct Password
Enter password
      ↓
Compare
      ↓
Correct
      ↓
Servo UNLOCK
      ↓
Delay
      ↓
Servo LOCK
Incorrect Password
Enter password
      ↓
Compare
      ↓
Incorrect
      ↓
Buzzer
      ↓
Access Denied
  • The LCD provides immediate feedback to the user.
  • This project introduces a basic form of embedded access control.
Components
  • ESP8266 NodeMCU
  • 4×4 keypad
  • SG90 servo
  • I²C LCD
  • Buzzer
Important Pin Planning
  • A 4×4 keypad requires 8 GPIO lines, while the LCD uses two I²C lines and the servo/buzzer require additional outputs.
  • Therefore, I recommend using a 4×3 keypad for the compact version of the kit, or using an I/O expander such as the PCF8574 if the kit specifically requires a 4×4 keypad.
  • The following example uses a 4×3 keypad.
Example Connections
Device ESP8266
Keypad R1 D1
Keypad R2 D2
Keypad R3 D5
Keypad R4 D6
Keypad C1 D7
Keypad C2 D8
Keypad C3 D0
LCD SDA I²C SDA
LCD SCL I²C SCL
Servo D4
Buzzer GPIO
Arduino IDE Code
#include <Keypad.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rowPins[ROWS] = {D1, D2, D5, D6};
byte colPins[COLS] = {D7, D8, D0};

Keypad keypad = Keypad(
  makeKeymap(keys),
  rowPins,
  colPins,
  ROWS,
  COLS
);

LiquidCrystal_I2C lcd(0x27, 16, 2);

Servo doorServo;

const int SERVO_PIN = D4;
const int BUZZER_PIN = D3;

const int LOCK_POSITION = 0;
const int UNLOCK_POSITION = 90;

const char PASSWORD[] = "1234";

String enteredPassword = "";

void setup() {

  Serial.begin(115200);

  pinMode(BUZZER_PIN, OUTPUT);

  doorServo.attach(SERVO_PIN);
  doorServo.write(LOCK_POSITION);

  lcd.init();
  lcd.backlight();

  lcd.setCursor(0, 0);
  lcd.print("Enter Password");

  lcd.setCursor(0, 1);
}

void loop() {

  char key = keypad.getKey();

  if (key == NO_KEY) {
    return;
  }

  if (key == '#') {

    checkPassword();

    return;
  }

  if (key == '*') {

    enteredPassword = "";

    lcd.clear();
    lcd.print("Password Clear");

    delay(1000);

    showPasswordPrompt();

    return;
  }

  if (enteredPassword.length() < 8) {

    enteredPassword += key;

    lcd.setCursor(enteredPassword.length() - 1, 1);
    lcd.print('*');
  }
}

void checkPassword() {

  if (enteredPassword == PASSWORD) {

    lcd.clear();
    lcd.print("Access Granted");

    Serial.println("Correct Password");

    doorServo.write(UNLOCK_POSITION);

    delay(3000);

    doorServo.write(LOCK_POSITION);

  } else {

    lcd.clear();
    lcd.print("Access Denied");

    Serial.println("Incorrect Password");

    digitalWrite(BUZZER_PIN, HIGH);
    delay(1000);
    digitalWrite(BUZZER_PIN, LOW);
  }

  enteredPassword = "";

  delay(1000);

  showPasswordPrompt();
}

void showPasswordPrompt() {

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("Enter Password");

  lcd.setCursor(0, 1);
}
Important

The exact LCD library and keypad pin allocation should be finalized according to the actual modules included in the Makers kit.

13. Project 08 — Smart Room Controller

This project combines multiple sensors into one automation system.

Components
  • ESP8266 NodeMCU
  • LDR
  • PIR
  • Relay
  • LED or low-voltage lamp
Operating Principle

The system uses both brightness and motion.

For example:

  • Room is dark + motion detected → Light ON
  • Room is bright → Light OFF

No motion for a defined period → Light OFF

Instead of reacting to only one sensor, the ESP8266 combines multiple conditions.

Example Decision Logic
              ┌── Room bright ──→ Light OFF
              │
LDR ──────────┤
              │
              └── Room dark
                       │
                       ▼
                     Check PIR
                       │
             ┌─────────┴─────────┐
             │                   │
       Motion detected      No motion
             │                   │
             ▼                   ▼
         Light ON          Light OFF

This is an important transition from individual experiments to real automation logic.

Connections
Component ESP8266
LDR A0
PIR OUT D5
Relay IN D6
Arduino IDE Code
const int LDR_PIN = A0;
const int PIR_PIN = D5;
const int RELAY_PIN = D6;

const int DARK_THRESHOLD = 500;

const unsigned long LIGHT_TIMEOUT = 30000;

unsigned long lastMotionTime = 0;

bool lightState = false;

void setup() {

  Serial.begin(115200);

  pinMode(PIR_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);

  // Relay OFF for an active-low module
  digitalWrite(RELAY_PIN, HIGH);

  Serial.println("Smart Room Controller");
}

void loop() {

  int lightValue = analogRead(LDR_PIN);
  int motion = digitalRead(PIR_PIN);

  bool dark = lightValue < DARK_THRESHOLD;

  if (motion == HIGH) {

    lastMotionTime = millis();

    Serial.println("Motion detected");
  }

  if (dark && (millis() - lastMotionTime < LIGHT_TIMEOUT)) {

    if (!lightState) {

      digitalWrite(RELAY_PIN, LOW);
      lightState = true;

      Serial.println("Room Light ON");
    }

  } else {

    if (lightState) {

      digitalWrite(RELAY_PIN, HIGH);
      lightState = false;

      Serial.println("Room Light OFF");
    }
  }

  delay(100);
}
Programming Concept

This project makes a decision using two different inputs:

Dark?
  +
Motion recently detected?
  ↓
Light ON

This is much closer to real smart-home automation than simply connecting one sensor to one output.

14. Project 09 — Home Security System

This project combines two different types of security sensors.

Components
  • ESP8266 NodeMCU
  • Reed switch
  • PIR sensor
  • Buzzer
  • LCD
  • Optional LED
Sensor Roles
  • Reed switch: monitors doors and windows.
  • PIR: monitors movement.
  • Buzzer: provides an audible alarm.
  • LCD: displays the security status.
Example System

When the system is armed:  Door opens → Alarm  or   Motion detected → Alarm

The LCD can display:

  • System Armed
  • System Disarmed
  • Door Open
  • Motion Detected
  • Alarm Active
Why This Project Is Different
  • The system now has several inputs and several possible events.
  • The ESP8266 must determine which sensor generated the event and select the appropriate response.
  • This introduces the concept of a small embedded state machine.
Connections
Component ESP8266
Reed switch D7
PIR D5
Buzzer D0
LCD I²C
Arduino IDE Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int REED_PIN = D7;
const int PIR_PIN = D5;
const int BUZZER_PIN = D0;

LiquidCrystal_I2C lcd(0x27, 16, 2);

bool systemArmed = true;
bool alarmActive = false;

void setup() {

  Serial.begin(115200);

  pinMode(REED_PIN, INPUT_PULLUP);
  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);

  lcd.init();
  lcd.backlight();

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Security System");

  delay(1500);

  updateDisplay();
}

void loop() {

  if (!systemArmed) {

    digitalWrite(BUZZER_PIN, LOW);

    return;
  }

  bool doorOpen = digitalRead(REED_PIN) == HIGH;
  bool motionDetected = digitalRead(PIR_PIN) == HIGH;

  if (doorOpen) {

    activateAlarm("Door Open");
  }
  else if (motionDetected) {

    activateAlarm("Motion Det.");
  }
  else {

    if (!alarmActive) {

      digitalWrite(BUZZER_PIN, LOW);

      lcd.setCursor(0, 0);
      lcd.print("System: ARMED  ");

      lcd.setCursor(0, 1);
      lcd.print("Area Secure     ");
    }
  }

  delay(100);
}

void activateAlarm(const char* message) {

  alarmActive = true;

  digitalWrite(BUZZER_PIN, HIGH);

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("ALARM!");

  lcd.setCursor(0, 1);
  lcd.print(message);

  Serial.print("ALARM: ");
  Serial.println(message);
}

void updateDisplay() {

  lcd.clear();

  if (systemArmed) {

    lcd.setCursor(0, 0);
    lcd.print("System: ARMED");

  } else {

    lcd.setCursor(0, 0);
    lcd.print("System: OFF");
  }
}
Recommended Improvement

For the actual Makers kit, add an Arm/Disarm push button or keypad command rather than hard-coding:

bool systemArmed = true;

That turns the project into a more realistic security system.

15. Project 10 — Complete Smart Home

The final project combines the concepts introduced throughout the previous nine projects.

Possible Components
  • ESP8266 NodeMCU
  • LDR
  • PIR
  • Reed switch
  • DHT22
  • Relay
  • LED/light
  • DC fan
  • Servo
  • Keypad
  • Buzzer
  • LCD/OLED
  • Push buttons
  • Wi-Fi network
System Architecture
                       SMART HOME
                           │
                           ▼
                    ESP8266 NodeMCU
                           │
       ┌───────────────────┼───────────────────┐
       │                   │                   │
       ▼                   ▼                   ▼
     Sensors            Actuators           Display
       │                   │                   │
 ┌─────┼─────┐       ┌─────┼─────┐       ┌────┴────┐
 │     │     │       │     │     │       │         │
LDR   PIR   Reed    Relay  LED  Servo   LCD       OLED
 │     │     │       │     │     │
 └─────┼─────┴───────┴─────┴─────┘
       │
      DHT22
       │
       ▼
    Temperature
       │
       ▼
   Fan Control

                           │
                           ▼
                         Wi-Fi
                           │
                           ▼
                  Phone / Web Interface
Example Automation Rules

The final system can implement rules such as:

Rule 1 — Lighting    Dark + motion → Light ON

Rule 2 — Fan     Temperature above threshold → Fan ON

Rule 3 — Door   Door opens while security is armed → Alarm ON

Rule 4 — Motion   Motion while security is armed → Alarm ON

Rule 5 — Access     Correct password → Unlock door

Rule 6 — Remote Control      Wi-Fi command → ESP8266 → Selected output

  • This demonstrates how individual circuits can be combined into a complete automation system.
  • The final project should not simply repeat the previous programs. It should combine them using a modular program structure.

The following is a foundation version that combines:

  • LDR
  • PIR
  • Reed switch
  • DHT22
  • Relay/light
  • Fan relay
  • Buzzer
  • Servo
  • OLED/LCD-compatible status concept
  • Wi-Fi

Because Project 10 has many peripherals, the final physical pin allocation should be finalized after selecting the exact keypad/display/relay modules.

Arduino IDE Code
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <Servo.h>

#define DHT_PIN D5
#define DHT_TYPE DHT22

const int LDR_PIN = A0;
const int PIR_PIN = D6;
const int REED_PIN = D7;

const int LIGHT_RELAY_PIN = D1;
const int FAN_RELAY_PIN = D2;

const int BUZZER_PIN = D0;
const int SERVO_PIN = D4;

const int DARK_THRESHOLD = 500;

const float FAN_ON_TEMP = 30.0;
const float FAN_OFF_TEMP = 28.0;

const unsigned long LIGHT_TIMEOUT = 30000;

const int LOCK_POSITION = 0;
const int UNLOCK_POSITION = 90;

// Wi-Fi settings
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

DHT dht(DHT_PIN, DHT_TYPE);

Servo doorServo;

bool lightState = false;
bool fanState = false;
bool alarmState = false;

unsigned long lastMotionTime = 0;

void setup() {

  Serial.begin(115200);

  pinMode(PIR_PIN, INPUT);
  pinMode(REED_PIN, INPUT_PULLUP);

  pinMode(LIGHT_RELAY_PIN, OUTPUT);
  pinMode(FAN_RELAY_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  // Active-low relay modules
  digitalWrite(LIGHT_RELAY_PIN, HIGH);
  digitalWrite(FAN_RELAY_PIN, HIGH);

  digitalWrite(BUZZER_PIN, LOW);

  doorServo.attach(SERVO_PIN);
  doorServo.write(LOCK_POSITION);

  dht.begin();

  connectWiFi();

  Serial.println();
  Serial.println("Makers Smart Home");
  Serial.println("System Ready");
}

void loop() {

  readSensors();

  controlLighting();

  controlFan();

  checkSecurity();

  handleDoorLock();

  delay(100);
}

void readSensors() {

  int lightValue = analogRead(LDR_PIN);
  int motion = digitalRead(PIR_PIN);
  int door = digitalRead(REED_PIN);

  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  Serial.println("----------------------");

  Serial.print("Light: ");
  Serial.println(lightValue);

  Serial.print("Motion: ");
  Serial.println(motion);

  Serial.print("Door: ");
  Serial.println(door);

  if (!isnan(temperature)) {

    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");
  }

  if (!isnan(humidity)) {

    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %");
  }
}

void controlLighting() {

  int lightValue = analogRead(LDR_PIN);
  int motion = digitalRead(PIR_PIN);

  bool dark = lightValue < DARK_THRESHOLD;

  if (motion == HIGH) {

    lastMotionTime = millis();
  }

  bool recentMotion =
    millis() - lastMotionTime < LIGHT_TIMEOUT;

  if (dark && recentMotion) {

    if (!lightState) {

      digitalWrite(LIGHT_RELAY_PIN, LOW);

      lightState = true;

      Serial.println("Smart Light: ON");
    }

  } else {

    if (lightState) {

      digitalWrite(LIGHT_RELAY_PIN, HIGH);

      lightState = false;

      Serial.println("Smart Light: OFF");
    }
  }
}

void controlFan() {

  float temperature = dht.readTemperature();

  if (isnan(temperature)) {
    return;
  }

  if (!fanState && temperature >= FAN_ON_TEMP) {

    fanState = true;

    digitalWrite(FAN_RELAY_PIN, LOW);

    Serial.println("Fan: ON");
  }

  if (fanState && temperature <= FAN_OFF_TEMP) {

    fanState = false;

    digitalWrite(FAN_RELAY_PIN, HIGH);

    Serial.println("Fan: OFF");
  }
}

void checkSecurity() {

  bool doorOpen = digitalRead(REED_PIN) == HIGH;
  bool motionDetected = digitalRead(PIR_PIN) == HIGH;

  if (doorOpen || motionDetected) {

    alarmState = true;

    digitalWrite(BUZZER_PIN, HIGH);

    if (doorOpen) {

      Serial.println("SECURITY: Door Open");
    }

    if (motionDetected) {

      Serial.println("SECURITY: Motion Detected");
    }

  } else {

    alarmState = false;

    digitalWrite(BUZZER_PIN, LOW);
  }
}

void handleDoorLock() {

  // Placeholder for keypad/password logic.

  // In the complete version:
  //
  // Correct password
  //       ↓
  // Servo → UNLOCK_POSITION
  //
  // Timeout
  //       ↓
  // Servo → LOCK_POSITION
}

void connectWiFi() {

  Serial.print("Connecting to Wi-Fi");

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  unsigned long startAttempt = millis();

  while (WiFi.status() != WL_CONNECTED &&
         millis() - startAttempt < 15000) {

    delay(500);

    Serial.print(".");
  }

  Serial.println();

  if (WiFi.status() == WL_CONNECTED) {

    Serial.println("Wi-Fi Connected");

    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());

  } else {

    Serial.println("Wi-Fi Connection Failed");

    // The smart-home functions continue
    // to operate locally.
  }
}
Important improvement for Project 10

I would not publish this Project 10 code as the final production code yet because the complete system needs one final hardware decision: which display and keypad architecture will be included in the actual Makers Smart Home Kit.

The ESP8266 has limited GPIO compared with an ESP32, so trying to connect every peripheral directly can create pin conflicts. This is especially important when combining:

  • 4×4 keypad
  • LCD
  • Servo
  • multiple sensors
  • two relays
  • buzzer
  • Wi-Fi

A cleaner professional design is to use I²C peripherals and/or an I/O expander for the final kit.

16. Programming and Wi-Fi Connectivity

The programming approach should also progress with the hardware.

Basic Programming

The first projects can use simple Arduino-style functions:

setup()
loop()
pinMode()
digitalRead()
digitalWrite()
analogRead()

This makes the first experiments easier for beginners.

Sensor Processing

As the projects become more advanced, the program can be organized into separate functions:

readLightSensor()
readMotionSensor()
readDoorSensor()
readTemperature()
controlLight()
controlFan()
controlAlarm()
controlDoorLock()
updateDisplay()

This approach makes the code easier to understand and maintain.

Automation Logic

Rather than placing all conditions into one large loop(), the program can be divided into logical tasks.

For example:

Read Sensors
      ↓
Update System State
      ↓
Apply Automation Rules
      ↓
Control Outputs
      ↓
Update Display
      ↓
Handle Wi-Fi
      ↓
Repeat

This architecture becomes particularly important in the Complete Smart Home project.

Wi-Fi Features

The ESP8266 can connect to a home Wi-Fi router and communicate using standard network protocols.

Possible educational features include:

  • Displaying sensor readings on a web page
  • Turning a light ON/OFF from a phone
  • Monitoring room temperature remotely
  • Checking door status
  • Displaying security status
  • Sending sensor data to an IoT platform

The ESP8266 supports TCP/IP networking and Wi-Fi station and SoftAP modes.

For an introductory Makers project, a simple local web dashboard is a good starting point because it demonstrates IoT functionality without requiring a separate mobile application.

17. Safety and Design Considerations

Use Low-Voltage Loads in the Learning Kit?

The safest approach for a beginner-oriented educational kit is to use:

  • LEDs
  • 5 V or 12 V lamps
  • Low-voltage DC fans
  • Servo motors
  • Buzzer modules

For the relay experiments, the relay can demonstrate the principle of switching without requiring the learner to connect directly to household mains.

If mains-powered equipment is ever used, the installation should be performed using appropriate rated components, enclosure, insulation, fusing, and electrical protection by a suitably qualified person.

Do Not Power Loads Directly From GPIO

An ESP8266 GPIO is a control signal, not a general-purpose power supply.

For example:

  • Incorrect:   ESP8266 GPIO → DC fan
  • Correct:  ESP8266 GPIO → suitable driver/relay → DC fan

The same principle applies to other loads whose current requirements exceed the GPIO’s safe operating limits.

Pay Attention to ESP8266 Boot Pins

GPIO0, GPIO2, and GPIO15 participate in the ESP8266 boot-mode selection. External circuits connected to these pins must not force inappropriate levels during startup.

This is particularly important when designing a reusable kit where different modules may remain connected while the board is reset.

Power Supply

The ESP8266 requires a stable 3.3 V operating supply at the chip level, and Wi-Fi transmission can create significant instantaneous current demand. Espressif specifies a 2.5–3.6 V operating range for the ESP8266EX, while the Arduino ESP8266 documentation recommends adequate supply capability and filtering for stable operation.

The USB-powered NodeMCU board handles the conversion to the ESP8266’s operating voltage, but the power supply must still be adequate for the board and connected peripherals.

LDR and the ADC

The ESP8266 provides only one user ADC input, so the LDR project should use A0 and the rest of the kit should preferentially use digital or I²C devices.

Also, do not assume that every ESP8266 development board has the same A0 voltage range. The bare ESP8266 ADC input is specified for 0–1.0 V, while some development boards include an input divider. The exact NodeMCU board should therefore be checked before applying an external analog voltage.

18. Frequently Asked Questions

Can the ESP8266 run all ten Makers Smart Home projects?

Yes. The ESP8266 provides enough digital interfaces for the proposed projects, while the single ADC can be reserved for the LDR. The kit should be designed carefully around the available GPIO and boot-sensitive pins.

Why use ESP8266 instead of an Arduino Uno?

The major advantage for this particular kit is integrated Wi-Fi. An Arduino Uno can control sensors and actuators, but adding Wi-Fi normally requires an additional communication module. The ESP8266 combines the controller and Wi-Fi functionality in one platform.

Does the ESP8266 have Bluetooth?

No. The ESP8266 is a Wi-Fi platform; it should not be selected when Bluetooth is a required feature.

Can the LDR and DHT22 be used together?

Yes. The LDR uses the ESP8266’s analog input, while the DHT22 communicates through a digital GPIO. They therefore do not require the same type of interface.

Can I connect several analog sensors to the ESP8266?

Not directly to separate built-in ADC channels because the ESP8266 has one user-accessible ADC channel. An external ADC or suitable analog multiplexer can be added if a future version of the kit requires several analog measurements.

Can the relay control a household appliance?

A relay can electrically switch a suitable load, but for a beginner educational kit it is preferable to demonstrate the circuit using low-voltage DC loads. Mains-voltage wiring requires appropriate electrical safety measures and qualified installation.

Can the kit be controlled from a smartphone?

Yes. The ESP8266’s Wi-Fi capability makes local web control, IoT dashboards, and other network-based interfaces possible.

Is the Makers Smart Home Kit only for beginners?

No. The first projects are deliberately beginner-friendly, but the later projects introduce multi-sensor logic, access control, state management, networking, and IoT concepts that can also be useful to electronics students, hobbyists, and engineers.

Can the same components be reused for different projects?

Yes. Reusability is one of the main advantages of the kit. For example, the same PIR can be used for the Motion Activated Light, Security Motion Alarm, Smart Room Controller, Home Security System, and Complete Smart Home projects.

What is the main purpose of the ten-project structure?

The projects are arranged as a learning progression. The learner starts with a single sensor and output and gradually moves toward a multi-sensor Wi-Fi smart-home system.

19. Conclusion

The Makers Smart Home Kit: 10 Practical ESP8266 Projects for Smart Home Automation provides a structured way to learn how modern smart-home systems are built.

Instead of treating each component as an isolated experiment, the ten projects progressively introduce the complete automation chain:

Sensors → ESP8266 → Decision Logic → Actuators → Display → Wi-Fi

The first projects establish the fundamentals with automatic lighting, motion detection, and door alarms. The following projects introduce temperature control, relays, servo motors, keypads, and displays. The final projects combine these elements into multi-sensor security and smart-home systems.

The ESP8266 is particularly suitable for this educational approach because Wi-Fi and several common microcontroller interfaces are integrated into the platform.

For Makers Electronics, the key value of this kit is therefore not simply the number of components included. It is the progressive learning path that allows a beginner to start with a simple LED and eventually build a practical Wi-Fi-connected smart-home controller.

Recommended Sources and Reference Ranking

For this article, I would keep the source list intentionally small and prioritize primary technical documentation first, followed by well-established educational references:

1. Espressif Systems — ESP8266EX Datasheet
Best source for electrical specifications, GPIO, ADC, Wi-Fi capabilities, interfaces, power requirements, and official application information.

Espressif ESP8266EX Datasheet

2. ESP8266 Arduino Core Documentation
Best practical software reference for Arduino IDE programming, GPIO, analog input, Wi-Fi libraries, I²C, SPI, and development-board configuration.

ESP8266 Arduino Core Documentation

3. Adafruit Learning System — DHT Sensors / Display Guides
Useful for beginner-friendly explanations and practical interfacing examples for components such as DHT sensors and SSD1306 displays.

Adafruit DHT Sensor Guide

Important current note: Espressif’s November 2025 ESP8266EX datasheet now marks the ESP8266EX as “Not Recommended for New Designs (NRND)” and points to newer Espressif devices. For this article, that does not prevent using an existing ESP8266 NodeMCU board as the basis of an educational Makers kit, but it is worth keeping in mind if Makers later develops a new-generation version of the kit.

مجموعة Makers للمنزل الذكي: 10 مشاريع عملية باستخدام ESP8266 لأتمتة المنزل الذكي

قائمة المحتويات

  1. المقدمة
  2. ما هي مجموعة Makers للمنزل الذكي؟
  3. لماذا نستخدم ESP8266 في مشاريع المنزل الذكي؟
  4. المكونات الرئيسية للمجموعة
  5. لوحة ESP8266 NodeMCU وتخطيط المنافذ
  6. المشروع 01 — مصباح ليلي تلقائي
  7. المشروع 02 — إضاءة تعمل عند اكتشاف الحركة
  8. المشروع 03 — إنذار فتح الباب
  9. المشروع 04 — إنذار الحركة الأمني
  10. المشروع 05 — وحدة تحكم تلقائية بالمروحة
  11. المشروع 06 — قفل باب إلكتروني
  12. المشروع 07 — قفل باب باستخدام كلمة مرور
  13. المشروع 08 — وحدة تحكم ذكية بالغرفة
  14. المشروع 09 — نظام أمان للمنزل
  15. المشروع 10 — المنزل الذكي المتكامل
  16. البرمجة والاتصال عبر Wi-Fi
  17. اعتبارات السلامة والتصميم
  18. الأسئلة الشائعة
  19. الخاتمة

مدة القراءة: 20 دقيقة.

1. المقدمة

تجمع تقنيات المنزل الذكي بين المستشعرات ووحدات التحكم والمشغلات ووسائل الاتصال اللاسلكي بهدف أتمتة المهام اليومية ومراقبة الظروف المختلفة داخل المنزل.

تم تصميم مجموعة Makers للمنزل الذكي كمنصة تعليمية عملية تعتمد على لوحة ESP8266 NodeMCU 30-Pin with CP2102 Micro USB. وبدلًا من اقتصار المجموعة على تجربة إلكترونية واحدة، تتيح للمبتدئين والهواة والمهندسين تنفيذ سلسلة من مشاريع المنزل الذكي المتدرجة في مستوى الصعوبة باستخدام وحدة التحكم الرئيسية نفسها.

تبدأ المشاريع بتجارب بسيطة مثل المصباح الليلي التلقائي، ثم تتطور تدريجيًا لتشمل اكتشاف الحركة، وأنظمة الإنذار، والتحكم في درجة الحرارة، والأقفال التي تعمل بمحرك السيرفو، والحماية بكلمة مرور، ودمج عدة مستشعرات، والمرحلات، والشاشات، بالإضافة إلى الاتصال عبر Wi-Fi.

يُعد ESP8266 مناسبًا بشكل خاص لهذا النوع من المشاريع لأنه يجمع بين وحدة تحكم دقيقة واتصال Wi-Fi بتردد 2.4 GHz، إلى جانب واجهات مثل GPIO وUART وSPI وI²C وPWM وADC. كما تذكر شركة Espressif تطبيقات متعددة لـ ESP8266EX، من بينها الأجهزة المنزلية، وأتمتة المنازل، والإضاءة الذكية، والمقابس الذكية، وشبكات المستشعرات، وتطبيقات الأمان والمراقبة.

وهذا يجعل المجموعة مفيدة ليس فقط لتعلم طريقة استخدام كل مكون إلكتروني على حدة، بل أيضًا لفهم كيفية تصميم نظام متكامل للأتمتة المنزلية يعتمد على تقنيات إنترنت الأشياء (IoT).

مجموعة Makers للمنزل الذكي باستخدام ESP8266

ماذا ستتعلم؟

من خلال تنفيذ المشاريع العشرة، سيتعرف المتعلم تدريجيًا على مجموعة من المفاهيم والمهارات العملية، ومنها:

  • المستشعرات الرقمية والتماثلية
  • مداخل ومخارج GPIO
  • التحكم التلقائي في الإضاءة
  • اكتشاف الحركة
  • مراقبة الأبواب والنوافذ
  • استخدام الجرس في أنظمة الإنذار
  • التحكم اعتمادًا على درجة الحرارة
  • تشغيل المرحلات والتحكم بها
  • التحكم في محركات السيرفو
  • إدخال البيانات باستخدام لوحة المفاتيح
  • شاشات LCD وOLED
  • دمج عدة مستشعرات وتطبيق منطق الأتمتة
  • الاتصال عبر Wi-Fi
  • المفاهيم الأساسية لإنترنت الأشياء (IoT)
  • تصميم بنية نظام متكامل للمنزل الذكي

2. ما هي مجموعة Makers للمنزل الذكي؟

مجموعة Makers للمنزل الذكي هي منصة إلكترونية تعليمية قابلة لإعادة الاستخدام، تتمحور حول لوحة تطوير ESP8266 NodeMCU.

منصة Makers Smart Home Kit

الفكرة الأساسية بسيطة:

استشعار → معالجة → اتخاذ القرار → تنفيذ → اتصال

  • يبدأ النظام باستشعار حالة أو تغير فيزيائي معين باستخدام أحد المستشعرات، ثم تقوم لوحة ESP8266 بمعالجة المعلومات وتطبيق المنطق البرمجي المحدد.
  • بعد ذلك، تتحكم اللوحة في مخرج مثل LED أو الجرس أو المرحل أو محرك السيرفو أو الشاشة.
  • وعند إضافة Wi-Fi، يمكن للـ ESP8266 أيضًا الاتصال بالشبكة المحلية أو بخدمة تعتمد على الإنترنت.

على سبيل المثال:

مستشعر PIR → ESP8266 → مرحل → إضاءة

  • يكتشف مستشعر PIR وجود حركة، ثم تحدد لوحة ESP8266 وفقًا للبرنامج ما إذا كان ينبغي تشغيل الإضاءة، وبعد ذلك يقوم المرحل بالتحكم في الحمل منخفض الجهد.
  • ويمكن توسيع هذا المبدأ نفسه ليصبح نظامًا متكاملًا لأتمتة المنزل.

3. لماذا نستخدم ESP8266 في مشاريع المنزل الذكي؟

اتصال Wi-Fi مدمج
  • من أهم مزايا ESP8266 أن الاتصال بشبكة Wi-Fi مدمج داخل الشريحة نفسها، ولذلك لا تحتاج إلى إضافة وحدة Wi-Fi منفصلة.
  • يدعم ESP8266EX معيار IEEE 802.11 b/g/n ضمن نطاق 2.4 GHz، ويمكنه العمل في وضع الاتصال بشبكة Wi-Fi أو كنقطة وصول (Access Point).
  • وبالنسبة إلى مجموعة تعليمية للمنزل الذكي، فهذا يعني أن وحدة التحكم نفسها يمكن استخدامها في التجارب الإلكترونية المحلية وكذلك في المشاريع المتصلة بالشبكة.
واجهات رقمية متعددة
  • توفر لوحة ESP8266 منافذ GPIO يمكن استخدامها مع المفاتيح، ومستشعرات PIR، ومصابيح LED، والجرسات، ووحدات المرحلات، ومحركات السيرفو، وغيرها من الأجهزة الرقمية.
  • كما تدعم واجهات اتصال متعددة، من بينها I²C وSPI وUART وPWM.
المدخل التماثلي
  • يحتوي ESP8266 على قناة ADC واحدة متاحة للمستخدم.
  • وهذه نقطة مهمة عند تخطيط المجموعة، إذ يمكن توصيل مستشعر ضوئي LDR أو مستشعر تماثلي آخر بالمدخل A0، لكن لا ينبغي تصميم المجموعة بحيث تعتمد على عدد كبير من المداخل التماثلية في الوقت نفسه.
  • ولهذا السبب، يُفضل في مجموعة Makers للمنزل الذكي الاعتماد على المستشعرات الرقمية والأجهزة التي تستخدم واجهة I²C كلما أمكن ذلك.

ESP8266 NodeMCU وواجهاته في مشاريع المنزل الذكي

مناسب لتعلم إنترنت الأشياء

يوفر Arduino Core الخاص بـ ESP8266 دعمًا لأسلوب البرمجة المعتمد على Arduino، بالإضافة إلى مكتبات ووظائف للتعامل مع Wi-Fi وI²C وSPI والمقاطعات والمداخل والمخارج الرقمية والمدخل التماثلي.

وهذا يمنح المبتدئ مسارًا تدريجيًا وواضحًا يبدأ من:

تشغيل مصباح LED وإيقافه

إلى:

بناء وحدة تحكم منزلية ذكية متصلة عبر Wi-Fi.

4. المكونات الرئيسية للمجموعة

يمكن أن تتضمن النسخة العملية من مجموعة Makers للمنزل الذكي المكونات التالية:

المكون الكمية المقترحة الاستخدام الرئيسي
ESP8266 NodeMCU 30-Pin CP2102 1 وحدة التحكم الرئيسية
لوحة تجارب Breadboard 1 تنفيذ النماذج الأولية والتجارب
أسلاك توصيل Jumper Wires مجموعة إجراء التوصيلات
مصابيح LED عدة قطع مؤشرات وإضاءة
مقاومات قيم متنوعة دوائر LED وLDR
LDR 1–2 اكتشاف مستوى الإضاءة
مستشعر PIR 1 اكتشاف الحركة
Reed Switch 1 اكتشاف فتح الأبواب والنوافذ
مغناطيس 1 تفعيل مفتاح Reed
Buzzer 1 إصدار إشارات الإنذار
DHT22 1 قياس درجة الحرارة والرطوبة
وحدة Relay 1 التحكم في الأحمال منخفضة الجهد
مروحة DC 1 مشروع التحكم في المروحة
Servo SG90 1 تنفيذ قفل إلكتروني
لوحة مفاتيح 4×4 1 إدخال كلمات المرور
شاشة LCD تعمل عبر I²C 1 عرض النصوص وحالة النظام
شاشة OLED مقاس 0.96 بوصة SSD1306 اختيارية شاشة رسومية صغيرة الحجم
أزرار ضغط عدة قطع التحكم اليدوي
مزود طاقة منظم 5V 1 تغذية المجموعة بالطاقة
كابل USB 1 البرمجة وتوفير الطاقة

المكونات الرئيسية لمجموعة Makers للمنزل الذكي

يحتوي مستشعر DHT22 على عنصر مخصص لاستشعار الرطوبة، وثرمستور لقياس درجة الحرارة، بالإضافة إلى دوائر إلكترونية داخلية لمعالجة وتحويل الإشارات، مما يجعله مناسبًا وسهل الاستخدام في مشاريع المتحكمات الدقيقة التعليمية.

5. لوحة ESP8266 NodeMCU وتخطيط المنافذ

  • يُعد التخطيط الجيد للمنافذ أمرًا مهمًا بشكل خاص عند استخدام ESP8266، لأن بعض منافذ GPIO لا يمكن التعامل معها باعتبارها منافذ عامة غير مقيدة.
  • تستخدم لوحة ESP8266 المنافذ GPIO0 وGPIO2 وGPIO15 أثناء بدء التشغيل لتحديد وضع الإقلاع.
  • لذلك، فإن توصيل المستشعرات أو الوحدات بهذه المنافذ دون مراعاة حالتها أثناء بدء التشغيل قد يؤدي إلى حدوث مشكلات تمنع اللوحة من الإقلاع بشكل صحيح.
  • وبناءً على ذلك، من الأفضل تخصيص منافذ اللوحة بعناية عند تصميم مجموعة Makers Smart Home.

تخطيط منافذ ESP8266 NodeMCU

توزيع مقترح للمنافذ
الوظيفة منفذ NodeMCU ESP8266 GPIO
SDA للشاشة OLED/LCD D2 GPIO4
SCL للشاشة OLED/LCD D1 GPIO5
DHT22 D5 GPIO14
PIR D6 GPIO12
Reed Switch D7 GPIO13
Buzzer D0 GPIO16
Relay D3/GPIO0* GPIO0
Servo D4/GPIO2* GPIO2
LDR A0 ADC
لوحة المفاتيح Keypad عدة منافذ GPIO متاحة —

* يجب التعامل مع D3/GPIO0 وD4/GPIO2 بحذر إضافي لأنهما من منافذ تحديد وضع الإقلاع.

  • عند تصميم مجموعة مخصصة للاستخدام الفعلي، يجب التحقق من توزيع المنافذ النهائي بالاعتماد على لوحة NodeMCU المحددة المستخدمة، وكذلك سلوك الوحدات المتصلة بها أثناء بدء التشغيل.
  • تشارك المنافذ GPIO0 وGPIO2 وGPIO15 في تحديد وضع إقلاع ESP8266.
  • لذلك، يُفضل في التصميم النهائي حجز هذه المنافذ الحساسة أثناء الإقلاع أو عزلها بالطريقة المناسبة، بدلًا من التعامل معها مثل أي منافذ GPIO عادية.
شاشة I²C

تُعد الشاشة التي تعمل عبر واجهة I²C خيارًا عمليًا بشكل خاص، لأنها تحتاج إلى خطي اتصال فقط، بالإضافة إلى التغذية والأرضي.

في حالة استخدام شاشة OLED تعمل عبر I²C، تكون التوصيلات كالتالي:

  • ESP8266 SDA → OLED SDA
  • ESP8266 SCL → OLED SCL
  • 3.3 V → OLED VCC
  • GND → OLED GND

تُستخدم شاشات OLED التي تعتمد على وحدات التحكم SSD1306 بشكل شائع مع المتحكمات الدقيقة، حيث يتم الاتصال بها من خلال خطي SDA وSCL.

6. المشروع 01 — المصباح الليلي التلقائي

يقدم المشروع الأول أحد أبسط مفاهيم المنزل الذكي، وهو التحكم في الإضاءة تلقائيًا اعتمادًا على مستوى الإضاءة المحيطة.

مشروع المصباح الليلي التلقائي باستخدام ESP8266

المكونات
  • لوحة ESP8266 NodeMCU
  • LDR
  • مقاومة
  • LED
  • لوحة تجارب Breadboard
  • أسلاك توصيل Jumper Wires
كيف يعمل المشروع؟
  • تتغير مقاومة LDR وفقًا لكمية الضوء الساقط عليها.
  • تُستخدم دائرة مقسم جهد لتحويل هذا التغير في المقاومة إلى جهد يمكن قياسه بواسطة محول ADC الموجود في ESP8266.

يعتمد التشغيل الأساسي على القاعدة التالية:

وجود إضاءة → إيقاف LED

انخفاض الإضاءة → تشغيل LED

تقرأ البرمجية قيمة A0 باستمرار وتقارن القيمة المقاسة بحد معين تمت برمجته مسبقًا.

لماذا هذا المشروع مهم؟

تقدم هذه الدائرة البسيطة مفهومًا أساسيًا يتكرر في أنظمة التحكم بالإضاءة الأكبر:

حالة فيزيائية → مستشعر → متحكم دقيق → قرار → مخرج

ويُستخدم المبدأ نفسه كأساس لتطوير أنظمة أكثر تقدمًا للتحكم التلقائي في الإضاءة.

ملاحظة مهمة حول ESP8266

نظرًا لأن ESP8266 يحتوي على قناة ADC واحدة متاحة للمستخدم، فمن الأفضل التعامل مع LDR باعتباره المستشعر التماثلي الأساسي في هذه المجموعة.

التوصيلات
المكون ESP8266
خرج مقسم جهد LDR A0
أنود LED عبر مقاومة D6 / GPIO12
كاثود LED GND
دائرة LDR 3.3 V / GND
كود Arduino IDE
const int LDR_PIN = A0;
const int LED_PIN = D6;

// Adjust this value after testing your LDR circuit.
const int LIGHT_THRESHOLD = 500;

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

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);

  Serial.println("Automatic Night Light");
}

void loop() {
  int lightValue = analogRead(LDR_PIN);

  Serial.print("LDR Value: ");
  Serial.println(lightValue);

  // Adjust this comparison according to your voltage-divider orientation.
  if (lightValue < LIGHT_THRESHOLD) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }

  delay(200);
}
شرح البرمجة

تقرأ لوحة ESP8266 قيمة LDR من خلال المدخل التماثلي الوحيد المتاح للمستخدم، وهو A0.

تقارن البرمجية القيمة المقروءة بالحد المحدد في المتغير LIGHT_THRESHOLD.

عندما تشير القراءة إلى وجود ظلام، تقوم اللوحة بتشغيل LED.

ولا توجد قيمة ثابتة تصلح لجميع دوائر LDR، لذلك يجب ضبط قيمة العتبة عمليًا بعد اختبار LDR والمقاومة الفعليين المستخدمين في المجموعة.

7. المشروع 02 — الإضاءة التي تعمل عند اكتشاف الحركة

في المشروع الثاني، يتم استبدال مستشعر الضوء بمستشعر حركة، بحيث تعمل الإضاءة عند اكتشاف وجود حركة في المنطقة التي يغطيها المستشعر.

مشروع الإضاءة التي تعمل عند اكتشاف الحركة باستخدام ESP8266

المكونات
  • لوحة ESP8266 NodeMCU
  • مستشعر حركة PIR
  • LED
  • مقاومة
كيف يعمل المشروع؟
  • يكتشف مستشعر PIR التغيرات في الأشعة تحت الحمراء المرتبطة بحركة الأشخاص أو الأجسام.
  • تقرأ لوحة ESP8266 الإشارة الرقمية الخارجة من مستشعر PIR.
  • عند اكتشاف الحركة: PIR → ESP8266 → تشغيل LED
  • بعد انتهاء الفترة الزمنية المحددة في البرنامج: LED → إيقاف
منطق التشغيل
Start
  ↓
Read PIR
  ↓
Motion detected?
  ├── No → Keep LED OFF
  └── Yes
       ↓
     LED ON
       ↓
    Wait period
       ↓
     LED OFF

يقدم هذا المشروع مفهوم المؤقتات والأتمتة التي تعتمد على الأحداث، وهي من الأفكار الأساسية في أنظمة المنزل الذكي.

التوصيلات
المكون ESP8266
PIR OUT D5 / GPIO14
PIR VCC 5 V أو جهد التغذية المحدد للوحدة
PIR GND GND
LED D6 / GPIO12
مقاومة LED على التوالي مع LED
كود Arduino IDE
const int PIR_PIN = D5;
const int LED_PIN = D6;

const unsigned long LIGHT_ON_TIME = 10000; // 10 seconds

unsigned long motionTime = 0;
bool lightOn = false;

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

  pinMode(PIR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(LED_PIN, LOW);

  Serial.println("Motion Activated Light");
}

void loop() {
  int motionState = digitalRead(PIR_PIN);

  if (motionState == HIGH) {
    digitalWrite(LED_PIN, HIGH);

    lightOn = true;
    motionTime = millis();

    Serial.println("Motion detected");
  }

  if (lightOn && (millis() - motionTime >= LIGHT_ON_TIME)) {
    digitalWrite(LED_PIN, LOW);
    lightOn = false;

    Serial.println("Light OFF");
  }
}
شرح البرمجة
  • تقرأ اللوحة خرج PIR باعتباره إشارة رقمية.
  • عندما تتحول إشارة PIR إلى HIGH، تقوم لوحة ESP8266 بتشغيل LED وتخزن قيمة الوقت الحالية التي تم الحصول عليها باستخدام millis().
  • استخدام millis() بدلًا من delay() يسمح للـ ESP8266 بالاستمرار في تنفيذ مهام أخرى أثناء تشغيل المؤقت الخاص بالإضاءة.

8. المشروع 03 — إنذار فتح الباب

يوضح هذا المشروع كيفية استخدام ESP8266 لمراقبة حالة باب أو نافذة، واكتشاف عملية الفتح وإطلاق تنبيه.

مشروع إنذار فتح الباب باستخدام Reed Switch وESP8266

المكونات
  • لوحة ESP8266 NodeMCU
  • مفتاح مغناطيسي Reed Switch
  • مغناطيس
  • Buzzer
  • LED اختياري
كيف يعمل المشروع؟
  • يغير مفتاح Reed حالته عندما يقترب المغناطيس منه أو يبتعد عنه.
  • يثبت المغناطيس على الجزء المتحرك من الباب، بينما يثبت مفتاح Reed على إطار الباب.
  • عند فتح الباب: ابتعاد المغناطيس → تغير حالة Reed Switch → اكتشاف الفتح بواسطة ESP8266 → تشغيل Buzzer
تطبيقات عملية

يمكن تطبيق المبدأ نفسه لمراقبة:

  • الأبواب
  • النوافذ
  • الخزائن
  • الأدراج
  • صناديق التخزين

وهذا يجعل المشروع مقدمة عملية مناسبة لفهم المبادئ الأساسية لاكتشاف حالات الفتح والتسلل.

التوصيلات
المكون ESP8266
Reed Switch D7 / GPIO13
الطرف الآخر لـ Reed Switch GND
Buzzer D0 / GPIO16
Buzzer GND GND

يعتمد هذا المثال على مقاومة السحب الداخلية INPUT_PULLUP الموجودة في ESP8266.

كود Arduino IDE
const int REED_PIN = D7;
const int BUZZER_PIN = D0;

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

  pinMode(REED_PIN, INPUT_PULLUP);
  pinMode(BUZZER_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);

  Serial.println("Door Open Alarm");
}

void loop() {

  int doorState = digitalRead(REED_PIN);

  // LOW = door closed
  // HIGH = door open
  if (doorState == HIGH) {

    digitalWrite(BUZZER_PIN, HIGH);

    Serial.println("WARNING: Door Open");
  }
  else {

    digitalWrite(BUZZER_PIN, LOW);

    Serial.println("Door Closed");
  }

  delay(100);
}
ملاحظة مهمة
  • تعتمد الحالة الفعلية للإشارة على طريقة تركيب مفتاح Reed وموقع المغناطيس.
  • إذا عمل مفتاح Reed بعكس المنطق المستخدم في المثال، يمكن ببساطة عكس حالتي HIGH وLOW في البرنامج.

9. المشروع 04 — نظام إنذار الحركة الأمنية

ينقل هذا المشروع وظيفة الخرج من مجرد مؤشر بسيط إلى نظام إنذار فعلي يستجيب لاكتشاف الحركة.

نظام إنذار الحركة الأمنية باستخدام ESP8266

المكونات
  • لوحة ESP8266 NodeMCU
  • مستشعر حركة PIR
  • جرس إنذار Buzzer
  • مصباح LED
طريقة التشغيل
  • يراقب مستشعر PIR المنطقة المراد حمايتها.
  • عند اكتشاف حركة، ينتقل النظام وفق التسلسل التالي: PIR → ESP8266 → Buzzer + LED
  • يمكن للبرنامج إبقاء الإنذار في حالة تشغيل لمدة زمنية محددة مسبقًا.
  • يمكن أيضًا إضافة زر ضغط ليكون بمثابة مدخل لإعادة ضبط الإنذار.
ماذا يتعلم المتدرب؟
  • يقدم هذا المشروع مفهومًا مهمًا، وهو أن المستشعر لا يتحكم مباشرة في الجهاز النهائي.
  • بدلًا من ذلك، تتم معالجة الإشارة وفق التسلسل التالي: المستشعر → وحدة التحكم → اتخاذ القرار → المشغل
  • تعمل لوحة ESP8266 هنا كطبقة لاتخاذ القرار بين المستشعر والأجهزة المنفذة.
التوصيلات
المكوّن ESP8266
خرج PIR D5 / GPIO14
جرس الإنذار D0 / GPIO16
LED D6 / GPIO12
كود Arduino IDE
const int PIR_PIN = D5;
const int BUZZER_PIN = D0;
const int LED_PIN = D6;

const unsigned long ALARM_TIME = 10000; // 10 seconds

bool alarmActive = false;
unsigned long alarmStartTime = 0;

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

  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);

  Serial.println("Security Motion Alarm");
}

void loop() {

  int motion = digitalRead(PIR_PIN);

  if (motion == HIGH && !alarmActive) {

    alarmActive = true;
    alarmStartTime = millis();

    Serial.println("MOTION DETECTED!");
  }

  if (alarmActive) {

    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED_PIN, HIGH);

    if (millis() - alarmStartTime >= ALARM_TIME) {

      digitalWrite(BUZZER_PIN, LOW);
      digitalWrite(LED_PIN, LOW);

      alarmActive = false;

      Serial.println("Alarm Reset");
    }
  }
}
مفهوم البرمجة

المفهوم الجديد والمهم في هذا المشروع هو حالة النظام:

NORMAL
   ↓
Motion detected
   ↓
ALARM ACTIVE
   ↓
Timeout
   ↓
NORMAL

10. المشروع 05 — وحدة تحكم تلقائية بالمروحة

يقدم هذا المشروع مفهوم الأتمتة المعتمدة على درجة الحرارة.

وحدة تحكم تلقائية بالمروحة باستخدام ESP8266

المكونات
  • لوحة ESP8266 NodeMCU
  • مستشعر درجة الحرارة والرطوبة DHT22
  • وحدة Relay
  • مروحة تيار مستمر منخفضة الجهد

يوفر مستشعر DHT22 معلومات رقمية عن درجة الحرارة والرطوبة إلى لوحة ESP8266.

كيف يعمل النظام؟

تقوم لوحة ESP8266 بقراءة درجة حرارة الغرفة على فترات زمنية منتظمة.

على سبيل المثال:

  • درجة الحرارة < 28°C → المروحة متوقفة
  • درجة الحرارة ≥ 30°C → المروحة تعمل

يؤدي استخدام حدّين مختلفين لدرجة الحرارة إلى إنشاء ما يُعرف باسم التباطؤ (Hysteresis)، مما يساعد على منع التبديل السريع للريليه عند تذبذب درجة الحرارة حول حد واحد.

لماذا نستخدم Relay؟
  • لا ينبغي استخدام منفذ GPIO في ESP8266 لتشغيل المروحة مباشرة.
  • توفر وحدة Relay واجهة تبديل كهربائية يتم التحكم فيها بواسطة وحدة التحكم، وتفصل بين دائرة التحكم والحمل.
  • بالنسبة إلى مجموعة تعليمية موجهة للمبتدئين، يُفضل استخدام مروحة DC منخفضة الجهد بدلًا من مروحة تعمل بجهد التيار الكهربائي الرئيسي.
  • في هذا المشروع، يُوصى باستخدام DHT22 مع مروحة DC منخفضة الجهد يتم التحكم بها بواسطة وحدة Relay.
المكتبات المطلوبة
  • ثبّت مكتبة DHT sensor library by Adafruit
  • وثبّت أيضًا المكتبة التابعة لها: Adafruit Unified Sensor
التوصيلات
المكوّن ESP8266
DHT22 DATA D5 / GPIO14
DHT22 VCC 3.3 V
DHT22 GND GND
Relay IN D6 / GPIO12
كود Arduino IDE
#include <DHT.h>

#define DHT_PIN D5
#define DHT_TYPE DHT22

const int RELAY_PIN = D6;

const float FAN_ON_TEMP = 30.0;
const float FAN_OFF_TEMP = 28.0;

DHT dht(DHT_PIN, DHT_TYPE);

bool fanState = false;

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

  dht.begin();

  pinMode(RELAY_PIN, OUTPUT);

  // Change these if your relay is active HIGH.
  digitalWrite(RELAY_PIN, HIGH);

  Serial.println("Automatic Fan Controller");
}

void loop() {

  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  if (isnan(temperature) || isnan(humidity)) {

    Serial.println("DHT22 reading failed");
    delay(2000);

    return;
  }

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" C");

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");

  // Hysteresis control
  if (!fanState && temperature >= FAN_ON_TEMP) {

    fanState = true;

    digitalWrite(RELAY_PIN, LOW);

    Serial.println("Fan ON");
  }

  if (fanState && temperature <= FAN_OFF_TEMP) {

    fanState = false;

    digitalWrite(RELAY_PIN, HIGH);

    Serial.println("Fan OFF");
  }

  delay(2000);
}
لماذا نستخدم درجتي حرارة مختلفتين؟

يؤدي استخدام:

  • تشغيل المروحة = 30°C
  • إيقاف المروحة = 28°C

إلى منع الريليه من التبديل بسرعة عندما تكون درجة الحرارة قريبة من 30°C.

وتُعرف هذه الطريقة باسم التباطؤ (Hysteresis).

11. المشروع 06 — قفل باب إلكتروني

يقدم هذا المشروع مفهوم التحكم في محرك السيرفو.

قفل باب إلكتروني باستخدام ESP8266 ومحرك سيرفو

المكونات
  • لوحة ESP8266 NodeMCU
  • زر ضغط
  • محرك سيرفو SG90
  • مصباح LED
  • جرس إنذار اختياري
كيف يعمل النظام؟
  • يعمل زر الضغط كمدخل بسيط للتحقق من السماح بالوصول.
  • على سبيل المثال: الضغط على الزر → تتحقق لوحة ESP8266 من الإدخال → يتحرك السيرفو إلى وضع فتح القفل
  • بعد مرور فترة زمنية محددة: يعود السيرفو إلى وضع القفل
  • يمثل السيرفو بذلك آلية قفل إلكترونية صغيرة يمكن استخدامها لأغراض تعليمية وتجريبية.
الهدف التعليمي

يعلم هذا المشروع المفاهيم التالية:

  • المدخلات الرقمية
  • التحكم في محرك السيرفو
  • التحكم الزمني
  • تغيير حالات النظام
  • منطق التحكم البسيط في الوصول
التوصيلات
المكوّن ESP8266
زر الضغط D7 / GPIO13
إشارة السيرفو D4 / GPIO2
تغذية السيرفو مصدر تغذية خارجي مناسب
أرضي السيرفو GND مشترك
المكتبة المطلوبة

تتضمن حزمة ESP8266 الخاصة بـ Arduino وظيفة التحكم في محرك السيرفو.

كود Arduino IDE
#include <Servo.h>

const int BUTTON_PIN = D7;
const int SERVO_PIN = D4;

const int LOCK_POSITION = 0;
const int UNLOCK_POSITION = 90;

Servo doorServo;

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

  pinMode(BUTTON_PIN, INPUT_PULLUP);

  doorServo.attach(SERVO_PIN);

  doorServo.write(LOCK_POSITION);

  Serial.println("Electronic Door Lock");
}

void loop() {

  int buttonState = digitalRead(BUTTON_PIN);

  if (buttonState == LOW) {

    Serial.println("Unlocking...");

    doorServo.write(UNLOCK_POSITION);

    delay(3000);

    Serial.println("Locking...");

    doorServo.write(LOCK_POSITION);

    // Prevent repeated triggering
    delay(500);
  }
}
ملاحظة مهمة حول تغذية السيرفو
  • لا تفترض أن منفذ 3.3 V في لوحة ESP8266 مناسب لتغذية محرك السيرفو.
  • يمكن لمحرك السيرفو الصغير أن يسبب تيارات لحظية مرتفعة أثناء الحركة.
  • استخدم مصدر تغذية خارجيًا مناسبًا للسيرفو، مع توصيل GND الخاص بمصدر التغذية إلى GND الخاص بلوحة ESP8266 لتكوين أرضي مشترك.

12. المشروع 07 — قفل باب باستخدام كلمة مرور

تتمثل الخطوة التالية في استبدال زر الضغط البسيط بلوحة مفاتيح تتيح للمستخدم إدخال كلمة مرور للتحكم في عملية فتح القفل.

قفل باب باستخدام كلمة مرور وESP8266

المكونات
  • لوحة ESP8266 NodeMCU
  • لوحة مفاتيح 4×4
  • محرك سيرفو SG90
  • شاشة LCD تعمل عبر I²C
  • جرس إنذار Buzzer
طريقة التشغيل الأساسية
  • تعرض شاشة LCD الرسالة: Enter Password
  • يدخل المستخدم سلسلة من الأرقام باستخدام لوحة المفاتيح.
  • تقارن لوحة ESP8266 التسلسل الذي أدخله المستخدم بكلمة المرور المخزنة في البرنامج.
عند إدخال كلمة المرور الصحيحة
Enter password
      ↓
Compare
      ↓
Correct
      ↓
Servo UNLOCK
      ↓
Delay
      ↓
Servo LOCK
عند إدخال كلمة مرور غير صحيحة
Enter password
      ↓
Compare
      ↓
Incorrect
      ↓
Buzzer
      ↓
Access Denied
  • توفر شاشة LCD تغذية راجعة فورية للمستخدم حول حالة العملية.
  • يقدم هذا المشروع نموذجًا مبسطًا لنظام تحكم في الوصول باستخدام المتحكمات المضمنة.
المكونات
  • لوحة ESP8266 NodeMCU
  • لوحة مفاتيح 4×4
  • محرك سيرفو SG90
  • شاشة LCD تعمل عبر I²C
  • جرس إنذار Buzzer
التخطيط المهم للمنافذ
  • تحتاج لوحة المفاتيح 4×4 إلى 8 خطوط GPIO، بينما تستخدم شاشة LCD خطين للاتصال عبر I²C، كما يحتاج السيرفو وجرس الإنذار إلى مخارج إضافية.
  • لذلك، أوصي باستخدام لوحة مفاتيح 4×3 في النسخة المدمجة من المجموعة التعليمية، أو استخدام موسّع مداخل/مخارج مثل PCF8574 إذا كانت المجموعة تتطلب استخدام لوحة مفاتيح 4×4 تحديدًا.
  • يستخدم المثال التالي لوحة مفاتيح 4×3.
التوصيلات المقترحة
الجهاز ESP8266
صف لوحة المفاتيح R1 D1
صف لوحة المفاتيح R2 D2
صف لوحة المفاتيح R3 D5
صف لوحة المفاتيح R4 D6
عمود لوحة المفاتيح C1 D7
عمود لوحة المفاتيح C2 D8
عمود لوحة المفاتيح C3 D0
LCD SDA I²C SDA
LCD SCL I²C SCL
السيرفو D4
جرس الإنذار GPIO
كود Arduino IDE
#include <Keypad.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rowPins[ROWS] = {D1, D2, D5, D6};
byte colPins[COLS] = {D7, D8, D0};

Keypad keypad = Keypad(
  makeKeymap(keys),
  rowPins,
  colPins,
  ROWS,
  COLS
);

LiquidCrystal_I2C lcd(0x27, 16, 2);

Servo doorServo;

const int SERVO_PIN = D4;
const int BUZZER_PIN = D3;

const int LOCK_POSITION = 0;
const int UNLOCK_POSITION = 90;

const char PASSWORD[] = "1234";

String enteredPassword = "";

void setup() {

  Serial.begin(115200);

  pinMode(BUZZER_PIN, OUTPUT);

  doorServo.attach(SERVO_PIN);
  doorServo.write(LOCK_POSITION);

  lcd.init();
  lcd.backlight();

  lcd.setCursor(0, 0);
  lcd.print("Enter Password");

  lcd.setCursor(0, 1);
}

void loop() {

  char key = keypad.getKey();

  if (key == NO_KEY) {
    return;
  }

  if (key == '#') {

    checkPassword();

    return;
  }

  if (key == '*') {

    enteredPassword = "";

    lcd.clear();
    lcd.print("Password Clear");

    delay(1000);

    showPasswordPrompt();

    return;
  }

  if (enteredPassword.length() < 8) {

    enteredPassword += key;

    lcd.setCursor(enteredPassword.length() - 1, 1);
    lcd.print('*');
  }
}

void checkPassword() {

  if (enteredPassword == PASSWORD) {

    lcd.clear();
    lcd.print("Access Granted");

    Serial.println("Correct Password");

    doorServo.write(UNLOCK_POSITION);

    delay(3000);

    doorServo.write(LOCK_POSITION);

  } else {

    lcd.clear();
    lcd.print("Access Denied");

    Serial.println("Incorrect Password");

    digitalWrite(BUZZER_PIN, HIGH);
    delay(1000);
    digitalWrite(BUZZER_PIN, LOW);
  }

  enteredPassword = "";

  delay(1000);

  showPasswordPrompt();
}

void showPasswordPrompt() {

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("Enter Password");

  lcd.setCursor(0, 1);
}
ملاحظة مهمة

يجب تحديد مكتبة شاشة LCD المستخدمة وتوزيع منافذ لوحة المفاتيح بشكل نهائي وفقًا للوحدات الفعلية المضمنة في مجموعة Makers.

13. المشروع 08 — وحدة تحكم ذكية للغرفة

يجمع هذا المشروع عدة مستشعرات ضمن نظام أتمتة واحد، مما يمثل خطوة متقدمة مقارنة بالتجارب التي تعتمد على مستشعر واحد.

وحدة تحكم ذكية للغرفة باستخدام ESP8266

المكونات
  • لوحة ESP8266 NodeMCU
  • مستشعر ضوئي LDR
  • مستشعر حركة PIR
  • وحدة Relay
  • مصباح LED أو مصباح منخفض الجهد
مبدأ التشغيل

يعتمد النظام على عاملين أساسيين هما مستوى الإضاءة والحركة.

على سبيل المثال:

  • الغرفة مظلمة + تم اكتشاف حركة → تشغيل الإضاءة
  • الغرفة مضيئة → إيقاف الإضاءة
  • عدم اكتشاف حركة لمدة محددة → إيقاف الإضاءة

وبدلًا من الاستجابة إلى مستشعر واحد فقط، تقوم لوحة ESP8266 بدمج عدة شروط معًا قبل اتخاذ القرار.

مثال على منطق اتخاذ القرار
              ┌── Room bright ──→ Light OFF
              │
LDR ──────────┤
              │
              └── Room dark
                       │
                       ▼
                     Check PIR
                       │
             ┌─────────┴─────────┐
             │                   │
       Motion detected      No motion
             │                   │
             ▼                   ▼
         Light ON          Light OFF

يمثل هذا المشروع انتقالًا مهمًا من التجارب الفردية البسيطة إلى منطق الأتمتة الحقيقي، حيث تعتمد النتيجة على مجموعة من المدخلات والشروط بدلًا من ربط مستشعر واحد بمخرج واحد.

التوصيلات
المكوّن ESP8266
LDR A0
خرج PIR D5
Relay IN D6
كود Arduino IDE
const int LDR_PIN = A0;
const int PIR_PIN = D5;
const int RELAY_PIN = D6;

const int DARK_THRESHOLD = 500;

const unsigned long LIGHT_TIMEOUT = 30000;

unsigned long lastMotionTime = 0;

bool lightState = false;

void setup() {

  Serial.begin(115200);

  pinMode(PIR_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);

  // Relay OFF for an active-low module
  digitalWrite(RELAY_PIN, HIGH);

  Serial.println("Smart Room Controller");
}

void loop() {

  int lightValue = analogRead(LDR_PIN);
  int motion = digitalRead(PIR_PIN);

  bool dark = lightValue < DARK_THRESHOLD;

  if (motion == HIGH) {

    lastMotionTime = millis();

    Serial.println("Motion detected");
  }

  if (dark && (millis() - lastMotionTime < LIGHT_TIMEOUT)) {

    if (!lightState) {

      digitalWrite(RELAY_PIN, LOW);
      lightState = true;

      Serial.println("Room Light ON");
    }

  } else {

    if (lightState) {

      digitalWrite(RELAY_PIN, HIGH);
      lightState = false;

      Serial.println("Room Light OFF");
    }
  }

  delay(100);
}
مفهوم البرمجة

يتخذ هذا المشروع القرار اعتمادًا على مدخلين مختلفين:

Dark?
  +
Motion recently detected?
  ↓
Light ON

وهذا يجعل النظام أقرب بكثير إلى مفهوم الأتمتة المنزلية الذكية الحقيقية مقارنةً بمجرد توصيل مستشعر واحد بمخرج واحد.

14. المشروع 09 — نظام أمان منزلي

يجمع هذا المشروع بين نوعين مختلفين من مستشعرات الأمان لإنشاء نظام قادر على مراقبة الأبواب والنوافذ واكتشاف الحركة داخل المنطقة المحمية.

نظام أمان منزلي باستخدام ESP8266

المكونات
  • لوحة ESP8266 NodeMCU
  • مفتاح Reed
  • مستشعر حركة PIR
  • جرس إنذار Buzzer
  • شاشة LCD
  • مصباح LED اختياري
وظيفة كل مستشعر
  • مفتاح Reed: يراقب حالة الأبواب والنوافذ.
  • مستشعر PIR: يراقب الحركة داخل المنطقة المحمية.
  • جرس الإنذار: يصدر تنبيهًا صوتيًا عند اكتشاف حدث أمني.
  • شاشة LCD: تعرض حالة نظام الأمان للمستخدم.
مثال على عمل النظام

عندما يكون النظام في وضع الحماية:

فتح الباب → تشغيل الإنذار

أو:

اكتشاف حركة → تشغيل الإنذار

ويمكن لشاشة LCD عرض حالات مختلفة، مثل:

  • النظام في وضع الحماية
  • النظام غير مسلح
  • الباب مفتوح
  • تم اكتشاف حركة
  • الإنذار نشط
ما الذي يميز هذا المشروع؟
  • أصبح النظام الآن يحتوي على عدة مدخلات وعدة أحداث محتملة.
  • يجب على ESP8266 تحديد المستشعر الذي تسبب في الحدث ثم اختيار الاستجابة المناسبة.
  • يقدم هذا المشروع مفهومًا مهمًا في الأنظمة المضمنة، وهو آلة الحالات المضمنة البسيطة (Embedded State Machine).
التوصيلات
المكوّن ESP8266
مفتاح Reed D7
PIR D5
جرس الإنذار D0
LCD I²C
كود Arduino IDE
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int REED_PIN = D7;
const int PIR_PIN = D5;
const int BUZZER_PIN = D0;

LiquidCrystal_I2C lcd(0x27, 16, 2);

bool systemArmed = true;
bool alarmActive = false;

void setup() {

  Serial.begin(115200);

  pinMode(REED_PIN, INPUT_PULLUP);
  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);

  lcd.init();
  lcd.backlight();

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Security System");

  delay(1500);

  updateDisplay();
}

void loop() {

  if (!systemArmed) {

    digitalWrite(BUZZER_PIN, LOW);

    return;
  }

  bool doorOpen = digitalRead(REED_PIN) == HIGH;
  bool motionDetected = digitalRead(PIR_PIN) == HIGH;

  if (doorOpen) {

    activateAlarm("Door Open");
  }
  else if (motionDetected) {

    activateAlarm("Motion Det.");
  }
  else {

    if (!alarmActive) {

      digitalWrite(BUZZER_PIN, LOW);

      lcd.setCursor(0, 0);
      lcd.print("System: ARMED  ");

      lcd.setCursor(0, 1);
      lcd.print("Area Secure     ");
    }
  }

  delay(100);
}

void activateAlarm(const char* message) {

  alarmActive = true;

  digitalWrite(BUZZER_PIN, HIGH);

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("ALARM!");

  lcd.setCursor(0, 1);
  lcd.print(message);

  Serial.print("ALARM: ");
  Serial.println(message);
}

void updateDisplay() {

  lcd.clear();

  if (systemArmed) {

    lcd.setCursor(0, 0);
    lcd.print("System: ARMED");

  } else {

    lcd.setCursor(0, 0);
    lcd.print("System: OFF");
  }
}
تحسين مقترح

في مجموعة Makers الفعلية، من الأفضل إضافة زر ضغط أو لوحة مفاتيح لتفعيل وإلغاء تفعيل النظام بدلًا من تثبيت حالة النظام داخل البرنامج باستخدام:

bool systemArmed = true;

يساعد هذا التعديل على تحويل المشروع إلى نظام أمان أكثر واقعية من الناحية التعليمية والوظيفية.

15. المشروع 10 — المنزل الذكي المتكامل

يجمع المشروع النهائي المفاهيم التي تم تقديمها وتطويرها خلال المشاريع التسعة السابقة ضمن نظام أتمتة منزلي واحد.

نظام المنزل الذكي المتكامل باستخدام ESP8266

المكونات المحتملة
  • لوحة ESP8266 NodeMCU
  • مستشعر ضوئي LDR
  • مستشعر حركة PIR
  • مفتاح Reed
  • مستشعر DHT22
  • وحدة Relay
  • مصباح LED أو مصباح إضاءة
  • مروحة DC
  • محرك سيرفو
  • لوحة مفاتيح
  • جرس إنذار Buzzer
  • شاشة LCD أو OLED
  • أزرار ضغط
  • شبكة Wi-Fi
بنية النظام
                       SMART HOME
                           │
                           ▼
                    ESP8266 NodeMCU
                           │
       ┌───────────────────┼───────────────────┐
       │                   │                   │
       ▼                   ▼                   ▼
     Sensors            Actuators           Display
       │                   │                   │
 ┌─────┼─────┐       ┌─────┼─────┐       ┌────┴────┐
 │     │     │       │     │     │       │         │
LDR   PIR   Reed    Relay  LED  Servo   LCD       OLED
 │     │     │       │     │     │
 └─────┼─────┴───────┴─────┴─────┘
       │
      DHT22
       │
       ▼
    Temperature
       │
       ▼
   Fan Control

                           │
                           ▼
                         Wi-Fi
                           │
                           ▼
                  Phone / Web Interface
أمثلة على قواعد الأتمتة

القاعدة 1 — الإضاءة: الظلام + اكتشاف حركة → تشغيل الإضاءة

القاعدة 2 — المروحة: درجة الحرارة أعلى من الحد المحدد → تشغيل المروحة

القاعدة 3 — الباب: فتح الباب أثناء تفعيل نظام الأمان → تشغيل الإنذار

القاعدة 4 — الحركة: اكتشاف حركة أثناء تفعيل نظام الأمان → تشغيل الإنذار

القاعدة 5 — الوصول: إدخال كلمة المرور الصحيحة → فتح القفل

القاعدة 6 — التحكم عن بُعد: أمر عبر Wi-Fi → ESP8266 → تشغيل أو التحكم في المخرج المحدد

  • يوضح هذا المشروع كيفية دمج الدوائر الفردية في نظام أتمتة متكامل.
  • يجب ألا يقتصر المشروع النهائي على تكرار البرامج السابقة، بل ينبغي دمج وظائفها باستخدام بنية برمجية معيارية ومنظمة.

الإصدار التالي يمثل نسخة أساسية تجمع بين المكونات التالية:

  • LDR
  • PIR
  • مفتاح Reed
  • DHT22
  • Relay للإضاءة
  • Relay للمروحة
  • جرس إنذار
  • محرك سيرفو
  • مفهوم حالة متوافق مع شاشة OLED أو LCD
  • اتصال Wi-Fi

نظرًا لأن المشروع 10 يحتوي على عدد كبير من الوحدات الطرفية، يجب تحديد التوزيع النهائي للمنافذ بعد اختيار وحدات لوحة المفاتيح والشاشة والـ Relay المستخدمة فعليًا.

كود Arduino IDE
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <Servo.h>

#define DHT_PIN D5
#define DHT_TYPE DHT22

const int LDR_PIN = A0;
const int PIR_PIN = D6;
const int REED_PIN = D7;

const int LIGHT_RELAY_PIN = D1;
const int FAN_RELAY_PIN = D2;

const int BUZZER_PIN = D0;
const int SERVO_PIN = D4;

const int DARK_THRESHOLD = 500;

const float FAN_ON_TEMP = 30.0;
const float FAN_OFF_TEMP = 28.0;

const unsigned long LIGHT_TIMEOUT = 30000;

const int LOCK_POSITION = 0;
const int UNLOCK_POSITION = 90;

// Wi-Fi settings
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

DHT dht(DHT_PIN, DHT_TYPE);

Servo doorServo;

bool lightState = false;
bool fanState = false;
bool alarmState = false;

unsigned long lastMotionTime = 0;

void setup() {

  Serial.begin(115200);

  pinMode(PIR_PIN, INPUT);
  pinMode(REED_PIN, INPUT_PULLUP);

  pinMode(LIGHT_RELAY_PIN, OUTPUT);
  pinMode(FAN_RELAY_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  // Active-low relay modules
  digitalWrite(LIGHT_RELAY_PIN, HIGH);
  digitalWrite(FAN_RELAY_PIN, HIGH);

  digitalWrite(BUZZER_PIN, LOW);

  doorServo.attach(SERVO_PIN);
  doorServo.write(LOCK_POSITION);

  dht.begin();

  connectWiFi();

  Serial.println();
  Serial.println("Makers Smart Home");
  Serial.println("System Ready");
}

void loop() {

  readSensors();

  controlLighting();

  controlFan();

  checkSecurity();

  handleDoorLock();

  delay(100);
}

void readSensors() {

  int lightValue = analogRead(LDR_PIN);
  int motion = digitalRead(PIR_PIN);
  int door = digitalRead(REED_PIN);

  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  Serial.println("----------------------");

  Serial.print("Light: ");
  Serial.println(lightValue);

  Serial.print("Motion: ");
  Serial.println(motion);

  Serial.print("Door: ");
  Serial.println(door);

  if (!isnan(temperature)) {

    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");
  }

  if (!isnan(humidity)) {

    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %");
  }
}

void controlLighting() {

  int lightValue = analogRead(LDR_PIN);
  int motion = digitalRead(PIR_PIN);

  bool dark = lightValue < DARK_THRESHOLD;

  if (motion == HIGH) {

    lastMotionTime = millis();
  }

  bool recentMotion =
    millis() - lastMotionTime < LIGHT_TIMEOUT;

  if (dark && recentMotion) {

    if (!lightState) {

      digitalWrite(LIGHT_RELAY_PIN, LOW);

      lightState = true;

      Serial.println("Smart Light: ON");
    }

  } else {

    if (lightState) {

      digitalWrite(LIGHT_RELAY_PIN, HIGH);

      lightState = false;

      Serial.println("Smart Light: OFF");
    }
  }
}

void controlFan() {

  float temperature = dht.readTemperature();

  if (isnan(temperature)) {
    return;
  }

  if (!fanState && temperature >= FAN_ON_TEMP) {

    fanState = true;

    digitalWrite(FAN_RELAY_PIN, LOW);

    Serial.println("Fan: ON");
  }

  if (fanState && temperature <= FAN_OFF_TEMP) {

    fanState = false;

    digitalWrite(FAN_RELAY_PIN, HIGH);

    Serial.println("Fan: OFF");
  }
}

void checkSecurity() {

  bool doorOpen = digitalRead(REED_PIN) == HIGH;
  bool motionDetected = digitalRead(PIR_PIN) == HIGH;

  if (doorOpen || motionDetected) {

    alarmState = true;

    digitalWrite(BUZZER_PIN, HIGH);

    if (doorOpen) {

      Serial.println("SECURITY: Door Open");
    }

    if (motionDetected) {

      Serial.println("SECURITY: Motion Detected");
    }

  } else {

    alarmState = false;

    digitalWrite(BUZZER_PIN, LOW);
  }
}

void handleDoorLock() {

  // Placeholder for keypad/password logic.

  // In the complete version:
  //
  // Correct password
  //       ↓
  // Servo → UNLOCK_POSITION
  //
  // Timeout
  //       ↓
  // Servo → LOCK_POSITION
}

void connectWiFi() {

  Serial.print("Connecting to Wi-Fi");

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  unsigned long startAttempt = millis();

  while (WiFi.status() != WL_CONNECTED &&
         millis() - startAttempt < 15000) {

    delay(500);

    Serial.print(".");
  }

  Serial.println();

  if (WiFi.status() == WL_CONNECTED) {

    Serial.println("Wi-Fi Connected");

    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());

  } else {

    Serial.println("Wi-Fi Connection Failed");

    // The smart-home functions continue
    // to operate locally.
  }
}
تحسين مهم للمشروع 10

لا يُنصح باعتبار كود المشروع 10 الحالي نسخة نهائية جاهزة للتنفيذ قبل اتخاذ قرار نهائي بشأن مكونات العتاد، وبالأخص نوع الشاشة وبنية لوحة المفاتيح التي سيتم تضمينها في مجموعة Makers Smart Home Kit.

تحتوي لوحة ESP8266 على عدد محدود من منافذ GPIO مقارنةً بـ ESP32، ولذلك قد يؤدي توصيل جميع الوحدات الطرفية مباشرة إلى حدوث تعارض في استخدام المنافذ. وتزداد أهمية هذه المشكلة عند الجمع بين:

  • لوحة مفاتيح 4×4
  • شاشة LCD
  • محرك سيرفو
  • عدة مستشعرات
  • وحدتي Relay
  • جرس إنذار
  • اتصال Wi-Fi

لذلك، يمكن أن يكون التصميم الأكثر تنظيمًا للمجموعة النهائية هو الاعتماد على وحدات تعمل عبر I²C و/أو استخدام موسّع مداخل ومخارج I/O Expander لتقليل استهلاك منافذ GPIO وتحسين تخطيط النظام.

16. البرمجة والاتصال عبر Wi-Fi

يجب أن تتطور طريقة البرمجة بالتوازي مع تطور مكونات النظام ومراحل المشروع.

البرمجة والاتصال عبر Wi-Fi

البرمجة الأساسية

يمكن للمشروعات الأولى استخدام دوال بسيطة بأسلوب Arduino، مثل:

setup()
loop()
pinMode()
digitalRead()
digitalWrite()
analogRead()

يساعد هذا الأسلوب على جعل التجارب الأولى أسهل وأكثر وضوحًا للمبتدئين.

معالجة بيانات المستشعرات

مع زيادة مستوى تعقيد المشروعات، يمكن تنظيم البرنامج إلى مجموعة من الدوال المنفصلة، مثل:

readLightSensor()
readMotionSensor()
readDoorSensor()
readTemperature()
controlLight()
controlFan()
controlAlarm()
controlDoorLock()
updateDisplay()

يساعد هذا التنظيم على جعل الكود أسهل في الفهم والصيانة والتطوير، خصوصًا عندما يبدأ المشروع في التعامل مع عدة مستشعرات ومخرجات في الوقت نفسه.

منطق التشغيل الآلي

بدلًا من وضع جميع الشروط داخل دالة loop() واحدة وكبيرة، يمكن تقسيم البرنامج إلى مهام منطقية منفصلة.

على سبيل المثال:

Read Sensors
      ↓
Update System State
      ↓
Apply Automation Rules
      ↓
Control Outputs
      ↓
Update Display
      ↓
Handle Wi-Fi
      ↓
Repeat

تصبح هذه البنية أكثر أهمية بشكل خاص في مشروع المنزل الذكي المتكامل، حيث يتعامل النظام مع عدة مستشعرات وقرارات تشغيل ومخرجات واتصال شبكي في الوقت نفسه.

إمكانات Wi-Fi

يمكن لـ ESP8266 الاتصال بموجّه Wi-Fi المنزلي والتواصل باستخدام بروتوكولات الشبكات القياسية.

ومن أمثلة الوظائف التعليمية التي يمكن تنفيذها:

  • عرض قراءات المستشعرات على صفحة ويب.
  • تشغيل وإيقاف الإضاءة من الهاتف.
  • مراقبة درجة حرارة الغرفة عن بُعد.
  • التحقق من حالة الباب.
  • عرض حالة نظام الأمان.
  • إرسال بيانات المستشعرات إلى منصة لإنترنت الأشياء (IoT).

يدعم ESP8266 الاتصال عبر شبكات TCP/IP، كما يدعم وضعي الاتصال بالشبكة اللاسلكية كمحطة Station وإنشاء شبكة لاسلكية مباشرة من خلال وضع SoftAP.

وبالنسبة إلى مشروع تعليمي مخصص للمبتدئين والهواة، فإن لوحة تحكم محلية بسيطة عبر الويب تمثل نقطة بداية مناسبة؛ لأنها توضح مفهوم إنترنت الأشياء والتحكم عبر الشبكة دون الحاجة إلى تطوير تطبيق مستقل للهاتف.

17. اعتبارات السلامة والتصميم

استخدام الأحمال منخفضة الجهد في مجموعة التعلم

بالنسبة إلى مجموعة تعليمية موجهة للمبتدئين، فإن النهج الأكثر أمانًا هو استخدام أحمال منخفضة الجهد، مثل:

  • مصابيح LED.
  • مصابيح تعمل بجهد 5V أو 12V.
  • مراوح DC منخفضة الجهد.
  • محركات السيرفو.
  • وحدات البازر.

وفي تجارب المرحل (Relay)، يمكن استخدام المرحل لتوضيح مبدأ التحكم في تشغيل وفصل الحمل دون أن يحتاج المتعلم إلى توصيل الدائرة مباشرة بجهد الشبكة الكهربائية المنزلية.

وفي حال استخدام أجهزة تعمل بجهد الشبكة الكهربائية المنزلية، فيجب أن يتم التركيب باستخدام مكونات ذات تصنيف مناسب، وعلبة حماية، وعزل كهربائي، وفيوزات ووسائل حماية كهربائية مناسبة، ومن خلال شخص مؤهل للتعامل مع التركيبات الكهربائية.

اعتبارات السلامة والتصميم

لا تقم بتغذية الأحمال مباشرة من منافذ GPIO

منفذ GPIO في ESP8266 هو إشارة تحكم، وليس مصدر طاقة عامًا لتغذية الأحمال.

على سبيل المثال:

  • التوصيل غير الصحيح: GPIO في ESP8266 ← مروحة DC
  • التوصيل الصحيح: GPIO في ESP8266 ← دائرة قيادة أو Relay مناسب ← مروحة DC

وينطبق المبدأ نفسه على أي حمل يتجاوز متطلبات التيار الخاصة بحدود التشغيل الآمن لمنفذ GPIO.

الانتباه إلى منافذ الإقلاع في ESP8266

تشارك المنافذ GPIO0 وGPIO2 وGPIO15 في تحديد وضع إقلاع ESP8266. لذلك يجب ألا تتسبب الدوائر الخارجية المتصلة بهذه المنافذ في فرض مستويات منطقية غير مناسبة أثناء بدء تشغيل اللوحة.

وتزداد أهمية هذه النقطة عند تصميم مجموعة تعليمية قابلة لإعادة الاستخدام، حيث قد تبقى وحدات ومكونات مختلفة متصلة باللوحة أثناء إعادة تشغيلها.

مصدر الطاقة

يحتاج ESP8266 على مستوى الشريحة إلى مصدر تشغيل مستقر بجهد 3.3V، كما يمكن أن يتسبب إرسال بيانات Wi-Fi في طلب تيار لحظي مرتفع نسبيًا. وتحدد Espressif نطاق تشغيل ESP8266EX بين 2.5V و3.6V، بينما توصي وثائق Arduino الخاصة بـ ESP8266 بتوفير قدرة كافية لمصدر الطاقة مع الترشيح المناسب لضمان استقرار التشغيل.

تتولى لوحة NodeMCU التي تعمل عبر USB تحويل جهد التغذية إلى الجهد المناسب لتشغيل ESP8266، ولكن يجب أن يظل مصدر الطاقة قادرًا على توفير الطاقة اللازمة للوحة وجميع الوحدات الطرفية المتصلة بها.

مستشعر LDR ومدخل ADC

يوفر ESP8266 مدخل ADC واحدًا متاحًا للمستخدم، ولذلك يُفضل توصيل مشروع LDR إلى A0، بينما تعتمد بقية مكونات المجموعة قدر الإمكان على الأجهزة الرقمية أو الأجهزة التي تستخدم واجهة I²C.

كذلك، لا ينبغي افتراض أن جميع لوحات تطوير ESP8266 تمتلك نطاق جهد متطابقًا على مدخل A0. فمدخل ADC في شريحة ESP8266 نفسها محدد للعمل ضمن نطاق 0 إلى 1.0V، بينما تحتوي بعض لوحات التطوير على مقسم جهد عند المدخل. لذلك يجب التحقق من مواصفات لوحة NodeMCU المستخدمة قبل تطبيق أي جهد تناظري خارجي على A0.

18. الأسئلة الشائعة

هل يستطيع ESP8266 تشغيل جميع المشروعات العشرة لمجموعة Makers Smart Home؟

نعم. يوفر ESP8266 عددًا كافيًا من الواجهات الرقمية لتنفيذ المشروعات المقترحة، بينما يمكن تخصيص مدخل ADC الوحيد لمشروع LDR. ومع ذلك، يجب تصميم المجموعة بعناية مع مراعاة عدد منافذ GPIO المتاحة والمنافذ الحساسة أثناء الإقلاع.

لماذا يتم استخدام ESP8266 بدلًا من Arduino Uno؟

الميزة الرئيسية لـ ESP8266 في هذه المجموعة تحديدًا هي وجود Wi-Fi مدمج. يستطيع Arduino Uno التحكم في المستشعرات والمشغلات، ولكن إضافة الاتصال عبر Wi-Fi تتطلب عادةً وحدة اتصال إضافية. أما ESP8266 فيجمع بين وحدة التحكم ووظائف Wi-Fi في منصة واحدة.

هل يحتوي ESP8266 على Bluetooth؟

لا. يعتمد ESP8266 على Wi-Fi، ولذلك لا يُنصح باختياره عندما تكون وظيفة Bluetooth مطلوبة في المشروع.

هل يمكن استخدام LDR وDHT22 معًا؟

نعم. يستخدم LDR المدخل التناظري في ESP8266، بينما يتواصل DHT22 من خلال منفذ GPIO رقمي، ولذلك لا يحتاج المستشعران إلى استخدام نوع الواجهة نفسه.

هل يمكن توصيل عدة مستشعرات تناظرية إلى ESP8266؟

ليس بشكل مباشر إلى عدة قنوات ADC داخلية منفصلة، لأن ESP8266 يحتوي على قناة ADC واحدة متاحة للمستخدم. وإذا احتاج إصدار مستقبلي من المجموعة إلى قياس عدة إشارات تناظرية، فيمكن إضافة محول ADC خارجي أو Multiplexer تناظري مناسب.

هل يمكن للـ Relay التحكم في جهاز منزلي؟

يمكن للمرحل فصل وتوصيل حمل كهربائي مناسب، ولكن بالنسبة إلى مجموعة تعليمية للمبتدئين، يُفضل تنفيذ التجارب باستخدام أحمال DC منخفضة الجهد. أما توصيل أحمال جهد الشبكة الكهربائية المنزلية فيتطلب مراعاة متطلبات السلامة الكهربائية المناسبة وتنفيذ التركيب بواسطة شخص مؤهل.

هل يمكن التحكم في المجموعة باستخدام الهاتف الذكي؟

نعم. تتيح إمكانية Wi-Fi في ESP8266 تنفيذ التحكم المحلي عبر الويب، ولوحات تحكم إنترنت الأشياء، وغيرها من الواجهات التي تعتمد على الاتصال بالشبكة.

هل مجموعة Makers Smart Home مخصصة للمبتدئين فقط؟

لا. تم تصميم المشروعات الأولى لتكون مناسبة للمبتدئين، بينما تقدم المشروعات المتقدمة مفاهيم مثل منطق التعامل مع عدة مستشعرات، والتحكم في الوصول، وإدارة حالات النظام، والاتصال الشبكي، وإنترنت الأشياء، وهي مفاهيم يمكن أن تكون مفيدة أيضًا لطلاب الإلكترونيات والهواة والمهندسين.

هل يمكن إعادة استخدام المكونات نفسها في مشروعات مختلفة؟

نعم. تعد قابلية إعادة استخدام المكونات من أهم مزايا هذه المجموعة. فعلى سبيل المثال، يمكن استخدام مستشعر PIR نفسه في مشروعات الإضاءة التي تعمل عند اكتشاف الحركة، وإنذار الحركة الأمني، ووحدة التحكم الذكية بالغرفة، ونظام الأمان المنزلي، ومشروع المنزل الذكي المتكامل.

ما الهدف الرئيسي من تقسيم المجموعة إلى عشرة مشروعات؟

تم ترتيب المشروعات وفق مسار تعليمي تدريجي؛ حيث يبدأ المتعلم بمستشعر واحد ومخرج واحد، ثم ينتقل خطوةً بخطوة إلى بناء نظام منزل ذكي متعدد المستشعرات ومتصلاً عبر Wi-Fi.

19. الخاتمة

توفر مجموعة Makers Smart Home Kit: 10 Practical ESP8266 Projects for Smart Home Automation طريقة منظمة لتعلم كيفية بناء أنظمة المنزل الذكي الحديثة وفهم طريقة عملها.

بدلًا من التعامل مع كل مكون باعتباره تجربة منفصلة، تقدم المشروعات العشرة مسارًا تدريجيًا يوضح سلسلة الأتمتة الكاملة:

المستشعرات ← ESP8266 ← منطق اتخاذ القرار ← المشغلات ← شاشة العرض ← Wi-Fi

تضع المشروعات الأولى الأساس من خلال الإضاءة التلقائية، واكتشاف الحركة، وإنذارات الأبواب. ثم تنتقل المشروعات التالية إلى التحكم في درجة الحرارة، والمرحلات، ومحركات السيرفو، ولوحات المفاتيح، وشاشات العرض. وفي المشروعات النهائية، يتم دمج هذه العناصر لبناء أنظمة أمان وأنظمة منزل ذكي تعتمد على عدة مستشعرات.

يُعد ESP8266 مناسبًا بشكل خاص لهذا الأسلوب التعليمي لأن Wi-Fi وعددًا من واجهات المتحكم الشائعة مدمجة بالفعل في المنصة.

لذلك، فإن القيمة الأساسية لهذه المجموعة بالنسبة إلى Makers Electronics لا تكمن فقط في عدد المكونات التي تحتوي عليها، بل في مسار التعلم التدريجي الذي يسمح للمبتدئ بالبدء من تجربة بسيطة باستخدام LED، ثم الانتقال تدريجيًا إلى بناء وحدة تحكم منزل ذكي عملية ومتصلّة عبر Wi-Fi.

المصادر الموصى بها وترتيب المراجع

بالنسبة إلى هذا المقال، من الأفضل إبقاء قائمة المصادر مختصرة مع إعطاء الأولوية للوثائق التقنية الرسمية والأساسية، ثم الاستعانة بالمراجع التعليمية المعروفة لدعم الشرح العملي:

1. Espressif Systems — ESP8266EX Datasheet

يُعد المصدر الأساسي للمواصفات الكهربائية، ومنافذ GPIO، وADC، وإمكانات Wi-Fi، والواجهات، ومتطلبات الطاقة، والمعلومات التقنية الرسمية الخاصة بالشريحة.

Espressif ESP8266EX Datasheet

2. ESP8266 Arduino Core Documentation

مرجع عملي مناسب لبرمجة ESP8266 باستخدام Arduino IDE، ويتناول GPIO، والمدخل التناظري، ومكتبات Wi-Fi، وواجهات I²C وSPI، وإعدادات لوحات التطوير.

ESP8266 Arduino Core Documentation

3. Adafruit Learning System — DHT Sensors / Display Guides

مرجع مفيد لشرح المكونات بطريقة مناسبة للمبتدئين، مع أمثلة عملية للتعامل مع مستشعرات DHT وشاشات مثل SSD1306 وغيرها من المكونات المستخدمة في المشروعات التعليمية.

Adafruit DHT Sensor Guide

ملاحظة مهمة وحديثة: تشير ورقة البيانات الخاصة بـ Espressif ESP8266EX، والمحدثة في نوفمبر 2025، إلى أن الشريحة أصبحت ضمن حالة Not Recommended for New Designs (NRND)، مع الإشارة إلى أجهزة أحدث من Espressif. ولا يمنع ذلك استخدام لوحات ESP8266 NodeMCU الموجودة بالفعل كأساس لمجموعة تعليمية مخصصة لمشروعات Makers، ولكن من المهم أخذ هذه النقطة في الاعتبار إذا قررت Makers Electronics تطوير إصدار جديد من المجموعة في المستقبل.

Leave a comment