Building a silly robot with Grove Starter Kit

I received a Grove Starter kit at an internal work Conference a few months ago. Of course, I did something entirely useless with it, so here is the tutorial on how to make your own useless Marvin.

Image for post
Image for post

This is Marvin, and he does the following:

  • Complains that he is melting when the temperature is above 30 C°
  • Tells you to turn the heater on if the temperature is below 15 C°
  • Tells you the temperature when it is between 15 C° and 30 C°
  • Swings a pendulum on the touch of the touch sensor
  • Lights up when playing the drum

The Grove Starter Kit comes with quite a few components:

Image for post
Image for post

Out of these I used the following:

  • Seeeduino board (extra to the starter kit)
  • Base Shield — goes on top of the Seeeduino to make connections easier for beginners
  • Temperature sensor — for Marvin to know the temperature
  • Sound sensor — for Marvin to hear the drum
  • Touch sensor — To start the pendulum swing
  • Servo — To create a pendulum
  • LED socket — For marvin to light up on drum beats
  • Some lego — to build the body

Hardware setup

You will need to connect the pieces to the following places in order to use the code directly:

Image for post
Image for post

The Base Shield would then go on top of the Seeeduino.

Code setup

First you need to download the following two repos as .zip files:

Download the Arduino IDE.

When you open the IDE it will open a new project.

Add the libraries to IDE via Sketch-> Include Library -> Add .ZIP Library

Image for post
Image for post

You will see thesetup and loop functions already set up for you at the opening of the IDE. You can fill the setup as follows:

#include "rgb_lcd.h"
#include <Servo.h>
rgb_lcd screen;
float temperature;
int thermistor=3975; // Used in the temperature calculations
float resistance; // Used in the temperature calculations
int pendulum_position = 0; // Used in the pendulum swinging
Servo myservo; // Servo tool which swings the pendulum
void setup()
{
screen.begin(16, 2);
setup_initialization();

myservo.attach(2);
delay(5000);
}

Code adding messages to RGB Backlight

The functions that change the colour and message on the RGB Backlight can be created using the following code:

void setup_message(String message, int colorR, int colorG, int 
colorB) {
screen.setRGB(colorR, colorG, colorB);
screen.print(message);
}
void add_second_line_to_message(String message) {
screen.setCursor(1, 1);
screen.print(message);
}

Code for the starting message

The setup code above sets up the initialization message which is Marvin greeting us. That can be done with the following code:

void setup_initialization() {
String message=" Hi! I'm Marvin.";
int colorR = 220;
int colorG = 220;
int colorB = 220;
setup_message(message, colorR, colorG, colorB);
}

Code for Marvin’s reactions to temperature

Marvin has three reactions to temperature: Thinking it’s too hot, thinking it’s too cold and being content and telling us the temperature. The messages are printed with the following code:

void setup_too_hot() {
String message="I am melting! :(";
int colorR = 255;
int colorG = 0;
int colorB = 0;
setup_message(message, colorR, colorG, colorB);
}
void setup_too_cold() {
String message="Heater on! D:";
int colorR = 0;
int colorG = 0;
int colorB = 255;
setup_message(message, colorR, colorG, colorB);
}
void setup_content(int temperature) {
String message=" No complaints";
String second_message = " It's " + (String)temperature +
"C" + (char)223;
int colorR = 230;
int colorG = 230;
int colorB = 250;
setup_message(message, colorR, colorG, colorB);
add_second_line_to_message(second_message);
}

Code for checking temperature

The temperature sensor does not give the temperature in degrees, and therefore needs to go through a conversion to degrees. The following code is used for Marvin to understand temperature:

float get_temperature() {
int sensor_value=analogRead(A3);
int max_voltage = 1023;
resistance = (float)(max_voltage-sensor_value) *
10000/sensor_value;

temperature = 1/(log(resistance/10000)/thermistor+1/298.15) -
273.15;
return temperature;
}
void check_temperature() {
temperature = get_temperature();
int touch = digitalRead(A1);
screen.clear();

if(temperature > 30) {
setup_too_hot();
} else if(temperature < 15) {
setup_too_cold();
} else if (touch == 0) {
setup_content(temperature);
}
}

Code for pendulum

The pendulum swings 5 times when the touch sensor is touched. This can be achieved with the following code:

void check_touch() {
int sensorValue = digitalRead(A1);
if(sensorValue==1) {
screen.clear();
screen.print(" Tick Tock!");

rotate_pendulum();
}

delay(1000);
}
void swing_pendulum() {
for (pendulum_position = 95; pendulum_position <= 135;
pendulum_position += 1) {
myservo.write(pendulum_position);
delay(15);
}
for (pendulum_position = 135; pendulum_position >= 95;
pendulum_position -= 1) {
myservo.write(pendulum_position);
delay(15);
}
}
void rotate_pendulum() {
for (int times = 0; times <= 5; times += 1) {
swing_pendulum();
}
}

Code for the Drum

When hitting the drum, Marvin should light bu. This is how we make that happen:

void react_to_drumming() {
int a=analogRead(A0);
if(a > 400){
digitalWrite(7, HIGH);
} else {
digitalWrite(7, LOW);
}
}

Finally, the loop that brings it all together

We have created all these functions, now we need to bring it all together to make Marvin work.

void loop() 
{
screen.setCursor(0, 1);
check_temperature();

react_to_drumming();
check_touch();

delay(3000);

}

The Lego

The body is up to you. I just found some random Lego around the house and made what I could from it. One thing that you will need in addition to this is some tape. The tape is to attach a lego piece to the pendulum and for creating the drum (if you so desire).

The final result

This video shows the ridiculous thing that we just made together:

And a video of the drum:

I hope that you enjoyed making your own Marvin.

Data scientist, software engineer, poet, writer, blogger, ammature painter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store