วันเสาร์ที่ 2 มิถุนายน พ.ศ. 2561

(งาน1) https://www.arduino-board.com/projects/arduino-thermometer

Arduino As A Thermometer

The Arduino Thermometer project is very similar to the Arduino Voltmeter project, in that it measures an analog voltage, calculates an output value, and displays that value. The difference is that the voltage comes from a TI LM35 temperature sensor.
Arduino thermometer project with LCD and LM35 temperature sensor.
This project is a modification to the older project, which used a parallel LCD interface. The parallel interface used 8 of the Uno's 11 useful digital lines. The I2C LCD which replaces it uses two analog inputs - A4 and A5.
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD to address 0x27, 16 chars, and 2 lines.
LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
  lcd.init();
  lcd.backlight();
}

void loop()
{
  char str[16];
  double degC, degF;

  // Read the LM35 sensor on A3.
  int adu = analogRead(A3);

  // Calculate the temperature.
  degC = adu * 0.488;
  degF = (adu * 0.8784) + 32;

  // Turn it into a string.
  memset(str, 0, sizeof(str));
  dtostrf(degC,1,2,str);
  strcat(str, " C ");
  dtostrf(degF,1,2,str+(strlen(str)));
  strcat(str, " F");

  // Display the header and the string.
  lcd.setCursor(0,0);
  lcd.print("Temperature");
  lcd.setCursor(0,1);
  lcd.print(str);

  delay(1000);
}
 
An Arduino thermometer using the LM35 and an LCD display to show the temperature in degrees Fahrenheight and Centigrade.
The LM35 uses A3 but you could connect it to any available analog input.
This project shows that most things Arduino center around the Arduino software, and the hardware sort of takes care of itself. For this project, I plugged in an I2C LCD, a three wire temperature sensor, and wrote a few lines of code. The software libraries for Arduino take care of the rest of it.
An Arduino thermometer using the LM35 and 2 diodes to show negative temperatures.
The LM35 with a pair of diodes in the ground lead allows you to read negative temperatures. The reading on A2 is subtracted from the reading on A1, and the result is processed as "adu" in the code above.
An Arduino thermometer using three LM35s and 2 diodes to show 3 different temperatures.
If you want more than one temperature probe, wire up the LM35 like this.read A1 and subtract it from A2, A3, and A4 for three temperatures that can be positive or negative. You can move the analog inputs around and still use A4 and A5 for an I2C LCD.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น