Safety and scope
Power the servo from a supply able to handle its current peaks. Keep the linkage clear of fingers.
Plan, predict and test
Suggested virtual study time: about 25 minutes. This is a planning estimate, not a validated construction time.
Preparation: Foundation electricity and basic programming logic. Adult supervision for children. Review a foundation lesson ↗
Use paper, a spreadsheet or a simulator. This is not a verified physical assembly guide.
- Scenario: Assume a 20 cm approach threshold. Model OPEN, CLOSED and a blocked closing state.
- Expected result: A blocked closing mechanism stops or reopens in the model.
- Checkpoint: Write your prediction, test it in the virtual model and explain any difference.
A correct answer does not certify the physical system.
Record your validation
Use only virtual inputs and indicators until the actual components, pinouts and electrical limits have been verified.
| Case | What to record |
|---|---|
| Normal input | Near or blocked switch active → open indicator |
| Boundary | Both inactive for 2,999 ms → open; 3,000 ms → close |
| Missing or invalid input | Inputs are Boolean proxies, not calibrated distance/obstruction sensors. Servo force and anti-pinch safety are not implemented. |
| Repeat test | Repeat the virtual test, record the actual output and compare with the expected result. |
These are test-planning requirements, not recorded hardware results.
Before building: understand the listed components and the relevant low-voltage safety rules. This is a concept brief, not a tested assembly manual.
What it does
Create a practical first automation build that combines distance sensing, a timed action and mechanical movement.
Engineering principle
The HC-SR04 measures the distance to a nearby object. When that measurement is below a configured threshold (for example, around 15 cm), the controller commands a servo to open the lid. After the hand moves away and a short hold time expires, the servo returns the lid to its closed position.
Hardware and components
- Arduino Uno or NanoReads the distance and manages the lid timing.
- HC-SR04 ultrasonic sensorDetects a hand within the chosen approach range.
- SG90 servo motorMoves the hinge or linkage through its open and closed angles.
- Buzzer and LED (optional)Provide an audible or visual response.
- 5 V supply, bin and linkageProvide stable servo power and a mechanical attachment.
Suggested build sequence
- Mount the sensor facing the approach area and measure its actual detection range.
- Attach the servo horn to a light lid linkage without forcing the servo at its end stops.
- Open the lid when the distance is under the threshold.
- Keep it open while the hand remains nearby, then close after a 3–5 second delay.
- Test repeated approaches and add an invalid-reading timeout.
Learning outcomes
- Ultrasonic proximity detection
- Servo angle control
- Timers and simple state logic
- Mechanical linkage design
Possible upgrades
Add a fill-level sensor, OLED status, battery power, sleep mode or a full-bin notification.
Practice the core principle
Use a virtual Arduino Uno circuit with the following substitute inputs and indicators. The exercise deliberately does not drive motors, powered mechanisms or real industrial equipment. Physical experimentation requires adult supervision for children, a suitable current-limited supply and checked wiring.
Reference components
- Arduino Uno (5 V)
- 2 pushbuttons
- LED with 330 Ω resistor
Connection plan
- D2 → simulated approach button → GND
- D3 → simulated obstruction button → GND
- D8 → 330 Ω → open-lid LED → GND
Reference sketch
unsigned long lastSeen=0;
bool open=false;
void setup(){
pinMode(2,INPUT_PULLUP); pinMode(3,INPUT_PULLUP);
pinMode(8,OUTPUT);
}
void loop(){
bool near=digitalRead(2)==LOW;
bool blocked=digitalRead(3)==LOW;
if(near||blocked){open=true; lastSeen=millis();}
else if(open && millis()-lastSeen>=3000) open=false;
digitalWrite(8,open); delay(20);
}How the code works
An LED represents the open state. When either input is active, the model opens and resets its timer. It closes only three seconds after both inputs clear.
Practice sequence
- Set up the virtual components with power disconnected in the simulator.
- Verify pin numbers and LED polarity before running the sketch.
- Run and record the expected inputs and outputs.
- Test the boundary cases described below.
Expected result and testing
Press and release approach; check the LED stays on for roughly 3 seconds. Hold obstruction and verify it remains on. This model does not drive a lid or provide safety-rated obstruction protection.
Troubleshooting
Check the specified pin assignments, supply and common ground, indicator polarity and serial monitor baud rate where applicable. If an input seems fixed, isolate that input and observe its value before changing the control logic.
Independent challenge
Change one model threshold or timing value, predict the resulting behaviour, and repeat the test. Explain the difference without adding physical actuators.