Danny van den Brande
Published © CC BY-SA

Arduino - LCD 1602A Keypad LCD Shield Relay Control

Simple project to control 4 relays with a keypad shield for Arduino.

BeginnerProtip1 hour11,711
Arduino - LCD 1602A Keypad LCD Shield Relay Control

Things used in this project

Story

Read more

Schematics

Schematic

Code

LCD_1602A_KEYPAD_RELAY_CONTROL.ino

Arduino
example on how to use a LCD keypad.
You can add anything to it. In this example we switch on and off relays.
/*
Author:Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
Hello world! Today i made a small example on how to use a LCD keypad.
You can add anything to it. In this example we switch on and off relays.
Good luck!
 */
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int relay1 = 30;
int relay2 = 31;
int relay3 = 32;
int relay4 = 33;

int lcdkeys;
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("BlueCore Tech");
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
}
void loop() {
  Serial.println(lcdkeys);// look in the serial monitor and press buttons to see values.
  lcdkeys=analogRead(0);
  if (lcdkeys<50) {  //if value less then 50 
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("DEVICE 1");
  lcd.setCursor(0, 1);
  lcd.print("IS ON");
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, LOW);
    digitalWrite(relay3, LOW);
    digitalWrite(relay4, HIGH);
  }
  else if(lcdkeys<195) { //if value less then 195 and so on. 
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("DEVICE 2");
    lcd.setCursor(0, 1);
    lcd.print("IS ON");
    digitalWrite(relay1, HIGH);
    digitalWrite(relay2, LOW);
    digitalWrite(relay3, LOW);
    digitalWrite(relay4, LOW);
    
  }
  else if(lcdkeys<380) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("DEVICE 3");
    lcd.setCursor(0, 1);
    lcd.print("IS ON");
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, HIGH);
    digitalWrite(relay3, LOW);
    digitalWrite(relay4, LOW);
  }
  else if(lcdkeys<650) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("DEVICE 4");
    lcd.setCursor(0, 1);
    lcd.print("IS ON");
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, LOW);
    digitalWrite(relay3, HIGH);
    digitalWrite(relay4, LOW);
  }
  else if(lcdkeys<1023) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("BLUECORE TECH");
    lcd.setCursor(0, 1);
    lcd.print("OFF");
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, LOW);
    digitalWrite(relay3, LOW);
    digitalWrite(relay4, LOW);  
  }
}

Credits

Danny van den Brande

Danny van den Brande

36 projects • 77 followers
"Hello world."

Comments