குறியீட்டை தேடு

அர்டுயினோ குறியீடு மற்றும் வீடியோ, Aosong AM2320 டிஜிட்டல் வெப்பநிலை மற்றும் ஈரப்பதம் சென்சார், LCD1602 மற்றும் I2C தொகுதியுடன்

அர்டுயினோ குறியீடு மற்றும் வீடியோ, Aosong AM2320 டிஜிட்டல் வெப்பநிலை மற்றும் ஈரப்பதம் சென்சார், LCD1602 மற்றும் I2C தொகுதியுடன்

இந்த டுடோரியலில், Aosong AM2320 டிஜிட்டல் வெப்பநிலை மற்றும் ஈரப்பதம் சென்சார் மற்றும் I2C தொகுதியைப் பயன்படுத்தும் LCD1602 டிஸ்ப்ளேவை எவ்வாறு பயன்படுத்துவது என்பதை ஆராய்வோம். வெப்பநிலை அளவீடுகளை ஃபாரன்ஹீட் மற்றும் செல்சியஸ் இரண்டிலும், அத்துடன் ஒப்பீட்டு ஈரப்பதத்தையும் காண்பிப்பதே குறிக்கோள். இந்த அமைப்பு பல்வேறு திட்டங்களில் சுற்றுச்சூழல் நிலைமைகளைக் கண்காணிக்க ஏற்றது, இது உங்கள் Arduino கருவித்தொகுப்பிற்கு பல்துறை சேர்ப்பாக அமைகிறது.

வெப்பநிலை மற்றும் ஈரப்பதத் தரவைச் சேகரிக்க AM2320 சென்சாரைப் பயன்படுத்துவோம், பின்னர் அது LCD1602 இல் காட்டப்படும். I2C தொகுதி வயரிங் செயல்முறையை எளிதாக்குகிறது, VCC, GND, SDA மற்றும் SCL ஆகிய நான்கு இணைப்புகள் மட்டுமே தேவை. வயரிங் மற்றும் நிரலாக்கத்தைப் பற்றிய தெளிவான புரிதலுக்கு, தொடர்புடைய வீடியோவைப் பார்க்க பரிந்துரைக்கிறேன் (வீடியோவில் 00:00 மணிக்கு).

வன்பொருள் விளக்கம்

இந்த திட்டத்தின் முக்கிய கூறுகளில் AM2320 சென்சார், LCD1602 டிஸ்ப்ளே மற்றும் I2C தொகுதி ஆகியவை அடங்கும். AM2320 என்பது ஒரு டிஜிட்டல் சென்சார் ஆகும், இது I2C இடைமுகம் மூலம் வெப்பநிலை மற்றும் ஈரப்பதத்தின் துல்லியமான அளவீடுகளை வழங்குகிறது. இது 3.3V முதல் 5.5V வரையிலான மின்னழுத்தத்தில் இயங்குகிறது மற்றும் வெப்பநிலைக்கு -40°C முதல் +80°C வரையிலும், ஈரப்பதத்திற்கு 0% முதல் 100% வரையிலும் அளவீட்டு வரம்பைக் கொண்டுள்ளது.

LCD1602 டிஸ்ப்ளே சென்சார் அளவீடுகளைக் காட்சிப்படுத்த அனுமதிக்கிறது. இது 16x2 எழுத்து டிஸ்ப்ளே ஆகும், இது I2C நெறிமுறை மூலம் தொடர்பு கொள்கிறது, இது தேவையான இணைப்புகளின் எண்ணிக்கையை நான்காகக் குறைக்கிறது. I2C தொகுதி LCD இலிருந்து இணையான தரவை தொடர் வடிவமாக மாற்றுகிறது, இது Arduino உடன் இணைப்பதை எளிதாக்குகிறது.

டேட்டாஷீட் விவரங்கள்

