Arduino Soil Moisture Sensor

 How the Soil Moisture Sensor Works

Resistive Sensor

Uses two metal probes to measure electrical resistance. Wet soil has lower resistance, while dry soil has higher resistance.

Capacitive Sensor

Measures changes in soil capacitance and has no exposed metal parts. It provides more stable and long-lasting performance.

Both sensors provide an analog output that Arduino reads.

Wiring the Soil Moisture Sensor

Soil Sensor → Arduino
VCC         → 5V
GND         → GND
AO          → A0

The digital output (DO) pin is optional and can be used with a preset threshold.

Arduino Code (Basic Reading)


int soilPin = A0;
int soilValue = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  soilValue = analogRead(soilPin);

  Serial.print("Soil Moisture Value: ");
  Serial.println(soilValue);

  delay(1000);
}

Understanding Soil Moisture Values

Sensor Value Soil Condition
0 – 300 Very Wet
300 – 600 Moist
600 – 900 Dry
900 – 1023 Very Dry

Values may vary depending on soil type. Always calibrate with dry and wet soil.

Improved Code with Moisture Status


int soilPin = A0;
int soilValue = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  soilValue = analogRead(soilPin);

  Serial.print("Soil Moisture: ");
  Serial.print(soilValue);

  if (soilValue < 300) {
    Serial.println(" - WET");
  }
  else if (soilValue < 600) {
    Serial.println(" - MOIST");
  }
  else {
    Serial.println(" - DRY");
  }

  delay(1000);
}

Testing the Sensor

  1. Upload the code to Arduino
  2. Open the Serial Monitor
  3. Set baud rate to 9600
  4. Insert the sensor into soil
  5. Add water and observe changes

Wet soil produces lower values, while dry soil produces higher values.

Troubleshooting

  • Always reads 1023: Sensor not properly inserted
  • No value change: Loose wiring or faulty sensor
  • Unstable readings: Electrical noise or dry air
  • Corrosion: Use capacitive sensor instead of resistive

Optional Upgrades

  • Add relay and water pump for automatic irrigation
  • Add LCD or OLED display
  • Use ESP8266/ESP32 for IoT monitoring
  • Log data to SD card for analysis.
[mai mult...]

Arduino Fingerprint Sensor

Required Components

Component Quantity Description
Arduino Uno / Nano / Mega 1 Main controller
Fingerprint Sensor (R307 / ZFM-20 / Adafruit) 1 Biometric identification
16×2 LCD with I2C Module 1 Display user messages
12V Solenoid Lock 1 Door/box locking mechanism
5V Relay Module 1 Controls solenoid lock
12V Power Supply 1 Powers solenoid
Jumper Wires Connections

The fingerprint sensor scans the user’s finger. Arduino checks if the fingerprint matches a stored ID. If it matches, the relay is activated and unlocks the solenoid lock. The LCD shows:

  • Scanning
  • Access Granted
  • Access Denied

Fingerprint Sensor → Arduino

VCC → 5V
GND → GND
TX  → D2
RX  → D3

I2C LCD → Arduino

VCC → 5V
GND → GND
SDA → A4
SCL → A5

Relay Module → Arduino

IN  → D8
VCC → 5V
GND → GND

Solenoid Lock Power Wiring

12V+ → COM on Relay
NO   → Solenoid +
Solenoid - → 12V -

IMPORTANT: Use a diode (1N4007) across solenoid terminals to prevent voltage spikes.

Arduino Code (Copy & Paste)

This code controls the fingerprint module, LCD display, and solenoid lock.


#include <Adafruit_Fingerprint.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>

SoftwareSerial fingerSerial(2, 3); // RX, TX
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&fingerSerial);
LiquidCrystal_I2C lcd(0x27, 16, 2);

int relayPin = 8;

void setup() {
lcd.init();
lcd.backlight();

pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // lock OFF at start

lcd.setCursor(0, 0);
lcd.print("Fingerprint");
lcd.setCursor(0, 1);
lcd.print("Access System");

delay(2000);
lcd.clear();

finger.begin(57600);
if (finger.verifyPassword()) {
lcd.print("Sensor Ready");
} else {
lcd.print("Sensor Error");
while (1);
}
delay(2000);
lcd.clear();
}

