วันเสาร์ที่ 1 มิถุนายน พ.ศ. 2562

ARDUINO CONTROL AC PLUG 1 PER 16 KEPAD BUZZER RELAY BOARD MODULE สั่งไฟ220V 1ต่อ16จุด





ARDUINO CONTROL AC PLUG 1 PER 16 KEPAD BUZZER RELAY BOARD MODULE สั่งไฟ220V 1ต่อ16จุด
1/6/2562 SONGCHAI PRAPATRUNGSEE
ARDUINO CONTROL AC PLUG 1 PER 16 KEPAD BUZZER RELAY BOARD MODULE สั่งไฟ220V 1ต่อ16จุด



ซื้อKEYPAD 4X4 https://shp.ee/jw738ga






////////////////SOURCE CODE////////////

/* RELAY BOARD MODULE WITH JDVCC. INPUT ACTIVE LOW */

#include <Keypad.h>

char KEY[4][4] = 
{
 {'1', '2', '3', 'A'},
 {'4', '5', '6', 'B'},
 {'7', '8', '9', 'C'},
 {'*', '0', '#', 'D'}
};

byte ROW[4]={7, 6, 5, 4};//CONNECT ROW PINOUTS OF KEYPAD
byte COL[4]={3, 2, 1, 0};//CONNECT COLUMN PINOUTS OF KEYPAD

// initialize an instance of class NewKeypad
Keypad KPAD=Keypad(makeKeymap(KEY),ROW,COL,4,4);

int BUZZER = 8; // Define the buzzer pin
int RELAY1;
int RELAY2;
int RELAY3;
int RELAY4;
void setup() 
{
  pinMode(BUZZER, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);
RELAY1=~RELAY1;
RELAY2=~RELAY2;
RELAY3=~RELAY3;
RELAY4=~RELAY4;
}
void loop() 
{
char PRESS;
PRESS = KPAD.getKey();
if (PRESS) 
{
  if(PRESS=='1')
  {
  RELAY1=~RELAY1;
  digitalWrite(9, RELAY1);
  }
  if(PRESS=='2')
  {
  RELAY2=~RELAY2;
  digitalWrite(10, RELAY2);
  }
  if(PRESS=='3')
  {
  RELAY3=~RELAY3;
  digitalWrite(11, RELAY3);
  }
  if(PRESS=='4')
  {
  RELAY4=~RELAY4;
  digitalWrite(12, RELAY4);
  }
 // Make a prompt tone each time press the key
  digitalWrite(BUZZER, HIGH);
  delay(100);
  digitalWrite(BUZZER, LOW);
  }  
}





ไม่มีความคิดเห็น: