Some new stuff
  1. Arduino Park Control
  2. Arduino USB2serial programming the bare bone
  3. Arduino Projects Videos added
  4. Arduino Xbee projects
  5. Arduino dB Meter 
  6. Trying to get the IOIO going. 
  7. IOIO is going....bluetooth
  8. Attiny 2313 bluetooth bee RC car
  9. Compass and temperature added
  10. AVR programmer
  11. USB2Serial and Ethernet POE
  12. Arduino LPG Sensor
  13. Program the Arduino Mini 05
  14. Lipo Rider Pro in action
  15. EZ Robot Builder kit arrived 10 Nov 2012
  16. Arduino VA Meter!
  17. 05 Nov 2012 Project Sentry Gun.
  18. Attiny85 PIR Sensor 10 Dec 2012 
  19. 0-30VDC3A and 2-28VDC10A bench PSU's
  20. 19 Dec 2012 Arduino Voltmeter LCD
  21. 29 Dec 2012 Arduino Tachometer&Speedometer LCD
  22. 03 Jan 2013 Arduino AC Phase Control. 
  23. 18 Jan 2013 Arduino Distance Meter
  24. 22 Jan 2013 Arduino Digital Clock and Date
  25. 31 Jan 2013 Arduino Digital Clock and Date 8x2 LCD
  26. Feb 2013 LCD and Backpack
  27. Feb 2013 7 Segment Serial Clock Sparkfun. Distance Sensor with "newping" library
  28. Feb 2013 Lelo Remote
  29. 01/03/2013 Arduino Adafruit 7 Seg Digital Clock with RTC and backpack 
  30. Arduino Frequency Meter 26/03/2013
  31. Another RC  Car controlled by Arduino 06/04/2013
  32. My quadcopter project update 25 April 2013
  33. My Aqua Quad Copter Flying 26 April 2013enlightened
  34. Another monster RC truck;strong one! 11July2013cool
  35. X-Frame Quad Copter 31 July 2013cool
  36. Arduino GSM Sheild added.28/8/2013
  37. 1.8inch TFT screen 13/09/2013cool
  38. 04/11/2014 added PID Soldering Iron Control
  39. Added bluetooth servo control 04/11/2014
  40. ESP8266 first try.16/03/2015
  41. Arduino Uno Quadcopter 19 May 2015
  42. IOT WemosD1 Amp Meter

 

 


Search    

26/09/2013

Arduino LM35 temp sens with 1.8inch TFT display.

Added buzzer and led in synch when set temperature is reached.

If set temperature is reached and higher, the display will change to red text and relay pin will be activated. Buzzer will sound in sync with ledpin, else default back to normal temperature display alternating with the clock display with RTC

Ontro text with melody.

Min and max temperature indications.

Code:

//1.04 IDE
#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};// notes in the melody:
int noteDurations[] = {
 4, 8, 8, 4,4,4,4,4 };  // note durations: 4 = quarter note, 8 = eighth note, etc.
#include <Wire.h> // library needed for RTC
#include "RTClib.h" //RTC Library
RTC_DS1307 RTC;
#include <SPI.h>
#define sclk 4
#define mosi 5
#define cs   6
#define dc   7
#define rst  8  // you can also connect this to the Arduino reset
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
int temperature = 0;       //declare a variable to store obtained temperature 
const char analog_pin = A0;   //assign analog_pin with analog pin A0 
const char buzzer = 2;//assign buzzer with digital pin 2
int relayPin = 12;//Relay via transistor
const int ledPin = 13;
int mini = 1000;//Must be higher than 100 to display result
int maxi = -100;

void setup()
{
  pinMode(ledPin,OUTPUT);//set ledPin13 as output
  pinMode(buzzer,OUTPUT);  //set buzzer (or pin 2) as output
  pinMode(relayPin,OUTPUT);
  pinMode(analog_pin,INPUT); //set analog_pin (or pin A0) as input
  analogReference(INTERNAL); //configure the ADC reference voltage to 1.1V (internal built-in)
  Serial.begin(9600);
  Wire.begin();
  RTC.begin();
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
  tft.setRotation(tft.getRotation()+1); //uncomment to rotate display
  uint16_t time = millis();// get time to display "sensor up time
  tft.fillScreen(ST7735_BLACK);
  time = millis() - time;
  tftPrintTest();
  delay(500);
  tft.fillScreen(ST7735_BLACK);// optimized lines
  testfastlines(ST7735_RED, ST7735_BLUE);
  delay(250);
  testdrawrects(ST7735_GREEN);
  delay(250);
  tft.fillScreen(ST7735_BLACK);
  }

