Cov txheej txheem:

Ntsuas Kev Ntsuas Siv HYT939 thiab Arduino Nano: 4 Cov Kauj Ruam
Ntsuas Kev Ntsuas Siv HYT939 thiab Arduino Nano: 4 Cov Kauj Ruam

Video: Ntsuas Kev Ntsuas Siv HYT939 thiab Arduino Nano: 4 Cov Kauj Ruam

Video: Ntsuas Kev Ntsuas Siv HYT939 thiab Arduino Nano: 4 Cov Kauj Ruam
Video: Qhia txuas xaim hluav taws xob daim: 02 2024, Kaum ib hlis
Anonim
Image
Image

HYT939 yog lub ntsuas hluav taws xob digital uas ua haujlwm ntawm I2C kev sib txuas lus raws tu qauv. Cov av noo yog qhov ntsuas tseem ceeb thaum nws los txog rau kev kho mob thiab chaw kuaj mob, Yog li txhawm rau ua kom tiav cov hom phiaj no peb tau sim cuam tshuam HYT939 nrog arduino nano. Hauv qhov kev qhia no kev cuam tshuam ntawm HYT939 sensor module nrog arduino nano tau pom.

Txhawm rau nyeem cov av noo qhov tseem ceeb, peb tau siv arduino nrog I2c adapter Qhov no I2C adapter ua rau kev txuas mus rau lub ntsuas qhov ntsuas tau yooj yim thiab ntseeg tau ntau dua.

Cov txheej txheem kev sib txuas lus uas lub sensor ua haujlwm yog I2C. I2C sawv cev rau kev sib koom ua ke. Nws yog cov txheej txheem kev sib txuas lus uas kev sib txuas lus tau tshwm sim los ntawm SDA (cov ntaub ntawv xov xwm) thiab SCL (cov xov tooj). Nws tso cai txuas ntau yam khoom siv tib lub sijhawm. Nws yog ib qho ntawm cov txheej txheem kev sib txuas lus yooj yim tshaj plaws thiab muaj txiaj ntsig tshaj plaws.

Kauj Ruam 1: Yuav Tsum Kho Vajtse:

Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse

Cov ntaub ntawv uas peb xav tau kom ua tiav peb lub hom phiaj suav nrog cov khoom siv hauv qab no:

1. HYT939

2. Arduino Nano

3. I2C Cable

4. I2C ntaub thaiv npog rau Arduino nano

Kauj ruam 2: Khoos phis tawj sib txuas:

Kho vajtse Hookup
Kho vajtse Hookup
Kho vajtse Hookup
Kho vajtse Hookup

Tshooj khoos phis tawj sib txuas ntu piav qhia qhov txuas txuas uas xav tau ntawm lub sensor thiab arduino nano. Ua kom muaj kev sib txuas raug yog qhov tseem ceeb xav tau thaum ua haujlwm ntawm ib qho system rau qhov xav tau cov zis. Yog li, qhov xav tau kev sib txuas yog raws li hauv qab no:

HYT939 yuav ua haujlwm dhau I2C. Nov yog qhov piv txwv kab hluav taws xob daim duab, qhia txog yuav ua li cas xaim txhua lub interface ntawm lub sensor.

Tawm-ntawm-lub thawv, lub rooj tsavxwm tau teeb tsa rau I2C interface, zoo li peb pom zoo siv qhov kev sib txuas no yog tias koj tsis ntseeg lwm yam. Txhua yam koj xav tau yog plaub lub xov hlau!

Tsuas yog plaub qhov kev sib txuas xav tau Vcc, Gnd, SCL thiab SDA tus pin thiab cov no txuas nrog kev pab ntawm I2C cable.

Cov kev sib txuas no tau qhia hauv cov duab saum toj no.

Kauj Ruam 3: Arduino Code rau Kev Ntsuas Kev Ntsuas:

Arduino Code rau Kev Ntsuas Kev Ntsuas
Arduino Code rau Kev Ntsuas Kev Ntsuas
Arduino Code rau Kev Ntsuas Kev Ntsuas
Arduino Code rau Kev Ntsuas Kev Ntsuas

Cia peb pib nrog Arduinoo code tam sim no.

Thaum siv lub ntsuas ntsuas nrog Arduino, peb suav nrog Wire.h lub tsev qiv ntawv. "Hlau" lub tsev qiv ntawv muaj cov haujlwm uas pab txhawb i2c kev sib txuas lus ntawm lub sensor thiab Arduino board.

Tag nrho cov cai Arduino tau muab hauv qab no kom yooj yim ntawm cov neeg siv:

#suav nrog

// HYT939 I2C chaw nyob yog 0x28 (40)

#define Ntxiv 0x28

void teeb tsa ()

{

// Pib I2C kev sib txuas lus li MASTER

Hlau.begin ();

// Initialise Serial Communication

Serial.begin (9600);

ncua (300);

}

void lub voj ()

{

unsigned int cov ntaub ntawv [4];

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa ib txwm hais kom ua hom

Hlau.write (0x80);

// Nres I2C kev xa mus

Wire.endTransmission ();

ncua (300);

// Thov 4 bytes ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 4);

// Nyeem 4 bytes ntawm cov ntaub ntawv

// humidity msb, humidity lsb, temp msb, temp lsb

yog (Wire.available () == 4)

{

cov ntaub ntawv [0] = Wire.read ();

cov ntaub ntawv [1] = Wire.read ();

cov ntaub ntawv [2] = Wire.read ();

cov ntaub ntawv [3] = Wire.read ();

// Hloov cov ntaub ntawv mus rau 14-ntsis

ntab ntub = (((data [0] & 0x3F) * 256.0) + data [1]) * (100.0 / 16383.0);

ntab cTemp = (((data [2] * 256.0) + (data [3] & 0xFC)) / 4) * (165.0 / 16383.0) - 40;

ntab fTemp = (cTemp * 1.8) + 32;

// Cov ntaub ntawv tso tawm rau tus saib xyuas

Serial.print ("Tus txheeb ze Vaum:");

Serial.print (av noo);

Serial.println (" %RH");

Serial.print ("Kub hauv Celsius:");

Serial.print (cTemp);

Serial.println ("C");

Serial.print ("Kub hauv Fahrenheit:");

Serial.print (fTemp);

Serial.println ("F");

}

ncua (300);

}

Hauv cov tsev qiv ntawv xaim Wire.write () thiab Wire.read () yog siv los sau cov lus txib thiab nyeem cov ntawv tso tawm. Ua raws ib feem ntawm txoj cai qhia txog kev nyeem ntawv ntawm cov zis sensor.

// Nyeem 4 bytes ntawm cov ntaub ntawv // humidity msb, humidity lsb, temp msb, temp lsb yog (Wire.available () == 4) {data [0] = Wire.read (); cov ntaub ntawv [1] = Wire.read (); cov ntaub ntawv [2] = Wire.read (); cov ntaub ntawv [3] = Wire.read ();

}

Cov zis sensor tau pom hauv daim duab saum toj no.

Kauj Ruam 4: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

HYT939 ua qhov ntsuas cov av noo zoo tau ua haujlwm hauv Kev Kho Mob, Autoclaves. Ntsuas dej ntsuas taw tes thiab Tshuab Kom Qhuav kuj pom qhov siv ntawm qhov ntsuas qhov ntsuas no. Hauv ntau qhov Laboratories qhov twg cov av noo tsim nyog yog qhov ntsuas tseem ceeb rau kev sim, qhov ntsuas no tuaj yeem siv rau qhov ntsuas qhov av noo.

Pom zoo: