Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Controlled Interactive Display with Keypad Input and Motor Feedback

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Interactive Display with Keypad Input and Motor Feedback

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with a variety of components including an I2C LCD 16x2 Screen, a 4x4 Membrane Matrix Keypad, a 12V DC Motor Encoder, a Pushbutton, a Resistor, an MKE-S03 Photo Diode Light Sensor, a 12V Pneumatic Solenoid Valve, a 2-Channel Relay, a Red Lamp, and a Step-Down Module. The circuit is powered by a 240V Power Source. The Arduino UNO is programmed to interact with these components, displaying information on the LCD, reading inputs from the keypad and the photo diode light sensor, controlling the motor encoder, and activating the pneumatic solenoid valve and lamp via the relays.

Component List

Arduino UNO

I2C LCD 16x2 Screen

4X4 Membrane Matrix Keypad

12V DC Motor Encoder

Pushbutton

Resistor (10k Ohms)

MKE-S03 Photo Diode Light Sensor

12V Pneumatic Solenoid Valve

2-Channel Relay

Lamp Red

240V Power Source

Step-Down Module

Wiring Details

Arduino UNO

I2C LCD 16x2 Screen

4X4 Membrane Matrix Keypad

12V DC Motor Encoder

Pushbutton

Resistor (10k Ohms)

MKE-S03 Photo Diode Light Sensor

2-Channel Relay

Step-Down Module

240V Power Source

Documented Code

// dupodmuch 1.2
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Encoder.h>

// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Keypad setup
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// Encoder setup
Encoder myEnc(12, 13);

// Pin definitions
const int buttonPin = 10;
const int photocellPin = 11;
const int relay1Pin = A0;
const int relay2Pin = A1;

// Parameters
float droga = 520.9; // Default distance in mm per 1000 encoder pulses
int licznik = 0; // Counter for interruptions
int cykl = 2; // Default cycle count
float dmuchstart = 20.0; // Start blowing at 20mm
float dmuchstop = 80.0; // Stop blowing at 80mm
float zero = 0.0; // Zero position
float zator = 520.9; // Default blockage distance

// State variables
long encoderPosition = 0;
bool relay1State = false;
bool relay2State = false;

void setup() {
  // Initialize LCD
  lcd.begin();
  lcd.backlight();
  lcd.print("Dupodmuch 1.2");
  delay(3000);
  lcd.clear();

  // Initialize pins
  pinMode(buttonPin, INPUT);
  pinMode(photocellPin, INPUT);
  pinMode(relay1Pin, OUTPUT);
  pinMode(relay2Pin, OUTPUT);

  // Initialize relays
  digitalWrite(relay1Pin, HIGH); // Relay 1 off
  digitalWrite(relay2Pin, HIGH); // Relay 2 off
}

void loop() {
  // Read encoder position
  long newPosition = myEnc.read();
  if (newPosition != encoderPosition) {
    encoderPosition = newPosition;
    // Update display with encoder position
    lcd.setCursor(0, 1);
    lcd.print("Pos: ");
    lcd.print(encoderPosition);
  }

  // Read keypad input
  char key = keypad.getKey();
  if (key) {
    handleKeypadInput(key);
  }

  // Read photocell state
  int photocellState = digitalRead(photocellPin);
  if (photocellState == LOW) {
    licznik++;
    lcd.setCursor(0, 1);
    lcd.print("Licznik: ");
    lcd.print(licznik);
  }

  // Check for relay 1 activation
  if (encoderPosition >= dmuchstart && encoderPosition <= dmuchstop) {
    digitalWrite(relay1Pin, LOW); // Activate relay 1
    relay1State = true;
  } else {
    digitalWrite(relay1Pin, HIGH); // Deactivate relay 1
    relay1State = false;
  }

  // Check for relay 2 activation
  if (encoderPosition >= zator) {
    digitalWrite(relay2Pin, LOW); // Activate relay 2
    relay2State = true;
  }

  // Check for button press
  if (digitalRead(buttonPin) == LOW) {
    digitalWrite(relay1Pin, LOW); // Manually activate relay 1
    relay1State = true;