arduino舵机门锁 红外遥控控制 刷卡 diy

版权声明:转载请注明出处 https://blog.csdn.net/weixin_43233189/article/details/82937977

温湿度 检测 能够显示 i2c12864
详情https://g.alicdn.com/idleFish-F2e/app-basic/item.html?itemid=573263642630&ut_sk=1.WxEIBJ%252FiSUoDADyw2O%252FQUZqV_21407387_1538638809582.Copy.detail.573263642630.1977947810&forceFlush=1

一下代码部分
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
} //摄氏温度度转化为华氏温度

double Kelvin(double celsius)
{
return celsius + 273.15;
} //摄氏温度转化为开氏温度

// 露点(点在此温度时,空气饱和并产生露珠)
// 参考: [url=http://wahiduddin.net/calc/density_algorithms.htm]http://wahiduddin.net/calc/density_algorithms.htm[/url]
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}

// 快速计算露点,速度是5倍dewPoint()
// 参考: [url=http://en.wikipedia.org/wiki/Dew_point]http://en.wikipedia.org/wiki/Dew_point[/url]
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
#include <LiquidCrystal.h>
#include <RSCG12864B.h>
#include <RFID.h>
#include <SPI.h>
#include <Servo.h>
#include <IRremote.h>
#include <dht11.h>
dht11 DHT11;

#define DHT11PIN 2
Servo myservo;
int PIN_SENSOR = 4;
int d=5;
int m=(float)DHT11.temperature;
int RECV_PIN = 3;//红外接收输入

decode_results results;
IRrecv irrecv(RECV_PIN);
extern uint8_t SmallFont[];
RFID rfid(10,8); //D10–接上SDA、D8–接RST D13–接上SCK D11–接上MOSI D12–接上MISO RQ不接
unsigned char serNum[5];

void setup()
{
int chk = DHT11.read(DHT11PIN);
unsigned char j;
char chn[]={0xBB, 0xB6,0xD3, 0xAD,0xBB, 0xD8,0xC0, 0xB4 }; //欢迎回来

char f1[]={ 0xBF, 0xAA,0xC3, 0xC5,0xD6, 0xD0,0, }; //开门中
char f2[]={ 0xC7, 0xEB,0xC7, 0xC3, 0xC3, 0xC5,0,}; //请敲门
char f3[]={ 0xBE, 0xDC, 0xBE, 0xF8,0xB9, 0xE3,0xB8, 0xE6,0,}; //拒绝广告
char f4[]={0xCA, 0xD2,0xC4, 0xDA,0xCE, 0xC2,0xB6, 0xC8,0, }; //shinei温度
char f5[]={ 0xCA, 0xAA,0xB6, 0xC8 ,0,}; //湿度
char f6[]={ 0xC7, 0xEB, 0xCB, 0xA2, 0xBF, 0xA8,0, }; //请刷卡
char f7[]={ 0xA1, 0xE6,0, }; //℃
Serial.begin(9600);
Serial.begin(9600);//串口用来读取需要添加的卡号,然后手动写到程序里
RSCG12864B.begin();//串口初始化
RSCG12864B.brightness(255);//屏幕亮度
myservo.attach(9);//舵机针脚位9
myservo.write(0); //舵机初始化0度
SPI.begin();
rfid.init();
irrecv.enableIRIn(); // Start the receiver
pinMode(d,OUTPUT);
digitalWrite(d,HIGH);
pinMode(PIN_SENSOR, INPUT);

RSCG12864B.clear();
RSCG12864B.print_string_16_xy(30,0,f3);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(37,15,f2);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(37,30,f6);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(5,45,f4);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(103,45,f7);//坐标0,15,显示chn里的内容

RSCG12864B.font_revers_on();
 char text[5];

{
dtostrf(DHT11.temperature,5,2,text);//dtostrf函数很好用,可以将字符变成字符串显示。
RSCG12864B.print_string_12_xy(70,47,text);//定义字符串坐标。
}

  delay(1000); 

}

