功能:指纹开门,射频遥控开门
硬件:AT301指纹模块,arduino-nano,射频模块,电磁锁,IIC屏幕, 贴片(mos管,电阻,电容,稳压管…)
代码如下:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
void(* resetFunc) (void) = 0;
unsigned char Re_buf[16],counter=0;
unsigned char sign=0;
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
static const uint8_t PROGMEM Qin_16x16[] = {
0x00,0x40,0x40,0x40,0x27,0xFC,0x20,0x40,0x03,0xF8,0x00,0x40,0xE7,0xFE,0x20,0x00,
0x23,0xF8,0x22,0x08,0x23,0xF8,0x22,0x08,0x2B,0xF8,0x32,0x08,0x22,0x28,0x02,0x10
};
static const uint8_t PROGMEM An_16x16[] = {
0x10,0x40,0x10,0x20,0x10,0x20,0x13,0xFE,0xFA,0x02,0x14,0x44,0x10,0x40,0x1B,0xFE,
0x30,0x88,0xD0,0x88,0x11,0x08,0x10,0xD0,0x10,0x20,0x10,0x50,0x50,0x88,0x23,0x04
};
static const uint8_t PROGMEM Zhi_16x16[] = {
0x11,0x00,0x11,0x04,0x11,0x38,0x11,0xC0,0xFD,0x02,0x11,0x02,0x10,0xFE,0x14,0x00,
0x19,0xFC,0x31,0x04,0xD1,0x04,0x11,0xFC,0x11,0x04,0x11,0x04,0x51,0xFC,0x21,0x04
};
static const uint8_t PROGMEM Wen_16x16[] = {
0x10,0x80,0x10,0x40,0x20,0x40,0x27,0xFC,0x49,0x10,0xF1,0x10,0x11,0x10,0x21,0x10,
0x41,0x10,0xF8,0xA0,0x40,0xA0,0x00,0x40,0x18,0xA0,0xE1,0x10,0x42,0x08,0x0C,0x06
};
static const uint8_t PROGMEM Jin_16x16[] = {
0x00,0x90,0x20,0x90,0x10,0x90,0x13,0xFC,0x00,0x90,0x00,0x90,0xF0,0x90,0x17,0xFE,
0x10,0x90,0x10,0x90,0x11,0x10,0x11,0x10,0x12,0x10,0x28,0x00,0x47,0xFE,0x00,0x00
};
static const uint8_t PROGMEM Suo0_16x16[] = {
0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x06,0x30,0x00,0x00,0x18,0x08,0x00,
0x00,0x20,0x04,0x00,0x00,0x20,0x04,0x00,0x00,0x20,0x04,0x00,0x00,0x20,0x04,0x00,
0x00,0x20,0x04,0x00,0x00,0x20,0x04,0x00,0x00,0x20,0x04,0x00,0x03,0xFF,0xFF,0x80,
0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,
0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,
0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,
0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,0x02,0x00,0x00,0x80,0x03,0xFF,0xFF,0x80,
0x00,0x00,0x00,0x00
};
static const uint8_t PROGMEM Suo1_16x16[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x0C,0x60,0x00,
0x00,0x30,0x10,0x00,0x00,0x40,0x08,0x00,0x00,0x40,0x08,0x00,0x00,0x40,0x00,0x00,
0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,
0x07,0xFF,0xFF,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,0x04,0x00,0x01,0x00,
0x07,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
void send()
{
Serial.write(0XEF);
Serial.write(0X01);
Serial.write(0XFF);
Serial.write(0XFF);
Serial.write(0XFF);
Serial.write(0XFF);
Serial.write(0X01);
Serial.write(0X00);
Serial.write(0X08);
Serial.write(0X32);
Serial.write(0X03);
Serial.write(0XFF);
Serial.write(0XFF);
Serial.write(0X01);
Serial.write(0X01);
Serial.write(0X02);
Serial.write(0X3E);
}
void serialEvent() {
while (Serial.available()) {
Re_buf[counter]=(unsigned char)Serial.read();
if(counter==0&&Re_buf[0]!=0xEF&&Re_buf[10]!=0x05) return;
counter++;
if(counter==17)
{
counter=0;
sign=1;
}
}
}
void closedisplay()
{
display.drawBitmap(15,5,Qin_16x16,16,16,WHITE);
display.display();
display.drawBitmap(40,5,An_16x16,16,16,WHITE);
display.display();
display.drawBitmap(65,5,Zhi_16x16,16,16,WHITE);
display.display();
display.drawBitmap(90,5,Wen_16x16,16,16,WHITE);
display.display();
display.drawBitmap(46,35,Suo0_16x16,32,32,WHITE);
display.display();
}
void opendisplay()
{
display.drawBitmap(45,5,Qin_16x16,16,16,WHITE);
display.display();
display.drawBitmap(65,5,Jin_16x16,16,16,WHITE);
display.display();
display.drawBitmap(46,35,Suo1_16x16,32,32,WHITE);
display.display();
}
void setup() {
Serial.begin(57600);
delay(100);
pinMode(4,INPUT);
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);
display.clearDisplay();
display.setTextSize(2);
}
void loop() {
closedisplay();
if(digitalRead(4)==HIGH)
{
tone(11,600,500);
digitalWrite(8,HIGH);
display.clearDisplay();
opendisplay();
delay(4000);
display.clearDisplay();
digitalWrite(8,LOW);
resetFunc();
}
send();
delay(1200);
if(sign){
if(Re_buf[0]==0xEF&&Re_buf[10]==0x05)
{
if(Re_buf[9]==0x00)
{
tone(11,532,200);
delay(200);
tone(11,659,200);
delay(200);
tone(11,1024,200);
delay(200);
digitalWrite(8,HIGH);
display.clearDisplay();
opendisplay();
delay(4000);
display.clearDisplay();
digitalWrite(8,LOW);
resetFunc();
}
else{
tone(11,600,300);
delay(200);
tone(11,1500,200);
display.clearDisplay();
display.setCursor(35,20);
display.println("Error!");
display.display();
delay(2000);
display.clearDisplay();
resetFunc();
}
}
}
}
然后用AD画个板子代替杜邦线连接
这里做了一个小电路设计 用mos管的通断来控制电磁锁,代替传统用继电器的方式
来看看上电的样子:
|