உற்பத்தியாளர்Aosong
பகுதி எண்AM2320
லாஜிக்/IO மின்னழுத்தம்3.3 V - 5.5 V
வழங்கல் மின்னழுத்தம்3.3 V - 5.5 V
வெளியீட்டு மின்னோட்டம்≤ 1.5 mA
அளவீட்டு வரம்பு (வெப்பநிலை)-40°C முதல் +80°C வரை
அளவீட்டு வரம்பு (ஈரப்பதம்)0% முதல் 100% வரை
பதில் நேரம்≤ 2s
பேக்கேஜ்DIP-4
குறிப்புகள் / மாறுபாடுகள்I2C இணைப்புகளுக்கு மின்தடை புல்-அப்கள் பரிந்துரைக்கப்படுகின்றன.

  • குறிப்பிட்ட மின்னழுத்த வரம்பிற்குள் சரியான மின்சார வழங்கலை உறுதி செய்யவும்.
  • SDA மற்றும் SCL கோடுகளுக்கு புல்-அப் மின்தடைகளை (4.7kΩ பரிந்துரைக்கப்படுகிறது) பயன்படுத்தவும்.
  • சரியான I2C முகவரியைச் சரிபார்க்கவும் (பெரும்பாலான LCD களுக்கு இயல்புநிலை 0x27 ஆகும்).
  • சென்சாரின் பிழைக் குறியீட்டைச் சரிபார்த்து சாத்தியமான பிழைகளைக் கையாளவும்.
  • ஒன்றுடன் ஒன்று சேர்வதைத் தவிர்க்க புதிய அளவீடுகளைக் காண்பிக்கும் முன் LCD ஐ அழிக்கவும்.

வயரிங் வழிமுறைகள்

Arduino wiring for AM2320 sensor with LCD
Arduino wiring for AM2320 sensor with LCD

AM2320 சென்சாரை வயர் செய்ய, இடது பின்னை (VCC) Arduino இல் 5V உடன் இணைக்கவும். இரண்டாவது பின் (SDA) Arduino Uno இல் A4 பின்னுக்கு (அல்லது Mega இல் பின் 20 க்கு) செல்கிறது. மூன்றாவது பின் (GND) தரையுடன் இணைக்கப்பட வேண்டும், மற்றும் நான்காவது பின் (SCL) Arduino Uno இல் A5 பின்னுடன் (அல்லது Mega இல் பின் 21 உடன்) இணைகிறது. கூடுதலாக, SDA பின்னுக்கும் 5V க்கும் இடையில் ஒரு 4.7kΩ மின்தடையையும், SCL பின்னுக்கும் 5V க்கும் இடையில் மற்றொரு 4.7kΩ மின்தடையையும் இணைக்கவும், இது சரியான சிக்னல் அளவுகளை உறுதி செய்கிறது.

I2C உடன் LCD1602 டிஸ்ப்ளேவுக்கு, VCC பின்னை 5V உடனும் GND பின்னை தரையுடனும் இணைக்கவும். LCD இலிருந்து SDA பின்னை சென்சாருக்குப் பயன்படுத்தப்படும் அதே SDA பின்னுடன் (A4) இணைக்கவும். இதேபோல், LCD இலிருந்து SCL பின்னை சென்சாருக்குப் பயன்படுத்தப்படும் அதே SCL பின்னுடன் (A5) இணைக்கவும். இந்த பகிரப்பட்ட வயரிங் இரண்டு சாதனங்களும் ஒரே I2C பேருந்தில் தொடர்பு கொள்ள அனுமதிக்கிறது.

குறியீடு எடுத்துக்காட்டுகள் & விளக்கம்

பின்வரும் குறியீடு AM2320 சென்சார் மற்றும் LCD1602 டிஸ்ப்ளேவை துவக்குகிறது. இது தேவையான நூலகங்களைச் சேர்ப்பதன் மூலம் தொடங்கி சென்சாரின் ஒரு நிகழ்வை உருவாக்குகிறது.

