Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino Nano Controlled Rain-Responsive Stepper Motor System

Image of Arduino Nano Controlled Rain-Responsive Stepper Motor System

Circuit Documentation

Summary

This circuit is designed to control a bipolar stepper motor using an Arduino Nano microcontroller and an A4988 stepper motor driver. The system also includes a rain sensor that, when detecting rain, triggers the stepper motor to move to a sheltered position. The circuit is powered by a 12V battery, which supplies power to the motor driver and, through voltage regulation, to the Arduino Nano and the rain sensor.

Component List

Arduino Nano

  • Microcontroller board based on the ATmega328P
  • It has a variety of digital and analog I/O pins
  • Used for controlling the stepper motor driver and reading the rain sensor

RAIN SENSOR

  • Sensor module for detecting rainwater
  • Outputs an analog signal that can be read by the Arduino Nano

Stepper Motor (Bipolar)

  • A bipolar stepper motor with four wires
  • Controlled by the A4988 stepper motor driver to perform precise movements

A4988 Stepper Motor Driver (Red)

  • A compact driver module for bipolar stepper motors
  • Interfaces with the Arduino Nano to control the stepper motor

Battery 12V

  • A 12V power source
  • Provides power to the stepper motor driver and indirectly to the other components through voltage regulation

Wiring Details

Arduino Nano

  • GND connected to the ground of the rain sensor and the A4988 stepper motor driver
  • D2 connected to the STEP pin of the A4988 stepper motor driver
  • D3 connected to the DIR pin of the A4988 stepper motor driver
  • D4 connected to the ENABLE pin of the A4988 stepper motor driver
  • 5V provides power to the VDD of the A4988 stepper motor driver and VCC of the rain sensor
  • A0 reads the analog output from the rain sensor

RAIN SENSOR

  • AO connected to A0 on the Arduino Nano
  • DO not connected
  • GRD connected to GND on the Arduino Nano
  • VCC connected to 5V on the Arduino Nano

Stepper Motor (Bipolar)

  • D connected to 2B on the A4988 stepper motor driver
  • B connected to 1B on the A4988 stepper motor driver
  • C connected to 2A on the A4988 stepper motor driver
  • A connected to 1A on the A4988 stepper motor driver

A4988 Stepper Motor Driver (Red)

  • ENABLE, MS1, MS2, MS3, RESET, SLEEP not connected or configured for basic operation
  • STEP connected to D2 on the Arduino Nano
  • DIR connected to D3 on the Arduino Nano
  • VMOT connected to + on the battery 12V
  • GND connected to - on the battery 12V and GND on the Arduino Nano
  • 2B, 2A, 1A, 1B connected to the respective wires of the stepper motor
  • VDD connected to 5V on the Arduino Nano

Battery 12V

  • + connected to VMOT on the A4988 stepper motor driver
  • - connected to GND on the A4988 stepper motor driver

Documented Code

#include <AccelStepper.h>

const int rainSensorPin = A0; // Pin connected to the rain sensor
const int threshold = 500;    // Rain detection threshold value
const int stepsPerRevolution = 200; // Steps per revolution of the stepper motor
const int stepsFor5Meter = 10000;   // Adjust this based on your motor and mechanism

AccelStepper stepper(AccelStepper::DRIVER, 2, 3); // Pins connected to step and direction

void setup() {
  pinMode(rainSensorPin, INPUT);
  
  stepper.setMaxSpeed(1000);  // Set maximum speed of the motor
  stepper.setAcceleration(500); // Set acceleration for smooth motion
}

void loop() {
  int sensorValue = analogRead(rainSensorPin); // Read the rain sensor

  if (sensorValue > threshold) { 
    // If rain is detected, move the rack to the sheltered area
    if (stepper.currentPosition() != stepsFor5Meter) {
      stepper.moveTo(stepsFor5Meter); // Move forward to the sheltered area
    }
  } else {
    // If no rain, retract the rack
    if (stepper.currentPosition() != 0) {
      stepper.moveTo(0); // Move back to the original position
    }
  }

  stepper.run();  // Moves the motor to the target position
  delay(1000);    // Delay to reduce noise and avoid false triggering
}

This code is designed to be uploaded to the Arduino Nano. It initializes the stepper motor and rain sensor, then continuously checks the rain sensor's output. If rain is detected, the stepper motor moves to a predefined position. If no rain is detected, it moves back to the starting position. The AccelStepper library is used for smooth acceleration and deceleration of the stepper motor.