Skip to main content
  1. Projects/

Hello Arduino! - Binary Thermometer

Arduino Electronics
Falk Zeh
Author
Falk Zeh
Data Engineer & Humanoid Robotics Student
Table of Contents

Binary Thermometer

Project Description
#

This was kind of my “Hello World!” project for the Arduino. The DHT11 will read temperature in Celsius and display the binary value of it via the 8 LEDs.

Parts List
#

  • Arduino Uno
  • DHT11 Temperature and Humidity Sensor
  • 8 LEDs
  • 8 220 Ohm Resistors
  • Breadboard
  • Jumper Wires

Installation
#

  1. Connect the DHT11 to the Arduino as follows:
    • VCC to 5V
    • GND to GND
    • DATA to Pin 13
  2. Connect the LEDs with resistors to the Arduino as follows:
    • LED 1 to Pin 1
    • LED 2 to Pin 2
    • LED 3 to Pin 3
    • LED 4 to Pin 4
    • LED 5 to Pin 5
    • LED 6 to Pin 6
    • LED 7 to Pin 7
    • LED 8 to Pin 8
  3. Upload the code to the Arduino
    #include "DHT.h"
    #define DHTPIN 13
    #define DHTTYPE DHT11
    DHT dht(DHTPIN, DHTTYPE);
    
    const int NUM_LEDS = 8;
    int outputPins[NUM_LEDS] = {1, 2, 3, 4, 5, 6, 7, 8};
    
    void displayTemperature(int temperature) {
      byte tempByte = (byte)temperature;
    
      for (int i = 0; i < NUM_LEDS; i++) {
        bool bitState = bitRead(tempByte, i);
        digitalWrite(outputPins[i], bitState);
      }
    }
    
    void setup() {
      Serial.begin(9600);
      dht.begin();
    
      for (int i = 0; i < NUM_LEDS; i++) {
        pinMode(outputPins[i], OUTPUT);
      }
    }
    
    void loop() {
      delay(2000);
      int t = dht.readTemperature();
      Serial.println(t);
      displayTemperature(t);
    }