#include 
AM2320 சென்சார்;
#include 
LiquidCrystal_I2C lcd(0x27, 16, 2);

இங்கே, சென்சார் பொருள் AM2320 நூலகத்திலிருந்து உருவாக்கப்படுகிறது, மேலும் lcd பொருள் காட்சியின் I2C முகவரியுடன் துவக்கப்படுகிறது.

setup() செயல்பாட்டில், சென்சார் மற்றும் LCD இரண்டையும் துவக்குகிறோம். இதில் பின்னொளியை இயக்குவது மற்றும் ஆரம்ப செய்தியை அச்சிடுவது அடங்கும்.

void setup() {
  sensor.begin();
  lcd.begin();
  lcd.backlight();
  lcd.print("Robojax AM2320 ");
  lcd.setCursor (0,1);
  lcd.print("LCD1602 I2C டெமோ");
  delay(3000);
}

இந்த குறியீடு காட்சியை 3 வினாடிகளுக்கு வரவேற்பு செய்தியைக் காட்ட அமைக்கிறது, இதனால் பயனர் அமைப்பு துவங்குவதைப் பார்க்க நேரம் கிடைக்கும்.

loop() செயல்பாடு தொடர்ந்து சென்சார் அளவீடுகளைச் சரிபார்த்து, அதற்கேற்ப காட்சியைப் புதுப்பிக்கிறது. ஒரு அளவீடு கிடைத்தால், அது திரையை அழித்து, வெப்பநிலையை பாரன்ஹீட் மற்றும் செல்சியஸ் இரண்டிலும், ஈரப்பதத்துடன் அச்சிடுகிறது.

void loop() {
  if (sensor.measure()) {
    lcd.clear();
    lcd.print("T:");
    lcd.print(temp('F'));
    lcd.print("F/");
    lcd.print(temp('C'));
    lcd.print("C");  
    lcd.setCursor (0,1);
    lcd.print("R.H. :");
    lcd.print(sensor.getHumidity());
    lcd.print("%"); 
  }
  else {
    int errorCode = sensor.getErrorCode();
    switch (errorCode) {
      case 1: lcd.print("பிழை: சென்சார் ஆஃப்லைன்"); break;
      case 2: lcd.print("பிழை: CRC தோல்வி."); break;
    }    
  }
  delay(500);
}

இந்த பகுதி, நிரல் சென்சார் தரவை எவ்வாறு பெற்று காட்சிப்படுத்துகிறது என்பதைக் காட்டுகிறது, அதே நேரத்தில் errorCode ஐச் சரிபார்த்து சாத்தியமான பிழைகளைக் கையாளுகிறது.

செயல்விளக்கம் / என்ன எதிர்பார்க்கலாம்

அமைப்பு முடிந்ததும், LCD வெப்பநிலையை பாரன்ஹீட் மற்றும் செல்சியஸ் இரண்டிலும், ஈரப்பத சதவீதத்தையும் காண்பிக்கும் என எதிர்பார்க்கலாம். சென்சார் ஆஃப்லைனில் இருந்தால் அல்லது CRC பிழை இருந்தால், காட்சி அதற்கான பிழை செய்திகளைக் காண்பிக்கும். எந்த பிரச்சனையும் ஏற்படாமல் இருக்க அனைத்து இணைப்புகளும் பாதுகாப்பாக இருப்பதை உறுதி செய்வது முக்கியம் (வீடியோவில் 02:45 இல்).

வீடியோ நேரக்குறிப்புகள்

  • 00:00 - திட்டத்திற்கான அறிமுகம்
  • 01:30 - வயரிங் வழிமுறைகள்
  • 03:15 - குறியீடு விளக்கம்
  • 04:45 - செயல்பாட்டின் செயல்விளக்கம்

படங்கள்

