Components and supplies
Sound sensor KY-038
Real Time Clock (RTC)
Catalex microSD adapter
Arduino Nano R3
DS18B20 Programmable Resolution 1-Wire Digital Thermometer
Project description
Code
Pool Log to microSD
c_cpp
1/* 2 Realiza la lectura de varios sensores (temperatura del agua, ruido,...) y graba 3 información en una microSD (externa) cada n segundos. 4 Developed by Pentiumcadiz - sept 2017 5 6 Based on "SD card read/write", created by David A. Mellis and modified by Tom Igoe 7 8*/ 9 10// Tarjeta microSD -------------------------------- 11#include <SD.h> 12 13#define chipSelect 10 // Funciona Ok con tarjeta micro SD Catalex dic2014 14 15File logfile; // Fichero de log de las temperaturas 16 17/* 18microSD card attached to SPI bus as follows: 19 ** MOSI - pin 11 20 ** MISO - pin 12 21 ** CLK - pin 13 22 ** CS - pin 10 23*/ 24 25 26// Sensor de temperatura -------------------------------- 27 28#include <OneWire.h> // librerías para sensor de temp 29#include <DallasTemperature.h> 30#define Pin 7 //pin donde se conectará el sensor de temp 31 32OneWire ourWire(Pin); //pin asignado al bus para la comunicación OneWire 33DallasTemperature sensors(&ourWire); //Se instancia la librería DallasTemperature 34 35// Sensor de ruido -------------------------------- 36 37# define pin_ruido 6 // pin de entrada del sensor de ruido (Digital) 38 39boolean unavez = true; 40boolean encendido = false; 41 42String motorstatus = "apagado "; 43 44// RTC (reloj) -------------------------------- 45 46 #include <Wire.h> 47 #include <Time.h> 48 #include <DS1307RTC.h> 49 50 String cadena; 51 52// ------- Fin de declaración de variables ----------- 53 54void setup() 55{ 56 // Open serial communications and wait for port to open: 57 Serial.begin(9600); 58 while (!Serial) 59 { 60 ; // wait for serial port to connect. Needed for Leonardo only 61 } 62 63 sensors.begin(); //Se inician los sensores de Onewire 64 65 Serial.print("Initializing SD card..."); 66 // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 67 // Note that even if it's not used as the CS pin, the hardware SS pin 68 // (10 on most Arduino boards, 53 on the Mega) must be left as an output 69 // or the SD library functions will not work. 70 pinMode(10, OUTPUT); 71 72 // See if the card is present and can be initialized: 73 if (!SD.begin(chipSelect)) { 74 Serial.println("Tarjeta microSD - Fallo al iniciar!"); 75 return; 76 } 77 Serial.println("Tarjeta microSD - Iniciada con éxito !"); 78 79 80 // Asignación de pines digitales a Vcc y Gnd 81 82 pinMode(pin_ruido, INPUT); // Entrada digital del sensor de sonido 83} 84 85void loop(void) 86{ 87 88 // ¿Suena el motor? 89 encendido = digitalRead(pin_ruido); 90 if (encendido) 91 { motorstatus= "Encendido" ; } 92 else 93 { motorstatus = " OFF " ; } 94 95 // Qué temperatura tiene el agua? 96 sensors.requestTemperatures(); //Prepara el sensor para la lectura 97 98 if (unavez) 99 { 100 Serial.print("Medidas actuales\ 101"); 102 } 103 104// Fecha y hora ----------------------------------- 105 tmElements_t tm; 106 107 if (RTC.read(tm)) 108 { 109 110 cadena = cadena + tm.Day + "/" + tm.Month; 111 cadena = cadena + "\ " + tm.Hour + ":" + tm.Minute; 112 113 Serial.println(cadena); 114 115 } 116 else 117 { 118 if (RTC.chipPresent()) { 119 Serial.println("The DS1307 is stopped. Please run the SetTime"); 120 Serial.println("example to initialize the time and begin running."); 121 Serial.println(); 122 } else { 123 Serial.println("DS1307 read error! Please check the circuitry."); 124 Serial.println(); 125 } 126 delay(9000); 127 } 128 129// Fin(Fecha y hora) ----------------------------------- 130 131 //Mostramos mensaje con las temperaturas 132 Serial.print(cadena); 133 Serial.print("Motor: "); 134 Serial.print(motorstatus); 135 Serial.print("\ "); 136 Serial.print(encendido); 137// Serial.print("\ Temperatura: \ "); 138// Serial.print(sensors.getTempCByIndex(0)); //Se lee e imprime la temperatura en grados Celsius 139 Serial.println(" grados Centigrados"); 140 141 142 143 // Grabar los datos leidos en la tarjeta 144 145// Open the file. 146 File logFile = SD.open("temp.log", FILE_WRITE); 147 if (logFile) 148 { 149 if (unavez) 150 { 151 logFile.println(" Fecha \ Hora \ Temp \ Motor "); 152 logFile.println(" ===== \ ===== \ ===== \ =========="); 153 } 154 logFile.print(cadena); 155 logFile.print("\ "); 156 logFile.print(sensors.getTempCByIndex(0)); 157 logFile.print("\ "); 158 logFile.println(motorstatus); 159 // close the file: 160 logFile.close(); 161 } 162 else 163 { 164 // if the file didn't open, print an error: 165 Serial.println("error opening temp.log"); 166 } 167 delay(20000); //Usamos un retardo de n segundos entre lectura y lectura 168 unavez = false; 169 cadena = " "; 170 171} 172 173
Pool Log to microSD
c_cpp
1/* 2 Realiza la lectura de varios sensores (temperatura del agua, ruido,...) y graba 3 información en una microSD (externa) cada n segundos. 4 Developed by Pentiumcadiz - sept 2017 5 6 Based on "SD card read/write", created by David A. Mellis and modified by Tom Igoe 7 8*/ 9 10// Tarjeta microSD -------------------------------- 11#include <SD.h> 12 13#define chipSelect 10 // Funciona Ok con tarjeta micro SD Catalex dic2014 14 15File logfile; // Fichero de log de las temperaturas 16 17/* 18microSD card attached to SPI bus as follows: 19 ** MOSI - pin 11 20 ** MISO - pin 12 21 ** CLK - pin 13 22 ** CS - pin 10 23*/ 24 25 26// Sensor de temperatura -------------------------------- 27 28#include <OneWire.h> // librerías para sensor de temp 29#include <DallasTemperature.h> 30#define Pin 7 //pin donde se conectará el sensor de temp 31 32OneWire ourWire(Pin); //pin asignado al bus para la comunicación OneWire 33DallasTemperature sensors(&ourWire); //Se instancia la librería DallasTemperature 34 35// Sensor de ruido -------------------------------- 36 37# define pin_ruido 6 // pin de entrada del sensor de ruido (Digital) 38 39boolean unavez = true; 40boolean encendido = false; 41 42String motorstatus = "apagado "; 43 44// RTC (reloj) -------------------------------- 45 46 #include <Wire.h> 47 #include <Time.h> 48 #include <DS1307RTC.h> 49 50 String cadena; 51 52// ------- Fin de declaración de variables ----------- 53 54void setup() 55{ 56 // Open serial communications and wait for port to open: 57 Serial.begin(9600); 58 while (!Serial) 59 { 60 ; // wait for serial port to connect. Needed for Leonardo only 61 } 62 63 sensors.begin(); //Se inician los sensores de Onewire 64 65 Serial.print("Initializing SD card..."); 66 // On the Ethernet Shield, CS is pin 4. It's set as an output by default. 67 // Note that even if it's not used as the CS pin, the hardware SS pin 68 // (10 on most Arduino boards, 53 on the Mega) must be left as an output 69 // or the SD library functions will not work. 70 pinMode(10, OUTPUT); 71 72 // See if the card is present and can be initialized: 73 if (!SD.begin(chipSelect)) { 74 Serial.println("Tarjeta microSD - Fallo al iniciar!"); 75 return; 76 } 77 Serial.println("Tarjeta microSD - Iniciada con éxito !"); 78 79 80 // Asignación de pines digitales a Vcc y Gnd 81 82 pinMode(pin_ruido, INPUT); // Entrada digital del sensor de sonido 83} 84 85void loop(void) 86{ 87 88 // ¿Suena el motor? 89 encendido = digitalRead(pin_ruido); 90 if (encendido) 91 { motorstatus= "Encendido" ; } 92 else 93 { motorstatus = " OFF " ; } 94 95 // Qué temperatura tiene el agua? 96 sensors.requestTemperatures(); //Prepara el sensor para la lectura 97 98 if (unavez) 99 { 100 Serial.print("Medidas actuales\ 101"); 102 } 103 104// Fecha y hora ----------------------------------- 105 tmElements_t tm; 106 107 if (RTC.read(tm)) 108 { 109 110 cadena = cadena + tm.Day + "/" + tm.Month; 111 cadena = cadena + "\ " + tm.Hour + ":" + tm.Minute; 112 113 Serial.println(cadena); 114 115 } 116 else 117 { 118 if (RTC.chipPresent()) { 119 Serial.println("The DS1307 is stopped. Please run the SetTime"); 120 Serial.println("example to initialize the time and begin running."); 121 Serial.println(); 122 } else { 123 Serial.println("DS1307 read error! Please check the circuitry."); 124 Serial.println(); 125 } 126 delay(9000); 127 } 128 129// Fin(Fecha y hora) ----------------------------------- 130 131 //Mostramos mensaje con las temperaturas 132 Serial.print(cadena); 133 Serial.print("Motor: "); 134 Serial.print(motorstatus); 135 Serial.print("\ "); 136 Serial.print(encendido); 137// Serial.print("\ Temperatura: \ "); 138// Serial.print(sensors.getTempCByIndex(0)); //Se lee e imprime la temperatura en grados Celsius 139 Serial.println(" grados Centigrados"); 140 141 142 143 // Grabar los datos leidos en la tarjeta 144 145// Open the file. 146 File logFile = SD.open("temp.log", FILE_WRITE); 147 if (logFile) 148 { 149 if (unavez) 150 { 151 logFile.println(" Fecha \ Hora \ Temp \ Motor "); 152 logFile.println(" ===== \ ===== \ ===== \ =========="); 153 } 154 logFile.print(cadena); 155 logFile.print("\ "); 156 logFile.print(sensors.getTempCByIndex(0)); 157 logFile.print("\ "); 158 logFile.println(motorstatus); 159 // close the file: 160 logFile.close(); 161 } 162 else 163 { 164 // if the file didn't open, print an error: 165 Serial.println("error opening temp.log"); 166 } 167 delay(20000); //Usamos un retardo de n segundos entre lectura y lectura 168 unavez = false; 169 cadena = " "; 170 171} 172 173
Downloadable files
pool_logger schema
pool_logger schema
Comments
Only logged in users can leave comments
pentiumcadiz
0 Followers
•0 Projects
0