设计一个报警保护架
扫描二维码
随时随地手机看文章
我有很多魔方。有些很大;有些很小;有些花费了一大笔钱。两年前,我的弟弟把我的一个立方体扔在地上,毁了它,从那以后,我花了90美元升级了安全设备,以防止这种情况再次发生。但即使他没有破坏我的立方体,他也会在我展示的时候破坏它们。我只想在不被触摸的情况下显示立方体。所以,我花了一个月的时间做了这个架子,每当你从架子上拿走东西时,它就会发出警报。
材料:
•频闪灯+压电蜂鸣器
•Arduino Uno
•4x测压元件+ HX711
•I2C液晶
•4 x4键盘
•电线、面包板和晶体管
•22x 12V电源
如果您正在设计自己的框架,可选
•框架部分
•螺钉和螺纹镶件
框架
我用tinkercad设计了框架,然后把文件发给Justway制作。
Justway是一家经济实惠的在线制造服务公司,提供3d打印、数控加工和钣金成型等服务。要在Justway下订单,请单击此链接打开菜单页面。选择您正在使用的服务,然后单击上传您的设计。
这将把你带到这个页面,在那里你可以上传你的设计,选择你的材料,颜色和其他特殊要求。一旦所有的选择都做出了,提交你的请求并等待它被批准。一旦批准,支付订单并等待零件到达。
当我第一次使用Justway 3d打印零件时,我收到了一封关于我的一个模型设计缺陷的订单后不久的电子邮件。制作团队问我是想继续我的原始设计还是修改他们创造的版本。我选择了最初的设计,因为这不是一个主要问题。
当我打开这些零件的盒子时,我不仅对零件的质量和尺寸精度感到惊讶,而且我还收到了可能是为了防止运输损坏而额外订购的批量订单。
这是一张所有电线连接的图表。这有点让人不知所措,所以让我们来分解一下。
KeypadandLCD
使用I2C LCD,连接如下所示的端口,如图所示
•VCC到5V(理想情况下通过面包板)
•GND到GND(理想情况下通过面包板)
•SDA到A4
•SCL到A5
使用4x4键盘,连接端口如下所示,并在图中显示
•第1至第5行
•第二至第四行
•第三排至第三排
•第4行至第2行
•第1至第9栏
•第2至8栏
•第3至7栏
•第4至6栏
LoadCells
Tinkercad电路没有HX711,所以我在图中使用了面包板。
使用四个测压元件和一个HX711,连接如下图所示的端口
•在架子的角落放置四个测压元件
•连接相邻的黑白线
•将两根相对的(对角线)红色电线连接到A+和A-
•将另外两根相对的(对角线)红色电线连接到E+和E-
•不要把b +和b -连起来
•VCC到5V
•地到地
•DT到12
•SCK至11
将压电的+连接到引脚13,将-连接到GND
通过一个mosfet晶体管连接12V电源到频闪灯
•Gate to 10
•电源的地漏
•光源到闪光灯的负极
•电源电源到频闪灯电源的功率
代码
我在这个项目中包含了示例代码。请注意,校准系数是我的测压元件。您必须使用HX711_ADC库中的校准示例自己校准。
代码
#include
#include
#include
//include libraries needed
#define calibration_factor -22233.33
#define LOADCELL_DOUT_PIN 12
#define LOADCELL_SCK_PIN 11
int alarmPin = 10;
int buzzerPin = 13;
//define pins used
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte colPins[ROWS] = {9, 8, 7, 6};
byte rowPins[COLS] = {5, 4, 3, 2};
//define keypad
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
HX711_ADC scale(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
//initialize keypad, lcd, and load cells
char resetKey = '*';
String code = "1234#";
String input = "";
bool alarmActive = false;
float oldWeight;
int timeOff = 60;
//changable values
void setup() {
Serial.begin(9600);
scale.begin();
scale.start(2000);
scale.setCalFactor(calibration_factor);
scale.tare();
//initialize scale
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SECURITY ON");
//initialize LCD
oldWeight = scale.getData();
//define initial weight
pinMode(buzzerPin, OUTPUT);
//initialize buzzer
}
void loop() {
scale.update();
char customKey = customKeypad.getKey();
//check for key presses
if (customKey) {
Serial.println(customKey);
if (customKey == resetKey) {
input = "";
lcd.clear();
//clear input if reset key pressed
}else {
input += customKey;
//add key press to input
}
lcd.setCursor(0, 1);
lcd.print(input);
}
if(input==code){
stopAlarm();
disableSecurity();
input = "";
//disable security if correct code entered
}
if (fabs(scale.getData() - oldWeight) > 0.2 && !alarmActive) {
soundAlarm();
//activate alarm if abnormal weight
}
}
void soundAlarm() {
alarmActive = true;
digitalWrite(alarmPin, HIGH);
tone(buzzerPin, 1200);
//activate strobe light and buzzer
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ALARM ACTIVE");
lcd.setCursor(0, 1);
lcd.print(input);
//print alarm active on lcd
}
void stopAlarm(){
noTone(buzzerPin);
alarmActive = false;
digitalWrite(alarmPin, LOW);
//turn off strobe light and buzzer
}
void disableSecurity() {
if (input == code) {
for (int i = timeOff; i > 0; i--) {
//if code is correct
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SECURITY OFF FOR");
lcd.setCursor(0, 1);
lcd.print(String(i) + " SECONDS");
delay(1000);
scale.update();
oldWeight = scale.getData();
//disable security and show countdown on LCD
}
scale.update();
oldWeight = scale.getData();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SECURITY ON");
//change oldWeight to after
}
}
本文编译自hackster.io