Components and supplies
Arduino Ethernet Shield 2
Temperature Sensor
Standard LCD - 16x2 White on Blue
Arduino UNO
Project description
Code
6ch temp logger
c_cpp
1/* 26 Channel analog temperature logger by Dooni 3 */ 4 5// include the library code: 6#include <LiquidCrystal.h> 7#include <SPI.h> 8#include <SD.h> 9 10// initialize the library with the numbers of the interface pins 11// LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 12// pins 4, 11, 12 are used by SPI 13 LiquidCrystal lcd(9, 8, 5, 7, 3, 2); 14 15String logFileName = "datalog.csv"; // set the File name 16String cs = ";"; // ste the comma separator 17const int startButton = 6; // set up a constant for the pushbutton pin 18const int numberOfSensors = 6; // how many sensors did you hook up? 19const int interval = 1000; // setup cycle Time to measure / update LCD (default: 1000) 20const int logInterval = 5; // setup logging interval in number of "interval" (default: 60) 21const int chipSelect = 4; 22const int numberOfReadings = 30; // set number of readings for average calculation 23const int numberOfRejects = 5; // the first readings are rejected 24int logCountDown = logInterval; // reset the downcounter 25int logCounter = 0; // count number of records 26float celsiusValues[numberOfSensors]; // an array to store the celsius values 27unsigned long previousTime = 0; // to store last timestamp 28boolean fileDelete = false; // set true to delete logfile each startup 29boolean autoStart = false; // set true to autostart logger on powerup 30 31/*========================================= SETUP ===================================================*/ 32 33void setup() { 34 35 // set up the Start Button pin as an input 36 pinMode(startButton, INPUT); 37 38 // Open serial communications and wait for port to open: 39 Serial.begin(9600); 40 while (!Serial) { 41 ; // wait for serial port to connect. Needed for native USB port only 42 } 43 44 // set up the number of columns and rows on the LCD 45 lcd.begin(16, 2); 46 47 // initialize SD Card! 48 Serial.println("Initializing SD card..."); 49 // see if the card is present and can be initialized: 50 if (!SD.begin(chipSelect)) { 51 Serial.println("Card failed, or not present"); 52 lcd.clear(); lcd.setCursor(0, 0); lcd.print("SD card failed."); 53 lcd.setCursor(0, 1); lcd.print("insert and reset!"); 54 //if failded, get trapped here 55 while (1) { } 56 } 57 Serial.println("card initialized."); 58 59 // Print a message to the LCD. 60 lcd.clear(); 61 lcd.print("6ch temp. logger"); 62 lcd.setCursor(0, 1); lcd.print("SD card ready..."); 63 Serial.println("SD card ready..."); 64 delay(2000); 65 66 // option to delete the log file 67 if (!fileDelete) { 68 lcd.clear(); 69 lcd.print("press button to"); 70 lcd.setCursor(0, 1); 71 lcd.print("delete log file"); 72 } 73 74 //push the button within the time to delete the file 75 while (millis()<4000) { 76 if (digitalRead(startButton) == HIGH) { 77 fileDelete = true; 78 } 79 } 80 81 if (fileDelete) { 82 SD.remove(logFileName); 83 lcd.clear(); 84 lcd.setCursor(0, 0); 85 lcd.print("file deleted!"); 86 Serial.println("Logfile deleted!"); 87 delay(2000); 88 //write table headers if file was deleted 89 fileWrite("T1"+cs+"T2"+cs+"T3"+cs+"T4"+cs+"T5"+cs+"T6"); 90 } else { 91 //write zero values to see each restart of the logger 92 fileWrite("0"+cs+"0"+cs+"0"+cs+"0"+cs+"0"+cs+"0"); 93 } 94 95 lcd.clear(); 96 lcd.print("Logger ready!"); 97 lcd.setCursor(0, 1); 98 99if (autoStart) { 100 lcd.print("starting..."); 101 Serial.println("starting..."); 102 delay(4000); 103} else { 104 lcd.print("press start..."); 105 Serial.println("press start..."); 106 //wait until somebody presses the button 107 while (digitalRead(startButton) == LOW) { } 108} 109 110lcd.clear(); 111 112} 113 114/*========================================= BEGIN LOOP ===================================================*/ 115 116void loop() { 117 118 //store current Time 119 previousTime = millis(); 120 121 // Read each sensor, calculate celsius and fill array 122 for (int i = 0; i < numberOfSensors; i++) { 123 int totalValue = 0; 124 for (int j = 0; j < numberOfReadings; j++) { 125 if (j >= numberOfRejects) { 126 totalValue += analogRead(i); 127 } 128 delay(1); 129 } 130 float voltage = totalValue * 5 / 1024.0 / (numberOfReadings-numberOfRejects); 131 float tempCels = (voltage - 0.5) * 100 ; 132 celsiusValues[i] = tempCels; 133 delay (20); 134 } 135 136 /*Serial.print(millis()); 137 Serial.println("<- end of measuring");*/ 138 139 //Assemble comma separated string and write to serial 140 String dataString = ""; 141 for (int i = 0; i < numberOfSensors; i++) { 142 dataString += String(celsiusValues[i]); 143 if (i < (numberOfSensors - 1)) { 144 dataString += cs; 145 } 146 } 147 Serial.println(dataString); 148 149 // if countdown is elapsed, write log to file 150 if (logCountDown < 1) { 151 fileWrite(dataString); 152 logCountDown = logInterval; // reset the downcounter 153 logCounter += 1; // count the record 154 } 155 156 logCountDown -= 1; // increment one down 157 158 //write data to LCD 159 lcd.clear(); //clear the LCD 160 lcd.setCursor(0, 0); lcd.print(celsiusValues[0]); 161 lcd.setCursor(3, 0); lcd.print(celsiusValues[1]); 162 lcd.setCursor(6, 0); lcd.print(celsiusValues[2]); 163 lcd.setCursor(0, 1); lcd.print(celsiusValues[3]); 164 lcd.setCursor(3, 1); lcd.print(celsiusValues[4]); 165 lcd.setCursor(6, 1); lcd.print(celsiusValues[5]); 166 lcd.setCursor(9, 0); lcd.print("t-" + String(logCountDown)); 167 //lcd.setCursor(9, 0); lcd.print(millis()); 168 lcd.setCursor(9, 1); lcd.print("n:" + String(logCounter)); 169 170 //wait until interval time reached 171 while (millis() - previousTime < interval) { } 172 173 /*Serial.print(millis()); 174 Serial.println("<- loop time elapsed");*/ 175} 176 177/*========================================= END LOOP ===================================================*/ 178 179void fileWrite(String data) { 180 // open the file. note that only one file can be open at a time, 181 // so you have to close this one before opening another. 182 File dataFile = SD.open(logFileName, FILE_WRITE); 183 // if the file is available, write to it: 184 if (dataFile) { 185 dataFile.println(data); 186 dataFile.close(); 187 } 188 // if the file isn't open, pop up an error: 189 else { 190 Serial.println("error opening logfile"); 191 lcd.clear(); 192 lcd.setCursor(0, 0); 193 lcd.print("error opening"); 194 lcd.setCursor(0, 1); 195 lcd.print("logfile"); 196 while (1) {} 197 } 198 Serial.println(data + " <-- written to file"); 199 } 200
6ch temp logger
c_cpp
1/* 26 Channel analog temperature logger by Dooni 3 */ 4 5// include 6 the library code: 7#include <LiquidCrystal.h> 8#include <SPI.h> 9#include 10 <SD.h> 11 12// initialize the library with the numbers of the interface pins 13// 14 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 15// pins 4, 11, 12 are used by SPI 16 17 LiquidCrystal lcd(9, 8, 5, 7, 3, 2); 18 19String logFileName = "datalog.csv"; 20 // set the File name 21String cs = ";"; // ste the comma 22 separator 23const int startButton = 6; // set up a constant for the 24 pushbutton pin 25const int numberOfSensors = 6; // how many sensors did 26 you hook up? 27const int interval = 1000; // setup cycle Time to measure 28 / update LCD (default: 1000) 29const int logInterval = 5; // setup logging 30 interval in number of "interval" (default: 60) 31const int chipSelect = 4; 32const 33 int numberOfReadings = 30; // set number of readings for average calculation 34const 35 int numberOfRejects = 5; // the first readings are rejected 36int logCountDown 37 = logInterval; // reset the downcounter 38int logCounter = 0; // 39 count number of records 40float celsiusValues[numberOfSensors]; // an array to 41 store the celsius values 42unsigned long previousTime = 0; // to store last 43 timestamp 44boolean fileDelete = false; // set true to delete logfile 45 each startup 46boolean autoStart = false; // set true to autostart 47 logger on powerup 48 49/*========================================= SETUP ===================================================*/ 50 51void 52 setup() { 53 54 // set up the Start Button pin as an input 55 pinMode(startButton, 56 INPUT); 57 58 // Open serial communications and wait for port to open: 59 Serial.begin(9600); 60 61 while (!Serial) { 62 ; // wait for serial port to connect. Needed for native 63 USB port only 64 } 65 66 // set up the number of columns and rows on the LCD 67 68 lcd.begin(16, 2); 69 70 // initialize SD Card! 71 Serial.println("Initializing 72 SD card..."); 73 // see if the card is present and can be initialized: 74 if 75 (!SD.begin(chipSelect)) { 76 Serial.println("Card failed, or not present"); 77 78 lcd.clear(); lcd.setCursor(0, 0); lcd.print("SD card failed."); 79 lcd.setCursor(0, 80 1); lcd.print("insert and reset!"); 81 //if failded, get trapped here 82 83 while (1) { } 84 } 85 Serial.println("card initialized."); 86 87 // 88 Print a message to the LCD. 89 lcd.clear(); 90 lcd.print("6ch temp. logger"); 91 92 lcd.setCursor(0, 1); lcd.print("SD card ready..."); 93 Serial.println("SD 94 card ready..."); 95 delay(2000); 96 97 // option to delete the log file 98 99 if (!fileDelete) { 100 lcd.clear(); 101 lcd.print("press button to"); 102 103 lcd.setCursor(0, 1); 104 lcd.print("delete log file"); 105 106 } 107 108 //push the button within the time to delete the file 109 while (millis()<4000) 110 { 111 if (digitalRead(startButton) == HIGH) { 112 fileDelete = true; 113 114 } 115 } 116 117 if (fileDelete) { 118 SD.remove(logFileName); 119 lcd.clear(); 120 121 lcd.setCursor(0, 0); 122 lcd.print("file deleted!"); 123 124 Serial.println("Logfile deleted!"); 125 delay(2000); 126 //write 127 table headers if file was deleted 128 fileWrite("T1"+cs+"T2"+cs+"T3"+cs+"T4"+cs+"T5"+cs+"T6"); 129 130 } else { 131 //write zero values to see each restart of the logger 132 133 fileWrite("0"+cs+"0"+cs+"0"+cs+"0"+cs+"0"+cs+"0"); 134 } 135 136 137 lcd.clear(); 138 lcd.print("Logger ready!"); 139 lcd.setCursor(0, 140 1); 141 142if (autoStart) { 143 lcd.print("starting..."); 144 Serial.println("starting..."); 145 146 delay(4000); 147} else { 148 lcd.print("press start..."); 149 Serial.println("press 150 start..."); 151 //wait until somebody presses the button 152 while (digitalRead(startButton) 153 == LOW) { } 154} 155 156lcd.clear(); 157 158} 159 160/*========================================= 161 BEGIN LOOP ===================================================*/ 162 163void loop() 164 { 165 166 //store current Time 167 previousTime = millis(); 168 169 // Read 170 each sensor, calculate celsius and fill array 171 for (int i = 0; i < numberOfSensors; 172 i++) { 173 int totalValue = 0; 174 for (int j = 0; j < numberOfReadings; 175 j++) { 176 if (j >= numberOfRejects) { 177 totalValue += analogRead(i); 178 179 } 180 delay(1); 181 } 182 float voltage = totalValue * 5 183 / 1024.0 / (numberOfReadings-numberOfRejects); 184 float tempCels = (voltage 185 - 0.5) * 100 ; 186 celsiusValues[i] = tempCels; 187 delay (20); 188 } 189 190 191 /*Serial.print(millis()); 192 Serial.println("<- end of measuring");*/ 193 194 195 //Assemble comma separated string and write to serial 196 String dataString 197 = ""; 198 for (int i = 0; i < numberOfSensors; i++) { 199 dataString += 200 String(celsiusValues[i]); 201 if (i < (numberOfSensors - 1)) { 202 dataString 203 += cs; 204 } 205 } 206 Serial.println(dataString); 207 208 // if countdown 209 is elapsed, write log to file 210 if (logCountDown < 1) { 211 fileWrite(dataString); 212 213 logCountDown = logInterval; // reset the downcounter 214 logCounter += 215 1; // count the record 216 } 217 218 logCountDown -= 1; // 219 increment one down 220 221 //write data to LCD 222 lcd.clear(); //clear the 223 LCD 224 lcd.setCursor(0, 0); lcd.print(celsiusValues[0]); 225 lcd.setCursor(3, 226 0); lcd.print(celsiusValues[1]); 227 lcd.setCursor(6, 0); lcd.print(celsiusValues[2]); 228 229 lcd.setCursor(0, 1); lcd.print(celsiusValues[3]); 230 lcd.setCursor(3, 1); lcd.print(celsiusValues[4]); 231 232 lcd.setCursor(6, 1); lcd.print(celsiusValues[5]); 233 lcd.setCursor(9, 0); lcd.print("t-" 234 + String(logCountDown)); 235 //lcd.setCursor(9, 0); lcd.print(millis()); 236 lcd.setCursor(9, 237 1); lcd.print("n:" + String(logCounter)); 238 239 //wait until interval time 240 reached 241 while (millis() - previousTime < interval) { } 242 243 /*Serial.print(millis()); 244 245 Serial.println("<- loop time elapsed");*/ 246} 247 248/*========================================= 249 END LOOP ===================================================*/ 250 251void fileWrite(String 252 data) { 253 // open the file. note that only one file can be open at a time, 254 255 // so you have to close this one before opening another. 256 File dataFile 257 = SD.open(logFileName, FILE_WRITE); 258 // if the file is available, write to 259 it: 260 if (dataFile) { 261 dataFile.println(data); 262 dataFile.close(); 263 264 } 265 // if the file isn't open, pop up an error: 266 else { 267 268 Serial.println("error opening logfile"); 269 lcd.clear(); 270 lcd.setCursor(0, 271 0); 272 lcd.print("error opening"); 273 lcd.setCursor(0, 274 1); 275 lcd.print("logfile"); 276 while (1) {} 277 } 278 279 Serial.println(data + " <-- written to file"); 280 } 281
Downloadable files
Breadboard wiring
Breadboard wiring
Comments
Only logged in users can leave comments
Dooni
0 Followers
•0 Projects
+1
Work attribution
Table of contents
Intro
12
0