Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 2843|回復: 2
打印 上一主題 下一主題

關於幫浦和繼電器

[複製鏈接]
跳轉到指定樓層
1#
發表於 2014-5-15 15:37:40 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 duop8600 於 2014-5-15 17:22 編輯

#include <LiquidCrystal.h>   
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  

#include <dht11.h>
dht11 DHT11;  
#define DHT11PIN 7  
const int readdht11 = 7;               

const int relayPin = 13;                 
int relayState = 0;                     


int val=0;
int b=0;

void switchRelay()
{
  if ( relayState = 0)                        
    relayState = 1;                     
  else
    relayState = 0;                          
  digitalWrite(relayPin, relayState);   
  Serial.print("Relay status: ");        
  Serial.println(relayState);

}

//判斷土壤sender
void anal()
{
  if(b< 500)
  {
    digitalWrite(relayPin, LOW);

      return;
  }
  else
  {
    digitalWrite(relayPin, HIGH);
     return;
  }
}

void setup(){
  lcd.begin(16, 2);  
  Serial.begin(9600);
  pinMode(readdht11, INPUT);   
  pinMode(relayPin, OUTPUT);            
}

void loop(){

  val=analogRead(A4);
  Serial.print("Moisture Sensor Value:");
  Serial.println(analogRead(4));

  delay(100);
  lcd.setCursor(0, 0);
  lcd.print("mois:");
  lcd.print(val);
  int chk = DHT11.read(DHT11PIN);   
  switch (chk) {     
  case 0:
    lcd.setCursor(0,1);
    lcd.print("H:");      
    lcd.print((float)DHT11.humidity, 1);      
    lcd.print("%");      
    lcd.setCursor(8,1);      
    lcd.print("T:");      
    lcd.print((float)DHT11.temperature, 1);      
    lcd.print("oC");           
    break;     
  }  
  b=val;

  anal();
}


電路是網站修改的http://coopermaa2nd.blogspot.tw/2011/03/lab21-12v.html


紅外線/按鈕 改成溫濕度感測器DHT11
風扇方面換成抽水幫浦RS360SH 一樣外掛電源上去5V/2A的電供
另外由類比腳位A4多接出 土壤感測器


程式方面是濕度小於500 抽水幫浦打開
但問題來了 幫浦沒電源時純粹讓繼電器動作 幫浦接上電源時候,LCD卻出現亂碼


不知道是不是程式問題 還是硬體方面有問題?
麻煩各位大大了
os:windows 7 64bit
arduino uno r3
軟體0022
2#
發表於 2014-5-17 02:44:48 | 只看該作者
本帖最後由 vegewell 於 2014-5-17 02:51 編輯

回復 1# duop8600

我是不曉得你 所有硬體是怎麼接法?
基本上,LCD出現亂碼,電力不足是原因之一,
另外,現在是 Arduino 1.0.5
你怎麼還是0022?
建議你買I2C LCD 可以減少腳位的使用,而且接線也比較簡單。
另外,程式可以加如下:
if(b< 500)
  {
    digitalWrite(relayPin, LOW);
    delay(10000);
      return;
  }
  else
  {
    digitalWrite(relayPin, HIGH);
  delay(10000);
     return;
  }
}

至少讓抽水幫浦轉個十秒吧,
免得繼電器在500附近跳來跳去,
3#
 樓主| 發表於 2014-5-18 18:34:56 | 只看該作者
回復 2# vegewell
0022是當初買版子附贈的版本
剛才也改用您講的1.0.5

之前用的LCD是LMC-S2A16忘了有這個錯誤訊息
avrdude stk500_getsync not in sync resp 0x00avrdude stk500_disable protocol error expect 0x14 resp 0x51
改用I2C LCD 就沒亂碼了 我在觀察看看好了
感謝您的回覆
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-9-30 15:30 , Processed in 0.217069 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表