🛠️Misty Tracker

This project aims to make Misty a temperature and light tracker in your room!

When you are using Arduino to collect data there is a big obstacle: Arduino can't move alone!

Misty will adapt her expression based on the conditions she will be in, for example when it will be dark and cold she will be scared and so on. You can adapt your actions and the path she will drive.


  • Misty's Arduino Backpack

  • Thermistor

  • Photoresistor

  • 3 LEDs

  • 3 resistance 330 Ω

  • 2 resistance 10 kΩ

  • Some wires of different lenght

Arduino Circuit:

Arduino Code:

// light and temperature
int light_lim = 300;
double temp_lim = 26; // temperature limit

void setup() {
  pinMode(A0, INPUT); // light sensor
  pinMode(A2, INPUT); // temperature sensor
  pinMode(11, OUTPUT); // light LED (white)
  pinMode(9, OUTPUT); // temperature LED hot (red)
  pinMode(8, OUTPUT); // temperature LED cold (blue)
void loop() {
  // read the value
  int light_value = analogRead(A0);
  double temp_value = (analogRead(A2) - 32) /1.8; // the value is originally read in Fahrenheit, so we convert it in Celsius
  //compare the value with limits 
  if ((light_value <= light_lim) && (temp_value <= temp_lim)) { // dark and cold
    digitalWrite(11, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    Serial.print("dark and cold|");
  else if ((light_value >= light_lim) && (temp_value <= temp_lim)){ // illuminated and cold
    digitalWrite (11, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    Serial.print("illuminated and cold|");
  else if ((light_value >= light_lim) && (temp_value >= temp_lim)){ // illuminated and hot
    digitalWrite(11, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    Serial.print("illuminated and hot|");
  else if ((light_value <= light_lim) && (temp_value >= temp_lim)){ // dark and hot
    digitalWrite(11, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    Serial.print("dark and hot|");
  else { // in any other case
    digitalWrite(11, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
  String values = "light value: " + String(light_value) + "    temperature value: " + String(temp_value); 
  delay(2000); // scan every 2 seconds

First of all, you can set some values of light and temperature that will be the limits to decide if an environment is dark or illuminated and cold or hot.

In this void setup, you open the serial and set the pins you’ll use in this project. In this void loop, you read the sensors and write a specific serial message based on your conditions:

There will be four possible conditions, and it has been also added an extra case that will save the program in case none of the conditions is selected. The Serial message, which is our way of transmitting the information to Misty is built in this way:

light condition and temperature condition | light value and temperature value

We insert the | because in this way, in the Misty python code, we can split the message and use them indipendently. We want it because:

  • it would be harder to build an if statement with all the different values each time

  • you can print the data and only the data that Misty captured in your output

Arduino will scan the different conditions every two seconds.

Misty Code:

from mistyPy.Robot import Robot
from mistyPy.Events import Events
import time

ROBOT_IP = "<your_robot_ip_address>"
misty = Robot(ROBOT_IP)

def msg(data):
    conditions = data["message"]["message"].split("|")[0]
    values = data["message"]["message"].split("|")[1]

    if conditions == "dark and cold":
        misty.move_arms(80, 80)
        misty.change_led(0, 0, 255)
    elif conditions == "illuminated and cold":
        misty.move_arms(-80, -80)
        misty.change_led(0, 255, 0)
    elif conditions == "illuminated and hot":
        misty.change_led(255, 0, 0)
    elif conditions == "dark and hot":
        misty.change_led(255, 0, 255)
    elif conditions == "searching":
        misty.change_led(100, 70, 160)

misty.register_event(event_name="serial_message_event", event_type=Events.SerialMessage, callback_function=msg, keep_alive=True)
# my tracked space
for i in range(2):
    misty.drive_time(50, 0, 4000)
    for j in range(4):
        misty.move_head(-20, 0, 0)
        misty.move_head(20, 0, 0)
    misty.drive_time(0, 50, 6500)
    misty.drive_time(50, 0, 4000)
    misty.drive_time(0, 50, 6500)
# end my tracked space

To allow Misty to read in the Serial you need to build an event, so you can import the usual libraries that Misty uses to register events. Then you can create the robot and the function that will be called with the event.

In this function Misty reads the serial message and if the condition that Arduino sent is verified Misty will act according to what you wrote in that case.

In the function, you can split values and conditions so you can use them independently as previously said. In the end, you can loop the space that will be tracked several times, in this case 2 and meanwhile Misty will track all your data.

Last updated