Light Controlled Stepper Motor + Wall Bracket/Stand

This stand is used to house an Arduino controlled stepper motor, designed to automatically control a curtain according to the light level in the room. You can also add an LCD screen to print the light level. The 3D gear is only for demonstration, a real gear may be needed for practical application such as the curtain but also any other application you can think of.

Step 1: Ingredients

To start this project you will need;

- 2 Arduino chip-sets
- An Arduino motor shield
- An Arduino LCD Screen
- 1 Breadboard
- 1 bi-polar Stepper Motor
- 1 D battery
- 1 Light Dependent Resistor
- 1 10k Ω Resistor
- 10 Male-male wires
- 6 Male-female wires
- Access to a 3D printer

Step 2: Construction of Arduino

First line up the motor shield with the Arduino pins and once they're lined up, place it down firmly.
Next attach the stepper motor's wires into pins 8, 9, 10 and 11 of the motor shield.
After that connect the D battery in the slots as shown in the diagram.
Next you will want to get the 6 wires (male to female) for the LCD screen and plug them into the other Arduino unit as shown in the circuit diagram.
Then set up the LDR as shown above, with the resistor connecting to the the negative row.
When adding the LDR, on the side with the resistor, add the A0 connections and on the opposite side, add 1 5V input for each board you are using, so if you are using 2 boards, you will want each of them to have a 5V and A0 pin going to the LDR.

Connect all wires so it is the same as the diagram
- 2 Inputs to the LDR
- 2 Outputs from the LDR and a resistor connecting to ground
- 8 wires to the LCD, 1 5V, 1 Ground and 6 inputs
- 4 wires connecting to the stepper
- 2 connections to the battery
- The breadboard ground should be connected

Step 3: Coding Arduino

Here is some sample code to change the status of the gear based on the LDR

This is the code that would allow the project to automatically control a curtain. The photo above explains the different paths through the nested IF statements in terms of the curtain going up, down or staying where it is. (click on the image to see it in full as there are formatting issues)

#defineLDRA0//Defines variable "LDR" to A0 pin
#include
<Stepper.h>//Includes the stepper motor code

constintstepsPerRevolution=200;//When the stepper motor is activated, its full rotation is equal to 200 steps

SteppermyStepper(stepsPerRevolution,8,9,10,11);//Defines the input to the the stepper as pins 8,9,10,11

