ผมเป็นมือใหม่
พอดีทำโปรเจคเครื่องอัตโนมัติ
เรื่องมีอยู่ว่าผมได้เขียนโปรแกรมไปแล้วแต่ผมอยากได้สวิตซ์เพื่อเริ่มการทำงาน
ครับ
การทำงานของเครื่องเป็นแบบนี้
Arduino สั่งรีเลย์และLCD I2C (รีเลย์บอร์ดมี 12ตัวอะครับ)แต่ใช้แค่10ตัวครับ
แต่ผมอยากได้เป็น กดสวิตซ์แล้วรีเลย์ทำงานถ้าไม่กดสวิตซ์รีเลย์จะไม่ทำงานอะครับ
เลยอยากรู้ว่าเราจะทำยังไงบ้างครับ
โปรแกรมผมเป็นแบบนี้ไม่รู้ว่าจะถูกไหมยังไงช่วยดูด้วยนะครับ
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int relay1 = 10;
int relay2 = 9;
int relay3 = 8;
int relay4 = 7;
int relay5 = 6;
int relay6 = 5;
int relay7 = 4;
int relay8 = 3;
int relay9 = 2;
int relay10 = 1;
void setup()
{
lcd.begin();
lcd.print("Pumps No.1 in");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay1, OUTPUT);
lcd.begin();
lcd.print("Solenoid No.1 Wind");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay2, OUTPUT);
lcd.begin();
lcd.print("Solenoid No.2 Wind");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay3, OUTPUT);
lcd.begin();
lcd.print("Solenoid Water No.1");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay4, OUTPUT);
lcd.begin();
lcd.print("Solenoid Valve");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay5, OUTPUT);
lcd.begin();
lcd.print("Pumps No.2 in");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay6, OUTPUT);
lcd.begin();
lcd.print("Solenoid No.2 Wind OUT ");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay7, OUTPUT);
lcd.begin();
lcd.print("baked");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay8, OUTPUT);
lcd.begin();
lcd.print("Fan in");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(60000);
pinMode(relay9, OUTPUT);
lcd.begin();
lcd.print("Hello !!!");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(4320000);
pinMode(relay10, OUTPUT);
}
void loop() {
digitalWrite(relay1, 0);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 0);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 0);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 0);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 0);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 0);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 0);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 0);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 0);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 0);
delay(1000);
}
ผมอยากรู้ว่าเราจะเขียนโปรแกรมArduino ให้กดสวิตซ์เพื่อเริ่มการทำงานยังไง
พอดีทำโปรเจคเครื่องอัตโนมัติ
เรื่องมีอยู่ว่าผมได้เขียนโปรแกรมไปแล้วแต่ผมอยากได้สวิตซ์เพื่อเริ่มการทำงาน
ครับ
การทำงานของเครื่องเป็นแบบนี้
Arduino สั่งรีเลย์และLCD I2C (รีเลย์บอร์ดมี 12ตัวอะครับ)แต่ใช้แค่10ตัวครับ
แต่ผมอยากได้เป็น กดสวิตซ์แล้วรีเลย์ทำงานถ้าไม่กดสวิตซ์รีเลย์จะไม่ทำงานอะครับ
เลยอยากรู้ว่าเราจะทำยังไงบ้างครับ
โปรแกรมผมเป็นแบบนี้ไม่รู้ว่าจะถูกไหมยังไงช่วยดูด้วยนะครับ
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int relay1 = 10;
int relay2 = 9;
int relay3 = 8;
int relay4 = 7;
int relay5 = 6;
int relay6 = 5;
int relay7 = 4;
int relay8 = 3;
int relay9 = 2;
int relay10 = 1;
void setup()
{
lcd.begin();
lcd.print("Pumps No.1 in");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay1, OUTPUT);
lcd.begin();
lcd.print("Solenoid No.1 Wind");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay2, OUTPUT);
lcd.begin();
lcd.print("Solenoid No.2 Wind");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay3, OUTPUT);
lcd.begin();
lcd.print("Solenoid Water No.1");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay4, OUTPUT);
lcd.begin();
lcd.print("Solenoid Valve");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay5, OUTPUT);
lcd.begin();
lcd.print("Pumps No.2 in");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay6, OUTPUT);
lcd.begin();
lcd.print("Solenoid No.2 Wind OUT ");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay7, OUTPUT);
lcd.begin();
lcd.print("baked");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(1000);
pinMode(relay8, OUTPUT);
lcd.begin();
lcd.print("Fan in");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(60000);
pinMode(relay9, OUTPUT);
lcd.begin();
lcd.print("Hello !!!");
lcd.setCursor(0, 1);
lcd.print("doing work");
delay(4320000);
pinMode(relay10, OUTPUT);
}
void loop() {
digitalWrite(relay1, 0);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 0);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 0);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 0);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 0);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 0);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 0);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 0);
digitalWrite(relay9, 1);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 0);
digitalWrite(relay10, 1);
delay(1000);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
digitalWrite(relay4, 1);
digitalWrite(relay5, 1);
digitalWrite(relay6, 1);
digitalWrite(relay7, 1);
digitalWrite(relay8, 1);
digitalWrite(relay9, 1);
digitalWrite(relay10, 0);
delay(1000);
}