void loop() {
lcd.setCursor(0, 0);
lcd.print("Place Finger...");
lcd.setCursor(0, 1);
lcd.print(" ");

int result = getFingerprintID();

if (result >= 0) {
lcd.clear();
lcd.print("Access Granted");
unlockDoor();
} else if (result == -1) {
lcd.clear();
lcd.print("Access Denied");
delay(1500);
}

lcd.clear();
}

int getFingerprintID() {
finger.getImage();
if (finger.image2Tz() != FINGERPRINT_OK) return -1;
if (finger.fingerSearch() != FINGERPRINT_OK) return -1;

return finger.fingerID; // valid ID returned
}

void unlockDoor() {
digitalWrite(relayPin, HIGH); // open lock
delay(3000); // unlock duration
digitalWrite(relayPin, LOW); // lock again
}

You must add fingerprints before using the system.

  1. In Arduino IDE, go to File → Examples → Adafruit Fingerprint Sensor Library → Enroll
  2. Upload the sketch
  3. Open Serial Monitor
  4. Type the fingerprint ID number (1–127)
  5. Place finger twice when instructed

Fingerprint is now stored.

LCD Display Messages

Event Message
Startup Fingerprint Access System
Ready Sensor Ready
Waiting Place Finger…
Match Access Granted
No Match Access Denied

Troubleshooting

  • Fingerprint not detected: TX/RX wiring reversed
  • LCD not showing text: Wrong I2C address (try 0x3F)
  • Solenoid not activating: Check relay NO/COM wiring
  • Machine resets: Solenoid drawing current — use separate 12V supply.
[mai mult...]

Arduino Air Quality Monitoring System

Build your own Arduino-based Air Quality Monitor using sensors like the MQ-135, MQ-7, and DHT11/DHT22. This guide explains how the sensors work, how to wire them, and includes a fully commented Arduino code example.

Components Needed

Component Qty Description
Arduino Uno / Nano / Mega 1 Main microcontroller
MQ-135 Gas Sensor 1 Detects VOCs, NH₃, CO₂, smoke, pollution
DHT11 or DHT22 1 Temperature & Humidity
MQ-7 (optional) 1 Carbon Monoxide sensor
0.96″ OLED (optional) 1 Displays readings
Breadboard & Jumper Wires Wiring
USB Cable 1 Power + programming

How the Sensors Work

MQ-135 (Air Quality Sensor)

Detects harmful gases such as CO₂, NH₃, NOx, benzene, and VOCs. The analog output value increases when the air becomes more polluted. Requires a short preheat time for accuracy.

MQ-7 (Carbon Monoxide)

Detects CO gas. Optional component for advanced monitoring.

DHT11 / DHT22

Reads temperature and humidity. These values help interpret gas sensor readings more accurately.

MQ-135 Wiring

MQ135 → Arduino
VCC   → 5V
GND   → GND
A0    → A0

DHT11 / DHT22

DHT Sensor → Arduino
VCC        → 5V
GND        → GND
DATA       → D2

OLED (I2C)

OLED → Arduino
VCC  → 5V
GND  → GND
SDA  → A4
SCL  → A5

Arduino Code (Copy & Paste)


#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT22 // change to DHT11 if needed
DHT dht(DHTPIN, DHTTYPE);

int mq135Pin = A0;

void setup() {
Serial.begin(9600);
dht.begin();
}

void loop() {

// --- Read MQ135 Sensor ---
int mqValue = analogRead(mq135Pin);
float airQuality = map(mqValue, 0, 1023, 0, 500);
// 0 = clean air, 500 = very polluted

// --- Read Temperature & Humidity ---
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();

// --- Output Data ---
Serial.println("----------- AIR QUALITY MONITOR -----------");
Serial.print("MQ135 Raw Value: ");
Serial.println(mqValue);

Serial.print("Air Quality Index (approx): ");
Serial.print(airQuality);
Serial.println(" / 500");

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

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

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

delay(1000);
}

Understanding the Readings

MQ135 Reading Air Quality Description
0–80 Excellent Very clean air
80–150 Good Normal indoor air
150–250 Moderate Needs ventilation
250–350 Poor Polluted environment
350–500+ Hazardous High VOCs or smoke detected

Troubleshooting

  • Sensor always reads high: MQ-135 needs 1–5 minutes warm-up time.
  • No DHT readings: Check DATA pin and DHT type in code.
  • Unstable values: Add a 100nF decoupling capacitor to MQ sensor.
  • OLED not showing: Wrong I2C address — run an I2C scanner.
[mai mult...]

Arduino Ultrasonic Sensor

