Misty Lessons
  • Misty Lessons
    • 📖Welcome to Misty Lessons
    • 📚Get to know your Misty
    • 📲Connect to Misty
    • 👩‍💻Misty Studio
    • 🖥️Desktop Environment
    • ⬆️Update your Misty
    • 👥Projects
  • Blockly
    • 🧩Blockly Lessons
      • 🤸Lesson 1: Movement
      • 🎶Lesson 2: Voice and Sound
      • 🎭Lesson 3: Expressions
      • 🎥Lesson 4: Robot Cinema
      • 🛠️Lesson 5: Events
      • ☺️Lesson 6: Face recognition
      • 🔢Lesson 7: Variables and Functions
      • 💬Lesson 8: NLP
    • 🏫Blockly projects
  • Blockly Elements
    • ⚛️Misty Blocks
      • Movement
      • Speech
      • Audio
      • Vision
      • Events
      • Miscellaneous
      • NLP
      • System
    • 🔁Basic Blocks
      • Logic
      • Loops
      • Math
      • Text
      • Lists
    • 🅰️Advanced Blocks
      • Variables
      • Functions
  • Python
    • 🐍Python Lessons
      • 🦿Lesson 1: Loco-motion
      • 🤖Lesson 2 : Build a character
      • 🧠Lesson 3: Create memories
      • ⚒️Lesson 4: Event skills
      • 👀Lesson 5: Expand awareness
      • 🔗Lesson 6: Compact code
      • 🗣️Lesson 7: Start a conversation
  • Python Elements
    • 🐸Misty Python API
      • Motion and Mobility
      • Display and LED
      • Record Assets
      • Change/Remove Assets
      • Stream Assets
      • Get Assets
      • Events
      • Sensor Events
      • Speech and NLP
      • Arduino Backpack
      • System
      • Slam
    • 📗Python Definitions
  • Python Projects
    • 🔮MistyGPT
    • 🚨Misty Intruder Alert
    • 📺Conference Assistant
    • 🏷️QR code detector
    • 🕵️‍♂️Misty follow human
    • 👋Misty wave back
    • 🖲️Misty OA
    • 🌐Get weather
    • 🚚Misty Delivery
    • 🫂Motivational Misty
    • 🖼️Misty Museum Guide
    • 🎃Who for Halloween
  • ARDUINO
    • ♾️Arduino Backpack
    • 🦎Arduino
    • 🔧Arduino Lessons
      • 🔌Arduino to Misty
      • ➕Misty to Arduino
  • ARDUINO PROJECTS
    • 🛠️Misty Tracker
    • 🦾Misty Arm
  • Community Projects
    • 🌤️Misty weather forecaster
  • HARDWARE EXTENSION
    • ⚙️Arduino breadboard support
    • 🦾Misty arm
    • 🥤Tin holder
  • Resource Database
    • 📁Image files
    • 📁Audio files
    • 📁Languages
    • 📁Known objects
    • 📁NLP Actions
    • 📁Action Commands
    • 📁ChatGPT PDF files
    • 📁AR Tag Dictionary
    • ⚙️Technical Specifications
Powered by GitBook
On this page
  • Materials:
  • Arduino Circuit:
  • Arduino Code:
  • Misty Code:
  1. ARDUINO PROJECTS

Misty Tracker

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

Last updated 1 year ago

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.

Materials:

  • Misty's Arduino Backpack

  • Thermistor

  • Photoresistor

  • 3 LEDs

  • 3 resistance 330 Ω

  • 2 resistance 10 kΩ

  • Some wires of different lenght

  • Optional Arduino breadboard support

Arduino Circuit:

Arduino Code:

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

void setup() {
  Serial.begin(9600);
  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);
    Serial.print("searching|");
  }
  String values = "light value: " + String(light_value) + "    temperature value: " + String(temp_value); 
  Serial.println(values); 
  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]
    print(values)

    if conditions == "dark and cold":
        misty.set_flashlight(True)
        misty.display_image("e_Fear.jpg")
        misty.move_arms(80, 80)
        misty.change_led(0, 0, 255)
    elif conditions == "illuminated and cold":
        misty.set_flashlight(False)
        misty.move_arms(-80, -80)
        misty.change_led(0, 255, 0)
    elif conditions == "illuminated and hot":
        misty.set_flashlight(False)
        misty.play_audio("s_Joy.wav")
        misty.display_image("e_Admiration.jpg")
        misty.change_led(255, 0, 0)
    elif conditions == "dark and hot":
        misty.set_flashlight(True)
        misty.start_action("love")
        misty.change_led(255, 0, 255)
    elif conditions == "searching":
        misty.set_flashlight(False)
        misty.start_action("look-left")
        time.sleep(0.5)
        misty.start_action("look-right")
    else:
        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)
    time.sleep(4500)
    for j in range(4):
        misty.move_head(-20, 0, 0)
        time.sleep(1)
        misty.move_head(20, 0, 0)
        time.sleep(1)
    misty.drive_time(0, 50, 6500)
    time.sleep(7000)
    misty.drive_time(50, 0, 4000)
    time.sleep(4500)
    misty.drive_time(0, 50, 6500)
    time.sleep(7000)
# end my tracked space
misty.start_action("hi")
misty.keep_alive()

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.

🛠️
Remember to use Misty's Arduino Backpack board, adapt your resistances to your sensors and check your individual connections, for example, our temperature sensor had only two wires.