Electronics Base for Irrigation System (light dependent rotation included)

It's a base/casing for "Automatic Irrigation Pot and Water Chamber". It holds and houses all the electronics with…
1
10
0
146
updated October 1, 2024

Description

PDF

It's a base/casing for "Automatic Irrigation Pot and Water Chamber". It holds and houses all the electronics with added stepper motor functionality that allows the pot to spin whenever it is daytime so that the plant can obtain full sun exposure. If the jumper wires you use aren't very long the sliding mechanism that the base uses might not be usable. If so, attach it using glue.

Print Settings

Printer Brand:

Creality

Printer:

Ender 3

Supports:

No

Infill:

15%

Filament: IIID MAX PLA+ BlackMaterials, Code, and Netlist

Materials

In addition to the materials used in the actual pot you'll need: • three MR95 ZZ miniature deep groove ball bearings • one 10k-ohm resistor, ½ watt • one 6V battery pack • a photoresistor (LDR) • a 28BYJ-48 5V 4-Phase stepper motor • a ULN2003 stepper motor driver board

Or you can ignore the additional functionality and use it just as a casing.

Code

// Define the pin connections const int soilMoisturePin = A0; // Soil moisture sensor connected to A0 const int waterPumpPin = 7; // Relay to control water pump const int waterLevelPin = A1; // Water level sensor connected to A1 const int ldrPin = A2; // LDR connected to A2 const int greenLEDPin = 4; // Green LED for full water level const int yellowLEDPin = 3; // Yellow LED for half water level const int redLEDPin = 2; // Red LED for empty water level const int motorPin1 = 8; // Stepper motor driver IN1 const int motorPin2 = 9; // Stepper motor driver IN2 const int motorPin3 = 10; // Stepper motor driver IN3 const int motorPin4 = 11; // Stepper motor driver IN4

unsigned long previousMillis = 0; // Store the last time the motor was updated const int stepDelay = 5; // Delay between steps for the motor int stepCount = 0; // Track steps for the motor bool motorActive = false; // Track motor state

void setup() { // Initialize the pins pinMode(soilMoisturePin, INPUT); pinMode(waterLevelPin, INPUT); pinMode(ldrPin, INPUT); pinMode(waterPumpPin, OUTPUT); // Control relay to turn the pump on/off pinMode(greenLEDPin, OUTPUT); pinMode(yellowLEDPin, OUTPUT); pinMode(redLEDPin, OUTPUT);

// Initialize motor pins pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT);

Serial.begin(9600); // Initialize serial communication for debugging Serial.println("Setup complete."); }

void loop() { // Soil moisture sensor reading int soilMoistureValue = analogRead(soilMoisturePin); Serial.print("Soil moisture value: "); Serial.println(soilMoistureValue);

// Control water pump based on soil moisture if (soilMoistureValue > 750) { // Dry condition digitalWrite(waterPumpPin, LOW); // Turn on the water pump (relay activates) Serial.println("Water pump ON."); } else { digitalWrite(waterPumpPin, HIGH); // Turn off the water pump Serial.println("Water pump OFF."); }

// Water level sensor reading int waterLevelValue = analogRead(waterLevelPin); Serial.print("Water level value: "); Serial.println(waterLevelValue);

// Water level indication using LEDs if (waterLevelValue > 342) { // Full water level digitalWrite(greenLEDPin, HIGH); digitalWrite(yellowLEDPin, LOW); digitalWrite(redLEDPin, LOW); Serial.println("Water level: FULL (Green LED ON)."); } else if (waterLevelValue > 195) { // Half water level digitalWrite(greenLEDPin, LOW); digitalWrite(yellowLEDPin, HIGH); digitalWrite(redLEDPin, LOW); Serial.println("Water level: HALF (Yellow LED ON)."); } else { // Low or empty water level digitalWrite(greenLEDPin, LOW); digitalWrite(yellowLEDPin, LOW); digitalWrite(redLEDPin, HIGH); Serial.println("Water level: LOW/EMPTY (Red LED ON)."); }

// LDR (light sensor) reading int ldrValue = analogRead(ldrPin); Serial.print("LDR value: "); Serial.println(ldrValue);

// Control the stepper motor based on daylight (when LDR detects enough light) if (ldrValue > 600) { // Start the motor if it's not already running if (!motorActive) { Serial.println("Daylight detected. Starting motor."); motorActive = true; // Set motor to active } } else { // Stop the motor if it's dark if (motorActive) { Serial.println("No daylight detected. Stopping motor."); stopMotor(); motorActive = false; // Set motor to inactive } }

// Manage motor rotation if (motorActive) { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= stepDelay) { previousMillis = currentMillis; // Update the last time a step was made stepMotor(); // Step the motor } } }

// Function to rotate the stepper motor continuously void stepMotor() { // Define a simple stepping sequence for continuous rotation static int step = 0; // Track the current step in the sequence switch (step) { case 0: digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); break; case 1: digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); break; case 2: digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); break; case 3: digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); break; } step = (step + 1) % 4; // Increment step and wrap around to create a continuous rotation Serial.println("Motor stepped."); }

// Function to stop the stepper motor void stopMotor() { digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); Serial.println("Motor stopped."); }

Netlist

  1. Arduino UNO R3 to Breadboard a. Connect the 5V and GND pins from the Arduino to the + and – rails of the breadboard. b. Use jumper wires to extend power across the entire length of the rails.
  2. Soil Moisture Sensor a. Connect the VCC pin of the soil moisture sensor to the + rail on the breadboard. b. Connect the GND pin to the – rail on the breadboard. c. Connect the signal pin to A0 on the Arduino.
  3. Water Pump and Relay Module a. Connect the positive wire of the water pump to the NO (Normally Open) terminal of the relay. b. Connect the COM (Common) terminal of the relay to the + rail of the breadboard (power supply). c. Connect the negative wire of the water pump to the – rail (ground). d. Connect the IN1 pin of the relay to pin 7 on the Arduino. e. Connect VCC and GND of the relay to the + and – rails of the breadboard, respectively.
  4. Water Level Sensor a. Connect the VCC and GND pins to the + and – rails on the breadboard. b. Connect the signal pin to A1 on the Arduino.
  5. LED Indicators (Water Level) a. Place the green, yellow, and red LEDs on the breadboard with their long legs (anodes) connected to digital pins 4, 3, and 2, respectively, via 220-ohm resistors. b. Connect their short legs (cathodes) to the – rail on the breadboard.
  6. Stepper Motor and Driver (ULN2003) a. Connect the motor driver’s IN1, IN2, IN3, and IN4 pins to Arduino digital pins 8, 9, 10, and 11, respectively. b. Connect the driver’s VCC to the + end of the 6V battery pack and GND to its – end.
  7. LDR (Light Sensor) a. Connect one leg of the LDR to the + rail on the breadboard. b. Connect the other leg to A2 on the Arduino and to the – rail via a 10k-ohm resistor.
  8. Power and Ground Connections a. Double-check all VCC and GND connections to ensure the components share a common ground through the breadboard rails to avoid damaging components.
Category: Engineering

Tags



Model origin

The author remixed this model. Imported from Thingiverse.

Differences of the remix compared to the original

Just a base for it.

License