AM2320-sensor-1
AM2320-sensor-1
AM2320-sensor-2
AM2320-sensor-2
AM2320-sensor-3
AM2320-sensor-3
AM2320-sensor-4
AM2320-sensor-4
Arduino wiring for AM2320 sensor with LCD
Arduino wiring for AM2320 sensor with LCD
85-This is the Arduino code for an Aosong AM2320 temperature and humidity sensor with an LCD1602 and I2C module.
மொழி: C++
++
/**
 * This is Arduino code for AM2320 Temperature and Humidity Sensor with LCD1602 and I2C Module
 * which displays the temperature and RH (relative humidity)
 * on an LCD1602 with an I2C module.  The code was combined by Robojax.
 * 
    Original Code For AM2320 :https://github.com/hibikiledo/AM2320
    Copyright 2016 Ratthanan Nalintasnai
    
    Modified for Robojax.com video by
    Ahmad S. on March 22, 2018 at 23:55 in Ajax, Ontario, Canada
    This code, with library and other codes, is available at
    https://robojax.com
    Watch the video instruction for this code: https://youtu.be/ym567hneDpE
**/

// Include library for AM2320
#include <AM2320.h>
// Create an instance of the sensor
AM2320 sensor;


#include <Wire.h> 
// Include the LiquidCrystal library for display
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);


void setup() {
  // Call sensor.begin() to initialize the library
  sensor.begin();

  // Robojax code for LCD with I2C
  // Initialize the LCD, 
  lcd.begin();
   // Turn on the backlight and print a message.
  lcd.backlight();
  lcd.print("Robojax AM2320 ");
  lcd.setCursor (0,1);
  lcd.print("LCD1602 I2C Demo");
  delay(3000);
}

void loop() {
  if (sensor.measure()) {
    lcd.clear();
    lcd.print("T:");
    lcd.print(temp('F'));
    lcd.print("F/");
    lcd.print(temp('C'));
    lcd.print("C");  
    lcd.setCursor (0,1); // go to start of 2nd line
    lcd.print("R.H. :");
    lcd.print(sensor.getHumidity());
    lcd.print("%"); 
  

  }
  else {  // An error has occurred
    int errorCode = sensor.getErrorCode();
    switch (errorCode) {
      case 1: lcd.print("ERR: Sensor offline"); break;
      case 2: lcd.print("ERR: CRC failed."); break;
    }    
  }

  delay(500);
}

/*
 * temp()
 * Returns the temperature based on the input character T.
 * If T == 'F', converts Celsius to Fahrenheit.
 * Otherwise, returns Celsius.
 * How to use:
 *  To get Fahrenheit, use temp('F').
 *  To get Celsius, use temp('C') or temp('').
 *  temp('') uses an empty single quote.
 * 
 */
float temp(char T)
{
  if (sensor.measure()) {
    if(T =='F')
    {
      // Convert to FAHRENHEIT and return
      // Robojax video tutorial
      return sensor.getTemperature()* 1.8 + 32;
    }else{
      return sensor.getTemperature();// Return CELSIUS
    }

  }// if sensor.measure  
}
86-This is the Arduino code for the Aosong AM2320 temperature and humidity sensor with an LCD1602 and I2C module.
மொழி: C++
/*********************************************************************
Original source: http://playground.arduino.cc/Main/I2cScanner

This program will find the I2C address on the I2C device. Just upload the code into your Arduino
and open the serial monitor and wait. It will display the I2C address as 0x3C or similar.

 * Please view other RoboJax codes and videos at http://robojax.com/learn/arduino
 * If you are sharing this code, you must keep this copyright note.
 * 
*********************************************************************/


#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The I2C scanner uses the return value of
    // the Wire.endTransmission to see if
    // a device did acknowledge the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

நீங்கள் தேவைப்படும் எண்ணங்கள்

வளங்கள் மற்றும் மேற்கோள்கள்

கோப்புகள்📁

தரவியல் அட்டவணை (பிடிஎப்)

பிரிட்சிங் கோப்பு