Project 2 – Crane

Build a crane capable of raising or lowering depending on the light, and vary its speed by pressing a button.

Inside your kit box you will find all material needed to build this activity. Anyway you can download the template here so you can cut and personalize your crane as many times as you want.

 

DIFFICULTY LEVEL: Intermediate.

EXERCISE DURATION: 45 min.

MATERIALS:

  • Maker Inventor Kit
    • 4in1 main board
    • DC Motor
    • LDR Sensor
    • Switch button
    • Crane template
    • Colored sticks
    • Velcro
    • Flanges
    • Fasteners
    • 20cm Wires
    • Battery holder
    • USB wire
  • Adhesive
  • 6 AA Cells
  • Computer

 

CONSTRUCTION:

Follow video steps to build your crane:

 

SCHEMATIC:

Electronic components should be connected according this diagram:

PROGRAM:

You can load your program to 4in1 main board using block programming or text code. If it’s your first time with 4in1 board or you have any problem connecting it to your computer you can view our first steps document.

Here you find basic blocks program using MBlock software.

In our video you can see how to upload this program to 4in1 board.

 

If you prefer use text code, you can use our basic code for Arduino IDE. Feel free to modify and test.

//Definición de puertos
//PULSADOR
#define BUTTON 2 // pulsador

// SENSOR DE LUZ
#define LDR0  A0 //Sensor de luz


//MOTORES
int PinSpeedMA = 5; // PIN DIGITAL PARA LA VELOCIDAD DEL MOTORE
int PinTurnMA = 4;  // PIN DIGITAL PARA SENTIDO DE GIRO DEL MOTOR
int PinSpeedMB = 6; // PIN DIGITAL PARA LA VELOCIDAD DEL MOTORE
int PinTurnMB = 7;  // PIN DIGITAL PARA SENTIDO DE GIRO DEL MOTOR
int SpeedL = 175; //velocidad Izq
int Spin = 0;
int Direction = 0;
bool Control = true;

//variables de input
int lightsensor = 0,  databutton = 0;

void setup()
{
  Serial.begin (9600);
  //  Sensores de luz
  pinMode(LDR0, INPUT);

    pinMode(PinSpeedMB, OUTPUT);
  pinMode(PinTurnMB, OUTPUT);
  // motores
  pinMode(PinSpeedMA, OUTPUT);
  pinMode(PinTurnMA, OUTPUT);

  // pulsador
  pinMode(BUTTON, INPUT); 
pinMode(PinSpeedMB, 0);
  //pinMode(PinTurnMB, LOW);
}

void loop()
{//lee el estado del sensor y el pulsador y los copia en las variables lightsensor y databutton
  lightsensor = analogRead(LDR0);
  databutton = digitalRead(BUTTON);
    analogWrite (PinSpeedMB, 0);
  
  if (lightsensor < 400)// si el valor de luz es más bajo que 400
  {
    digitalWrite (PinTurnMA, LOW);
  }
  else//si el valor de luz es más alto que 400
  {
    digitalWrite (PinTurnMA, HIGH);
  }
  if (databutton == HIGH)//si el boton está pulsado
  {
    analogWrite (PinSpeedMA, 200);
    analogWrite (PinSpeedMB, 0);
  }
  else// si el botón no está pulsado
  {
    analogWrite (PinSpeedMA, 0);
    analogWrite (PinSpeedMB, 0);
  }
}

And our video showing you how to upload this code uisng Arduino IDE

You can download files for MBlock 5 and ArduinoIDE

FINAL RESULT:
See this project finished and working:

0 0

0