How to Make a “Moody” Robot That Hates Hot Weather

Why make a moody robot?

Sometimes it’s necessary to make your robot react the same way every time it receives a certain type of input.  For example, consistency is crucial if you want your robot to be able to balance on two wheels.  A two-wheeled balancing robot needs to be able to sense its exact angle relative to the ground and adjust its motors in the same way every single time.

Other times, however, consistency is boring.  If you plan on using human language to interact with your robot, for example, you want it to surprise you occasionally.

You can make your robot react in more interesting ways by adding a few extra variables into the mix.

Pro Tip!  If you’re new to hobby robotics, read my free beginner robotics guide before you proceed.  The beginner guide is short and sweet and should take you about 15 minutes to finish.

Use and adapt code that someone else has written

Don’t be afraid to plunder someone else’s Arudino IDE code.  If someone has made their code available online, they want you to use it and learn from it!

ITP student Bruna Calheiros created an Arduino device that uses a temperature sensor to emulate a mood ring emulator.  Let’s see if we can adapt Bruna’s Arduino IDE code and use it to create a robot whose mood changes with the temperature.

Got Arduino?  If not, get yourself an official one from the official Arduino site or see if you can find a good imitation Arduino board on Amazon.

int temperaturePin = 0

The line of code contained in the code box above connects your Arduino Uno to a temperature sensor.

You should be able to use any temperature sensor for this project since they are all pretty much the same, but Brauna used the TMP36 to create his Arduino mood ring.  I looked up the price of the TMP36 temperature sensor on Amazon and discovered that it currently costs less than a Big Mac.

After you hook the temperature pin up, you should set up a loop.

void loop()

The above command tells your robot to keep on collecting temperature info.

float temperature = getVoltage(temperaturePin); 
temperature = (((temperature – .5) * 100)*1.8)+32; 
int newTemperature = temperature; 
Serial.println(newTemperature); 

delay(7000);

The code in the box above does 4 main things.  It:

  1. grabs “raw” temperature info from the sensor
  2. converts the raw info into degrees
  3. saves the current temperature to a variable called “newTemperature”
  4. tells the sensor to pause 7 seconds before repeating the loop

Now that your robot has temperature data coming in, let’s use that data to set your robot’s mood.  First, we have to create a robot mood variable.  Let’s call it “moodVariableWeather.”

int moodVariableWeather = 0

With the mood variable established, we can now make it change with the weather using if/then logic.

if ((newTemperature>40) && (newTemperature<=71))

{
moodVariableWeather = 1;
 }

if ((newTemperature>72) && (newTemperature<=102))

{
moodVariableWeather = 2;
 }

The code above set your robot’s mood to “1” if the temperature is greater than 40 and less than 71.  It also sets it to “2” if the temperature is more than 72 but less than 102.

You can program as many different moods as you want by copying/pasting the code and changing the numbers around.

What do I do now?

Now that your robot can sense weather changes, here are just a few ideas of things you can make it do:

  • Walk/roll slower when it’s hot
  • If your bot is capable of responding to voice commands, you can make it respond in a cranky way when the weather is too hot or cold
  • Have your robot display the current temperature when you press a button

Got any other suggestions or ideas for how to use moodVariableWeather?  Visit Robot Fanatics on Facebook and drop us a line.

About Alex Munkachy

Hello and thanks for visiting Robot Fanatics! The aim of this site is to introduce people to the fun and interesting world of robotics. Please like us on Facebook and follow us on Twitter @RobotFanatics.