voidsetup(){myStepper.setSpeed(60);//Sets how fast the motor does a rotation
pinMode(LDR,INPUT);//Defines variable "LDR" as an input
Serial.begin(9600);//Starts a serial reading}

voidloop(){intlightlevel=analogRead(LDR);//Defines the variable "lightlevel" as an action that reads the value of "LDR"Serial.print("Light Level: ");
Serial.println(lightlevel);// Prints the value of "lightlevel" with the caption above

/* There is now a loop which detects the light level at every point of the way
* 3 options are available, go up, go down, stay in the same position
* It is designed so that if the lightlevel stays the same, it will stay the same, if not it will change

* i.e. if it is 950, then goes to 952, nothing will happen, however if it went from 950 to 600 it would pull the curtain up and vise versa

* Each step is signified by a letter in front of the step to track where it is at in the loop through the serial monitor */

if(lightlevel>=900){
Serial.println("A");// Which step it is in the loop
myStepper.step(3*stepsPerRevolution);//The stepper makes 3 forward revolutions. If it's negative, it goes backwards
delay
(30000);// Leaves it there for 5 mins
intlightlevel=analogRead(LDR);// Defines the varible "lightlevel" as the latest reading from the LDRSerial.print("Light Level: ");//Prints the text in front of the variable
Serial
.println(lightlevel)// Prints the value of the light level

if(lightlevel>=900){
Serial.println("B");
myStepper.step(0);
delay(10000);
intlightlevel=analogRead(LDR);
Serial.print("Light Level: ");
Serial.println(lightlevel);

if(lightlevel>=900){
Serial
.println("C");
myStepper.step(3*-stepsPerRevolution);
delay(500);
int
lightlevel=analogRead(LDR);
Serial
.print("Light Level: ");
Serial.println(lightlevel);}

else{
Serial
.println("D");
myStepper.step(3*-stepsPerRevolution);
delay(10000);
intlightlevel=analogRead(LDR);
Serial
.print("Light Level: ");
Serial.println(lightlevel);
}

}

else{
Serial.println("E");
myStepper.step(3*-stepsPerRevolution);
delay(10000);
intlightlevel=analogRead(LDR);
Serial.print("Light Level: ");
Serial.println(lightlevel);

if(lightlevel>=900){
Serial
.println("F");
myStepper
.step(0);
delay(500);
intlightlevel=analogRead(LDR);
Serial.print("Light Level: ");
Serial.println(lightlevel);}

else{
Serial.println("G");
myStepper.step(0);
delay(10000);
intlightlevel=analogRead(LDR);
Serial.print("Light Level: ");
Serial.println(lightlevel);
}
}

}

else{
Serial.println("H");
myStepper
.step(0);
delay(10000);
intlightlevel=analogRead(LDR);
Serial.print("Light Level: ");
Serial.println(lightlevel);

if(lightlevel>=900){
Serial
.println("I");
myStepper.step(3*stepsPerRevolution);
delay(10000);
int
lightlevel=analogRead(LDR);
Serial
.print("Light Level: ");
Serial.println(lightlevel);

if(lightlevel>=900){
Serial
.println("J");
myStepper.step(3*-stepsPerRevolution);
delay(500);
intlightlevel=analogRead(LDR);
Serial.print("Light Level: ");
Serial.println(lightlevel);
}

else{
Serial.println("K");
myStepper.step(3*-stepsPerRevolution);
delay(10000);
intlightlevel=analogRead(LDR);
Serial.print("Light Level: ");
Serial.println(lightlevel);

}
}

else{
Serial.println("L");
myStepper
.step(0);
delay(10000);
intlightlevel=analogRead(LDR);
Serial
.print("Light Level: ");
Serial.println(lightlevel);

if(lightlevel>=900){
Serial.println("M");
myStepper.step(0);
delay(500);
intlightlevel=analogRead(LDR);
Serial
.print("Light Level: ");
Serial.println(lightlevel);
}

else{
Serial.println("N");
myStepper.step(0);
delay(10000);
intlightlevel=analogRead(LDR);
Serial.print("Light Level: ");
Serial.println(lightlevel);

}
}

}

}

Step 4: Optional: LCD Screen

This would print the light level detected by the LDR on the LCD screen.

#include <LiquidCrystal.h> //Adds the liquid crystal library with additional code
#define ldr A0 //Defines the variable "ldr" to the A0 pin

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // initialize the library with the numbers of the interface pins

voidsetup() { //code that runs once at the start
lcd.begin(16, 2); // set up the LCD's number of columns and lines respectively
pinMode(ldr, INPUT); // Defines the ldr as an input pin
Serial.begin(9600); // Starts communication with the serial monitor

}

voidloop() { //code that will be repeated continuously
Serial.println(analogRead(ldr)); // Prints the reading the ldr picks up (a number between 0-1023) on the serial monitor
lcd.setCursor(6, 0); // set the cursor to column 6, line 0
lcd.print(analogRead(ldr)); // Prints this reading on the LCD screen
delay
(1000); // Delays the next command for one second

}

Step 5: Printed Parts

Use the following files to print the stand and gear. You can customize the gear for your own purposes and you can use the bracket to mount it on a wall or as a display. As the 3D gear is weak, a real gear may be used as a substitute for it as long as it matches the curtain it would control.

If the 3D printed gear is going to be used, one of the gear's teeth has been removed so that a set screw could fix it to the motor.

The front 2 legs of the wall bracket can also be removed if it were to be mounted to a wall. They were only added so it would stand up while we were testing with it.

Step 6: Placement

Now that all the parts are ready, it is time to start the final placement.

Firstly, place the stepper motor into the provided box on the stand and put the gear on the axle
Next, move the wires so they are going behind the stand
Finally, place the arduino and battery behind the stand

Your board should now look like the one pictured above.

Congratulations!

The gear may be used for automated curtains or any other thing you want controlled by the LDR.

You are done. Enjoy your new creation.

Share

    Recommendations

    • Toys Contest

      Toys Contest
    • PCB Contest

      PCB Contest
    • First Time Author

      First Time Author

    2 Discussions

    0
    None
    54534

    23 days ago

    Great project!

    1
    None

    Great first Instructable. Thanks for sharing with the community.