Ella Suzanne

Documentation site as intern at Fablab in Waag, Amsterdam

MY WEBSITE ABOUT ME VIEW ON GITHUB

BACK TO HOME

Part of Hormao Machine

On this page, I document my process of and research on controlling the movement of motors with light sensors.

COMPONENTS I CAN USE

Servo motors

analog clock making with servo motors: https://electronics-project-hub.com/analog-clock-using-arduino/

NOTES ON SERVO MOTORS

previous work with it documented: https://app.archbee.com/docs/hac8usg8LteFu7mWCOJMo/3i1QbF-wiJoXSA8UivstD

Stepper motors

Stepper motor basics: https://forum.arduino.cc/t/stepper-motor-basics/275223 (not applied to unipolar steppers)

JK42HS40-1704-83AF

Data sheet : https://datasheetspdf.com/pdf/1380131/ETC/JK42HS/1

Someone working with the same and trying to find driver : https://forum.arduino.cc/t/stepper-driver-to-this-stepper-motor/299923

possible drivers:

28BYJ-48

Data sheet : https://www.digikey.nl/en/datasheets/mikroelektronika/mikroelektronika-step-motor-5v-28byj48-datasheet

NOTES ON STEPPER MOTORS

Unipolar:

Bipolar:

Light sensor

Light sensor LM393 9AM

https://www.instructables.com/LDR-Sensor-Module-Users-Manual-V10/

Light sensor TEMT 60000

Stepper motor to Arduino

connecting Stepper motor 28BYJ-48 and driver ULN2003 to Arduino UNO

code: https://soldered.com/learn/how-to-use-stepper-motor-and-uln2003-driver/

/*
*  BYJ48 Stepper motor with the ULN breakout board
*  Connect :
*  IN1 - D8
*  IN2 - D9
*  IN3 - D10
*  IN4 - D11
*  VCC - 5V
*  Gnd - gnd
* 
*  e-radionica.com
*/
#define IN1  8
#define IN2  9
#define IN3  10
#define IN4  11
int koraci = 0;
boolean smjer = true;
unsigned long vrijemeZadnje = 0;    // we will note the time
unsigned long vrijemeTrenutno = 0;  // needed to
unsigned long vrijeme = 0;          // execute the given angle
int koraciPreostalo = 4095; //this stepper has 4095 steps in total
void setup()
{
    Serial.begin(115200);
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);
}
void loop()
{
  while(koraciPreostalo > 0) // steps remaining until the full circle
  {
    vrijemeTrenutno = micros(); //write down the current time in microseconds
    if(vrijemeTrenutno - vrijemeZadnje >= 1000)
    {
      stepper(1); //call the stepper function (check void stepper below)
      vrijeme = vrijeme + micros() - vrijemeZadnje;
      vrijemeZadnje = micros();
      koraciPreostalo--;
    }
   }
   
   Serial.println(vrijeme);
   Serial.println("Wait..!");
   delay(2000);
   smjer = !smjer; // opposite direction
   koraciPreostalo = 4095;  // reset the number of steps
}
void stepper(int brojKoraka)
{
  for (int x=0; x < brojKoraka; x++) { switch(koraci) { case 0: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break; case 1: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, HIGH); break; case 2: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break; case 3: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break; case 4: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 5: digitalWrite(IN1, HIGH); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 6: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 7: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break; default: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; } postaviSmjer(); } } void postaviSmjer() { if(smjer==1){ koraci++; } if(smjer==0){ koraci--; } if(koraci>7){ koraci=0; }
    if(koraci<0){ koraci=7; }
}

1 tooth gear (video of code running with 1 tooth gear)

On how I made this gear, see my gear production page

Light sensor reading serial monitor

https://www.hackster.io/kiranpaul/light-magic-using-lm393-and-arduino-uno-14eadc

giving digital input

void setup() {
  pinMode(7,INPUT);
  /*pinMode(9,OUTPUT); */
  Serial.begin(9600); //initialise serial monitor

}

void loop() {
  int temp=digitalRead(8);      //assign value of LDR sensor to a temporary variable
  Serial.println("Intensity="); //print on serial monitor using ""
  Serial.println(temp);         //display output on serial monitor
  delay(300);
  if(temp==HIGH)               //HIGH means,light got blocked
  digitalWrite(9,HIGH);        //if light is not present,LED on
  else
  digitalWrite(9,LOW);         //if light is present,LED off
}

Light sensor and stepper motor

// Arduino stepper motor and LDR
// based on https://www.instructables.com/Light-Sensor-Stepper-Motor-Arduino/ but with some modifications
#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 LDR = 7;

void setup()

{

Serial.begin(9600);

stepper.setSpeed(200);



pinMode(LDR, INPUT);

}

void loop()

{

int LDRValue = digitalRead(LDR);

Serial.print("sensor = ");

if (LDRValue ==LOW)

{


val = Serial.parseInt();

stepper.step(512);

Serial.println(val);

//for debugging

}

else

{

//digitalWrite(LED, LOW);


}

}

1 tooth gear with light sensor (video of gear running when light is detected, and stops once all light is blocked)

On how I made this gear, see my gear production page

ASSEMBLY:

Stepper 28YJ-48 5 wires to Driver ULN2003

Driver ULN2003 to Arduino UNO

Int1 to pin D8

Int2 to pin D9

Int3 to pin D10

Int4 to pin D11

Ground to pin Ground

Power to pin 5V

LM393 9AM sensor to Arduino UNO

VCC to pin 5V

GROUND to pin Ground

DO to D7