0% found this document useful (0 votes)
10 views4 pages

Código para Implementación Del Módulo de Medición de Temperatura

This document contains code for implementing a temperature measurement module using an ESP32 microcontroller, WiFi connectivity, and DS18B20 temperature sensors. It connects to a specified WiFi network, reads temperatures from three sensors, and sends the data to a Google Sheets application via a web script. The code is structured with setup and loop functions, allowing for data retrieval and transmission every five seconds.

Uploaded by

csarias2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Código para Implementación Del Módulo de Medición de Temperatura

This document contains code for implementing a temperature measurement module using an ESP32 microcontroller, WiFi connectivity, and DS18B20 temperature sensors. It connects to a specified WiFi network, reads temperatures from three sensors, and sends the data to a Google Sheets application via a web script. The code is structured with setup and loop functions, allowing for data retrieval and transmission every five seconds.

Uploaded by

csarias2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CÓDIGO PARA IMPLEMENTACIÓN DEL MÓDULO DE MEDICIÓN DE TEMPERATURA

#include <WiFi.h>

#include <HTTPClient.h>

#include <OneWire.h>

#include <DallasTemperature.h>

// **CONFIGURAR TU RED WIFI AQUÍ**

const char* ssid = "COMPUSEBAS";

const char* password = "12345678";

// **URL de tu aplicación web en Google Apps Script**

String scriptURL = "https://script.google.com/macros/s/AKfycbwCSQcuUYZgZfEzQcIKJ1Iiiaz-


rpbjHOdZnnWuDs2Z0YgO8kPhe0xHScVWntoE0JXZ/exec";

// **Definir el pin de datos del sensor DS18B20**

#define ONE_WIRE_BUS 4 // Puedes cambiarlo por otro pin

// **Crear instancia OneWire**

OneWire oneWire(ONE_WIRE_BUS);

// **Crear instancia DallasTemperature**

DallasTemperature sensors(&oneWire);

// **Definir las direcciones ROM de los sensores**

DeviceAddress sensor1 = {0x28, 0xFF, 0xCE, 0x2D, 0x60, 0x17, 0x03, 0xE0};

DeviceAddress sensor2 = {0x28, 0xFF, 0x8E, 0xC6, 0x60, 0x17, 0x05, 0x09};

DeviceAddress sensor3 = {0x28, 0xFF, 0x05, 0x01, 0x60, 0x17, 0x03, 0xD0};

void setup() {
Serial.begin(115200);

sensors.begin();

Serial.println(" Conectando a WiFi...");

WiFi.begin(ssid, password);

int intentos = 0;

while (WiFi.status() != WL_CONNECTED && intentos < 20) {

delay(500);

Serial.print(".");

intentos++;

if (WiFi.status() == WL_CONNECTED) {

Serial.println("\n✅ Conectado a WiFi");

Serial.print(" IP: ");

Serial.println(WiFi.localIP());

} else {

Serial.println("\n❌ Error al conectar a WiFi.");

// Configurar la resolución de los sensores a 12 bits (mayor precisión)

sensors.setResolution(sensor1, 12);

sensors.setResolution(sensor2, 12);

sensors.setResolution(sensor3, 12);

void loop() {
sensors.requestTemperatures(); // Solicitar temperatura a todos los sensores

float temp1 = sensors.getTempC(sensor1);

float temp2 = sensors.getTempC(sensor2);

float temp3 = sensors.getTempC(sensor3);

Serial.print(" Sensor 1: "); Serial.print(temp1); Serial.println(" °C");

Serial.print(" Sensor 2: "); Serial.print(temp2); Serial.println(" °C");

Serial.print(" Sensor 3: "); Serial.print(temp3); Serial.println(" °C");

Serial.println("----------------------");

// **Enviar datos a Google Sheets**

if (WiFi.status() == WL_CONNECTED) {

HTTPClient http;

String url = scriptURL + "?sensor1=" + String(temp1) + "&sensor2=" + String(temp2) + "&sensor3=" +


String(temp3);

http.begin(url);

int httpCode = http.GET();

if (httpCode > 0) {

Serial.println("✅ Datos enviados a Google Sheets");

} else {

Serial.println("❌ Error al enviar datos");

http.end();

}
delay(5000); // **Actualizar cada 5 segundos**

You might also like