Relay is
Relay is an electrical switch that is controlled by an electrical signal. It is used for:
Control high voltage electrical devices (e.g. fans, 220V bulbs) with electrical signals from Arduino (5V).
This allows the Arduino to safely control high-current devices (since the Arduino cannot directly supply high current).
Relay Module is available in various types such as 1 Channel, 2 Channel, 4 Channel depending on the number of devices to be controlled.
Specifications of Relay 5V Module
list
details
Control pressure (Input)
5V DC (from Arduino)
Load voltage (Output)
Up to ~250V AC or 30V DC
Maximum load current
10A
Number of channels (Channel)
1, 2, 4 (select according to the number of devices to be controlled)
Logic Control
Active LOW (some models)
There is an optocoupler.
Some models have a circuit breaker to isolate the electrical circuit (safer).
Output legs (3 legs)
NO (Normally Open), NC (Normally Closed), COM (Common)
Using Relay with Arduino
Wiring (Example 1 Channel):
Relay Pin
Arduino Pin
VCC
5V
GND
GND
IN1
D7 (or as required)
The IN1 leg is used to turn the relay on/off.
If it is 2/4 Channel, there will be IN2, IN3, IN4 added.
Example of connecting electrical equipment to a house:
Warning: You should have knowledge of 220V electricity and be very careful.
Use an extension cord or an electrician if you are not sure.
Connection:
COM → Connect to AC power (input line)
NO → Connect to the device you want to turn on/off (light, fan).
When Arduino sends a signal → Relay closes the circuit → Power goes to the device.
Code example:
int relayPin = 7;
void setup() { pinMode(relayPin, OUTPUT); }
void loop() {
digitalWrite(relayPin, LOW); // Open relay (some models LOW means open)
delay(3000); // leave open for 3 seconds
digitalWrite(relayPin, HIGH); // close relay
delay(3000); // wait another 3 seconds }
If your relay is Active HIGH, switch LOW and HIGH.
What can it be used with?
Turn on/off 220V light bulbs
Water pump control
Order to turn on the fan/electrical appliance
Make a Smart Home System
ESP32 Wi-Fi USB Type-C is
The ESP32 is a microcontroller board developed by Espressif Systems, which is an enhanced version of the ESP8266, with more capabilities such as:
Built-in Wi-Fi and Bluetooth (BLE)
More speed and RAM
Better support for multi-threading and complex tasks.
You can use it to program through Arduino IDE, MicroPython, or ESP-IDF.
Nowadays, newer ESP32 boards come with USB Type-C ports for easy plugging in, easier to use than Micro USB and more durable.
ESP32 Specifications (General)
list
details
Main chip
ESP32 (various models such as ESP32-WROOM-32, S2, C3, S3)
CPU
Dual-core Xtensa LX6 @ 240MHz
Wi-Fi
802.11 b/g/n 2.4GHz
Bluetooth
Bluetooth 4.2 + BLE (some models support BT 5.0)
Flash memory
4MB or more
SRAM
~520KB
Working pressure
3.3V (but can receive power via USB 5V, has a built-in regulator)
GPIO (digital pin)
Up to ~30 legs (depending on model)
Analog Input (ADC)
Up to 18 channels (12-bit)
Analog Output (DAC)
2 channels (8-bit)
Communication
UART, I2C, SPI, PWM, CAN, IR, etc.
USB Type-C
Used for uploading programs and supplying power.
Support Li-ion battery
Some models have built-in charging circuitry (e.g. ESP32-C3 DevKit).
Using ESP32
✅ Suitable for work:
IoT (Internet of Things) such as controlling devices via Wi-Fi
Smart Home (turn on/off lights, measure temperature, control via mobile phone)
Bluetooth communication, such as sending and receiving data with mobile phones
ESP-NOW / MQTT / HTTP / WebSocket all work.
Connect to Cloud such as Firebase, LINE Notify, Blynk, Telegram, etc.
✅ Popular usage examples:
Measure temperature and humidity with DHT11/DHT22 and send it to the web.
Control lights/relays via mobile app or web server
Connect OLED/LED display wirelessly
Use as a Wi-Fi Hotspot or Web Server
Make an AI training system (some models have Camera + TensorFlow Lite)
Example code to open Wi-Fi Web Server on ESP32:
#include <WiFi.h>
const char* ssid = "WiFi name";
const char* password = "password";
WiFiServer server(80);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected successfully: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop() {
WiFiClient client = server.available();
if (client) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<h2>Hello from ESP32!</h2>");
delay(1000);
}
}
📌 Advantages of the USB Type-C model:
Easy to insert, no need to worry about turning it inside out.
Good current support
The cable can be used with new mobile phones.
MC-38 Normally Closed <Normally Closed principle is together, the signal is on, with the wired host use can not be used alone>
MC-38 is normally closed: the magnet is close to the conduction, the magnet is away from the circuit breaker.
MC-38A is normally open: the magnet is close to the closed (disconnected), the magnet is away from the open circuit
Action distance: 18mm ± 6mm
Lifetime: 1,000,000 times Switching output: often closed (together with the conductive) Open type, suitable for non-ferrous doors or windows Surface mountin
It is used for directional control, similar to that used in video games, by providing an analog output using two potentiometers to read the position of the joystick.
Working voltage : DC 5 V Static current : 3 mA Working temperature : 0 ~ + 70 Output way : GPIO Induction Angle : Less than 15 Detection range : 2 cm to 4 m Detecting precision : 0.3 cm + 1% Sensor size : Approx. 45.1 x 20 x 14.5mm
Soil Moisture Sensor is a popular device in Smart Farm projects or automatic watering systems. It works with Arduino easily, is cheap, and is suitable for learning and experimenting.
Soil Moisture Sensor
Soil moisture sensor is a sensor that detects the moisture level in the soil by measuring the conductivity between the probe legs (similar to measuring the resistance of soil).
Dry soil → low conductivity → low value obtained
Moist soil → High conductivity → High obtained value
Sensors often come with a conversion module that provides both analog and digital pins.
Soil Moisture Sensor Specifications
list
details
Supply voltage
3.3V – 5V
Current used
About 10mA
Output signal
Analog (A0) and Digital (D0)
Detection range
General soil moisture levels
structure
2 probe legs (ground plug), signal converter board has a threshold adjustment potentiometer
The Digital Output will give a HIGH or LOW value according to the threshold we set.
Using with Arduino
Wiring:
Soil Sensor Pin
Arduino Pin
VCC
5V
GND
GND
A0 (Analog)
A0
D0 (Digital)
D2 (if used)
Analog code example:
------------------------------------------------------------------------------
int sensorPin = A0;
void setup() { Serial.begin(9600); }
void loop() { int value = analogRead(sensorPin); Serial.print("Soil moisture : "); Serial.println(value);
delay(1000); }
----------------------------------------------------------------------------------------------
The value returned by analogRead() will be between 0–1023.
High value = dry soil
Low value = moist soil
Digital code example:
----------------------------------------------------------------------
int sensorDigital = 2;
void setup() { pinMode(sensorDigital, INPUT); Serial.begin(9600); }
void loop() { int value = digitalRead(sensorDigital);
if (value == LOW) { Serial.println("Moist soil"); } else { Serial.println("Dry soil"); }
delay(1000); }
Additional tips:
Do not leave the sensor plugged into the ground for a long time (rust may occur).
Use the relay together with a water pump or electric valve to automatically water plants.
If you want more accuracy, try using a capacitive soil moisture sensor instead of the regular one (it is more durable and does not rust).
The MQ-2 sensor is a very popular gas sensor for use with Arduino and other microcontroller boards, and is ideal for home gas or smoke detection projects, such as gas leak alarms.
MQ-2 is
The MQ-2 is a gas sensor that can detect many types of gases such as:
LPG (cooking gas)
Butane gas
Propane gas
Methane gas (CH₄)
Hydrogen gas (H₂)
Smoke
alcohol
Inside the sensor is a heating coil and a SnO₂ (tin dioxide) gas detector, whose resistance changes in the presence of gas in the air, allowing it to be converted to an electrical signal.
MQ-2 specifications
list
details
Supply voltage
5V DC
Electrical power
About 800mW
Signal type
Analog and digital (depending on module)
Warm-up time
About 20 seconds to 2 minutes
Detectable gases
LPG, Methane, Alcohol, Propane, Hydrogen, Smoke
Detection range
Approximately 300 - 10,000 ppm
Number of legs
4 legs (VCC, GND, AOUT, DOUT)
AOUT (Analog Out) – Analog signal indicating gas level. DOUT (Digital Out) – Digital signal (1 or 0) when gas level exceeds set point.
Using MQ-2 with Arduino
Wiring:
MQ-2 Pin
Arduino Pin
VCC
5V
GND
GND
AOUT
A0 (Analog)
DOUT
D2 (Digital) (if used)
Some MQ-2 modules have a potentiometer (adjuster) to set the threshold level on DOUT.
Example code for use in Analog:
int mq2Pin = A0;
void setup() { Serial.begin(9600); }
void loop() { int gasLevel = analogRead(mq2Pin); Serial.print("gasLevel: "); Serial.println(gasLevel); delay(1000); }
Example of code for Digital usage:
int mq2Digital = 2;
void setup() { pinMode(mq2Digital, INPUT); Serial.begin(9600); }
void loop() { int gasDetected = digitalRead(mq2Digital);
if (gasDetected == LOW) { Serial.println("gas detect!"); } else { Serial.println("Safe"); }
delay(1000); }
The DHT11 sensor is one of the most popular sensors for measuring temperature and humidity, especially in Arduino projects because it is easy to use, cheap, and readily available.
What is DHT11?
DHT11 is a sensor that measures temperature and relative humidity in the air. This sensor has a capacitive humidity sensor and a thermistor temperature sensor inside, which outputs digital data, making it very easy to connect to Arduino.
DHT11 specifications
list
details
Humidity measurement range
20–90% RH (±5% RH)
Temperature measurement range
0–50°C (±2°C)
Supply voltage
3.3V – 5.5V
Output signal
Single-wire digital
Read Rate
1 time/second (1Hz)
Number of legs
3 legs (VCC, GND, Data) or 4 legs (if it is a module but actually uses 3 legs)
Using DHT11 with Arduino
Wiring:
DHT11
Arduino
VCC
5V
GND
GND
DATA
Digital Pin (eg. D2)
Some models have a pull-up resistor (about 10KΩ) already attached to the module. If it is a bare sensor, you may need to connect your own resistance.
Arduino code example:
Requires DHT library, which can be installed via Library Manager.
define DHTPIN 2 // The pin connected to the DHT11's Data #define DHTTYPE DHT11 // The type of sensor
DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); }
void loop() { float h = dht.readHumidity(); float t = dht.readTemperature();
if (isnan(h) || isnan(t)) { Serial.println("Read failed!"); return; }
Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.println(" *C"); delay(2000); // wait 2 seconds }