Software Overview  |  Sitemap  |  Downloads  |  Developers  |  Forums
Small_clear_logo_llc

Recipe to Measure Temperature with an Arduino

This recipe uses an Arduino and a Grove Temperature Sensor to measure temperature. The sensor is connected to an Arduino analog input.

Ingredients

For this recipe, you will need:

  • an Arduino (running Firmata)
  • a Grove Shield
  • a Grove Temperature Sensor

Script

You can find the Script in the Scripts "examples" area. The Script is called "temperature_sensor.script". The Script is as follows:

# Read the temperature from a Grove temperature sensor.
# Requires an Arduino with a Grove temperature sensor wired to one
# of its analog input pins.

# Get the file name of the Arduino device.
# On *nix systems, the file will be in the "/dev" directory with
# a name like "/dev/cu.usbmodem411" or "/dev/ttyUSB0".
# On Windows systems, the name will be something like "COM1", "COM2", ....
script_parameters("arduino_port")

# Get the analog input pin connected to the temp sensor - default is "A0"
optional_script_parameters(temp_sensor_pin:"A0")


# add Arduino device
run_script("Scripts/Device/Arduino/Arduino", port_location:arduino_port, id:"arduino")

# add temperature sensor - Fahrenheit
# to read in Celsius, use the (commented) TemperatureSensor_C Script instead
run_script("Scripts/Device/Arduino/Devices/Seeed/TemperatureSensor_F", arduino_id:"arduino", name:"temp_F", pin:temp_sensor_pin)
#run_script("Scripts/Device/Arduino/Devices/Seeed/TemperatureSensor_C", arduino_id:"arduino", name:"temp_C", pin:temp_sensor_pin)

To run this Script, you need 2 parameters: the arduino_port and temp_sensor_pin parameters. The arduino_port parameter is the name of the USB port where the Arduino is plugged in. On *nix hosts, the USB port name is in the "/dev" directory. To see the devices in order of their creation, type "ls -lrt /dev" at a shell prompt and look near the bottom of the list for your Arduino's USB port. The temp_sensor_pin parameter defines the Arduino pin where the temperature sensor is located. It has a default value of "A0" (analog input 0).

As an example, for an Arduino at USB port "/dev/ttyUSB0" with a Grove temperature sensor at pin A0, the Script parameters are:

arduino_port: "/dev/ttyUSB0"
temp_sensor_pin: "A0"

Running the Script

Run this Script and then go to the Device Explorer page. Click on the "arduino" device and look at its "temp_F" (or "temp_C") terminal and see the temperature in Fahrenheit (or Celsius).

Temperature Sensor

Catalina Computing, LLC.

Copyright © Catalina Computing, LLC. (2013-2017)




Page last updated: Wed Sep 24 15:37:21 2014 (UTC)