Dkovacic74
Published © LGPL

LOL Surprise Doll Hotel Elevator controled by mobile phone

My daughter made three floor hotel for LOL dolls, but wasn’t satisfied with manual elevator. So I automated it.

BeginnerWork in progress3,066
LOL Surprise Doll Hotel Elevator controled by mobile phone

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Stepper Motor, Mini Step
Stepper Motor, Mini Step
×1
Stepper motor driver board A4988
SparkFun Stepper motor driver board A4988
×1
LED (generic)
LED (generic)
×3
Test Connector, Tip Jack
Test Connector, Tip Jack
×3
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1

Software apps and online services

Arduino IDE
Arduino IDE
MIT app inventor

Story

Read more

Schematics

shema_elevator-edit2_wKOwas79d5.png

Code

sketch_nov16b.ino

Arduino
#include <SoftwareSerial.h>

// define pin input and outputs
#define buttonFlor1 2
#define buttonFlor2 3
#define buttonFlor3 4
#define LEDFlor1 5
#define LEDFlor2 6
#define LEDFlor3 7
#define dirPin 8
#define stepPin 9
#define TxD 10
#define RxD 11
#define stepsPerRevolution 200
#define speed 2000 // in fact us delay between stepper pulses, higher number, slower speed
int position = 0; //current position of elevator
int newPosition = 0;
int positionFlor1 = 0;
int positionFlor2 = 860;
int positionFlor3 = 1720;
int z; 

SoftwareSerial bluetoothSerial(TxD, RxD);
char c;

void setup() {
  // put your setup code here, to run once:
pinMode (buttonFlor1, INPUT);
pinMode (buttonFlor2, INPUT);
pinMode (buttonFlor3, INPUT);
pinMode (LEDFlor1, OUTPUT);
pinMode (LEDFlor2, OUTPUT);
pinMode (LEDFlor3, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);

bluetoothSerial.begin(9600);
Serial.begin(9600);


// Testing LEDs - turn on/off leds 1,2,3
 digitalWrite(LEDFlor1, HIGH);
    delay(1000);
    digitalWrite(LEDFlor1, LOW);
digitalWrite(LEDFlor2, HIGH);
    delay(1000);
    digitalWrite(LEDFlor2, LOW);
digitalWrite(LEDFlor3, HIGH);
    delay(1000);
    digitalWrite(LEDFlor3, LOW);

// Testing steppeer motor - one circle clockwise, one circle counterlockwise
  digitalWrite(dirPin, LOW);
  for (int i = 0; i < stepsPerRevolution; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(speed);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(speed);
  }
  
  digitalWrite(dirPin, HIGH);
  for (int i = 0; i < stepsPerRevolution; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(speed);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(speed);
    }
// set zero position
position = 0;
digitalWrite(LEDFlor1, HIGH);
}

int GoToFlor1(int position, int positionFlor1) {
  //Turn off all LEDs
   digitalWrite(LEDFlor1, LOW);
   digitalWrite(LEDFlor2, LOW);
   digitalWrite(LEDFlor3, LOW);
   
  if (position < positionFlor1) {
  digitalWrite(dirPin, LOW); //define direction CV
     for (int i = position; i < positionFlor1; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(speed);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(speed);
    }
  }
  
  else    {
  digitalWrite(dirPin, HIGH); //define direction CCV
  z=(position-positionFlor1)/7;
  
     for (int i = positionFlor1; i < position; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(speed);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(speed);

 if (i>(positionFlor1+z)){
     digitalWrite(LEDFlor1, HIGH); 
    }
     if (i>(positionFlor1+(2*z))){
     digitalWrite(LEDFlor1, LOW); 
    }
      if (i>(positionFlor1+(3*z))){
     digitalWrite(LEDFlor1, HIGH); 
    }
       if (i>(positionFlor1+(4*z))){
     digitalWrite(LEDFlor1, LOW); 
    }
       if (i>(positionFlor1+(5*z))){
     digitalWrite(LEDFlor1, HIGH); 
    }       
      if (i>(positionFlor1+(6*z))){
     digitalWrite(LEDFlor1, LOW); 
    }



    
    }
  }
 
 //Turn on LEDFlor1
 digitalWrite(LEDFlor1, HIGH);

// Set new position
return positionFlor1;

}


