Arduino UNO-Based Conveyor Control System with Multiple I2C LCD Displays and Pushbutton Inputs
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control a conveyor system using an Arduino UNO microcontroller. The system includes multiple 16x2 I2C LCD displays, pushbuttons, a DS3231 RTC module, an L298N DC motor driver, and a DC motor. The LCDs display the current date, time, and downtime of the conveyor system. The pushbuttons are used to stop the conveyor, and the RTC module keeps track of the current time.
Component List
16x2 I2C LCD
- Description: 16x2 character LCD with I2C interface.
- Pins: GND, VCC, SDA, SCL
L298N DC Motor Driver
- Description: Dual H-Bridge motor driver.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
Pushbutton
- Description: Simple pushbutton switch.
- Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
9V Battery
- Description: Standard 9V battery.
- Pins: -, +
Adafruit DS3231
- Description: Real-Time Clock (RTC) module.
- Pins: Vin, GND, SCL, SDA, BAT, 32KHZ, SQW, !RTC_RST
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
DC Motor
- Description: Standard DC motor.
- Pins: pin 1, pin 2
Wiring Details
16x2 I2C LCD
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- SDA: Connected to Arduino UNO A4
- SCL: Connected to Arduino UNO A5
L298N DC Motor Driver
- IN1: Connected to Arduino UNO D13
- OUT1: Connected to DC Motor pin 2
- OUT2: Connected to DC Motor pin 1
- 12V: Connected to 9V Battery +
- GND: Connected to Arduino UNO GND
Pushbutton
- Pin 1 (in): Connected to Arduino UNO D2, D3, D4, D5, D6, D7 (one pin per button)
- Pin 2 (in): Connected to Arduino UNO GND
9V Battery
- +: Connected to L298N DC Motor Driver 12V
- -: Connected to Arduino UNO GND
Adafruit DS3231
- Vin: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- SDA: Connected to Arduino UNO A4
- SCL: Connected to Arduino UNO A5
Arduino UNO
- 5V: Connected to 16x2 I2C LCD VCC, Adafruit DS3231 Vin
- GND: Connected to 16x2 I2C LCD GND, Adafruit DS3231 GND, L298N DC Motor Driver GND, Pushbutton Pin 2 (in), 9V Battery -
- A4: Connected to 16x2 I2C LCD SDA, Adafruit DS3231 SDA
- A5: Connected to 16x2 I2C LCD SCL, Adafruit DS3231 SCL
- D2: Connected to Pushbutton Pin 1 (in)
- D3: Connected to Pushbutton Pin 1 (in)
- D4: Connected to Pushbutton Pin 1 (in)
- D5: Connected to Pushbutton Pin 1 (in)
- D6: Connected to Pushbutton Pin 1 (in)
- D7: Connected to Pushbutton Pin 1 (in)
- D13: Connected to L298N DC Motor Driver IN1
DC Motor
- pin 1: Connected to L298N DC Motor Driver OUT2
- pin 2: Connected to L298N DC Motor Driver OUT1
Code Documentation
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
// Define constants
#define NUM_POSTS 6
#define CONVEYOR_PIN 13 // pin to control conveyor motor
// Button and LCD pin definitions
const int buttonPins[NUM_POSTS] = {2, 3, 4, 5, 6};
LiquidCrystal_I2C lcds[NUM_POSTS] = {
LiquidCrystal_I2C(0x27, 16, 2),
LiquidCrystal_I2C(0x26, 16, 2),
LiquidCrystal_I2C(0x25, 16, 2),
LiquidCrystal_I2C(0x24, 16, 2),
LiquidCrystal_I2C(0x23, 16, 2),
LiquidCrystal_I2C(0x22, 16, 2),
};
// Variables
RTC_DS3231 rtc;
bool conveyorStopped = false;
unsigned long lastMoveTime = 0;
unsigned long downtimeStart[NUM_POSTS] = {0};
unsigned long totalDowntime[NUM_POSTS] = {0};
bool buttonPressed[NUM_POSTS] = {false};
void setup() {
// Initialize serial monitor
Serial.begin(9600);
// Initialize conveyor control pin
pinMode(CONVEYOR_PIN, OUTPUT);
digitalWrite(CONVEYOR_PIN, LOW); // start with conveyor off
// Initialize buttons
for (int i = 0; i < NUM_POSTS; i++) {
pinMode(buttonPins[i], INPUT_PULLUP); // Pull-up configuration
}
// Initialize LCDs
for (int i = 0; i < NUM_POSTS; i++) {
lcds[i].init();
lcds[i].backlight();
lcds[i].setCursor(0, 0);
lcds[i].print("Initializing....");
}
// Initialize RTC
if (!rtc.begin()) {
Serial.println("RTC not found!");
while (1);
}
}
void loop() {
// Update date and time
DateTime now = rtc.now();
// Check buttons and calculate downtime
conveyorStopped = false;
for (int i = 0; i < NUM_POSTS; i++) {
bool isPressed = !digitalRead(buttonPins[i]); // Active low
if (isPressed) {
if (!buttonPressed[i]) {
// Button just pressed
downtimeStart[i] = millis();
}
buttonPressed[i] = true;
conveyorStopped = true;
} else if (buttonPressed[i]) {
// Button just released
buttonPressed[i] = false;
totalDowntime[i] += millis() - downtimeStart[i];
}
}
// Control conveyor
if (conveyorStopped) {
digitalWrite(CONVEYOR_PIN, LOW); // Stop conveyor
} else if (millis() - lastMoveTime >= 120000) { // 2 minutes interval
digitalWrite(CONVEYOR_PIN, HIGH); // Move conveyor
delay(2000); // Allow conveyor to move briefly
digitalWrite(CONVEYOR_PIN, LOW);
lastMoveTime = millis();
}
// Update LCDs
for (int i = 0; i < NUM_POSTS; i++) {
lcds[i].clear();
lcds[i].setCursor(0, 0);
lcds[i].print("Date:");
lcds[i].print(now.day(), DEC);
lcds[i].print("/");
lcds[i].print(now.month(), DEC);
lcds[i].print(now.year(), DEC);
lcds[i].setCursor(0, 1);
lcds[i].print("Time:");
lcds[i].print(now.hour(), DEC);
lcds[i].print(":");
lcds[i].print(now.minute(), DEC);
lcds[i].print(" DT:");
lcds[i].print(totalDowntime[i] / 1000); // Display downtime in seconds
}
delay(100); // small delay for stability
}
This code initializes the necessary components, checks the status of the pushbuttons, controls the conveyor motor, and updates the LCD displays with the current date, time, and downtime.