The sensor sends out an ultrasonic sound wave from the TRIG pin. When the sound wave hits an object, it reflects back and is detected by the ECHO pin.
The Arduino measures the time it takes for the signal to return and uses that to calculate the distance.

Distance (cm) = (Time in microseconds × 0.034) / 2

The speed of sound is 0.034 cm/µs. We divide by 2 because the sound travels to the object and back.

Required Components

Component Quantity Purpose
Arduino Uno / Nano / Mega 1 Main microcontroller
HC-SR04 Ultrasonic Sensor 1 Measures distance
Jumper Wires 4 Connections
Breadboard (optional) 1 Easy wiring
USB Cable 1 Power & programming

Pin Connections

Connect the HC-SR04 sensor to the Arduino as shown below:

HC-SR04 Pin Arduino Pin
VCC 5V
GND GND
TRIG Digital Pin 9
ECHO Digital Pin 10

Note: The ECHO pin outputs 5V, which is safe for Arduino Uno/Nano/Mega.

Arduino Code

Upload the following code to your Arduino:


#define TRIG_PIN 9
#define ECHO_PIN 10

void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}

void loop() {
long duration;
float distance;

// Clear trigger
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);

// Trigger ultrasonic burst
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);

// Measure echo time
duration = pulseIn(ECHO_PIN, HIGH);

// Convert time to distance
distance = (duration * 0.034) / 2;

// Output result
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

delay(500);
}

Code Explanation

  • pulseIn() measures the duration of the ECHO signal.
  • The sensor sends a 40 kHz ultrasonic burst using the TRIG pin.
  • Arduino calculates the distance based on the speed of sound.
  • Distance is printed in centimeters to the Serial Monitor.

Testing the Sensor

  1. Upload the code to your Arduino
  2. Open the Serial Monitor
  3. Set the baud rate to 9600
  4. Move your hand in front of the sensor
  5. Watch the distance update live

You should see something like:

Distance: 15.4 cm

Troubleshooting

Issue Cause Solution
Always reads 0 cm Incorrect pin wiring Check TRIG and ECHO
Values jump around Object surface curved or too small Use a flat object
No Serial output Wrong baud rate Set Serial Monitor to 9600
Sensor not working No power Ensure 5V and GND connected properly

 

[mai mult...]

Arduino Weather Station guide

The DHT11 and DHT22 measure temperature and humidity. DHT22 offers higher accuracy and a wider range.

Pin Description
VCC +5V
DATA Data output (connect to D2)
NC Not connected
GND Ground

BMP180 / BME280

Measures pressure and temperature using the I2C interface.

Pin Description
VIN +3.3V or +5V
GND Ground
SCL I2C Clock (A5)
SDA I2C Data (A4)

LCD (16×2 I2C)

Displays data using the I2C interface — only two wires are required (SDA, SCL).
The most common I2C addresses are 0x27 or 0x3F.

Wiring Diagram

Component Arduino Pin Notes
DHT11 Data D2 Use 10kΩ pull-up resistor (optional)
BMP180 SDA A4 I2C Data
BMP180 SCL A5 I2C Clock
LCD SDA A4 Shared with BMP180
LCD SCL A5 Shared with BMP180
Power (+) 5V Common power line
Ground (–) GND Common ground

On Arduino Mega, use SDA = 20 and SCL = 21 instead.

Arduino Code Example


#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>

// Define sensors
#define DHTPIN 2
#define DHTTYPE DHT11   // or DHT22

DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change address if needed (0x3F or 0x27)

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.backlight();
  dht.begin();

  if (!bmp.begin()) {
    Serial.println("BMP180 not found!");
    lcd.print("BMP Error!");
    while (1);
  }

  lcd.clear();
  lcd.print("Weather Station");
  delay(2000);
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float p = bmp.readPressure() / 100.0; // hPa

  if (isnan(h) || isnan(t)) {
    Serial.println("DHT read error!");
    return;
  }

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("T:");
  lcd.print(t);
  lcd.print((char)223);
  lcd.print("C H:");
  lcd.print(h);
  lcd.print("%");

  lcd.setCursor(0, 1);
  lcd.print("P:");
  lcd.print(p);
  lcd.print(" hPa");

  Serial.print("Temp: "); Serial.print(t);
  Serial.print(" °C  Hum: "); Serial.print(h);
  Serial.print("%  Pressure: "); Serial.print(p);
  Serial.println(" hPa");

  delay(2000);
}