int GoToFlor2(int position, int positionFlor2) {
  //Turn off all LEDs
   digitalWrite(LEDFlor1, LOW);
   digitalWrite(LEDFlor2, LOW);
   digitalWrite(LEDFlor3, LOW);
  
    
  if (position < positionFlor2) {
  z=(positionFlor2-position)/7;
  digitalWrite(dirPin, LOW); //define direction CV
     for (int i = position; i < positionFlor2; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(speed);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(speed);

    if (i>z){
     digitalWrite(LEDFlor2, HIGH); 
    }
     if (i>2*z){
     digitalWrite(LEDFlor2, LOW); 
    }
      if (i>3*z){
     digitalWrite(LEDFlor2, HIGH); 
    }
       if (i>4*z){
     digitalWrite(LEDFlor2, LOW); 
    }
       if (i>5*z){
     digitalWrite(LEDFlor2, HIGH); 
    }       
      if (i>6*z){
     digitalWrite(LEDFlor2, LOW); 
    }
   
    }
  }
  
  else    {
  digitalWrite(dirPin, HIGH); //define direction CCV
     z=(position-positionFlor2)/7;
     
     for (int i = positionFlor2; i < position; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(speed);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(speed);
    
    if (i>(positionFlor2+z)){
     digitalWrite(LEDFlor2, HIGH); 
    }
     if (i>(positionFlor2+(2*z))){
     digitalWrite(LEDFlor2, LOW); 
    }
      if (i>(positionFlor2+(3*z))){
     digitalWrite(LEDFlor2, HIGH); 
    }
       if (i>(positionFlor2+(4*z))){
     digitalWrite(LEDFlor2, LOW); 
    }
       if (i>(positionFlor2+(5*z))){
     digitalWrite(LEDFlor2, HIGH); 
    }       
      if (i>(positionFlor2+(6*z))){
     digitalWrite(LEDFlor2, LOW); 
    }
    
    }
  }
 
 //Turn on LEDFlor2
 digitalWrite(LEDFlor2, HIGH);
 

// Set new position
return positionFlor2;

}

int GoToFlor3(int position, int positionFlor3) {
  //Turn off all LEDs
   digitalWrite(LEDFlor1, LOW);
   digitalWrite(LEDFlor2, LOW);
   digitalWrite(LEDFlor3, LOW);
   
  if (position < positionFlor3) {
  
   z=(positionFlor3-position)/7;
  

   
  digitalWrite(dirPin, LOW); //define direction CV
     for (int i = position; i < positionFlor3; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(speed);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(speed);

  if (i>(position+z)){
     digitalWrite(LEDFlor3, HIGH); 
    }
     if (i>(position+(2*z))){
     digitalWrite(LEDFlor3, LOW); 
    }
      if (i>(position+(3*z))){
     digitalWrite(LEDFlor3, HIGH); 
    }
       if (i>(position+(4*z))){
     digitalWrite(LEDFlor3, LOW); 
    }
       if (i>(position+(5*z))){
     digitalWrite(LEDFlor3, HIGH); 
    }       
      if (i>(position+(6*z))){
     digitalWrite(LEDFlor3, LOW); 
    }

   
    }
  }
  
  else    {
  digitalWrite(dirPin, HIGH); //define direction CCV
     for (int i = positionFlor3; i < position; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(speed);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(speed);
    }
  }
 
 //Turn on LEDFlor3
 digitalWrite(LEDFlor3, HIGH);
 

// Set new position
return positionFlor3;

}

void loop() {
  // Check calls for elevator
int CallFlor1 = digitalRead(buttonFlor1);
int CallFlor2 = digitalRead(buttonFlor2);
int CallFlor3 = digitalRead(buttonFlor3);

  if (bluetoothSerial.available()){
    c = bluetoothSerial.read();
    if (c == '1'){
      newPosition = GoToFlor1(position, positionFlor1);
      position = newPosition;
    }
    if (c == '2'){
      newPosition = GoToFlor2(position, positionFlor2);
      position = newPosition;
    }
    if (c == '3'){
      newPosition = GoToFlor3(position, positionFlor3);
      position = newPosition;
    }
    
  }


  if (CallFlor1 == HIGH) {
  newPosition = GoToFlor1(position, positionFlor1);
  position = newPosition;
  }

    if (CallFlor2 == HIGH) {
  newPosition = GoToFlor2(position, positionFlor2);
  position = newPosition;
  }

    if (CallFlor3 == HIGH) {
  newPosition = GoToFlor3(position, positionFlor3);
  position = newPosition;
  }
}

Credits

Dkovacic74
0 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.