Hi guys, I'm gonna make a stepper motor that saves the the step where the light is the most powerfull and then returns to that step ( position ).

So it's like an light analyzer.

The stepper motor gets 360 degres and create a maximum light intensity, then after he rotates another -360 degres ( to the start position ) he rotates n steps and gets to the position where the light intenisity was maximum.

## Step 1: Parts:

Things you need :
*Arduino Uno

http://www.gearbest.com/development-boards/pp_6297...

*Light sensor

* Stepper Motor with Driver ( I use KYES MOTOR set )

http://www.gearbest.com/other-accessories/pp_22727...

*Straw

OPTIONAL ( LCD )

http://www.gearbest.com/other-accessories/pp_216639.html?vip=1131775

## Step 2: Conections:

Connect the Motor Drivers like this:

VCC - 5v

GND - GND

INA - 8

INB - 9

INC - 10

IND - 11

Connect the light sensor :

VCC - 3v

GND - GND

OUT - A0

Add a straw on top the motor and attach to the straw a light sensor.

Note:

The straw is optional, you can use something else if you have, a wheel, etc...

## Step 3: CODE:

THE CODE IS NOW IN ENGLISH ! (UPDATE)

( I AM USING AN OPTIONA 16x2 LCD )

#include LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int motorPin1 = 8;

int motorPin2 = 9;

int motorPin3 = 10; int motorPin4 = 11;

int delayTime = 2;

// min = 2;

int const steps = 510; // 510 steps = 360 degrees (for my motor)

float x;

int valoareIluminare;

void setup() { lcd.begin(16, 2); pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); Serial.begin(9600); pinMode(13, OUTPUT); }

void rotate_clock() (360grade); [x - nr steps] {clockwise} { digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime);

} void rotate_couterclock() { digitalWrite(motorPin4, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, LOW); delay(delayTime); digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, LOW); delay(delayTime); digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin1, LOW); delay(delayTime); digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, HIGH); delay(delayTime);

} int pas,maxim=0,initializare=1;; void inita() { digitalWrite(13, HIGH); lcd.print("INIT - 1/2..."); initializare=0; x = steps; while(x > 0) { rotate_clock(); valoareIluminare = analogRead(0);delay(2); if(valoareIluminare > maxim) { maxim = valoareIluminare; pas = x; // salveaza la 'pas' pasum maximei intensitati; } x--; } delay(100); lcd.clear(); lcd.print("INIT - 2/2..."); while(x < steps) // se intoarce inapoi in poz 0; { rotate_couterclock(); x++; } lcd.clear(); lcd.print("INIT - DONE!"); lcd.setCursor(0,1); lcd.print(maxim); lcd.setCursor(9,1); lcd.print(pas); } void loop() { if(initializare == 1) { inita(); delay (100); x=0; while(x < pas) { rotate_clock(); x++; } digitalWrite(13, LOW); } } /* LCD : lcd.setCursor(0, 1); lcd.print(millis() / 1000); * */

Any chance of releasing the code in English? Won't compile on my English system and I can't read the notes. Thanks.
<p>Sure, I will replace it in a few minutes.</p>
<p>I have that same stepper with a driver board, but the one you bought is quite nifty with the motor on the PCB :-)<br>Nice project</p>
<p>Thank you,</p><p>My motor is going pretty fast for ~4\$.</p><p>I will make more soon.</p>
<p>yes, nifty little steppers :-)</p>
<p>I see that you have entered a contest. I tried your code and did not get it to compile. Perhaps check this to get votes. Then add as file just as you add photos.</p>
<p>Hi, i uploaded the code, thank you for the idea /w file.</p>