ivanzlatni
Published © LGPL

Baby Merry-Go-Round

This project is saving time for all parents who hate to change batteries or other mechanisms for the merry-go-round above their baby's bed.

BeginnerShowcase (no instructions)1 hour1,888
Baby Merry-Go-Round

Things used in this project

Hardware components

28BYJ-48 Stepper Motor
×1
ULN2003 Driver
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Arduino PINs setup

Standard connection 6 wires pinout:
Digital pins 2,3,4,5
5V
GND

Code

Code for driving the baby marry-go-around

C/C++
Program is choosing the direction of the rotation and then chose a speed (rounds per turn).
#include <Stepper.h>



long randNumberSMER;

// -------------------------STEPPER MOTOR
int bluePin = 2;    //IN1 on the ULN2003 Board, BLUE end of the Blue/Yellow motor coil
int pinkPin = 3;    //IN2 on the ULN2003 Board, PINK end of the Pink/Orange motor coil
int yellowPin = 4;  //IN3 on the ULN2003 Board, YELLOW end of the Blue/Yellow motor coil
int orangePin = 5;  //IN4 on the ULN2003 Board, ORANGE end of the Pink/Orange motor coil

//Keeps track of the current step. 
int currentStep = 0;

//One circle count
int oneCircleNo;



// =====================

void setup(){
  Serial.begin(9600);

// STEPPER MOTOR
  pinMode(bluePin, OUTPUT);
  pinMode(pinkPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(orangePin,OUTPUT);
  
  digitalWrite(bluePin, LOW);
  digitalWrite(pinkPin, LOW);
  digitalWrite(yellowPin, LOW);
  digitalWrite(orangePin, LOW);


}

void loop() {
  // print a random number from 0 to 299
  randNumberSMER = random(100);
  Serial.println(randNumberSMER);  

        if (randNumberSMER > 50){
          damperOpen();
        }
        if (randNumberSMER < 50){
          damperClose();
        }

  delay(1000);
}

void damperOpen(){     // clockwise subroutine 1 turn
      int fullcircleSteps = 2048;
        Serial.println(fullcircleSteps);
      long timeOpen = random(2,10); // chosing the speed
        Serial.println(timeOpen);
          while (fullcircleSteps > 0){
            switch(currentStep){
              case 0:
                digitalWrite(bluePin, HIGH);
                digitalWrite(pinkPin, LOW);
                digitalWrite(yellowPin, LOW);
                digitalWrite(orangePin, LOW);
                break;
              case 1:
                digitalWrite(bluePin, LOW);
                digitalWrite(pinkPin, HIGH);
                digitalWrite(yellowPin, LOW);
                digitalWrite(orangePin, LOW);
                break;
              case 2:
                digitalWrite(bluePin, LOW);
                digitalWrite(pinkPin, LOW);
                digitalWrite(yellowPin, HIGH);
                digitalWrite(orangePin, LOW);
                break;
              case 3:
                digitalWrite(bluePin, LOW);
                digitalWrite(pinkPin, LOW);
                digitalWrite(yellowPin, LOW);
                digitalWrite(orangePin, HIGH);
                break;
            }
          currentStep = (++currentStep < 4) ? currentStep : 0;
          delay(timeOpen);
          fullcircleSteps--;
          }
}

void damperClose(){     // count clockwise subroutine 1 turn
      int fullcircleSteps = 2048;
         Serial.println(fullcircleSteps);
      long timeClose = random(2,10);// chosing the speed
         Serial.println(timeClose);
          while (fullcircleSteps > 0){
            switch(currentStep){
              case 0:
                digitalWrite(bluePin, LOW);
                digitalWrite(pinkPin, LOW);
                digitalWrite(yellowPin, LOW);
                digitalWrite(orangePin, HIGH);
                break;
              case 1:
                digitalWrite(bluePin, LOW);
                digitalWrite(pinkPin, LOW);
                digitalWrite(yellowPin, HIGH);
                digitalWrite(orangePin, LOW);
                break;
              case 2:
                digitalWrite(bluePin, LOW);
                digitalWrite(pinkPin, HIGH);
                digitalWrite(yellowPin, LOW);
                digitalWrite(orangePin, LOW);
                break;
              case 3:
                digitalWrite(bluePin, HIGH);
                digitalWrite(pinkPin, LOW);
                digitalWrite(yellowPin, LOW);
                digitalWrite(orangePin, LOW);
                break;
            }   
          currentStep = (++currentStep < 4) ? currentStep : 0;
          delay(timeClose);            
          fullcircleSteps--;
          }
}

Credits

ivanzlatni

ivanzlatni

1 project • 3 followers

Comments