0 đánh giá

Điều khiển Đèn trang trí giáng sinh với Arduino

Giáng sinh sắp đến rồi, bài này mình sẽ hướng dẫn các bạn làm sao để làm một mạch điều khiển sáng tắt các Đèn trang trí ở các cây hoặc nhiều đèn khác nhau sáng tắt thật đẹp.

Bước 1: Chuẩn bị
khoere_arduino-uno-8185435910.jpg khoere_8-relay-voi-opto-cach-ly-a6240-600x600-3603969076.jpg khoere_day-trang-tri-7937678736.jpg

Bạn cần 1 Board Arduino UNO,  Role 4 hoặc 8 cổng như trên. Cứ 1 cổng ta nối 1 dây đèn

 

Bước 2: Nối dây
khoere_noi-day-9684561719.png khoere_den-5769600993.jpg

Bạn tiến hành nối như hình trên, với hình trên, dây đèn trang trí được nối tương tự bóng đèn trên.

Với phần nối đến Arduino, bạn nối 5V của Board Relay với 5V Aduino, tương tự với GND.

in1 nối với chân  6 Arduino

in2 nối với chân  7 Arduino

in3 nối với chân  8 Arduino

in4 nối với chân  9 Arduino

in5 nối với chân  2 Arduino

in6 nối với chân  3 Arduino

in7 nối với chân  4 Arduino

in8 nối với chân  5 Arduino

Bước 3: Chương trình

Tiến hành nạp chương trình này vào và tận hưởng nhé, chúc bạn thành công

int tree1 = 6;
int tree2 = 7;
int tree3 = 8;
int tree4 = 9;
int tree5 = 2;
int tree6 = 3;
int tree7 = 4;
int tree8 = 5;
int s = 150;
int ds = 225;
int e = 300;
int de = 450;
int q = 600;
int dq = 900;
int h = 1200;
int dh = 1800;
int start;
int end;
int time;

void setup()
{
  pinMode(tree1, OUTPUT);
  pinMode(tree2, OUTPUT);
  pinMode(tree3, OUTPUT);
  pinMode(tree4, OUTPUT);
  pinMode(tree5, OUTPUT);
  pinMode(tree6, OUTPUT);
  pinMode(tree7, OUTPUT);
  pinMode(tree8, OUTPUT);
  digitalWrite(tree1, HIGH);
  delay(1000);
  digitalWrite(tree2, HIGH);
  delay(1000);
  digitalWrite(tree3, HIGH);
  delay(1000);
  digitalWrite(tree4, HIGH);
  delay(1000);
  digitalWrite(tree5, HIGH);
  delay(1000);
  digitalWrite(tree6, HIGH);
  delay(1000);
  digitalWrite(tree7, HIGH);
  delay(1000);
  digitalWrite(tree8, HIGH);
  delay(1000);
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);
  Serial.begin(9600);
}

void loop()
{
  start = millis();
  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  delay(q);
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  delay(de);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);

  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  delay(s);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);

  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  delay(1050);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  delay(s);
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  delay(q);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);

  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  delay(q);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);

  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  delay(dq);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  delay(e);
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree7, HIGH);
  delay(dq);
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  delay(e);
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  delay(dq);
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  delay(e);
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  delay(dq);
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree8, HIGH);
  delay(e);
  digitalWrite(tree8, LOW);

  digitalWrite(tree1, HIGH);
  delay(e);
  digitalWrite(tree1, LOW);

  digitalWrite(tree7, HIGH);
  delay(e);
  digitalWrite(tree7, LOW);

  digitalWrite(tree2, HIGH);
  delay(e);
  digitalWrite(tree2, LOW);

  digitalWrite(tree6, HIGH);
  delay(e);
  digitalWrite(tree6, LOW);

  digitalWrite(tree3, HIGH);
  delay(de);
  digitalWrite(tree3, LOW);

  digitalWrite(tree5, HIGH);
  delay(s);
  digitalWrite(tree5, LOW);

  digitalWrite(tree4, HIGH);
  delay(e);
  digitalWrite(tree4, LOW);

  digitalWrite(tree8, HIGH);
  delay(e);
  digitalWrite(tree8, LOW);

  digitalWrite(tree1, HIGH);
  delay(e);
  digitalWrite(tree1, LOW);

  digitalWrite(tree7, HIGH);
  delay(e);
  digitalWrite(tree7, LOW);

  digitalWrite(tree2, HIGH);
  delay(e);
  digitalWrite(tree2, LOW);

  digitalWrite(tree6, HIGH);
  delay(e);
  digitalWrite(tree6, LOW);

  digitalWrite(tree3, HIGH);
  delay(de);
  digitalWrite(tree3, LOW);

  digitalWrite(tree5, HIGH);
  delay(s);
  digitalWrite(tree5, LOW);

  digitalWrite(tree4, HIGH);
  delay(e);
  digitalWrite(tree4, LOW);

  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  delay(e);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  delay(e);
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  delay(e);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  delay(e);
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  delay(75);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);

  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  delay(75);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);

  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  delay(dq);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);

  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  delay(75);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);

  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  delay(75);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);

  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  delay(e);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);

  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  delay(e);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);

  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  delay(e);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);

  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  delay(75);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);

  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  delay(75);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  delay(dq);
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  delay(75);
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);

  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree7, HIGH);
  delay(75);
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);

  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  delay(e);
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);

  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree
														
(!) Nếu có bất kỳ thắc mắc nào cần hỏi vui lòng đặt câu hỏi tại HỏiHay.Net, Cộng đồng Hỏi đáp Hỏi Hay sẽ trả lời bạn.
329 lượt xem ^tháng ^ngày, ^năm
admin 2,030 điểm

Please log in or register to Comment this Media.