-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensoresTemperatura.html
149 lines (122 loc) · 8.51 KB
/
sensoresTemperatura.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="es">
<head>
<meta name="description=" content="curso tutorial aprende arduino básico desde cero facíl">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Curso Arduino">
<meta name="author" content="Studio Miranda">
<title>arduinoes</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.css" rel="stylesheet">
<!-- Custom fonts for this template -->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<!-- <link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'> -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto&display=swap" rel="stylesheet" type='text/css'>
<link href="css/studio.css" rel="stylesheet">
</head>
<body>
<!-- Sección -->
<div class="container" style = "margin-top: 50px">
<div class="row">
<div class="col-lg-8 mx-auto">
<div class="modal-body">
<div class="miranda">
<!-- Project Details Go Here -->
<h2 class="text-uppercase text-center"><bl>ESP8266 ARDUINO CON WIFI</bl></h2>
<br>
<img class="img-fluid d-block mx-auto" src="img/tutoriales/Arduino1.png" alt="">
<br>
<h2 class="text-center"><or>CARACTERÍSTICAS DEL ESP8266</or></h2>
<br>
<div class="text-left">
<!-- ESP8266 -->
<h3>
LM35 & TMP36 Sketch
</h3>
<br>
<pre class="hljs" style="display: block; overflow-x: auto; padding: 0.5em; background: rgb(240, 240, 240); color: rgb(68, 68, 68);"><span class="hljs-comment" style="color: rgb(136, 136, 136);">/*
Calibration
Demonstrates one technique for calibrating sensor input. The sensor readings
during the first five seconds of the sketch execution define the minimum and
maximum of expected values attached to the sensor pin.
The sensor minimum and maximum initial values may seem backwards. Initially,
you set the minimum high and listen for anything lower, saving it as the new
minimum. Likewise, you set the maximum low and listen for anything higher as
the new maximum.
The circuit:
- analog sensor (potentiometer will do) attached to analog input 0
- LED attached from digital pin 9 to ground
created 29 Oct 2008
by David A Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Calibration
*/</span>
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// These constants won't change:</span>
<span class="hljs-keyword" style="font-weight: 700;">const</span> <span class="hljs-keyword" style="font-weight: 700;">int</span> sensorPin = A0; <span class="hljs-comment" style="color: rgb(136, 136, 136);">// pin that the sensor is attached to</span>
<span class="hljs-keyword" style="font-weight: 700;">const</span> <span class="hljs-keyword" style="font-weight: 700;">int</span> ledPin = <span class="hljs-number" style="color: rgb(136, 0, 0);">9</span>; <span class="hljs-comment" style="color: rgb(136, 136, 136);">// pin that the LED is attached to</span>
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// variables:</span>
<span class="hljs-keyword" style="font-weight: 700;">int</span> sensorValue = <span class="hljs-number" style="color: rgb(136, 0, 0);">0</span>; <span class="hljs-comment" style="color: rgb(136, 136, 136);">// the sensor value</span>
<span class="hljs-keyword" style="font-weight: 700;">int</span> sensorMin = <span class="hljs-number" style="color: rgb(136, 0, 0);">1023</span>; <span class="hljs-comment" style="color: rgb(136, 136, 136);">// minimum sensor value</span>
<span class="hljs-keyword" style="font-weight: 700;">int</span> sensorMax = <span class="hljs-number" style="color: rgb(136, 0, 0);">0</span>; <span class="hljs-comment" style="color: rgb(136, 136, 136);">// maximum sensor value</span>
<span class="hljs-keyword" style="font-weight: 700;">void</span> <span class="hljs-built_in" style="color: rgb(57, 115, 0);">setup</span>() {
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// turn on LED to signal the start of the calibration period:</span>
<span class="hljs-built_in" style="color: rgb(57, 115, 0);">pinMode</span>(<span class="hljs-number" style="color: rgb(136, 0, 0);">13</span>, <span class="hljs-literal" style="color: rgb(120, 169, 96);">OUTPUT</span>);
<span class="hljs-built_in" style="color: rgb(57, 115, 0);">digitalWrite</span>(<span class="hljs-number" style="color: rgb(136, 0, 0);">13</span>, <span class="hljs-literal" style="color: rgb(120, 169, 96);">HIGH</span>);
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// calibrate during the first five seconds</span>
<span class="hljs-built_in" style="color: rgb(57, 115, 0);">while</span> (<span class="hljs-built_in" style="color: rgb(57, 115, 0);">millis</span>() < <span class="hljs-number" style="color: rgb(136, 0, 0);">5000</span>) {
sensorValue = <span class="hljs-built_in" style="color: rgb(57, 115, 0);">analogRead</span>(sensorPin);
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// record the maximum sensor value</span>
<span class="hljs-built_in" style="color: rgb(57, 115, 0);">if</span> (sensorValue > sensorMax) {
sensorMax = sensorValue;
}
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// record the minimum sensor value</span>
<span class="hljs-built_in" style="color: rgb(57, 115, 0);">if</span> (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// signal the end of the calibration period</span>
<span class="hljs-built_in" style="color: rgb(57, 115, 0);">digitalWrite</span>(<span class="hljs-number" style="color: rgb(136, 0, 0);">13</span>, <span class="hljs-literal" style="color: rgb(120, 169, 96);">LOW</span>);
}
<span class="hljs-keyword" style="font-weight: 700;">void</span> <span class="hljs-built_in" style="color: rgb(57, 115, 0);">loop</span>() {
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// read the sensor:</span>
sensorValue = <span class="hljs-built_in" style="color: rgb(57, 115, 0);">analogRead</span>(sensorPin);
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// apply the calibration to the sensor reading</span>
sensorValue = <span class="hljs-built_in" style="color: rgb(57, 115, 0);">map</span>(sensorValue, sensorMin, sensorMax, <span class="hljs-number" style="color: rgb(136, 0, 0);">0</span>, <span class="hljs-number" style="color: rgb(136, 0, 0);">255</span>);
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// in case the sensor value is outside the range seen during calibration</span>
sensorValue = <span class="hljs-built_in" style="color: rgb(57, 115, 0);">constrain</span>(sensorValue, <span class="hljs-number" style="color: rgb(136, 0, 0);">0</span>, <span class="hljs-number" style="color: rgb(136, 0, 0);">255</span>);
<span class="hljs-comment" style="color: rgb(136, 136, 136);">// fade the LED using the calibrated value:</span>
<span class="hljs-built_in" style="color: rgb(57, 115, 0);">analogWrite</span>(ledPin, sensorValue);
}</pre>
<br>
<p>
1 - Asignamos el sensor de temperatura a un <or>pin</or> analógico.
</p>
<p>
2 - El pin del sensor es de <or>entrada</or>, no haría falta declararlo. También iniciamos la comunicación <or>serial</or>.
</p>
<p>
3 - Vamos a ver otra forma de declarar una variable a la que directamente le asignamos la función <or>analogRead</or>.
</p>
<p>
4 - Creamos otra variable en la que guardamos el resultado de la fórmula.
</p>
<p>
5 - Con la siguiente varible transformanos los milivoltios en grados centígrados.
</p>
<p>
6 - Finalmente lo imprimimos en el monitor serial esperando 1 segundo.
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>