Modular Pets

Introduction: Modular Pets

// Project by Mahdieh Hadian Rasanani & Håkon Toth //

Our idea for this project was to design a modular code that could be used for different types of moving robots. We have a couple of base components which are similar in different modules to collect input data. This input data is used to trigger presets of behaviors which we have designed in our main code and enables the user to customize the output behavior of the robot. In this instructable, we will show you how to make one of the modules step by step and how we can customize the behavior for other modules. The base behaviors of the module includes object following/avoidance and do different actions when they get close to and interact with the object. For the Module 2 shown in this Instructable we'll make an object-following robot that actuates different dance moves based on the color it senses.

Step 1: Material List

Common components for the Modules:


Arduino UNO Controller Board

Mini Breadboard

Male-Male Jumper Wires

Female-Male Jumper Wires

Female-Female Jumper Wires (optional)


2 x DC Motors

SG90 Servo Motor


9V Battery

9V Battery Connector

Power-Switch (optional, but highly recommended)



2 x Wheels

Rubber Bands

Ice Cream Sticks



Specific components for each Module:

Module 2:
TCS3200 RGB Color Sensor

2 x IR Proximity Sensors

Module 1:

One extra SG90 Servo Motor

Step 2: Attach the DC Motors

Connect the two DC Motors and a 9V battery directly to the L293D Motor Driver. Then connect the outputs from the Motor Driver with the digital pins in the Sensor Shield, as shown in the diagram above. Place the Sensor Shield on top of the UNO Board. The shield is not required, but will make wiring easier and protect the UNO board. As we'll have shared VCC pins, you have to more actively use the breadboard if you want to make this without the Sensor Shield.

Step 3: Attach Servo Motor

Connect the servo motor to the digital pins as shown above. Make sure to connect the Servo S output (source) with a PWM enabled pin, like the one choosen in this example.

Step 4: Attach the Ultrasonic Sensor

Connect the Ultrasonic sensor to the Analog pins in the Sensor Shied as shown above.

Step 5: Attach the IR Sensors

Connect the IR Proximity sensors as shown above. To calibrate both of the sensors for the right distance, rotate the screw located on top of the little blue cube on each sensor. Be aware that the range for object detection is relatively small (0 - 10 cm) and that the calibration is very sensitive. Trial and error is essential to adjust for the correct detection distance.

Step 6: Calibrate the Color Sensor

For this step you will need the following:

TCS3200 Color Sensor

Colored Sheets (white, black, red, green and blue)

Something to hold the sensor still and evenly distanced from the colored sheets (ice cream sticks in this example)

Before we can actually implement the color sensor with the rest of the circuit we have to calibrate it so that it can read colors correctly in a given environment. The reason for this is that we want to optimize for your specific color tones, and that the ambient lighting conditions may vary during application. The built in LEDs provides a more uniform color scan, but you should still remember to calibrate it at the same time you wish to use it. Daytime and nighttime lighting may affect your results. In addition the distance from the sensor to the colored sheets during calibration should approximate the distance from the sensor to the colored object when we apply it to the moving robot (3 - 5 cm in this example).

Briefly what will be doing is that we will search for the lowest values of red, green and blue when scanning the white sheet, then secondly we will search for the highest values of red, green and blue during scanning of the black sheet. With this information we're able to establish the color value range for each of the three primary colors. When we have this done, we can simply remap our values to match with the RGB value scale from 0-255. Now the sensor is able to determine which primary color has the highest value for a colored object. If we show it red, the red color value will be significantly higher than for green and blue, and so on.

Now we're ready to implement our sensor with the rest of the circuit!

Download the attached Arduino file for the complete code with explanations of this process.

Step 7: Complete the Circuit

Finally we can apply the Color Sensor to the rest of the circuit, which completes this part of the process.

Step 8: Assembly Sequence

The GIF briefly explains how you assemble the Module 2 Robot step by step. Download the attached ZIP-file to have a closer look at each step individually in the assembly process.

Step 9: Code Implementation

In the final step we'll open the code in the Arduino IDE, and then upload it to the Arduino UNO board.

Make sure to follow the instructions inside the code thoroughly, as it explains which sections you would need for different types of moving behaviors.

Now you're all set and ready to make your own awesome movable robot!

Step 10: Test Run

The following GIFs shows how each core behavior works. From object detection on long range, position calibration on short range and how the color sensor triggers custom dance moves.

Step 11: Explore!

Now that you have a basic understanding of the fundamental parts of the code, you’re free to expand the possibilities of your own modular robot.

In this example called Module 1 we’ve added an extra servo motor to the circuit and left out the IR sensors. The assembly setup is almost identical to the one for Module 2, but in stead of sensing and actuating through wheel movements, the additional servo controls the tail of an imaginary peacock which moves when the ultrasonic sensor is close to your hand. We encourage you to use our Modular Code for further exploration, and wish you good luck!

Hope you enjoyed this Instrucable. As it is our very first project with Arduino your feedback is highly appreciated.

Be the First to Share


    • 3D Printed Student Design Challenge

      3D Printed Student Design Challenge
    • Micro:bit Contest

      Micro:bit Contest
    • Plastic Challenge

      Plastic Challenge