Skip to content

Instantly share code, notes, and snippets.

@koenhendriks
Last active December 23, 2016 12:20
Show Gist options
  • Select an option

  • Save koenhendriks/794accd29d501b6b780c4d00569ab279 to your computer and use it in GitHub Desktop.

Select an option

Save koenhendriks/794accd29d501b6b780c4d00569ab279 to your computer and use it in GitHub Desktop.

Revisions

  1. koenhendriks revised this gist Dec 23, 2016. 1 changed file with 24 additions and 3 deletions.
    27 changes: 24 additions & 3 deletions TempLCD.ino
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,8 @@
    (middle) SCL : A0 Arduino
    (right) VCC : 5v
    Button : Digital 4 Arduino
    */

    #include <Wire.h>
    @@ -25,9 +27,11 @@ const int colorR = 118;
    const int colorG = 232;
    const int colorB = 220;

    int TsensorPin = A0;
    int TsensorPin = A0;
    int buttonPin = 4;
    int ledPin = 13;
    int loops = 0;
    int loops = 0;
    boolean screenOn = true;
    double temperature = 0.0;
    int totalTemperature = 0;
    int avegareTemp = 0;
    @@ -46,7 +50,8 @@ void setup()

    // Set Pins
    pinMode(TsensorPin, INPUT);
    pinMode(ledPin, OUTPUT);
    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT);
    }

    void loop()
    @@ -73,9 +78,25 @@ void loop()
    lcd.print("Gem: ");
    lcd.print(temp);
    lcd.print("C");
    if(digitalRead(buttonPin)){
    onButtonPress();
    }
    delay(1000);
    }

    void onButtonPress(){
    if(screenOn){
    lcd.noDisplay();
    lcd.setRGB(0,0,0);
    screenOn = false;
    }else{
    lcd.display();
    lcd.setRGB(colorR, colorG, colorB);
    screenOn = true;
    }

    }

    double TMP36GT_AI_value_to_Celsius(int AI_value)
    {
    float voltage;
  2. koenhendriks created this gist Dec 23, 2016.
    86 changes: 86 additions & 0 deletions TempLCD.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    /*
    TempLcd.ino
    2017 Copyright (c) Koen Hendriks. All right reserved.
    Connect LCD:
    VCC : 5v
    GND : GND
    SDA : A4 Arduino
    SCL : A5 Arduino
    Connect Temperature Sensor,
    Flat side down, left to right:
    (left) GND : GND
    (middle) SCL : A0 Arduino
    (right) VCC : 5v
    */

    #include <Wire.h>
    #include "rgb_lcd.h"

    rgb_lcd lcd;

    const int colorR = 118;
    const int colorG = 232;
    const int colorB = 220;

    int TsensorPin = A0;
    int ledPin = 13;
    int loops = 0;
    double temperature = 0.0;
    int totalTemperature = 0;
    int avegareTemp = 0;

    void setup()
    {
    // set up the LCD's number of columns and rows
    lcd.begin(16, 2);

    // set up the LCD default text
    lcd.print("Welkom bij Koen!");
    lcd.setCursor(0,1);

    // Background color
    lcd.setRGB(colorR, colorG, colorB);

    // Set Pins
    pinMode(TsensorPin, INPUT);
    pinMode(ledPin, OUTPUT);
    }

    void loop()
    {
    loops++;
    temperature = TMP36GT_AI_value_to_Celsius(analogRead(TsensorPin));
    totalTemperature += temperature;
    avegareTemp = totalTemperature / loops;

    //Start displaying on second row
    lcd.setCursor(0,1);

    // Cast to int for rounded number
    int lastMeasure = (int) temperature;
    lcd.print("T:");
    lcd.print(lastMeasure);
    lcd.print("C");

    // Cast to int for rounded number
    int temp = (int) avegareTemp;

    // Set cursor to align left
    lcd.setCursor(8,1);
    lcd.print("Gem: ");
    lcd.print(temp);
    lcd.print("C");
    delay(1000);
    }

    double TMP36GT_AI_value_to_Celsius(int AI_value)
    {
    float voltage;
    voltage = AI_value * (5000.0/1024);
    // Temperature according to datasheet: 750 mV = 25 °C
    return ((voltage -750) /10) +25;

    }