Light Sensor Stepper Motor Arduino
by andre1jr in Circuits > Arduino
5311 Views, 4 Favorites, 0 Comments
Light Sensor Stepper Motor Arduino
Mechatronics class project
Light Sensor Stepper Motor Arduino
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
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)
Power Stepper Driver
The breadboard helped me jump 5v to photoresistor & stepper driver (Brown wire NOT used)
Yup Light
LED positive to Arduino pin 7
ground on one side of 1k resistor to LED negative (Flat side) on the other
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);
}
}
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