How to make keypad timer Switch
How to make keypad timer Switch
Components and supplies
1
3x4 Keypad
1
Jumper Wires
1
Relay Module
1
Arduino UNO
Project description
Code
Code
arduino
Comments
Only logged in users can leave comments
Components and supplies
3x4 Keypad
Jumper Wires
Relay Module
Arduino UNO
Project description
Code
Code
arduino
1#include <Keypad.h> 2 3int relay_pin = A0; 4 5long int timer = 0; 6 7const int ROW_NUM = 4; //four rows 8const int COLUMN_NUM = 3; //three columns 9 10char keys[ROW_NUM][COLUMN_NUM] = { 11 {'1', '2', '3'}, 12 {'4', '5', '6'}, 13 {'7', '8', '9'}, 14 {'*', '0', '#'} 15}; 16 17byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad 18byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad 19 20Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 21 22 23String input_value; 24 25void setup() { 26 27 pinMode(relay_pin, OUTPUT); 28 29 30 Serial.begin(9600); 31 input_value.reserve(32); // maximum input characters is 33, change if needed 32} 33 34void loop() { 35 char key = keypad.getKey(); 36 37 if (key) { 38 Serial.println(key); 39 40 if (key == '*') { 41 input_value = ""; // clear input value 42 } else if (key == '#') { 43 44 timer = input_value.toInt(); 45 46 47 timer = timer * 1000; //time in seconds 48 //timer = timer * 1000 * 60; //time in minuts 49 // timer = timer * 1000 * 60 * 60; //time in hours 50 51 digitalWrite(relay_pin, HIGH); 52 Serial.println("relay on"); 53 54 delay(timer); 55 digitalWrite(relay_pin, LOW); 56 Serial.println("relay off"); 57 58 timer = 0; 59 60 61 62 input_value = ""; // clear input value 63 } else { 64 input_value += key; // append new character to input value string 65 } 66 } 67} 68
Comments
Only logged in users can leave comments