Project 3 – Turtle

Do you know that turtles look for a dark place to rest? Build your turtle and program it so that it will search darkness and stops when it’s all dark!

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

 

DIFFICULTY LEVEL: Intermediate.

EXERCISE DURATION: 45 min.

MATERIALS:

  • Maker Inventor Kit
    • 4in1 main board
    • 2 Light sensors (LDR)
    • Buzzer
    • 2 DC Motors
    • Turtle template
    • Colored sticks
    • Velcro
    • 20cm Wires
    • Battery holder
    • USB wire
  • 6 AA Cells
  • Computer

 

CONSTRUCTION:

Follow video steps to build your turtle:

 

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.

//buzzer
#define BUZZER  9 //buzzer to arduino pin 9

// LIGHT SENSORS
#define LDR0  A0 //Left LDR
#define LDR1  A1 //Right LDR


//MOTORS
//motor A -> Right. Motor B -> Left
int PinSpeedMA = 5, PinSpeedMB = 6; // MOTORS SPEED DIGITAL PINS
int PinTurnMA = 4, PinTurnMB = 7; // MOTORS TURNING SENSE DIGITAL PINS


int SpeedL = 175; // SPEED LEFT
int SpeedR = 175; // SPEED RIGHT

int Spin = 0;
int Direction = 0;
bool Control = true;

//TEST
int leftsensor = 0, rightsensor = 0, us = 0, dataled = 0, databutton = 0;




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

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

void loop()
{
 
  leftsensor = analogRead(LDR0);
  rightsensor = analogRead(LDR1);
 
Spin = analogRead(LDR0) - analogRead(LDR1);
  //Serial.println (Spin);

  if (Spin < abs(70)) { digitalWrite(PinTurnMA, LOW); // sentido HACIA DELANTE digitalWrite(PinTurnMB, LOW); analogWrite(PinSpeedMA, SpeedR); analogWrite(PinSpeedMB, SpeedL); } if (Spin > 71)
  { 
    digitalWrite(PinTurnMA, LOW); // sentido HACIA DERECHA
    digitalWrite(PinTurnMB, HIGH);
    analogWrite(PinSpeedMA, SpeedR);
    analogWrite(PinSpeedMB, SpeedL);
  }
  if (Spin < -71)
  { 
    digitalWrite(PinTurnMA, HIGH); // sentido HACIA IZQUIERDA
    digitalWrite(PinTurnMB, LOW);
    analogWrite(PinSpeedMA, SpeedR);
    analogWrite(PinSpeedMB, SpeedL);
  }
  if ((analogRead(LDR0) < 250) && (analogRead(LDR1) < 250)) {
    digitalWrite(PinTurnMA, LOW); // sentido atrás
    digitalWrite(PinTurnMB, LOW);
    analogWrite(PinSpeedMA, 0);//velocidad cero
    analogWrite(PinSpeedMB, 0);

    tone(BUZZER, 1000);
    delay(200);
    noTone(BUZZER);
    delay(100);
  }
}

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