Led matrix with HT1632C controller (6)

by luca
4 comments

Some readers wrote me asking more “real” examples using this display… in this post I’ll write a sketch to use it as a thermometer.

The sensor

I chose the DS18B20 sensor from Maxim Integrated to read the room temperature.

The connection to Arduino is very simple: the sensor has 3 pins (VDD, GND e DQ) and I joined DQ to pin 2 of my Arduino:

This sensor provides 2 supply modes:

  • using the VDD pin
  • parasite, through the DQ pin (in this mode, VDD must be grounded)

In both modes, DQ pin requires a 4.7Kohm pull-up resistor.

The library

Miles Burton developed a convenient library to talk with Maxim’s sensor… here’s how to use it:

– include in your sketch both OneWire and DallasTemperature libraries:

#include <OneWire.h>
#include <DallasTemperature.h>

– init the library passing the pin you connected the sensor to:

#define ONE_WIRE_BUS  2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&amp;oneWire);

– read the temperature value (float) – if you connected only a sensor, it will have index 0:

sensors.requestTemperatures();
float float_temp = sensors.getTempCByIndex(0);

The display

Use the sprintf function to prepare the complete text to be displayed:

sprintf(display_string, "Temperature: %s", string_temp);

A little problem is that sprintf does not support float type; you have to convert it into a string variable.

Demo

The sketch is available on Github, here’s how it works:

[youtube id=”CweI_vBFeGo” width=”600″ height=”350″]

Related Posts

4 comments

Robert Wednesday September 25th, 2013 - 02:23 AM

How would I display scrolling text while the text itself is changing?

For example, let’s say I want a clock with seconds. How would the transition from, say, 8:39:59 to 8:40:00 work?

Reply
Robert Wednesday September 25th, 2013 - 02:28 AM

As for your thermometer example: I see the sign shows the temperature in hundredths of a degree — but by the time the sign scrolls around to show the numbers, won’t they already be wrong?

Reply
Thongchai Thursday August 14th, 2014 - 06:49 AM

Hi
If I want to add the date to the code here?

Reply
kevin Friday November 13th, 2015 - 03:39 PM

Hi Luca,

I have problem, if the temperature is 20c, and i only want the led to light up when temperature reach 22c, how could I change it?

Reply

Leave a Comment

1 × 5 =