春天来了,别忘给爱花浇水
写这个项目主要是因为之前用的带比较器那种土壤传感工作不稳。想试下更好用的土壤传感。用它来照顾爱花。https://v.youku.com/v_show/id_XNDU5Njc3MzQ5Mg==.html?spm=a2hzp.8244740.0.0、、
硬件清单
arduino pro mini
土壤传感
RGB led
蜂鸣器
===========================================
连线图
/*This sketch is created by gada888*/
const int soil = A0;
int moistVal = 0;
int RLed = 2;
int GLed = 3;
int BLed = 4;
int piezoPin = 8;
int pitches[] = {523, 587, 659, 698, 784};
int numPitches = 5;
void setup(){
pinMode(soil, INPUT);
Serial.begin(9600);
pinMode(RLed, OUTPUT);
pinMode(GLed, OUTPUT);
pinMode(BLed, OUTPUT);
}
void loop(){
int percent = 2.718282 * 2.718282 * (.008985 * moistVal + 0.207762);
moistVal = analogRead(soil);
Serial.println(moistVal);
Serial.print(percent);
Serial.println("% Moisture ");
if(moistVal>600&&moistVal<900){
Serial.println("i feel good");
digitalWrite(RLed, LOW);
digitalWrite(BLed, LOW);
digitalWrite(GLed, HIGH); //Green LED
int i;
for( i=0; i<numPitches; i++){
tone(piezoPin, pitches, 200);
delay(200);
}
if(moistVal>700){
Serial.println("too much water");
digitalWrite(RLed, LOW);
digitalWrite(BLed, HIGH); //Blue LED
digitalWrite(GLed, LOW);
}
}
delay(2000);
}
项目运行后,RGB led会显示白色,在把土壤传感探针浸入水中后,RGB会变蓝色,之后蜂鸣器会鸣叫5个不同的频率值。作为对浇水太多的报警。
如果想反向操作,例如缺水的报警,就改这一行if(moistVal>600&&moistVal<900){,例如改成if(moistVal<600){
而RGB led颜色的改动,可以改digitalWrite语句,例如digitalWrite(BLed, HIGH);改成digitalWrite(BLed, LOW);
供电用的5v电源。5v+连的是arduino mini 的raw脚。
为毛这么好贴没人回复
页:
[1]