เปลี่ยนพัดลมธรรมดา ให้เป็นสุดยอดพัดลม ควมคุมผ่านมือถือ
วัสดุอุปกรณ์
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());
}
-----------------------------------
同時也有10000部Youtube影片,追蹤數超過2,910的網紅コバにゃんチャンネル,也在其Youtube影片中提到,...
「arduino if (serial)」的推薦目錄:
arduino if (serial) 在 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 if (serial) 在 Audom Idea Facebook 的最佳貼文
ทำวงจรควบคุมมอเตอร์ระยะไกลด้วยรีโมทวิทยุ+Arduino
https://www.youtube.com/watch?v=PsXB_kWwp8Y
-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
โค้ด
int ch1;
int ch2;
int ch3;
const int relay1 = 2;
const int relay2 = 3;
const int relay3 = 4;
const int relay4 = 5;
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(A1);
pinMode(6, INPUT); // Set our input pins as such
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
Serial.begin(9600); // Pour a bowl of Serial
}
void loop() {
ch1 = pulseIn(5, HIGH, 25000); // Read the pulse width of
ch2 = pulseIn(6, HIGH, 25000); // each channel
ch3 = pulseIn(7, HIGH, 25000);
Serial.print("Channel 1:"); // Print the value of
Serial.println(ch1); // each channel
Serial.print("Channel 2:");
Serial.println(ch2);
Serial.print("Channel 3:");
Serial.println(ch3);
delay(10); // I put this here just to make the terminal
// window happier
if (ch3 >1700)
{
digitalWrite(relay1,LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW);
digitalWrite(relay4, HIGH);
}
else {
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
if (ch3 <1200)
{
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, LOW);
}
if (ch2 >1700)
{
digitalWrite(relay1,LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, LOW);
}
if (ch2 <1300)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, HIGH);
}
}