Arduino Light Sensitive Stepper Motor

7,068

37

10

Introduction: Arduino Light Sensitive Stepper Motor

About: I like finding new uses for things, making things, and improving things. I'm a student who is currently looking for a better job, one where I can make an actual difference.

I've come up with a simple way to make a stepper motor move from one position to another based on the lighting in a room. Using a handful of basic components I had lying around, no need for fancy motor / stepper shields. This setup could be used to automate blinds, so they open and close based on ambient light. The code allows you to edit amount of steps in either direction and sensitivity to light. I've also wrote in code to turn off the stepper once it is done moving. The components required are : Arduino board with 4 digital outputs and 1 analog input, 4x general purpose npn transistors, 4x 1k resistors,10k resistor, light dependent resistor (LDR),12volt stepper motor,12 volt power supply, 5 volt power supply for the arduino, I used a 7805 5 volt regulator for this.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Code

This code steps the motor 150 steps clockwise when it gets dark, then steps the motor counterclockwise 150 steps once it detects light again. The amount of steps, speed, and light sensitivity are all easily adjustable. Make sure to enter how many steps your motor has where it says define steps (mine had 48). Also I used a 5 wire 12v motor where one wire always received positive voltage, and the other four wires were grounded in sequence to turn the motor.

Be the First to Share

    Recommendations

    • Arduino Contest 2020

      Arduino Contest 2020
    • First Time Author Contest

      First Time Author Contest
    • Space Challenge

      Space Challenge

    10 Discussions

    0
    AlinaD12
    AlinaD12

    3 years ago

    hello friend. i tried this code and doesnt work,it just sping clockwise 150 step in a loop. i want to use this stepper(28byj-48) to open blinds when it is light on ldr and close them when is no light outside.please help

    0
    czopek12
    czopek12

    Reply 2 months ago

    It's seems to missing { } in 'if' function, I added this and everythings works fine

    CODE for 28BYJ-48 with ULN2003:
    #include
    #define STEPS 32
    Stepper stepper (STEPS, 8, 10, 9, 11);
    int state = 1;
    void setup() {
    stepper.setSpeed (900);
    pinMode (0,INPUT);
    int ldr = 0;
    Serial.begin (9600);
    }
    void loop(){
    int ldr = analogRead (0);
    Serial.println(state);
    if ( state<2 && ldr>750 ){
    stepper.step(2048);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
    digitalWrite(11,LOW);
    delay(1000);
    }
    if ( ldr>750 ) {
    state = 5;
    Serial.println(state);
    }
    if ( state>2 && ldr<750 ) {
    stepper.step(-2048);
    digitalWrite(8,LOW);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);
    digitalWrite(11,LOW);
    delay(1000);
    }
    if ( ldr<750 ) {
    state = 1;
    Serial.println(state);
    delay(1000);
    }
    }

    0
    SalumuD
    SalumuD

    11 months ago

    making a solar tracker using arduino mega 2560 ,8ldrs and 2 stepper motors want some help please

    0
    DomineA
    DomineA

    1 year ago on Introduction

    hi i am domine . i need your help guys. i wannt to program automatic window blinds using 2 ldr inside and out and stepper motor. I Really need it for my project.

    0
    AlejandroR68
    AlejandroR68

    4 years ago

    what are the NPN transistors you used? specifically

    0
    Khaleel123
    Khaleel123

    Reply 4 years ago

    I used 2n5190 npn transistors in my final build, but on the breadboard I think those are tip120 npn transistors. Any similar npn transistor should work fine.

    0
    inovation
    inovation

    Reply 3 years ago

    Hi Khaleel,

    I've sent you a direct e-mail, but it seems you did not get it.

    can you please provide the full schematic for the LDR Sensitive Stepper? i did not knot where to connect the motor. My e-mail is: oraby2014@icloud.com. Thanks in advance.

    0
    Khaleel123
    Khaleel123

    Reply 3 years ago

    I don't recall seeing the previous message, I also don't receive email updates on comments made on instructables. I think it has something to do with my email server or something. The schematic posted in the instructable is the full schematic I used. I used a stepper motor with 5 wires, one of those is a common for all 4 coils inside the stepper. I used a multimeter in ohms to figure out which wire is the common one. Then used a small 12 volt wall adapter, to provide momentary power to each coil. This gave me an idea as to what the sequence is for the coils to properly step either forward or backward. Of course you can avoid all of this extra testing if you already have a pinout for your stepper motor. This shematic only works for unipolar 5 lead stepper motors.

    0
    inovation
    inovation

    Reply 3 years ago

    Hi Khaleel,

    Thank you much for the reply. I wanted to know where did you connect the motor's four (4) wires on the schematic? It is not shown on the schematic. Did you connect them at the diode's Emitter?

    0
    Khaleel123
    Khaleel123

    Reply 3 years ago

    The connection from the arduino digital pin goes into a 1k resistor and that connects to the base of the general purpose npn transistor. The emitter on the transistor is connected to ground and the collector is connected to the stepper motor. Hope this helps.