Step1: Cardboard Cutout Demo
Create a cardboard demo cupboard. Here we have taken cardboard and created a box with a cover as "door".
We are going to control the opening & closing of the door using an ultrasonic Sensor. The door will open automatically when we bring our hands close to the sensor.
Step 2: Circuit Connection

the components used are an ultrasonic sensor, servo motor, and arduino.
Step3 Assembly

So this project is a smart cupboard in which the servo motor is attached with an ultrasonic sense on the top of the cupboard such that when an object such as a human comes close to the ultrasonic sensor, it generates signals and sends them to the servo motor to rotate by angle of 90° such that the door of the cupboard gets open.
when an object such as a human moves behind that is it gets out of the range of the ultrasonic sensor then the signals are now stopped being generated and the motor again rotates by 90°so that the door closes. so the initial position of the servo motor was 90°, on coming close it became zero degrees then on moving far, it became 90°. this is a sample model just for demonstration purposes and the supply to our Arduino is provided through the lead. the other means of supply can also be used.
Step4: Code
#include <Servo.h>
Servo my1;
int trigPin=11;
int echoPin= 9;
long duration, cm, inches;
void setup()
{
my1.attach(8);
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
}
void loop()
{
digitalWrite(trigPin,LOW);
delayMicroseconds(1);
digitalWrite(trigPin,HIGH);
delayMicroseconds(1);
digitalWrite(trigPin,LOW);
pinMode(echoPin,INPUT);
duration=pulseIn(echoPin,HIGH);
cm=(duration/2)/29.1;
inches=(duration/2)/74;
Serial.print(inches);
Serial.print("in");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(1000);
my1.write(0);
if (cm<20){
my1.write(90);
}
if (cm>20){
my1.write(0);
}
}