Mini project
Arduino เปิดปิดไฟบ้านผ่านมือถือ เชื่อมต่อ
bluetooh
Code
int d1=8;
int d2=9;
int d3=10;
int d4=11;
void setup()
{
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
Serial.begin(9600);
}
void loop()
{
while(Serial.available())
{
char In=Serial.read();
if(In=='a' || In=='A')
{
digitalWrite(d1, HIGH);
}
else if(In=='s' || In=='S')
{
digitalWrite(d2, HIGH);
}
else if(In=='d' || In=='D')
{
digitalWrite(d3, HIGH);
}
else if(In=='f' || In=='F')
{
digitalWrite(d4, HIGH);
}
else if(In=='g' || In=='G')
{
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
}
else if(In=='h' || In=='H')
{
digitalWrite(d1, LOW);
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
digitalWrite(d4, LOW);
}
}
}
อ้างอิง
https://www.myarduino.net/product/1810/%E0%B8%8A%E0%B8%B8%E0%B8%94%E0%B8%84%E0%B8%B4%E0%B8%97%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%80%E0%B8%88%E0%B8%84-arduino-%E0%B9%80%E0%B8%9B%E0%B8%B4%E0%B8%94%E0%B8%9B%E0%B8%B4%E0%B8%94%E0%B9%84%E0%B8%9F%E0%B8%9A%E0%B9%89%E0%B8%B2%E0%B8%99%E0%B8%9C%E0%B9%88%E0%B8%B2%E0%B8%99%E0%B8%A1%E0%B8%B7%E0%B8%AD%E0%B8%96%E0%B8%B7%E0%B8%AD-%E0%B9%80%E0%B8%8A%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%A1%E0%B8%95%E0%B9%88%E0%B8%AD-bluetooth
ความคิดเห็น
แสดงความคิดเห็น