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

Arduino UNO Solenoid Valve Controller with L293D Driver and I2C LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO Solenoid Valve Controller with L293D Driver and I2C LCD Display

Circuit Documentation

Summary

This circuit is designed to control a 12V solenoid valve using an Arduino UNO and an L293D driver shield. The valve is opened and closed based on predefined time intervals. Additionally, a 16x2 I2C LCD is used to display the current state of the valve. The circuit includes the following components:

Component List

Arduino UNO

L293D Driver Shield

Solenoid Valve 12V

4x4 Keypad (Simulator)

16x2 I2C LCD

Wiring Details

Arduino UNO

L293D Driver Shield

Solenoid Valve 12V

16x2 I2C LCD

Documented Code

/*
 * Arduino Sketch to control a solenoid valve using an L293D driver shield.
 * The valve is opened and closed based on a predefined time interval.
 * The circuit includes:
 * - Arduino UNO
 * - L293D driver shield
 * - 12V Solenoid Valve
 * - 16x2 I2C LCD for display
 *
 * Connections:
 * - Solenoid Valve GND to L293D M1
 * - Solenoid Valve 12V to L293D M1
 * - L293D M+ to Arduino 5V
 * - L293D GND to Arduino GND
 * - LCD VCC to Arduino 5V
 * - LCD GND to Arduino GND
 * - LCD SDA to Arduino A4
 * - LCD SCL to Arduino A5
 */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

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

// Define the solenoid valve control pin
const int valvePin = 9; // L293D M1 is connected to Arduino D9

// Define the time intervals (in milliseconds)
const unsigned long openDuration = 5000; // Valve open for 5 seconds
const unsigned long closeDuration = 5000; // Valve closed for 5 seconds

// Variables to store the current state and timing
unsigned long previousMillis = 0;
bool valveState = false; // false = closed, true = open

void setup() {
  // Initialize the LCD
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Valve Control");

  // Initialize the valve control pin
  pinMode(valvePin, OUTPUT);
  digitalWrite(valvePin, LOW); // Start with the valve closed
}

void loop() {
  // Get the current time
  unsigned long currentMillis = millis();

  // Check if it's time to change the valve state
  if ((valveState && (currentMillis - previousMillis >= openDuration)) ||
      (!valveState && (currentMillis - previousMillis >= closeDuration))) {
    // Toggle the valve state
    valveState = !valveState;
    digitalWrite(valvePin, valveState ? HIGH : LOW);

    // Update the LCD display
    lcd.setCursor(0, 1);
    lcd.print(valveState ? "Valve: OPEN " : "Valve: CLOSED");

    // Update the previousMillis to the current time
    previousMillis = currentMillis;
  }
}

This code initializes the LCD and sets up the solenoid valve control pin. In the loop function, it toggles the valve state based on predefined time intervals and updates the LCD display accordingly.