Explanation: This program reads data from the DHT and BMP sensors, then prints it to both the Serial Monitor and the LCD screen.

How It Works

  1. The sensors measure temperature, humidity, and pressure.
  2. Arduino reads and formats this data.
  3. The LCD displays readings in real time.
  4. Every few seconds, the data updates automatically.

Troubleshooting

Problem Possible Cause Solution
LCD shows random text Wrong I2C address Try 0x3F instead of 0x27
“BMP180 not found!” Wiring issue Check SDA/SCL and power
DHT readings show NaN Missing library or bad sensor Install DHT library, recheck wiring
LCD blank Contrast too low or backlight off Adjust contrast screw or enable backlight

Install these from Arduino IDE → Sketch → Include Library → Manage Libraries:

  • DHT sensor library by Adafruit
  • Adafruit Unified Sensor
  • Adafruit BMP085 Library or Adafruit BME280
  • LiquidCrystal_I2C

Optional: IoT Integration

Add an ESP8266 or ESP32 to send data to cloud platforms such as:

  • ThingSpeak
  • Blynk
  • Adafruit IO

Use libraries like ESP8266WiFi.h and HTTPClient.h to upload readings as HTTP requests.

Expansion Ideas

  • Add a rain sensor or anemometer (wind speed)
  • Store data on an SD card
  • Add a real-time clock (RTC) for timestamped data
  • Display graphs on a web dashboard.
[mai mult...]

Arduino Distance Sensor with OLED Display

This project uses an HC-SR04 Ultrasonic Distance Sensor and a 0.96” I2C OLED display to measure and display the distance to an object in real-time.
It’s an excellent beginner-to-intermediate Arduino project that teaches sensor interfacing, I2C communication, and real-time data display.

In this guide, you’ll learn how to:

  • Connect and use the HC-SR04 Ultrasonic Sensor
  • Display the measured distance on an OLED screen
  • Format readings for easy readability

Components Required

Component Quantity Description
Arduino Uno / Nano / Mega 1 Main controller
HC-SR04 Ultrasonic Sensor 1 Measures distance via sound waves
0.96” OLED Display (SSD1306) 1 I2C display for output
Breadboard 1 For wiring
Jumper wires 6–8 Male-to-male connections
USB cable 1 For programming and power

The HC-SR04 measures distance by sending out an ultrasonic pulse and timing how long it takes to bounce back.
The Arduino calculates the distance based on the time delay and the known speed of sound.

Distance Formula:

Distance (cm) = (Time in microseconds × 0.034) / 2

The division by 2 accounts for the round trip of the sound wave (out and back).

Pin Connections

Component Arduino Pin Notes
HC-SR04 VCC 5V Power supply
HC-SR04 GND GND Common ground
HC-SR04 TRIG D9 Trigger pin
HC-SR04 ECHO D10 Echo pin
OLED VCC 5V Power
OLED GND GND Ground
OLED SDA A4 I2C Data
OLED SCL A5 I2C Clock

Note: On Arduino Mega, use SDA = 20 and SCL = 21 instead.

Arduino Code Example


#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define TRIG_PIN 9
#define ECHO_PIN 10
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);

// Initialize OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED not found!");
while (true);
}

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Distance Sensor");
display.display();
delay(1500);
}

void loop() {
long duration;
float distance;

// Send trigger pulse
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);

// Measure echo time
duration = pulseIn(ECHO_PIN, HIGH);
distance = (duration * 0.034) / 2;

// Print to Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

// Display on OLED
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("Distance Sensor");

display.setTextSize(2);
display.setCursor(0, 30);
display.print(distance, 1);
display.println(" cm");
display.display();

delay(500);
}

Explanation: The Arduino sends a pulse from the HC-SR04 and measures the time it takes to return.
It then converts this time into distance and displays it on the OLED screen.

Code Breakdown

  • pulseIn() measures the length of time the echo pin is HIGH.
  • Distance is calculated using the speed of sound (0.034 cm/μs).
  • Adafruit_SSD1306 and Adafruit_GFX libraries drive the OLED.
  • Display refreshes every 0.5 seconds for updated readings.

Install these via Arduino IDE → Sketch → Include Library → Manage Libraries:

  • Adafruit SSD1306
  • Adafruit GFX

Search for “Adafruit SSD1306” and “Adafruit GFX” and click Install.

Troubleshooting

Issue Cause Solution
OLED blank Wrong I2C address Try changing 0x3C to 0x3D
Distance always 0 Echo pin not connected Check TRIG and ECHO wiring
Unstable readings Object too close or far HC-SR04 range: 2–400 cm
Serial Monitor empty Wrong baud rate Ensure 9600 baud in Serial Monitor

Optional Upgrades

  • Add a buzzer that activates when an object is too close.
  • Display a bar graph or animation on the OLED.
  • Send readings to the cloud using ESP8266 / ESP32.
  • Log readings to an SD card.

Applications

  • Parking assist system
  • Object detection robot
  • Smart trash bin (auto open lid)
  • Liquid level detector.
[mai mult...]

Arduino Motion Sensor Guide (Using a PIR Sensor)

A PIR (Passive Infrared) sensor detects motion by measuring changes in infrared radiation emitted by objects (like humans or animals) within its field of view.

PIR sensors are commonly used for:

Component Quantity Notes
Arduino Uno (or Nano, Mega, etc.) 1 Any compatible board
PIR Motion Sensor (HC-SR501 or similar) 1 Adjustable sensitivity and delay
Breadboard 1 For easy connections
Jumper wires ~5 Male-to-male recommended
LED 1 Optional for visual indication
220Ω resistor 1 For LED current limiting
USB cable 1 For programming and power

 Understanding the PIR Sensor

Typical PIR module (e.g., HC-SR501) has 3 pins:

Pin Label Function
1 VCC Power (connect to +5V)
2 OUT Sends HIGH when motion is detected
3 GND Connects to Ground

Adjustable knobs (optional):

  • Sensitivity: changes detection range (typically 3–7 meters)
  • Time delay: how long output stays HIGH after motion (usually 0.3s–5min)

Wiring Diagram

PIR Sensor Arduino Notes
VCC 5V Power supply
OUT D2 Digital input pin
GND GND Common ground
LED (+) D13 Visual output (optional)
LED (–) GND (via 220Ω resistor) Current limit

Connect VCC → 5V, GND → GND, OUT → D2, LED → D13 (optional)

Arduino Code Example


// PIR Motion Sensor with LED Example

int pirPin = 2; // PIR sensor output pin
int ledPin = 13; // LED pin

int pirState = LOW; // Default state
int val = 0; // Variable for reading the pin status

void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("PIR Motion Sensor Active");
}

void loop() {
val = digitalRead(pirPin); // Read input value from PIR

if (val == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED ON
if (pirState == LOW) {
Serial.println("Motion detected!");
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // Turn LED OFF
if (pirState == HIGH) {
Serial.println("Motion ended!");
pirState = LOW;
}
}
}

Explanation: The PIR output goes HIGH when motion is detected. The LED turns on and a message is printed to the Serial Monitor.

How It works

  1. Warm-up time: After powering up, the PIR sensor takes ~30–60 seconds to stabilize.
  2. Detection: When an object moves, the sensor’s output pin goes HIGH.
  3. Reset: After the set delay, the output returns LOW until new motion is detected.

1. Control a Relay

Use motion detection to control a light or appliance:


int relayPin = 8; // connect to relay module IN pin
// Replace ledPin with relayPin in code

2. Buzzer Alarm

Add a buzzer that sounds when motion is detected:


int buzzerPin = 9;
digitalWrite(buzzerPin, HIGH);

3. Serial Logging

Send motion logs to a computer or IoT platform for analysis.

4. Automation

Combine PIR with an LDR (light sensor) so it only triggers lights at night.


[mai mult...]

RFID Door Lock with Arduino

In this detailed guide, you’ll learn how to build an RFID door lock system using an Arduino Uno and an MFRC522 RFID reader. The system reads RFID cards or keyfobs, checks authorization, and controls a solenoid lock or servo latch to grant access. It’s perfect for home automation, maker projects, or educational demonstrations.

Solenoid Lock Wiring

Arduino D7 → Gate of MOSFET (via 100Ω resistor)
MOSFET Source → GND (common)
MOSFET Drain → Solenoid negative terminal
Solenoid positive → +12V
12V supply GND → Arduino GND
Flyback diode across solenoid (1N4007, cathode to +12V)

Optional Servo Connection

Servo Signal → D7 (PWM)
Servo V+ → 5V external supply
Servo GND → Common GND

Arduino Code — Basic Version

This version uses a hard-coded list of authorized RFID tags.

/* RFID Door Lock - Basic Version */
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define RST_PIN 9
#define SDA_PIN 10
MFRC522 rfid(SDA_PIN, RST_PIN);

#define ACTUATOR_TYPE 0  // 0=Solenoid/Relay, 1=Servo
const int RELAY_PIN = 7;
const int LED_PIN = 4;
const int BUZZER_PIN = 5;
const int SERVO_PIN = 7;
const unsigned long UNLOCK_MS = 3000;
Servo lockServo;

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  if (ACTUATOR_TYPE == 0) {
    pinMode(RELAY_PIN, OUTPUT);
    digitalWrite(RELAY_PIN, LOW);
  } else {
    lockServo.attach(SERVO_PIN);
    lockServo.write(0);
  }
  Serial.println("RFID door lock ready");
}

// Replace these with your own card UIDs
byte allowedUIDs[][4] = {
  {0xDE, 0xAD, 0xBE, 0xEF},
  {0x11, 0x22, 0x33, 0x44}
};
const int allowedCount = sizeof(allowedUIDs)/4;

bool uidAllowed(byte *uid, byte uidSize) {
  if (uidSize != 4) return false;
  for (int i=0;i<allowedCount;i++) {
    bool match = true;
    for (int j=0;j<4;j++) if (allowedUIDs[i][j] != uid[j]) { match = false; break; }
    if (match) return true;
  }
  return false;
}

void unlockAction() {
  Serial.println("UNLOCK!");
  digitalWrite(LED_PIN, HIGH);
  tone(BUZZER_PIN, 1000, 150);
  if (ACTUATOR_TYPE == 0) {
    digitalWrite(RELAY_PIN, HIGH);
    delay(UNLOCK_MS);
    digitalWrite(RELAY_PIN, LOW);
  } else {
    lockServo.write(90);
    delay(UNLOCK_MS);
    lockServo.write(0);
  }
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  if (!rfid.PICC_IsNewCardPresent()) return;
  if (!rfid.PICC_ReadCardSerial()) return;

  Serial.print("Card UID:");
  for (byte i=0;i<rfid.uid.size;i++) {
    Serial.print(" ");
    Serial.print(rfid.uid.uidByte[i], HEX);
  }
  Serial.println();

  if (uidAllowed(rfid.uid.uidByte, rfid.uid.size)) {
    Serial.println("Access granted");
    unlockAction();
  } else {
    Serial.println("Access denied");
    for (int i=0;i<2;i++) {
      tone(BUZZER_PIN, 600, 150);
      digitalWrite(LED_PIN, HIGH);
      delay(200);
      digitalWrite(LED_PIN, LOW);
      delay(100);
    }
  }

  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();
}

Advanced Version — Store Tags in EEPROM

This version allows adding and removing authorized cards dynamically through the Serial Monitor.

/* RFID Door Lock - EEPROM Version */
#include <SPI.h>
#include <MFRC522.h>
#include <EEPROM.h>

#define RST_PIN 9
#define SDA_PIN 10
MFRC522 rfid(SDA_PIN, RST_PIN);

#define RELAY_PIN 7
#define LED_PIN 4
#define BUZZER_PIN 5
#define UNLOCK_MS 3000
#define MAX_TAGS 20
#define UID_SIZE 4
#define EEPROM_START 0

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  Serial.println("RFID lock with EEPROM ready");
}

/* Helper functions omitted for brevity in this preview — see full code in guide */

Serial commands:

  • l — List stored tags
  • a — Add a new tag (scan after command)
  • r — Remove a tag
  • c — Clear all stored tags

Power Considerations

  • Use a separate 12V supply for the solenoid; common the grounds.
  • Add a large capacitor (470µF–2200µF) across the solenoid supply.
  • Always include a flyback diode to protect electronics.
  • If using a servo, power it from an external 5V supply.

Mechanical Installation

  • Ensure alignment between lock and strike plate.
  • Provide a manual override or emergency key.
  • Mount RFID reader within 5–10 cm of tag presentation area.
  • Keep metal objects away from the RC522 antenna.

Testing Steps

  1. Upload code and open Serial Monitor (115200 baud).
  2. Scan a card — its UID should appear.
  3. Add card to allowed list or EEPROM memory.
  4. Test actuator operation and timing.
  5. Confirm power supply stability under load.

Troubleshooting

Issue Possible Cause Fix
No response from reader Wrong wiring or 5V used Use 3.3V and correct SPI pins
Actuator not moving Power supply too weak or wrong driver Use proper MOSFET/relay and check GND
UIDs print gibberish Wrong Serial baud rate Match Serial.begin(115200)
Unstable lock Power noise Add capacitor or separate supply

Security Enhancements

  • Use MIFARE DESFire or NTAG cards for better encryption.
  • Add a keypad for two-factor access (RFID + PIN).
  • Implement attempt-limit lockout for brute-force protection.
  • Use metal enclosure and tamper switch for extra security.

Optional Upgrades

  • OLED/LCD display for user feedback
  • Wi-Fi / MQTT integration (ESP8266 or ESP32)
  • RTC + SD card logging for audit trail
  • Battery backup for power loss protection
  • Cloud dashboard or mobile control app.
[mai mult...]

Arduino Temperature Sensor

You’ll build a simple digital thermometer that measures ambient temperature using a temperature sensor (like the LM35, TMP36, or DHT11) and displays the reading via the Serial Monitor or LCD screen.

We’ll cover two main versions:

  1. Basic Version — Using an analog temperature sensor (LM35 or TMP36).

  2. Advanced Version — Using a digital sensor (DHT11 or DHT22) with humidity support.

Materials Needed

Component Quantity Description
Arduino Uno (or Nano/Mega) 1 The main microcontroller board
LM35 or TMP36 sensor 1 Analog temperature sensor
Breadboard 1 For easy circuit assembly
Jumper wires ~6 Male-to-male wires
USB cable 1 To connect Arduino to your computer
(Optional) 16×2 LCD Display 1 For local display
(Optional) 10kΩ Potentiometer 1 LCD contrast control

Step 1: Understand the Sensor

 LM35 Pinout

Pin Label Function
1 VCC +5V from Arduino
2 VOUT Analog output (connect to Arduino analog input)
3 GND Ground

The LM35 outputs 10 mV per °C.
So if the output voltage = 250 mV → temperature = 25°C.

Step 2: Wiring the LM35 to Arduino

Connections

LM35 Pin Connects To
VCC 5V on Arduino
GND GND on Arduino
VOUT A0 on Arduino

Circuit Diagram (Text Form)

[Arduino 5V] ---- [LM35 VCC]
[Arduino GND] ---- [LM35 GND]
[Arduino A0] ---- [LM35 OUT]

Step 3: Arduino Code (LM35 Version)

// Simple Temperature Sensor with LM35

const int sensorPin = A0; // LM35 connected to A0
float temperatureC;

void setup() {
Serial.begin(9600);
Serial.println(“LM35 Temperature Sensor”);
}

void loop() {
int sensorValue = analogRead(sensorPin); // Read analog value
float voltage = sensorValue * (5.0 / 1023.0); // Convert to voltage
temperatureC = voltage * 100; // 10mV per degree C (LM35)

Serial.print(“Temperature: “);
Serial.print(temperatureC);
Serial.println(” °C”);

delay(1000); // Update every second
}

Explanation

  • analogRead(A0): reads 0–1023 corresponding to 0–5V.

  • Voltage calculation: (value * 5.0) / 1023.0.

  • LM35 output scaling: 10 mV = 1°C → multiply voltage by 100.

Step 4: Viewing Data

  • Open Arduino IDE → Tools → Serial Monitor.

  • Set baud rate = 9600.

  • You’ll see continuous readings like:

    Temperature: 24.87 °C
    Temperature: 25.02 °C

Step 5: Calibration (Optional)

Real sensors may have small offsets.
You can adjust the output manually:

temperatureC = (voltage * 100) - 0.5; // Adjust by small offset

Compare readings with a known thermometer and tweak the offset until accurate.

Advanced: Using DHT11 / DHT22 (Digital Sensor)

Required Library

  • Install “DHT sensor library” by Adafruit from Arduino Library Manager.

Wiring (DHT11)

DHT11 Pin Connects To
VCC 5V
GND GND
DATA Digital Pin 2

Code (DHT11)

#include "DHT.h"

#define DHTPIN 2 // Data pin connected to digital pin 2
#define DHTTYPE DHT11 // or DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
dht.begin();
}

void loop() {
float tempC = dht.readTemperature();
float humidity = dht.readHumidity();

if (isnan(tempC) || isnan(humidity)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}

Serial.print(“Temperature: “);
Serial.print(tempC);
Serial.print(” °C, Humidity: “);
Serial.print(humidity);
Serial.println(” %”);

delay(2000);
}

Step 6: (Optional) Display on LCD