void loop()
{
  temperature = get_temperature();  //get the temperature
  if(temperature > maxi) {maxi = temperature;} // set max temperature
  if(temperature < mini) {mini = temperature;} // set min temperature
  if(temperature>320) {  //test if the temperature > 29(or any other given temperature setting)celsius
    beep();//buzzer activated
    blink_LED();//led in synch with buzzer
    highTemp();//if yes, activate red text display
    relayControl();//if yes, activate relay pin 12
     
  } else {
    digitalWrite(relayPin, LOW);  
    tft.setTextColor(ST7735_WHITE);
    tft.setCursor(32,0);
    tft.setTextSize(2);
    tft.println("CHEMCOOL");
    tft.setCursor(0, 16);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_BLUE);
    tft.print("Max=");
    tft.setCursor(48, 16);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_RED);
    tft.print(maxi/10,DEC);//current temp and set to max
    tft.setCursor(70, 15);
    tft.setTextSize(2);
    tft.print(".");
    tft.setCursor(80, 16);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_RED);
    tft.print(maxi%10,DEC);//remainder of current temperature
    tft.setCursor(92, 15);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_YELLOW);
    tft.print("(32)");//remainder of current temperature
    tft.setCursor(0, 92);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_BLUE);
    tft.print("Min=");
    tft.setCursor(48, 93);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_RED);
    tft.print(mini/10,DEC);//current temp and set to min
    tft.setCursor(70, 93);
    tft.setTextSize(2);
    tft.print(".");
    tft.setCursor(80, 93);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_RED);
    tft.print(mini%10,DEC);//remainder of current temperature
    tft.setCursor(0, 40);
    tft.setTextColor(ST7735_YELLOW);
    tft.setTextSize(6);
    tft.print(temperature/10,DEC);
    tft.setCursor(65, 60);
    tft.setTextSize(3);
    tft.print(".");
    tft.setTextSize(6);
    tft.setCursor(85, 40);
    tft.print(temperature%10,DEC);
    tft.setCursor(20, 110);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.setCursor(130, 35);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_YELLOW);
    tft.print("o");
    tft.setCursor(130, 55);
    tft.setTextSize(4);
    tft.setTextColor(ST7735_YELLOW);
    tft.print("C");
    tft.setCursor(32,110);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_WHITE);
    tft.println(" -2013-");
    delay(5000);
    tft.fillScreen(ST7735_BLACK);
    tft.setCursor(35,10);
    tft.setTextColor(ST7735_WHITE);
    tft.setTextSize(2);
    tft.println("CHEMCOOL");
    tft.setTextColor(ST7735_YELLOW,ST7735_BLACK);
    tft.setTextSize(2);
    tft.setCursor(30,28);
    DateTime now = RTC.now();
    tft.print(now.year(), DEC);
    tft.print('/');
    tft.print(now.month(), DEC);
    tft.print('/');
    tft.print(now.day(), DEC);
    tft.println(' ');
    tft.drawLine(0, 50, tft.width()-1, 50, ST7735_WHITE);
    
    tft.setCursor(15,80);
    tft.setTextSize(4);
    tft.setTextColor(ST7735_BLUE,ST7735_BLACK);
    tft.print(now.hour(), DEC);
    
    tft.setCursor(37,80);
    tft.setTextSize(4);
    tft.setTextColor(ST7735_BLUE,ST7735_BLACK);
    tft.print(':');
    
    tft.setCursor(54,80);
    tft.setTextSize(4);
    tft.setTextColor(ST7735_BLUE,ST7735_BLACK);
    tft.print(now.minute(), DEC);
    
    tft.setCursor(95,80);
    tft.setTextSize(4);
    tft.setTextColor(ST7735_BLUE,ST7735_BLACK);
    tft.print(':');
    
    tft.setCursor(110,80);
    tft.setTextSize(4);
    tft.setTextColor(ST7735_BLUE,ST7735_BLACK);
    tft.print(now.second(), DEC);
    
    
    tft.println(" ");
    delay(5000);
    tft.fillScreen(ST7735_BLACK);
    }
}
  void beep()
{
  //buzzer sound pattern
  digitalWrite(buzzer,HIGH);  //buzzer on
  delay(50);  //short delay
  digitalWrite(buzzer,LOW);  //buzzer off
  delay(50);  //short delay
  digitalWrite(buzzer,HIGH);  //buzzer on
  delay(50);  //short delay
  digitalWrite(buzzer,LOW);  //buzzer off
  delay(50);  //short delay
}
void blink_LED ()
{
  //blink ledPin pattern
  digitalWrite(ledPin,HIGH);  //led on
  delay(50);  //short delay
  digitalWrite(ledPin,LOW);  //led off
  delay(50);  //short delay
  digitalWrite(ledPin,HIGH);  //led on
  delay(50);  //short delay
  digitalWrite(ledPin,LOW);  //led off
  delay(50);  //short delay
}
void highTemp()
  {
  tft.setCursor(20, 50);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(6);
  tft.print(temperature/10,DEC);
  tft.setCursor(85, 72);
  tft.setTextSize(3);
  tft.print(".");
  tft.setTextSize(6);
  tft.setCursor(105, 50);
  tft.print(temperature%10,DEC);
  delay(2000);
  tft.fillScreen(ST7735_BLACK);
  
}
void relayControl()

    digitalWrite(relayPin, HIGH);
}
void intro()
{
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {
    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(2, melody[thisNote],noteDuration);
    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    noTone(2);// stop the tone playing:
}
}
//Get temperature subroutine
int get_temperature()
{
  /*****get temperature subroutine*****
  -The formula to convert ADC reading to temperature is shown below:
   Temperature = 100 x ADC reading x 1.1 / 1024 x 10
  -The temperature sensor (LM35DZ or LM35DT) sensing range is between 0 - 100 celsius
  -Sensitivity --> 10mv per celsius
  -With the sensing range --> 0 - 100 celsius, the LM35DZ/DT voltage output --> 0 - 1V
  -With analog voltage reference = 1.1, maximum ADC value obtained = 1 / 1.1 * 1024 = 930. Hence, the ADC value range is between 0 - 930
  -A multipler 1.1 have to be introduced so that we can get 100 celsius when the value is 930 as 930 x 1.1 --> approximately 1024
  -Another multipler 10 also have to be introduced, so we can obtain the temperature in one decimal place instead of rounded number without decimal place
   eg:
   As temperature --> 61.5 celsius is sensed,
   -if multiplier 10 is introduced, average temperature store in a variable average_temperature is 615 instead of 61
   -the round number part is obtained using average_temperature / 10 --> 61
   -the decimal number part is obtained using average_temperature % 10 --> 5
   -By manipulating this, we can display the temperature with one decimal place
  ************************************/
  
  float adc_value = 0;  //declare a variable to store ADC value
  float total_temperature = 0;  //declare a variable to store sum of multiple temperatures
                                //for average temperature calculation
  int average_temperature = 0;  //declare a variable to store the average temperature calculated
  
  for(int count =0; count<100; count++)  //obtainning the sum of multiple temperatures (100 samples in this case) 
  {
    adc_value = analogRead(analog_pin);  //obtain ADC reading
    total_temperature += adc_value/1024*100*1.1*10;  //accumulate the sum of temperatures untill all samples are taken, same as total_temperature = total_temperature + adc_value/1024*100*1.1*10;
  }
  average_temperature = int(total_temperature / 100);  //calculate the average temperature, convert it from float to integer 
  return average_temperature;  //return average temperature to the main 
}
 
void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 30);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(2);
  tft.println("LM35/RTC");
  tft.println("Temp&Clock");
  tft.setTextColor(ST7735_YELLOW);
  tft.setTextSize(2);
  tft.println("Display");
  tft.setTextColor(ST7735_BLUE);
  tft.setTextSize(2);
  tft.println("by Chemcool");
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(2);
  tft.println("2013");
  intro();//play intro
  delay(3000);
  }
 
void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t y=0; y < tft.height(); y+=5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x=0; x < tft.width(); x+=5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

Back Back to top