เปลี่ยนพัดลมธรรมดา ให้เป็นสุดยอดพัดลม ควมคุมผ่านมือถือ
วัสดุอุปกรณ์
1.บอร์ด Relay 4ช่อง 5V Arduino Relay Module 5V 4 Channel isolation control 250V/10A
2. Power Adapter 12v 1A อะแดปเตอร์ 12v กระแส 1A หัวแจ็ค 5.5x2.5mm
3.Bluetooth Module HC05
4.Jumper Arduino สายไฟจัมเปอร์ยาว 15cm เมีย - เมีย
5.Arduino Nano 3.0
6.Funduino Nano Shield
โค้ด
-----------------------------------
#include <SoftwareSerial.h>
int i =0;
char str[11]={'0','0','0','0','0','0','0','0','0','0','0'};
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
Serial.begin(9600);
while (!Serial) ;
mySerial.begin(9600);
}
void loop()
{
if (mySerial.available()){
//Serial.write(mySerial.read());
//Serial.println("ok");
i=i+1;
str[i]=mySerial.read();
//Serial.println(str[i]);
if(i ==9)
i=0;
if(str[5] == '1' && str[7] == '3')
digitalWrite(8, LOW);
if(str[5] == '1' && str[7] == '2')
digitalWrite(8, HIGH);
if(str[5] == '2' && str[7] == '3')
digitalWrite(9, LOW);
if(str[5] == '2' && str[7] == '2')
digitalWrite(9, HIGH);
if(str[5] == '3' && str[7] == '3')
digitalWrite(10, LOW);
if(str[5] == '3' && str[7] == '2')
digitalWrite(10, HIGH);
if(str[5] == '4' && str[7] == '3')
digitalWrite(11, LOW);
if(str[5] == '4' && str[7] == '2')
digitalWrite(11, HIGH);
}
if (Serial.available())
mySerial.write(Serial.read());
}
-----------------------------------
「arduino while」的推薦目錄:
- 關於arduino while 在 Audom Idea Facebook 的最佳貼文
- 關於arduino while 在 Audom Idea Facebook 的精選貼文
- 關於arduino while 在 Might Electronic 邁特電子 Facebook 的精選貼文
- 關於arduino while 在 Arduino Uno: While-loop fails to "restart" using Button to reset ... 的評價
- 關於arduino while 在 How to use while(1) loop in arduino? 的評價
- 關於arduino while 在 Simple updated examples of arduino serial communications 的評價
arduino while 在 Audom Idea Facebook 的精選貼文
เปลี่ยนพัดลมธรรมดา ให้เป็นสุดยอดพัดลม ควมคุมผ่านมือถือ
วัสดุอุปกรณ์
1.บอร์ด Relay 4ช่อง 5V Arduino Relay Module 5V 4 Channel isolation control 250V/10A
2. Power Adapter 12v 1A อะแดปเตอร์ 12v กระแส 1A หัวแจ็ค 5.5x2.5mm
3.Bluetooth Module HC05
4.Jumper Arduino สายไฟจัมเปอร์ยาว 15cm เมีย - เมีย
5.Arduino Nano 3.0
6.Funduino Nano Shield
โค้ด
-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
#include <SoftwareSerial.h>
int i =0;
char str[11]={'0','0','0','0','0','0','0','0','0','0','0'};
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
Serial.begin(9600);
while (!Serial) ;
mySerial.begin(9600);
}
void loop()
{
if (mySerial.available()){
//Serial.write(mySerial.read());
//Serial.println("ok");
i=i+1;
str[i]=mySerial.read();
//Serial.println(str[i]);
if(i ==9)
i=0;
if(str[5] == '1' && str[7] == '3')
digitalWrite(8, LOW);
if(str[5] == '1' && str[7] == '2')
digitalWrite(8, HIGH);
if(str[5] == '2' && str[7] == '3')
digitalWrite(9, LOW);
if(str[5] == '2' && str[7] == '2')
digitalWrite(9, HIGH);
if(str[5] == '3' && str[7] == '3')
digitalWrite(10, LOW);
if(str[5] == '3' && str[7] == '2')
digitalWrite(10, HIGH);
if(str[5] == '4' && str[7] == '3')
digitalWrite(11, LOW);
if(str[5] == '4' && str[7] == '2')
digitalWrite(11, HIGH);
}
if (Serial.available())
mySerial.write(Serial.read());
}
-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
arduino while 在 Might Electronic 邁特電子 Facebook 的精選貼文
📢Mighty Tech🚩
📌 How is LPWAN Integrated into IoT Space❓
While working on IoT devices, developers need to consider what LPWAN technologies could be applied to their project before 5G is ready, such as LoRa, Sigfox, NB-IoT, eMTC, etc🌐
📔Read more from TechDesign.com 👉http://bit.ly/2PNEEnw
🚀The world's first open-source development kit that Integrates Arduino MCU and Sigfox Technology👉http://www.mightynet.co/news
-----------
📢邁特新知🚩
📌低功率廣域網路如何打通各個物聯網領域❓
使用物聯網裝置時,開發商需要評估各大 LPWAN技術的優缺點,像是Lora、sigfox或NB-IoT 等🌐
📔閱讀全文 👉http://bit.ly/2PNEEnw
🚀全球第一個整合Arduino MCU與Sigfox技術且開源的開發工具吧👉http://tw.mightynet.co/news
-----------
圖片來源: https://www.statista.com/…/iot-number-of-connected-devices…/
arduino while 在 How to use while(1) loop in arduino? 的推薦與評價
1. The while(1) loop executes once, every time loop() is called, printing or not, depending on the state of pin2. · The loop function loops (is called repeatedly) ... ... <看更多>
相關內容
arduino while 在 Simple updated examples of arduino serial communications 的推薦與評價
SERIAL COM - HANDELING MULTIPLE BYTES inside ARDUINO - 01_simple version. * by beltran berrocal ... while (Serial.available()>0){. ... <看更多>
arduino while 在 Arduino Uno: While-loop fails to "restart" using Button to reset ... 的推薦與評價
... <看更多>
相關內容