設計一個報警保護架
我有很多魔方。有些很大;有些很小;有些花費了一大筆錢。兩年前,我的弟弟把我的一個立方體扔在地上,毀了它,從那以后,我花了90美元升級了安全設備,以防止這種情況再次發(fā)生。但即使他沒有破壞我的立方體,他也會在我展示的時候破壞它們。我只想在不被觸摸的情況下顯示立方體。所以,我花了一個月的時間做了這個架子,每當你從架子上拿走東西時,它就會發(fā)出警報。
材料:
?頻閃燈+壓電蜂鳴器
?Arduino Uno
?4x測壓元件+ HX711
?I2C液晶
?4 x4鍵盤
?電線、面包板和晶體管
?22x 12V電源
如果您正在設計自己的框架,可選
?框架部分
?螺釘和螺紋鑲件
框架
我用tinkercad設計了框架,然后把文件發(fā)給Justway制作。
Justway是一家經(jīng)濟實惠的在線制造服務公司,提供3d打印、數(shù)控加工和鈑金成型等服務。要在Justway下訂單,請單擊此鏈接打開菜單頁面。選擇您正在使用的服務,然后單擊上傳您的設計。
這將把你帶到這個頁面,在那里你可以上傳你的設計,選擇你的材料,顏色和其他特殊要求。一旦所有的選擇都做出了,提交你的請求并等待它被批準。一旦批準,支付訂單并等待零件到達。
當我第一次使用Justway 3d打印零件時,我收到了一封關于我的一個模型設計缺陷的訂單后不久的電子郵件。制作團隊問我是想繼續(xù)我的原始設計還是修改他們創(chuàng)造的版本。我選擇了最初的設計,因為這不是一個主要問題。
當我打開這些零件的盒子時,我不僅對零件的質(zhì)量和尺寸精度感到驚訝,而且我還收到了可能是為了防止運輸損壞而額外訂購的批量訂單。
這是一張所有電線連接的圖表。這有點讓人不知所措,所以讓我們來分解一下。
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
?電源的地漏
?光源到閃光燈的負極
?電源電源到頻閃燈電源的功率
代碼
我在這個項目中包含了示例代碼。請注意,校準系數(shù)是我的測壓元件。您必須使用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