#include <Stepper.h>
const int stepsPerRevolution = 20;
const int stop = 0;
int echoPin = 4;
int trigPin = 2;
int ldrVal = 0;
const float GAMMA = 0.7;
const float RL10 = 50;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
Stepper stopper(stop, 8, 9, 10, 11);
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(2,OUTPUT);
pinMode(4, INPUT);
myStepper.setSpeed(600);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
float duration_us = pulseIn(echoPin, HIGH);
ldrVal = 0.017 * duration_us;// Read the analog value of the LDR
float voltage = ldrVal / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
if (lux > 200) {
myStepper.step(stepsPerRevolution);
}
else {
stopper.step(stop);
}
}