如何使用Arduino构建室温监视器

电子说

1.3w人已加入

描述

步骤1:您需要的东西

监视器

您将需要arduino入门套件

以下内容需要使用该套件:

arduino uno。

7段。

LM35(温度)传感器。

蜂鸣器

RGB LED模块。

连接电线。

电池。

一个电阻器。

面包板

安装了arduino IDE的笔记本电脑或个人电脑。

等。

第2步:

监视器

监视器

监视器

现在制作根据上图给出的电路。

将第2引脚连接到第9引脚至7段显示。

arduino引脚7段引脚

第2 =》 e

3rd =》 d

4th =》 c

5th =》 dp

6th =》 b

7th = 》 a

8th =》 f

9th =》 g

现在将A0引脚arduino连接到LM35的第2引脚。

现在将RGB led和蜂鸣器连接到arduino uno引脚no.0 ,1,13和12.

步骤3:编程。。.。。

只需将以下代码复制并粘贴到Arduino IDE并将代码刻录到Arduino UNO///

inti = 0;

intval;

int temp = 0;

void setup()

{

Serial.begin(9600);

pinMode(2,OUTPUT);

pinMode( 3,OUTPUT);

pinMode(4,OUTPUT);

pinMode(5,OUTPUT);

pinMode(6,OUTPUT);

pinMode(7,OUTPUT);

pinMode(8,OUTPUT);

pinMode(9,OUTPUT);

pinMode(10, OUTPUT);

pinMode(11,OUTPUT);

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

pinMode(1,OUTPUT);

pinMode(0,OUTPUT);

digitalWrite(0,LOW);

digitalWrite(12,LOW)

digitalWrite(1,LOW);

digitalWrite(13,LOW);

digitalWrite(10,LOW);

digitalWrite(11,LOW);

}

void loop()

{

val = analogRead(A0);

float mv =(val/1 024.0)* 5000;

intcel = mv/10;

if(cel 《= 30)

{

digitalWrite(0,HIGH);

digitalWrite(1,LOW);

digitalWrite(12,LOW);

延迟(10);

digitalWrite(0,LOW);

digitalWrite(1,LOW);

digitalWrite(12,LOW);

digitalWrite(13,LOW);

//Serial.println(“lower 30”);

}

if(cel》 30&< cel 《40)

{

digitalWrite(0,LOW);

digitalWrite(1,HIGH);

digitalWrite(12,LOW);

延迟(10);

digitalWrite(0,LOW);

digitalWrite(1,LOW);

digitalWrite(12,LOW);

digitalWrite(13,LOW);

//Serial.println(“Higher 30”);

}

如果(CEL》 = 40)

{

digitalWrite(13,HIGH);

digitalWrite(0,LOW);

digitalWrite(1,LOW);

digitalWrite(12,HIGH);

延迟(10);

digitalWrite(0,LOW);

digitalWrite(1,LOW);

digitalWrite(12,LOW);

digitalWrite(13,LOW);

//Serial.println(“Higher 40”);

}

否则{

digitalWrite(0,LOW);

digitalWrite(1,LOW);

digitalWrite(12,LOW);

}

临时= CEL/10;

digitalWrite(11,HIGH);

SevenSegament(温度);

digitalWrite(11,LOW);

I = CEL%10;

digitalWrite(10,HIGH);

SevenSegament(ⅰ);

digitalWrite(10,LOW);

}

voidSevenSegament(int j)

{

if (j == 0){

digitalWrite(2,LOW);

digitalWrite(3,LOW);

digitalWrite(4,LOW);

digitalWrite(5,HIGH);

digitalWrite(6,LOW);

digitalWrite(7,LOW);

digitalWrite( 8,LOW);

digitalWrite(9,HIGH);

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7, HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

}

if(j = = 1){

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,LOW);

digitalWrite(5,HIGH);

digitalWrite(6,LOW);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH );

digitalWrite(9,HIGH);

digitalWrite(2,HIGH);

位alWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

}

if(j == 2){

digitalWrite(2,LOW);

digitalWrite(3,LOW);

digitalWrite(4,HIGH);

digitalWrite(5,HIGH);

digitalWrite(6, LOW);

digitalWrite(7,LOW);

digitalWrite(8,HIGH);

digitalWrite(9,LOW);

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite(5,HIGH)

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

}

if(j == 3)

{digitalWrite(2,HIGH);

digitalWrite(3,LOW);

digitalWrite(4,LOW);

digitalWrite(5,HIGH);

digitalWrite(6,LOW);

digitalWrite(7,LOW);

digitalWrite(8,HIGH);

digitalWrite(9,LOW);

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite (5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

}

if(j == 4){

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,LOW);

digitalWrite(5,HIGH);

digitalWrite( 6,LOW);

digitalWrite(7,HIGH);

digitalWrite(8,LOW);

digitalWrite(9,LOW);

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite(5, HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);}

如果(j == 5){

digitalWrite(2,HIGH);

digitalWrite(3, LOW);

digitalWrite(4,LOW);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,LOW);

digitalWrite(8,LOW);

digitalWrite(9,LOW);

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite (5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);}

如果(j == 6){

digitalWrite(2,LOW);

digitalWrite (3,LOW);

digitalWrite(4,LOW);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,LOW);

digitalWrite(8,LOW);

digitalWrite(9,LOW);

digitalWrite(2 ,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH );

}

if(j == 7){

digitalWrite(2,HIGH);

digitalWrite(3, HIGH);

digitalWrite(4,LOW);

digitalWrite(5,HIGH);

digitalWrite(6,LOW);

digitalWrite(7,LOW);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

digitalWrite(2,HIGH)

digitalWrite(3,HIGH);

digitalW仪式(4,HIGH);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);}

if(j == 8)

{

digitalWrite(2,LOW);

digitalWrite(3,LOW);

digitalWrite(4,LOW);

digitalWrite (5,HIGH);

digitalWrite(6,LOW);

digitalWrite(7,LOW);

digitalWrite(8,LOW);

digitalWrite(9,LOW);

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4- ,HIGH);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);}

如果(j == 9){

digitalWrite(2 ,HIGH);

digitalWrite(3,LOW);

digitalWrite(4,LOW);

digitalWrite(5,HIGH);

digitalWrite(6,LOW);

digitalWrite(7,LOW);

digitalWrite(8,LOW);

digitalWrite(9,LOW );

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

}

}

步骤4:电源。。.

现在只需从套件中提供的电池组供电即可。你会看到7段的温度读数。

就是这样。享受。

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分