Optic encoded precise step motor (3D printed)
Test code counting steps
Okey so now that we have the optic switch connected to the arduino input D2 and to the 5V supply let's upload the next code and open the serial monitor. Compile and open the serial monitor of the arduino and set the baud rate to 9600.
int sensor = 2;
int steps=0; //initial steps value is 0
int previous_step=0;
void setup() {
pinMode(sensor,INPUT); //define the pin as input
Serial.begin(9600);
}
void loop() {
if (digitalRead(sensor)==0 && previous_step==1)
{
steps=steps+1;
previous_step=0;
Serial.println(steps);
}
if (digitalRead(sensor)==1 && previous_step==0)
{
steps=steps+1;
previous_step=1;
Serial.println(steps);
}
}
Now that we tested the circuit we can build the case of the optic encoded step motor. Let's go to the next page and start the 3D printed case building.
About me
History
Let's learn
Contact us
Arduino tutorials
Circuits tutorials
Robotics tutorials
Q&A
Blog
Arduino
Circuits
Robotics
Modules
Gadgets
Printers
Materials
3D objects
3D edit
Donate
Reviews
Advertising



