攏(龍)來防疫-超音波酒精噴霧器
緣起
疫情期間,酒精噴霧器的製作專題很夯,用現成套件的當然方便,但是想著:能否利用一些閒置或棄置的材料製作,不但刺激孩子動腦,應該也更能養成孩子們愛物惜物的習慣!
基本構想
超音波感測器→觸動電源→噴霧
材料
電源供應器→從不用的舊電腦上拆下來的
arduino uno 一片
噴霧裝置:
水幫浦:汽車雨刷噴水幫浦(到廢車回收廠,請好心的老闆送的)
噴頭:我們找了幾款酒精噴務的噴頭,發現:學校用的這一款,噴霧細,單次的噴霧量也很恰當!
酒精容器:直接使用市售大容量酒精的桶子,在下方鑽洞後接出硬管.
塑膠接管:用以簡單連接酒精瓶與幫浦
繼電器:因為是要用來控制水幫浦的運作,而汽車雨刷水幫浦的供電是12V,所以要用匹配的規格
杜邦線:若干
麵包板:一片
IDE的程式碼(附件spray.ino)
=======================================================
// Use the HC-SR04 to detect movement after 13 CM to turn on a light for 15 seconds
#define trigPin 6 //定義 HC-SR04 triger 在 arduino 上的腳位是 6
#define echoPin 5 //定義 HC-SR04 echo 在arduino上的腳位是 5
#define relay 9 //定義 relay 訊號 在arduino 上的腳位是 9
void setup()
{
Serial.begin (9600); //開使 serial 埠監控
pinMode(trigPin, OUTPUT); //設定 trigpin 為輸出
pinMode(echoPin, INPUT); //設定 echopin 為輸入
pinMode (relay, OUTPUT); //設定 relay的 腳位為輸出
}
void loop()
{
int duration, distance; //Define two intregers duration and distance to be used to save data
digitalWrite(trigPin, HIGH); //給 Trig 高電位,write a digital high to the trigpin to send out the pulse
delayMicroseconds(50); //持續 0.05秒 wait 0.05 second
digitalWrite(trigPin, LOW); //turn off the trigpin
duration = pulseIn(echoPin, HIGH); //measure the time using pulsein when the echo receives a signal set it to high
distance = (duration/2) / 29.1; // 超音波發射的距離為來回,因此單程距離 = 時間差/2 再除以 29.1 微秒/公分,如果要換算成英吋,只要將 29.1 再乘以 2.54 即可。攝氏零度海平面音速331.5公尺/秒,每升高1攝氏度,音速增加0.607公尺/秒 音速 c = 331.5 + 0.607 * t (其中 t 為攝氏溫度)。
if (distance < 20 && distance > 0) //距離要大於0並且小於20cm
{
Relay(); //執行下方的 relay 副程式
}
Serial.print(distance); //Dispaly the distance on the serial monitor
Serial.println(" CM"); //in centimeters
delay(50); //延遲 0.05 秒
}
void Relay() // relay 副程式
{
digitalWrite(relay, HIGH); //開啟 relay
delay (300); //延遲 0.3 秒
digitalWrite(relay, LOW); //關掉 relay
}
=============================================================