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.
5V
connected to I2C LCD Screen VCC (5V) and Pushbutton Pin 1 (in)GND
connected to I2C LCD Screen GND, Resistor pin1, and Step-Down Module 5v OUT-Vin
connected to Step-Down Module 5v OUT+A0
connected to 2ch Relay IN2A1
connected to 2ch Relay IN1A4
connected to I2C LCD Screen SDAA5
connected to I2C LCD Screen SCLD2
to D9
connected to 4X4 Membrane Matrix Keypad R1 to C4 respectivelyD10
connected to Resistor pin2 and Pushbutton Pin 3 (out)D11
connected to MKE-S03 Photo Diode Light Sensor SIGD12
connected to 12V DC Motor Encoder AD13
connected to 12V DC Motor Encoder BVCC (5V)
and GND
connected to Arduino UNOSDA
and SCL
connected to Arduino UNO A4 and A5 respectivelyR1
to R4
connected to Arduino UNO D2 to D5 respectivelyC1
to C4
connected to Arduino UNO D6 to D9 respectivelyA
and B
connected to Arduino UNO D12 and D13 respectivelyPin 1 (in)
connected to Arduino UNO 5VPin 3 (out)
connected to Arduino UNO D10pin1
connected to Arduino UNO GNDpin2
connected to Arduino UNO D10 and Pushbutton Pin 3 (out)SIG
connected to Arduino UNO D11IN1
and IN2
connected to Arduino UNO A0 and A1 respectivelyNO
connected to 12V Pneumatic Solenoid Valve GND and Lamp Red -COM
connected to 240V Power Source Live5v OUT+
and 5v OUT-
connected to Arduino UNO Vin and GND respectively24v IN+
connected to 240V Power Source LiveNeutral
connected to 12V Pneumatic Solenoid Valve VCCLive
connected to Step-Down Module 24v IN+ and 2ch Relay COM// 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;