Cov txheej txheem:

Arduino Nano - STS21 Kub Sensor Qhia: 4 Kauj Ruam
Arduino Nano - STS21 Kub Sensor Qhia: 4 Kauj Ruam

Video: Arduino Nano - STS21 Kub Sensor Qhia: 4 Kauj Ruam

Video: Arduino Nano - STS21 Kub Sensor Qhia: 4 Kauj Ruam
Video: ⛅️Погодная станция на Arduino своими руками 2024, Kaum ib hlis
Anonim
Image
Image

STS21 Digital Kub Sensor muab qhov ua tau zoo tshaj plaws thiab txuag chaw hneev taw. Nws muab kev ntsuas ntsuas, kab cim qhia tawm hauv digital, hom I2C. Kev tsim cov ntsuas no yog ua raws CMOSens thev naus laus zis, uas yog tus yam ntxwv zoo rau kev ua tau zoo thiab ntseeg tau ntawm STS21. Kev daws teeb meem ntawm STS21 tuaj yeem hloov pauv los ntawm kev hais kom ua, roj teeb qis tuaj yeem kuaj pom thiab daim tshev nyiaj pab txhim kho kev sib txuas lus ntseeg tau. Nov yog nws qhov ua piv txwv ntawm kev cuam tshuam nrog Arduino nano.

Kauj Ruam 1: Yam Koj Xav Tau..

Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

1. Arduino Nano

2. STS21

3. I²C Cable

4. I²C Shield rau Arduino Nano

Kauj Ruam 2: Kev Sib Txuas:

Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas

Siv daim I2C daim thaiv rau Arduino Nano thiab maj mam thawb nws hla tus pin ntawm Nano.

Tom qab ntawd txuas ib kawg ntawm I2C cable rau STS21 sensor thiab lwm qhov kawg rau I2C daim ntaub thaiv.

Kev sib txuas tau qhia hauv daim duab saum toj no.

Kauj ruam 3: Code:

Txoj Cai
Txoj Cai

Tus lej Arduino rau STS21 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom-Dcube Store.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/STS21…

Peb suav nrog tsev qiv ntawv Wire.h los pab txhawb I2c kev sib txuas lus ntawm lub sensor nrog Arduino board.

Koj tseem tuaj yeem luam cov cai los ntawm no, nws tau muab raws li hauv qab no:

// Faib nrog daim ntawv tso cai yuav dawb.

// Siv nws txhua txoj hauv kev uas koj xav tau, muaj txiaj ntsig lossis pub dawb, muab nws haum rau hauv daim ntawv tso cai ntawm nws cov haujlwm ua haujlwm.

// TSI 21

// Cov cai no tau tsim los ua haujlwm nrog STS21_I2CS I2C Mini Module muaj nyob hauv Dcube Store.

#suav nrog

// STS21 I2C chaw nyob yog 0x4A (74)

#define ntxiv 0x4A

void teeb tsa ()

{

// Pib I2C kev sib txuas lus li MASTER

Hlau.begin ();

// Pib kev sib txuas lus, teeb tsa tus lej = 9600

Serial.begin (9600);

ncua (300);

}

void lub voj ()

{

unsigned int cov ntaub ntawv [2];

// Pib I2C Kev Kis

Wire.beginTransmission (addr);

// Xaiv tsis tuav tus tswv

Hlau.write (0xF3);

// Xaus I2C Kev Kis

Wire.endTransmission ();

ncua (300);

// Thov 2 bytes ntawm cov ntaub ntawv

Wire.requestFrom (addr, 2);

// Nyeem 2 bytes ntawm cov ntaub ntawv

yog (Wire.available () == 2)

{

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

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

}

// Hloov cov ntaub ntawv

int rawtmp = cov ntaub ntawv [0] * 256 + cov ntaub ntawv [1];

int tus nqi = rawtmp & 0xFFFC;

ob cTemp = -46.85 + (175.72 * (tus nqi / 65536.0));

ob fTemp = cTemp * 1.8 + 32;

// Cov ntaub ntawv tso tawm rau tus saib xyuas

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

Serial.print (cTemp);

Serial.println ("C");

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

Serial.print (fTemp);

Serial.println ("F");

ncua (300);

}

Kauj Ruam 4: Cov ntawv thov:

STS21 Digital Kub Sensor tuaj yeem ua haujlwm hauv cov kab ke uas xav tau qhov ntsuas kub kom raug. Nws tuaj yeem suav nrog hauv ntau lub tshuab computer, cov cuab yeej siv kho mob thiab kev tswj hwm kev lag luam nrog qhov xav tau ntawm kev ntsuas kub nrog qhov ua tau zoo.

Pom zoo: