Home and IoTA Code Lock with a Keypad
Type the secret code and press #: with the right code the green light comes on and a servo slides the bolt open, with the wrong one the buzzer beeps three times.
Home and IoTA DHT11 sensor measures the temperature and humidity, and a 16×2 display shows both, updating every two seconds.
Written by the RoboHub team. A question? Write to us.
Choose a variation and the parts list updates.
In the Library Manager, install “DHT sensor library” (Adafruit) and “LiquidCrystal I2C” (Frank de Brabander). When the IDE offers extra libraries, choose “Install all”.
The I2C display has four pins: GND to ground, VCC to 5V, and SDA and SCL to the board's SDA and SCL pins. On the Uno they sit next to AREF (A4 and A5 are the same), on the Mega they are pins 20 and 21.
Connect the DHT11 module's “+” to 5V, “−” to ground and OUT (or DATA) to pin 2. The board has one 5V pin, so feed the display and the sensor from one breadboard rail. If your sensor has four legs and no little board, put a 10 kΩ resistor between DATA and 5V.
If you have a DHT22, change DHT11 to DHT22 in the code. If the screen lights up but shows no text, turn the blue knob on the back (contrast). If nothing shows at all, try address 0x3F instead of 0x27. On the Uno R4 the IDE warns that LiquidCrystal I2C was written for AVR: the warning does no harm.

Illustration, made with AI
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
DHT dht(2, DHT11); // a DHT22? write DHT22 here
LiquidCrystal_I2C lcd(0x27, 16, 2); // some displays use 0x3F
void setup() {
dht.begin();
lcd.init();
lcd.backlight();
}
void loop() {
float t = dht.readTemperature(); // °C
float h = dht.readHumidity(); // %
lcd.clear();
if (isnan(t) || isnan(h)) {
lcd.print("Sensor error");
} else {
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t, 1);
lcd.print((char)223); // the degree sign on these displays
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(h, 0);
lcd.print("%");
}
delay(2000); // a DHT11 can be read at most once a second
}Illustration: on a bookshelf an LCD shows temperature and humidity, with a DHT11 sensor and the board beside it.
Step 4: Upload the code
Home and IoTType the secret code and press #: with the right code the green light comes on and a servo slides the bolt open, with the wrong one the buzzer beeps three times.
SensorsAn ultrasonic sensor measures the distance. Three LEDs show how close the obstacle is, and the buzzer beeps faster the closer you get.
GamesAn LED lights at a random moment. Whoever presses their button first wins. Built from Student Kit parts in 45 minutes.