Introduction: MMR: Magnetic Motion Robot

About: IT Teacher (Andalucía, Spain)

Magnetic Motion Robot (MMR) is a DIY STEAM education robot thinked to build children’s interest in science and cultivate their essential skills of coding using mBlock

MMR is an original robot can only move in a ferromagnetic surface using eletromagnets.

Equipped with an IR sensor, a line follower sensor or a buzzer, MMR could be a treasure trove of fun with easy coding, empowering children with the skills to turn their imagination into reality and experience the delight out of their achievement.

Using Makeblock, programming is as simple as assembling building blocks.

I hope you like.

Supplies

  • Arduino NANO
  • (2) micro servos
  • (3) electromagnets
  • (1) IR sensor
  • (1) buzzer
  • (1) led strip
  • (1) step up boost converter (DC-DC) (MT3608)
  • (1) micro USB battery charger
  • (1) 3,7V battery 1800 mah
  • Magnetic board
  • Plywood
  • Plastic Ball
  • Wires

Step 1: Cutting the Plywood Base and Installing the Servos

  • Cutting a circular plywood base (9 centimeters diameter)
  • Open two holes to install the servos with screws and hot silicone
  • The initial angle of the servos in the position you see in the picture is 90º
  • Open a little hole to install the main switch

Step 2: Install the Arduino Board and the Power Supply

  • In the first image you can see the arduino board installed, the boost step up converter, the two servos, the main switch and two connection terminals
  • In the other side of the plywood base, in the second image, you can see the micro USB charger installed and a piece of wood where one of the electromagnet will be installed.

Step 3: Installing the Electromagnets

  • Cut two pieces of plywood and open two holes on each piece as you can see in the first image
  • One of the hole will be used to fix the electromagnet as you can see in the first image
  • The other hole will be used to fix the electromagnet and the piece of plywood to the servo
  • In the second image you can see two terminal connections (5V and ground) for the three electromagnets

Step 4: Installing the LED Strip and the IR Receiver

  • Glue a LED strip in a plastic half sphere over 9 centimeters diameter (14 leds in this robot)
  • Open three littles holes in the plastic to install the IR receiver as you can see in the second image

Step 5: Installing the Buzzer and the Battery

  • Connect the buzzer to the ARDUINO board
  • Fix the battery over both servos as you can see in the image
  • Fix the half sphere to the plywood base

Step 6: Installing the Line Follower Sensor

To install the line follower sensor I have used a little piece of 2 millimeters wire and I have opened a little hole in the plywood base to place the sensor.

The three needed wires (5V, GROUND and data) are all connected out of the plastic ball

Step 7: Fritzing Circuit and MMR Pinout

  • Pin #2: LED strip
  • Pin #3: IR receiver
  • Pin #4: Right servo
  • Pin #5: Left servo
  • Pin #6: Buzzer
  • Pin #7: Left electromagnet
  • Pin #8: Right electromagnet
  • Pin #9: Center electromagnet
  • Pin #10: Line follower

Step 8: MBlock 3 and MBlock 5 Extensions

To code the robot, I have created and published a mBlock 5 (first image) and a mBlock 3 (second image) extensions called Magnetic Robot.

Both extensions have the following blocks:

  • initialize MMR block. Initialize the Magnetic Motion Robot. Include in the code all the declarations needed the robot works. Include the following code:
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
extern void playTone (unsigned int pinnumber, unsigned int toneHrz, unsigned long beat);
#include <servo.h>
#include "Adafruit_NeoPixel.h"
#include "IRremoteExt.h"
#include "pinOut.h"
double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
Servo servo_1;
Servo servo_2;
Adafruit_NeoPixel Strip_1 = Adafruit_NeoPixel(NUMLEDS, PINLEDSTRIP, NEO_GRB + NEO_KHZ800);
void setup(){    
    pinMode(PINLELECTROMAGNET,OUTPUT);
    pinMode(PINCELECTROMAGNET,OUTPUT);
    pinMode(PINRELECTROMAGNET,OUTPUT);
    pinMode(PINLINEF,INPUT);
    pinMode(PINIRREMOTE,INPUT);
    pinMode(PINBUZZER,OUTPUT);
    servo_1.attach(PINLSERVO);
    servo_1.write(OFFSET);
    servo_2.attach(PINRSERVO);
    servo_2.write(OFFSET);
    Strip_1.begin();
    Strip_1.show();
    beginIRremote(PINIRREMOTE);
}
  • set led strip color to R [number_1 ]G [number_2] B [number_3] block. The led strip lights up the specified RGB color.
  • set led strip LED [index] color to R [number_1] G [number_2] B [number_3] block. The specified LED [index] in the led strip lights up the specified RGB color.
  • show led strip block. It shows the lighting changes in the led strip.
  • is remote [key] pressed block. It is a boolean block that returns true if the specified [key] has been pressed on a remote IR control and received by the robot.
  • set leftservo/rightservo angle as [angle] blocks. Set the position of the right or left servo to [angle]
  • move [steps] steps [millisecs] millisecs angle [angle] block. The MMR will move forward or backward [steps] steps. The millisecs between steps are [millisecs], so it is the movement velocity. The position of the electromagnet during the steps is the angle [angle], so it will determinate if MMR goes forward (positive angle) or backward (negative angle).
  • turnRight/turnLeft [steps] steps [millisecs] millisecs angle [angle] blocks. The MMR will move to left or right [steps] steps. The millisecs between steps are [millisecs], so it is the movement velocity. The angle when the MMR goes right or left is [angle]. Again, if the angle is positive the MMR will move forward and backward if it is negative.
  • play tone on note [note] during [number_1] millisecs block. The buzzer will play the specified [note] during [number_1] milliseconds.
  • set rightEM/leftEM/centerEM output as [HIGH/LOW] block. Set the specified electromagnet to HIGH (magnet) or LOW (not magnet)

Step 9: Adding the Extensions

To add the mBlock 5 extension (first image), you have to do the following:

  1. Download and install mBlock 5
  2. Add an "Arduino Nano" device from the device library
  3. Add a new extension from the extension center. Search for "Magnetic Robot"

To add the mBlock 3 extension (second image), you have to do the following:

  1. Download and install mBlock 3
  2. Select "Arduino Nano (mega 328)" options from "Boards"
  3. Select "Manage Extensions" options from "Extensions"
  4. Search for "Magnetic Robot"

Step 10: How MMR Moves

The code “DemoCircularMovement.sb2” is an example how the MMR describes a closed square trajectory.

The code is very simple as you can see in the image:

  • Initialize the Magnetic Motion Robot (MMR).
  • The block "forever" (loop in the Arduino code)
  • Initialize the velocity variable to 150 (time between each MMR step 150 millisecs)
  • The block "forever" (loop in the Arduino code).
  • Basically the MMR describes a clockwise closed square trajectory using the “move” and “turnRight” blocks.

We could propose the kids the following simples activities to code the MMR:

  • Code the MMR to describe an anticlockwise closed square trajectory faster than the example above.
  • Code the MMR to describe a clockwise closed circular trajectory

In the following video you can see a demo how the MMR moves

Step 11: How to Use the Buzzer (Several Film Themes Examples)

To learn how to use the buzzer, I have coded the DemoBuzzer.sb2 (Star Wars Imperial March) project.

The code is very simple as you can see in the image:

  • Initialize the Magnetic Motion Robot (MMR).
  • The block "forever" (loop in the Arduino code).
  • The code block “play tone”, plays the specified note during a specified interval in milliseconds.

We could propose the kids the following simples activities to code the MMR:

  • Search for the Star Wars Theme and code a project to play it.

In the following video you can see a demo of the buzzer (Game of Thrones)

Step 12: How to Use the LED Strip

To learn how to use the LED Strip, I have coded the DemoLedStrip.sb2 project.

The code is very simple as you can see in the image:

  • Initialize the Magnetic Motion Robot (MMR).
  • The block "forever" (loop in the Arduino code)
  • The code switch on (blue, red and green) the LED strip during one second.
  • Observe the code use the “set led_strip color to RGB” block that sets the LED strip to a specific RGB color in one sentence and the “set led_strip LED index to RGB” block that only change a specific LED to a specific RGB color. So, in the last case, we have to use a repeat block to switch on the LED strip.
  • Observe too, that only in the last case we have to use a “show led_strip” block to view the effects in the LED strip.

We could propose the kids the following simples activities to code the MMR:

  1. Switch on the LED #1 (red), waits 1 second, switch off the same LED and waits 1 second
  2. Switch on the LED #1 and #2 (red), waits 1 second, switch off the same LEDs
  3. Switch on the LED #1 (red) and #2 (blue), waits 1 second, switch off the same LEDs and waits 1 second
  4. Switch on LED´s from #1 to #10 (green), waits 1 second, switch off all the LED´s and waits 1 second
In the following video you can see a demo using the LED strip

Step 13: How to Control MMR (IR Remote Receiver) (38 KHz)

To learn how to control the MMR using the IR remote receiver and an IR remote control (38 KHz) (see image), I have coded the DemoIRRemote.sb2 project.

The code is very simple as you can see in the image:

  • Initialize the Magnetic Motion Robot (MMR)
  • The block "forever" (loop in the Arduino code)
  • The code switch on the LED strip (red)
  • The code switch on the LED strip (green) during 2 seconds if the 1 key is pressed on the remote control.
  • Observe that if we change the color to the LED strip the block “show led_strip” is not necessary
  • Observe too, the 500 milliseconds delay at the end of the block forever.

We could propose the kids the following simples activities to code the MMR:

  • Switch on red the strip LED; if the 2 key is pressed change the color to blue during two seconds and if the 3 key is pressed change the color to green during four seconds
  • Switch on red only the LEDs #1 y #2; if the 2 key is pressed change only the LEDs #1 y #2 color to blue during two seconds and if the 3 key is pressed change only the LEDs #1 y #2 color to green during four seconds
  • Switch on red only the LEDs from #1 to #3; if the 2 key is pressed switch on blue only the LEDs from #4 to #6 and if the 3 key is pressed switch on green only the LEDs #7 y #9

In the following video you can see a demo of IR remote control and LED strip

Step 14: How MMR Follows a Black Line

The code “DemoLineFollower.sb2” is an example how the MMR follows a black line.
The code is very simple as you can see in the image:

  • Initialize the Magnetic Motion Robot (MMR).
  • In the main loop, the MMR is continuously testing is a black line is detected by the sensor.
  • If the black line is detected, MMR moves one step forward (angle = 20º; velocity=250 millisecs).
  • If the black line is not detected, MMR moves several steps to the left and to the right to find again the black line.

We could propose the kids the following simples activities to code the MMR:

  • Code the MMR to increase the motion velocity.
  • Code the MMR to improve the line follower algorithm.

You can see a demo how MMR follows black line in the following video

Step 15: Mblock 3 and Mblock 5 File Projects

In the attached files you can find all the Mblock 3 and Mblock 5 file projects used in this instructable.

Thanks for reading this instructable.

Robots Contest

Runner Up in the
Robots Contest