我们不仅销售产品,我们还传播知识
商品分类

arduino 小花的饮料机源代码

1.湿度控制模块相关代码
//----------通过D0的值来控制Arduino引脚3,4,5置高电平来打开电磁阀-----------
  int a = analogRead(Moisture0);
  int b = analogRead(Moisture1);
  int c = analogRead(Moisture2);
  float d = 100*(1023-a)/1023;
  float e = 100*(1023-b)/1023;
  float f = 100*(1023-c)/1023; //计算湿度的百分比
  if(d<=50||(float)DHT11.humidity<=20.00||(float)DHT11.temperature>=30.00){
digitalWrite(5,HIGH);
//当土壤湿度或空气温湿度达到临界值将继电器置高电位打开电磁阀,以下同理
  }
  else digitalWrite(5,LOW);
  if(e<=50||(float)DHT11.humidity<=20.00||(float)DHT11.temperature>=30.00){
    digitalWrite(4,HIGH);
  }
  else digitalWrite(4,LOW);
  if(f<=50||(float)DHT11.humidity<=20.00||(float)DHT11.temperature>=30.00){
    digitalWrite(3,HIGH);
  }
  else digitalWrite(3,LOW);

  2.红外遥控模块
  3.LCD显示模块相关代码
 //-----------------各种定义的字符----------------------------------
uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clockl[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = {0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
lcd.init();     // 初始化LCD
  lcd.backlight();
  lcd.createChar(0, bell);//创建字符
  lcd.createChar(1, note);
  lcd.createChar(2, clockl);
  lcd.createChar(3, heart);
  lcd.createChar(4, duck);
  lcd.createChar(5, check);
  lcd.createChar(6, cross);
  lcd.createChar(7, retarrow);
  lcd.home();
//-------------------------LCD液晶屏显示------------------------
  lcd.init();           
  lcd.backlight();
  //------------------------显示各种字符---------------------------
  lcd.print("Hello world...");
  lcd.setCursor(0, 1);
  lcd.print(" I ");
  lcd.printByte(3);
  lcd.print(" Arduinos!");
  delay(5000);
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("Many types");
// ---------------显示创建的七个字符----------------------
  lcd.setCursor(0,1);
  lcd.printByte(0);
  lcd.print("");
  lcd.printByte(1);
  lcd.print("");
  lcd.printByte(2);
  lcd.print("");
  lcd.printByte(3);
  lcd.print("");
  lcd.printByte(4);
  lcd.print("");
  lcd.printByte(5);
  lcd.print("");
  lcd.printByte(6);
  lcd.print("");
  lcd.printByte(7);
  lcd.print("");
  delay(5000);
  //----------------------显示温湿度到液晶屏-------------------------
  lcd.clear();
  lcd.print("Tep: ");
  lcd.print((float)DHT11.temperature, 2);
  lcd.print("C");
  lcd.setCursor(13,0);
  lcd.printByte(3);
  lcd.setCursor(0, 1);
  lcd.print("Hum: ");
  lcd.print((float)DHT11.humidity, 2);
  lcd.print("%");
  lcd.setCursor(13,1);
  lcd.printByte(3);
  delay(5000);
  lcd.clear();
  lcd.print("A:");
  lcd.print(d);
  lcd.print("%");
  lcd.print(" B:");
  lcd.print(e);
  lcd.print("%");
  lcd.setCursor(0,1);
  lcd.print("C:");
  lcd.print(f);
  lcd.print("% ");
  lcd.printByte(0);
  lcd.print("haha..");
  delay(5000);
  lcd.clear();
  lcd.print("I ");
  lcd.printByte(3);
  lcd.print(" Arduino! ");
  lcd.printByte(7);
  lcd.setCursor(4,1);
  lcd.printByte(3);
  lcd.print("");
  lcd.printByte(2);
  lcd.print("");
  lcd.printByte(3);
  lcd.print("");
  delay(5000);
  4.继电器与电磁阀控制模块相关代码
int a = analogRead(Moisture0);
  int b = analogRead(Moisture1);
  int c = analogRead(Moisture2);
  float d = 100*(1023-a)/1023;
  float e = 100*(1023-b)/1023;
  float f = 100*(1023-c)/1023; //计算湿度的百分比
  if(d<=50||(float)DHT11.humidity<=20.00||(float)DHT11.temperature>=30.00){
digitalWrite(5,HIGH);
//当土壤湿度或空气温湿度达到临界值将继电器置高电位打开电磁阀,以下同理
  }
  else digitalWrite(5,LOW);
  if(e<=50||(float)DHT11.humidity<=20.00||(float)DHT11.temperature>=30.00){
    digitalWrite(4,HIGH);
  }
  else digitalWrite(4,LOW);
  if(f<=50||(float)DHT11.humidity<=20.00||(float)DHT11.temperature>=30.00){
    digitalWrite(3,HIGH);
  }
  else digitalWrite(3,LOW);
  5.温湿度传感器模块相关代码
//-----------------------DTH11---------------------------------------
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
  int chk = DHT11.read(DHT11PIN);
  Serial.print("Read sensor: ");
  switch (chk)  //Dht11的异常处理部分
  {
    case DHTLIB_OK: 
                Serial.println("OK"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.println("Checksum error"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.println("Time out error"); 
                break;
    default: 
                Serial.println("Unknown error"); 
                break;
  }
 //-------将空气中的湿度温度等数据量显示到串口监视器--------------------
  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);
  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);
  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);
  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);
  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

发表评论

登录后才能评论
联系我们

联系我们

微信:13823392571

在线咨询:点击这里给我发消息

工作时间:周一至周五,9:30-18:30,节假日休息

微信客服
微信客服
分享本页
返回顶部