Introduction: Light Sensor Stepper Motor Arduino
Mechatronics class project
Step 1: Light Sensor Stepper Motor Arduino
Step 2: Plug in Your Stepper to the Stepper Driver
IN1 to Arduino pin 11
IN2 to Arduino pin 10
IN3 to Arduino pin 9
IN 4 to Arduino pin 8
Step 3: Photo Resistor to A0
One side of Photo resistor to 5v
Other side of Photo resistor to A0 on Arduino
Resistor from ground ALSO to A0 (I used 1k)
Step 4: Power Stepper Driver
The breadboard helped me jump 5v to photoresistor & stepper driver (Brown wire NOT used)
Step 5: Yup Light
LED positive to Arduino pin 7
ground on one side of 1k resistor to LED negative (Flat side) on the other
Step 6: Code :)
// Arduino stepper motor control code
#include <Stepper.h>
// Include the header file
// change this to the number of steps on your motor
#define STEPS 32
// create an instance of the stepper class using the steps and pins
Stepper stepper(STEPS, 8, 10, 9, 11);
int val = 0;
int LED = 7;
int LDR = A0;
void setup()
{
Serial.begin(9600);
stepper.setSpeed(200);
pinMode(LED, OUTPUT);
pinMode(LDR, INPUT);
}
void loop()
{
int LDRValue = analogRead(LDR);
Serial.print("sensor = ");
if (LDRValue <=100)
{
digitalWrite(LED, HIGH);
val = Serial.parseInt();
stepper.step(512);
Serial.println(val);
//for debugging
}
else
{
digitalWrite(LED, LOW);
}
}
Step 7: Special Thanks!
-Aswinth Raj
https://circuitdigest.com/microcontroller-projects...
The difference maker in putting this together!
-IoT Solutions
This gave me some key elements to roll
Comments
2 years ago
Thanks for sharing :)