This museum anti-theft security system uses weight sensing and servo-controlled barriers to protect valuable artifacts on display. Built around an ESP32 microcontroller, the system monitors a load cell to detect when an object is removed from its case, triggers visual and audible alarms, and activates servo-driven locking mechanisms to prevent unauthorized removal.
The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions for integrating the weight sensor, alarm indicators, push-button controls, and servo actuators. Firmware is included to handle the system's three operational states: commissioning, armed monitoring, and active alarm response.
Wiring diagram
Gather all the parts
Assemble it in 4 steps
1. Separate the two supplies
With all power off, use USB for the NodeMCU and a regulated 5 V 3 A adapter with a suitable wire-output breakout for the actuator rail. Join the grounds, not the positive rails. Run the servo power and ground wires directly to the adapter distribution point. Put C3 across the servo feed, minus to ground.
2. Wire the indicators and switches
Place U2 across the breadboard gap. On its DIP package VDD is pin 9, VSS 10, SCL 12, SDA 13, A0–A2 pins 15–17, RESET 18, and GPA0–GPA6 pins 21–27. Fit C1 beside pins 9 and 10. Connect the LEDs through their individual resistors, short legs to ground. Fit the reed magnet so the contacts close when the case is shut. Place the reset button on the staff side of the model.
3. Mount the weighing platform
Bolt one end of the load cell to a rigid base and the other to the artifact platform with spacers. Leave the bending section clear. Match bridge leads by their terminal names, not by insulation colour. Use a 3.3 V capable HX711 board with single VCC input.
4. Wire the sounder and model servos
Check the PN2222A lead order against its datasheet. Mount C2 near U4 power pins. Check servo connector polarity before applying 5 V. Test the horns unloaded, then fit M1 to the miniature case latch and M2 to a model exit indicator flag only.
- Do not connect this circuit to any occupied room exit. Keep fingers clear of moving horns.
Review all connections
1. Connections between "PS1" and "ESP32"
2. Connections between "U2" and "ESP32"
3. Connections between "R1" and "ESP32"
4. Connections between "R2" and "ESP32"
5. Connections between "D1" and "ESP32"
6. Connections between "R3" and "ESP32"
7. Connections between "D2" and "ESP32"
8. Connections between "R4" and "ESP32"
9. Connections between "D3" and "ESP32"
10. Connections between "R5" and "ESP32"
11. Connections between "D4" and "ESP32"
12. Connections between "R6" and "ESP32"
13. Connections between "SW1" and "ESP32"
14. Connections between "SW2" and "ESP32"
15. Connections between "R7" and "ESP32"
16. Connections between "R8" and "ESP32"
17. Connections between "U3" and "ESP32"
18. Connections between "LC1" and "ESP32"
19. Connections between "U4" and "ESP32"
20. Connections between "M1" and "ESP32"
21. Connections between "M2" and "ESP32"
22. Connections between "R9" and "ESP32"
23. Connections between "R10" and "ESP32"
24. Connections between "Q1" and "ESP32"
25. Connections between "R11" and "ESP32"
26. Connections between "R12" and "ESP32"
27. Connections between "BZ1" and "ESP32"
28. Connections between "C1" and "ESP32"
29. Connections between "C2" and "ESP32"
30. Connections between "C3" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <Servo.h>
#include <HX711.h>
HX711 scale;
Servo displayCase, exitFlag;
constexpr uint8_t address=0x20;
bool wr(uint8_t reg,uint8_t value){Wire.beginTransmission(address);Wire.write(reg);Wire.write(value);return Wire.endTransmission()==0;}
int ports(){Wire.beginTransmission(address);Wire.write(0x12);if(Wire.endTransmission(false)||Wire.requestFrom(address,uint8_t(1))!=1)return -1;return Wire.read();}
enum State {Commission, Armed, Alarm};
State state=Commission;
uint32_t lastSample, opened, held, lastOutput;
long baseline; int misses; bool released;
// Set from the serial readings: threshold should exceed idle drift but be
// comfortably smaller than the raw change measured when lifting the artifact.
constexpr long threshold=50000;
void enter(State s){state=s;held=opened=0;released=false;misses=0;
displayCase.write(s==Alarm?75:20); exitFlag.write(s==Alarm?75:20);
wr(0x14,s==Alarm?0x1f:s==Armed?1:0);
Serial.println(s==Alarm?"ALARM":s==Armed?"ARMED":"COMMISSION: close case with artifact fitted and hold reset");}
void setup(){Serial.begin(115200);Wire.begin(4,5);Wire.setClock(100000);
wr(0x14,0);wr(0x00,0xe0);scale.begin(12,14);lastSample=millis();
displayCase.attach(13,1000,2000);exitFlag.attach(16,1000,2000);enter(Commission);}
void loop(){uint32_t now=millis();int io=ports();bool closed=io>=0&&!(io&0x20), pressed=io>=0&&!(io&0x40);
static long sample=0;static bool sampled=false;
if(scale.is_ready()){sample=scale.read();lastSample=now;sampled=true;
if(now-lastOutput>=500){lastOutput=now;Serial.printf("Raw %ld; baseline %ld\n",sample,baseline);}
if(state==Armed){if(labs(sample-baseline)>threshold){if(++misses>=2)enter(Alarm);}else misses=0;}}
bool fresh=sampled&&now-lastSample<800;
if(state==Armed){if(closed)opened=0;else if(!opened)opened=now;
if(!fresh||(opened&&now-opened>=50))enter(Alarm);}
if(state==Alarm)wr(0x14,0x1f);
if(!pressed){held=0;released=io>=0;}
if(state!=Armed&&released&&pressed&&closed&&fresh&&(state==Commission||labs(sample-baseline)<threshold/2)){
if(!held)held=now;else if(now-held>=1500){if(state==Commission)baseline=sample;enter(Armed);}
}else held=0;
delay(5);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