void loop()
{
int chk = DHT11.read(DHT11PIN);

unsigned charj;
char chn[]={0xBB, 0xB6,0xD3, 0xAD,0xBB, 0xD8,0xC0, 0xB4 ,0, }; //欢迎回来

char f1[]={ 0xBF, 0xAA,0xC3, 0xC5,0xD6, 0xD0 ,0, }; //开门中
char f2[]={ 0xC7, 0xEB,0xC7, 0xC3, 0xC3, 0xC5,0,}; //请敲门
char f3[]={ 0xBE, 0xDC, 0xBE, 0xF8,0xB9, 0xE3,0xB8, 0xE6,0,}; //拒绝广告
char f4[]={0xCA, 0xD2,0xC4, 0xDA,0xCE, 0xC2,0xB6, 0xC8,0, }; //shinei温度
char f5[]={ 0xCA, 0xAA,0xB6, 0xC8,0, }; //湿度
char f6[]={ 0xC7, 0xEB, 0xCB, 0xA2, 0xBF, 0xA8,0, }; //请刷卡
char f7[]={ 0xA1, 0xE6,0, }; //℃
char f8[]={ 0xC7, 0xEB,0xC1, 0xBD,0xC3, 0xEB, 0xC4, 0xDA, 0xCD, 0xC6,0xC3, 0xC5,0xBD, 0xF8 ,0, }; //请两秒内推门进
char f9[]={ 0xB3, 0xF4,
0xBF, 0xA8,
0xC4, 0xC3,
0xBF, 0xAA,
0xA3, 0xAC,
0xB2, 0xBB,
0xC8, 0xC3,
0xBD, 0xF8,0, }; //把你的臭卡拿开
digitalWrite(5,HIGH);

if (irrecv.decode(&results))

{
if (results.value == results.value)
{
Serial.println(results.value, HEX);
Serial.println(“2”);
myservo.write(180);
digitalWrite(6,HIGH);
RSCG12864B.clear();
RSCG12864B.print_string_16_xy(0,0,f8);//坐标0,15,显示chn里的内容
delay(3500);
RSCG12864B.clear();
RSCG12864B.print_string_16_xy(30,0,f3);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(37,15,f2);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(37,30,f6);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(5,45,f4);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(103,45,f7);//坐标0,15,显示chn里的内容
char text[5];
{
dtostrf(DHT11.temperature,5,2,text);//dtostrf函数很好用,可以将字符变成字符串显示。
RSCG12864B.print_string_12_xy(70,47,text);//定义字符串坐标。
}
digitalWrite(6,LOW);
myservo.write(0);
irrecv.resume();
}
delay(100);
irrecv.resume();

}/*
int x = digitalRead(PIN_SENSOR);
Serial.println(x);
if (x==0)
{ myservo.write(180);
digitalWrite(6,HIGH);
delay(3500);
digitalWrite(6,LOW);
myservo.write(0);
}*/
long randNumber = random(0, 20);
unsigned char i,tmp;
unsigned char status;
unsigned char str[MAX_LEN];
unsigned char RC_size;

//找卡
rfid.isCard();
//读卡号
if (rfid.readCardSerial())
{
Serial.print("your card id is : “);
Serial.print(rfid.serNum[0]);
Serial.print(” , “);
Serial.print(rfid.serNum[1],BIN);
Serial.print(” , “);
Serial.print(rfid.serNum[2],BIN);
Serial.print(” , “);
Serial.print(rfid.serNum[2],BIN);
Serial.print(” , “);
Serial.print(rfid.serNum[4],BIN);
Serial.println(” ");

//下面是改卡号区域
if(rfid.serNum[0]==1||rfid.serNum[0]==19||rfid.serNum[0]==195||rfid.serNum[0]==147||rfid.serNum[0]==99||rfid.serNum[0]==67||rfid.serNum[0]==179||rfid.serNum[0]==225){//第一道筛选

  {
     
    if(rfid.serNum[1]==2||rfid.serNum[1]==235||rfid.serNum[1]==152||rfid.serNum[1]==141||rfid.serNum[1]==12||rfid.serNum[1]==164||rfid.serNum[1]==113||rfid.serNum[1]==100)//第二道筛选,支持一人一号
    {
   if(rfid.serNum[2]==3||rfid.serNum[2]==139||rfid.serNum[2]==30||rfid.serNum[2]==29||rfid.serNum[2]==31||rfid.serNum[2]==109)
    {
       if(rfid.serNum[3]==3||rfid.serNum[3]==60||rfid.serNum[3]==63||rfid.serNum[3]==109)
 
      Serial.println("Welcome test 1"); 
      for(int i=0;i<100;i++ )
      myservo.write(180);
      digitalWrite(6,HIGH);  
    }
    if(rfid.serNum[0]==1||rfid.serNum[0]==19||rfid.serNum[0]==195||rfid.serNum[0]==147||rfid.serNum[0]==99||rfid.serNum[0]==67||rfid.serNum[0]==179||rfid.serNum[0]==225&&rfid.serNum[1]==2||rfid.serNum[1]==235||rfid.serNum[1]==100||rfid.serNum[1]==152||rfid.serNum[1]==141||rfid.serNum[1]==12||rfid.serNum[1]==164||rfid.serNum[1]==113&&rfid.serNum[2]==3||rfid.serNum[2]==139||rfid.serNum[2]==30||rfid.serNum[2]==29||rfid.serNum[2]==109||rfid.serNum[2]==31&&rfid.serNum[3]==3||rfid.serNum[3]==60||rfid.serNum[3]==109||rfid.serNum[3]==63)
    
    {

      Serial.println(DHT11.temperature);
      myservo.write(180); 
      digitalWrite(6,HIGH); 
      RSCG12864B.clear();
RSCG12864B.print_string_16_xy(15,15,chn);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(15,30,f1);//坐标0,15,显示chn里的内容
 delay(2500);
 myservo.write(0);
   digitalWrite(6,LOW);
  Serial.println("closed1");
    }
  }       
 else
 {
  myservo.write(0);
   digitalWrite(6,LOW);
  Serial.println("closed");
  RSCG12864B.clear();
  RSCG12864B.print_string_16_xy(0,0,f9);//坐标0,15,显示chn里的内容 

delay(2500);
}
irrecv.resume();
RSCG12864B.clear();
RSCG12864B.print_string_16_xy(30,0,f3);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(37,15,f2);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(37,30,f6);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(5,45,f4);//坐标0,15,显示chn里的内容
RSCG12864B.print_string_16_xy(103,45,f7);//坐标0,15,显示chn里的内容

RSCG12864B.font_revers_on();
 char text[5];

{
dtostrf(DHT11.temperature,5,2,text);//dtostrf函数很好用,可以将字符变成字符串显示。
RSCG12864B.print_string_12_xy(70,47,text);//定义字符串坐标。
}

  }
}

}

if (!rfid.readCardSerial())
rfid.halt(); //休眠
}

猜你喜欢

转载自blog.csdn.net/weixin_43233189/article/details/82937977
今日推荐