Код для поиска

Lesson 46-2: Using an MLX90614 with an LCD2004 Display

Lesson 46-2: Using an MLX90614 with an LCD2004 Display

499-Lesson 46: Using the MLX90614 with an LCD
Язык: C++
++
/******
 * Robojax Arduino Step By Step Course
 * Part 4: Temperature Sensors
 * Lesson 46, MLX90614 with LCD2004
 
  This is a library example for the MLX90614 Temp Sensor
Original Library and code source: https://github.com/adafruit/Adafruit-MLX90614-Library

   Please watch video instruction here https://youtu.be/IAj0gHTTWfw
   Introduction video is https://youtu.be/548PLHgZkoQ
 This code is available at http://robojax.com/course1/?vid=lecture46
 
with over 100 lectures free on YouTube. Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339  

  This is a library example for the MLX90614 Temp Sensor
Original Library and code source: https://github.com/adafruit/Adafruit-MLX90614-Library

 this code has been mostly updated.
 it displays the temperature on LCD1602 or LCD2004 in C, F, and K for object and for ambient.
 

updated/written by Ahmad Shamshiri on Jun 28, 2020 
 
 * in Ajax, Ontario, Canada. www.robojax.com

 * Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place. Purchase My course on Udemy.com http://robojax.com/L/?id=62

If you found this tutorial helpful, please support me so I can continue creating 
content like this. 

or make a donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

Origin
  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_MLX90614.h>
char *typeName[]={"Object:","Ambient:"};


Adafruit_MLX90614 mlx = Adafruit_MLX90614();

#include <LiquidCrystal_I2C.h>
const uint8_t I2C_ADDRESS =0x27;
const uint8_t LCD_CHAR= 20;
const uint8_t LCD_ROW= 4;
char type ='C';// what to display. Watch video for details
bool ambient=1;//1=yes , 0=no
// C = Celsius
//  K = Kelvin
// F = Fahrenheit

LiquidCrystal_I2C lcd(I2C_ADDRESS, LCD_CHAR,LCD_ROW);


void setup() {
  Serial.begin(9600);

  Serial.println("Robojax MLX90614 test");  
  
  
 mlx.begin();

  Wire.begin();
  lcd.begin();
  lcd.backlight();  
      lcd.print("Robojax MLX90614");
      lcd.setCursor(0,1);
      lcd.print("Infrared Temp.");          
      delay(2000);       
      clearCharacters(1,0, LCD_CHAR-1);
      
      lcd.setCursor(0,1);
      lcd.print(typeName[0]);
      lcd.setCursor(0,2);
      lcd.print(typeName[1]);             
  
}//setup() end

void loop() {
  //Robojax.com code for MLX90614 Infrared Sensor on LCD
  if(type =='C')
  {
  printTemp('C');//object temperature in C    
  }
  //Robojax Example for MLX90614 with LCD
  if(type =='F')
  {
  printTemp('F');//object temperature in F    
  }

  if(type =='K')
  {
  printTemp('K');//object temperature in K    
  }

  if( getTemp('C')>40)
  {
    //do something here
  }
  
  delay(2000);  


  //Robojax Example for MLX90614 with LCD2004
}

/*
 * @brief returns temperature or relative humidity
 * @param "type" is a character
 *     C = Object Celsius
 *     D = Ambient Celsius
 *     
 *     K = Object Kelvin
 *     L = Ambient in Kelvin
 *     
 *     F = Object Fahrenheit
 *     G = Ambient in Fahrenheit

 * @return returns one of the values above
 * Usage: to get Fahrenheit type: getTemp('F')
 * to print it on serial monitor Serial.println(getTemp('F'));
 * Written by Ahmad Shamshiri on Mar 30, 2020. 
 * in Ajax, Ontario, Canada
 * www.Robojax.com 
 */