If using a 16×2 LCD (I2C):

  1. Install “LiquidCrystal_I2C” library.

  2. Connect SDA → A4, SCL → A5.

  3. Example snippet:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
lcd.init();
lcd.backlight();
}

void loop() {
lcd.setCursor(0, 0);
lcd.print(“Temp: “);
lcd.print(temperatureC);
lcd.print(“C”);
}

Troubleshooting Guide

Issue Possible Cause Solution
No readings / 0°C Wrong wiring or pin Check sensor pins
Negative readings Wrong sensor type (TMP36 needs offset) Adjust formula
Unstable readings Noisy analog signal Add capacitor (0.1 µF) between VOUT & GND
“nan” or “Failed to read” DHT library issue Check sensor type & connections

Next Steps & Enhancements

  • Add OLED / LCD display for portable thermometer

  • Store data using SD card module

  • Upload readings to the cloud via ESP8266 / WiFi module

  • Use RGB LED to indicate temperature range (blue/cool, red/hot)

  • Build an IoT dashboard (ThingSpeak, Blynk, etc.).

[mai mult...]

How to install macOS 15 Sequoia

What you need to check first

  1. Compatibility
    Make sure your Mac is officially supported by macOS 15 Sequoia. Supported models include:
    • iMac (2019 or later)
    • MacBook Air (2020 and later)
    • MacBook Pro (2018 and later)
    • Mac mini (2018 and later)
    • Mac Pro (2019 and later)
    • Mac Studio (all models)

  2. Backup Your Data
    Always back up your important files. Time Machine is a good option, or clone your drive. This protects against data loss if something goes wrong.

  3. Free Space
    Ensure you have enough free disk space. The installer itself requires several gigabytes, plus extra space for temporary files during installation.

  4. Power
    If using a laptop, keep it plugged into power throughout the update.

  5. Software & Firmware Updates
    It’s best to start from the latest version of your current macOS. Some firmware updates may be required before Sequoia can install properly.

Installation Methods

There are a few ways to install Sequoia:

  • Standard upgrade: from your current macOS via Software Update.

  • Clean install: erase the disk & install fresh.

  • Bootable installer: useful for multiple Macs, or offline reinstalls.

  • macOS Recovery: reinstall via recovery mode.

If you want to keep your apps, data, and settings:

  1. Open System Settings (or System Preferences on older macOS versions) → General → Software Update

  2. If Sequoia is available, click Upgrade Now (or “Update Now”)

  3. Read & accept the license agreement

  4. Enter your admin password if required

  5. Wait for the installer to download. Time depends on your internet speed

  6. Once the download finishes, the Mac will prompt you to restart and begin installation

  7. The Mac will reboot several times during the process

  8. After the final restart, follow setup prompts (region, Apple ID, etc.).

If you prefer a clean slate or need to install on multiple Macs:

  1. Download the macOS Sequoia installer
    It will appear as “Install macOS Sequoia” in your Applications folder.

  2. Prepare a USB drive (16 GB or larger)
    Format it as Mac OS Extended (Journaled) or APFS using Disk Utility.

  3. Create the bootable installer
    In Terminal, run:

    sudo /Applications/Install\ macOS\ Sequoia.app/Contents/Resources/createinstallmedia --volume /Volumes/MyUSB

    Replace MyUSB with your USB drive’s name.

  4. Boot from USB

    • Plug in the USB.

    • Restart while holding Option (⌥) on Intel Macs.

    • For Apple Silicon, hold the power button until startup options appear.

    • Choose the USB drive labeled “Install macOS Sequoia.”

  5. Erase / format the internal drive (optional for clean install)
    In macOS Utilities → Disk Utility → Show All Devices → select the internal drive → Erase → format as APFS. Warning: this erases all data.

  6. Run the installer
    Choose “Install macOS,” select your drive, and follow prompts.

  7. Setup after installation completes.

If your Mac won’t boot or you need to reinstall:

  • Intel Macs: hold Command-R at startup.

  • Apple Silicon: hold the power button until startup options appear.

  • Choose “Reinstall macOS,” select your disk, and follow the prompts.

Troubleshooting / Tips

  • Installer doesn’t appear → check Mac compatibility, firmware updates, or free disk space

  • Slow download / installation → use reliable internet and keep plugged into power

  • Errors during install → run Disk Utility → First Aid on your drive

  • Post-install issues → update apps for Sequoia compatibility; some older apps may need patches.

[mai mult...]