float getTemp(char type)
{
     //Robojax.com code for MLX90614 Infrared Sensor on LCD
  float value;
    float tempObjec = mlx.readObjectTempC();//in C object
    float tempAmbient = mlx.readAmbientTempC();
   if(type =='F')
   {
    value = mlx.readObjectTempF(); //Fah. Object
   }else if(type =='G')
   {
    value = mlx.readAmbientTempF();//Fah Ambient
   }else if(type =='K')
   {
    value = tempObjec + 273.15;// Object Kelvin
   }else if(type =='L')
   {
    value = tempAmbient + 273.15;//Ambient Kelvin
   }else if(type =='C')
   {
    value = tempObjec;
   }else if(type =='D')
   {
    value = tempAmbient;
   }
   return value;
      //Robojax.com code for MLX90614 Infrared Sensor on LCD
}//getTemp

/*
 * @brief nothing
 * @param "type" is a character
 *     C = Object Celsius
 *     D = Ambient Celsius
 *     
 *     K = Object Kelvin
 *     L = Ambient in Kelvin
 *     
 *     F = Object Fahrenheit
 *     G = Ambient in Fahrenheit

 * @return prints temperature value in serial monitor
 * Usage: to get Fahrenheit type: getTemp('F')
 * to print it on serial monitor Serial.println(getTemp('F'));
 * Written by Ahmad Shamshiri on Mar 30, 2020 at 21:51
 * in Ajax, Ontario, Canada
 * www.Robojax.com 
 */
void printTemp(char type)
{

    //Robojax.com code for MLX90614 Infrared Sensor on LCD

  float tmp =getTemp(type);    
  if(type =='C')
  {

      clearCharacters(1,strlen(typeName[0])-1, LCD_CHAR-1 );   
      lcd.setCursor(strlen(typeName[0])-1,1);      
      lcd.print(": ");
      lcd.print(tmp);        
      lcd.print((char)223);// 
      lcd.print("C");   
      

      clearCharacters(2,strlen(typeName[1])-1, LCD_CHAR-1 );   
      lcd.setCursor(strlen(typeName[1])-1,2);      
      lcd.print(": ");
      lcd.print(getTemp('D'));        
      lcd.print((char)223);// 
      lcd.print("C");            
              

  }else if(type =='F')
  {
      clearCharacters(1,strlen(typeName[0])-1, LCD_CHAR-1 );   
      lcd.setCursor(strlen(typeName[0])-1,1);      
      lcd.print(": ");
      lcd.print(tmp);        
      lcd.print((char)223);// 
      lcd.print("F");   
      

      clearCharacters(2,strlen(typeName[1])-1, LCD_CHAR-1 );   
      lcd.setCursor(strlen(typeName[1])-1,2);      
      lcd.print(": ");
      lcd.print(getTemp('F'));        
      lcd.print((char)223);// 
      lcd.print("F");           
  }
  else if(type =='K')
  {
      clearCharacters(1,strlen(typeName[0])-1, LCD_CHAR-1 );   
      lcd.setCursor(strlen(typeName[0])-1,1);      
      lcd.print(": ");
      lcd.print(getTemp('K'));        
      lcd.print((char)223);// 
      lcd.print("K");   
      

      clearCharacters(2,strlen(typeName[1])-1, LCD_CHAR-1 );   
      lcd.setCursor(strlen(typeName[1])-1,2);      
      lcd.print(": ");
      lcd.print(getTemp('L'));        
      lcd.print((char)223);// 
      lcd.print("K");                  
  }  
  

  //Robojax.com code for MLX90614 Infrared Sensor on LCD
}//printTemp(char type)


/*
   clearCharacters(uint8_t row,uint8_t start, uint8_t stop)
 * @brief clears a line of display (erases all characters)
 * @param none
 * @return does not return anything
 * Written by Ahmad Shamshiri
 * www.Robojax.com code May 28, 2020 at 16:21 in Ajax, Ontario, Canada
 */
void clearCharacters(uint8_t row,uint8_t start, uint8_t stop )
{
    for (int i=start; i<=stop; i++)
    {
    lcd.setCursor (i,row); //  
    lcd.write(254);
    } 

}//clearCharacters

Ресурсы и ссылки

Ресурсов пока нет.

Файлы📁

Нет доступных файлов.