{"id":1523,"date":"2013-11-21T22:47:18","date_gmt":"2013-11-21T22:47:18","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=1523"},"modified":"2019-04-02T10:23:38","modified_gmt":"2019-04-02T10:23:38","slug":"arduino-datalogger-with-temperature-sensor-and-photoresistor","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-datalogger-with-temperature-sensor-and-photoresistor\/","title":{"rendered":"Arduino &#8211; Datalogger with Temperature Sensor and Photoresistor"},"content":{"rendered":"<p>In this project I&#8217;m going to create a simple Datalogger with my Arduino and an Ethernet shield.<!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter  wp-image-1535\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/thumbnaildatalogger.jpg?resize=700%2C527&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"527\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/thumbnaildatalogger.jpg?w=956&amp;quality=100&amp;strip=all&amp;ssl=1 956w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/thumbnaildatalogger.jpg?resize=300%2C225&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>With this concept you can change my code and monitor any sensor you desire.<\/p>\n<p>I&#8217;ll be using a photoresistor and a temperature sensor\u00a0and all the information will be stored in a micro SD card.<\/p>\n<h2>Watch the\u00a0video below for a complete tutorial<\/h2>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/R19On2w5qbU?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p><span style=\"text-decoration: underline;\">Note:<\/span> I apologize for my voice. I&#8217;m a bit sick so my voice sounded a bit different than usual.<\/p>\n<h2>Parts Required<\/h2>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-1534\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/parts1.jpg?resize=270%2C202&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"parts1\" width=\"270\" height=\"202\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/parts1.jpg?resize=300%2C224&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/parts1.jpg?resize=1024%2C764&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/parts1.jpg?w=2400&amp;quality=100&amp;strip=all&amp;ssl=1 2400w\" sizes=\"(max-width: 270px) 100vw, 270px\" \/><\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/ethernet-shield-w5100-arduino-shield\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Ethernet Shield<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/microsd-card-raspberry-pi-16gb-class-10\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Micro SD Card<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/lm335lm35dz-temperature-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Temperature Sensor (I\u2019m using the LM335Z)<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/photoresistor-light-dependent-resistor-ldr\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Photoresistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 1k ohm Resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 4700 ohm Resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Breadboard (or\u00a0 two)<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper Cables<\/a><\/li>\n<\/ul>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h2>Schematics<\/h2>\n<p style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/Schematics1.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-1524\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/Schematics1.png?resize=362%2C429&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Schematics\" width=\"362\" height=\"429\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/Schematics1.png?w=452&amp;quality=100&amp;strip=all&amp;ssl=1 452w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/Schematics1.png?resize=252%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 252w\" sizes=\"(max-width: 362px) 100vw, 362px\" \/><\/a><\/p>\n<h2>Upload the code below<\/h2>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n Modified by Rui Santos\n For more Arduino Projects: http:\/\/randomnerdtutorials.com \n \n SD card datalogger\n \n This example shows how to log data from three analog sensors \n to an SD card using the SD library.\n    \n The circuit:\n * analog sensors on analog ins 0, 1, and 2\n * SD card attached to SPI bus as follows:\n ** MOSI - pin 11\n ** MISO - pin 12\n ** CLK - pin 13\n ** CS - pin 4\n \n based on Tom Igoe example.\n *\/\n \n#include &lt;SD.h&gt;\nfloat tempK;  \/\/stores kelvin temperature\nint sensor;   \/\/stores sensor value everytime we use the analog read function\n\/\/ On the Ethernet Shield, CS is pin 4. Note that even if it's not\n\/\/ used as the CS pin, the hardware CS pin (10 on most Arduino boards,\n\/\/ 53 on the Mega) must be left as an output or the SD library\n\/\/ functions will not work.\nconst int chipSelect = 4;\nint analogPin=0;      \/\/help us read the analogpin of our INPUTS\nvoid setup()\n{\n \/\/ Open serial communications and wait for port to open:\n  Serial.begin(9600);\n  while (!Serial) {\n    ; \/\/ wait for serial port to connect. Needed for Leonardo only\n  }\n  Serial.print(&quot;Initializing SD card...&quot;);\n  \/\/ make sure that the default chip select pin is set to\n  \/\/ output, even if you don't use it:\n  pinMode(10, OUTPUT);\n  \n  \/\/ see if the card is present and can be initialized:\n  if (!SD.begin(chipSelect)) {\n    Serial.println(&quot;Card failed, or not present&quot;);\n    \/\/ don't do anything more:\n    return;\n  }\n  Serial.println(&quot;card initialized.&quot;);\n  \/\/Defines Photoresistor as an INPUT on PIN Number 0\n  pinMode(0, INPUT);\n  \/\/Defines Temperature sensor as an INPUT on PIN Number 1\n  pinMode(1, INPUT);\n}\n\nvoid loop()\n{\n  \/\/ make a string for assembling the data to log:\n  String dataString = &quot;&quot;;\n  \/\/ reads three sensors and append to the string:\n  for (analogPin = 0; analogPin &lt; 3; analogPin++){\n    \/\/reads the photoresistor on PIN0\n    if( analogPin==0){\n      sensor = analogRead(analogPin);\n    }\n    \/\/reads the kelvin Tempeature on PIN1 \n    \/\/then converts our tempeature to Degrees\n    else if(analogPin==1){  \n      \/\/reads temperature and converts to kelvin\n      tempK = (((analogRead(analogPin)\/ 1023.0) * 5.0) * 100.0);\n      \/\/Converts Kelvin to Celsius minus 1.5 degrees error\n      sensor = tempK - 273.0; \n    }\n    \/\/reads the Kelvin temperature on PIN1\n    \/\/then converts our tempeature to Farenheit\n    else{\n      \/\/reads temperature and converts to kelvin\n      tempK = (((analogRead(analogPin-1)\/ 1023.0) * 5.0) * 100.0);\n      \/\/Converts Kelvin to Farenheit\n      sensor = ((tempK - 2.5) * 9 \/ 5) - 459.67;\n    }\n    \/\/stores our values\n    dataString += String(sensor);\n    if (analogPin &lt; 2) {\n      dataString += &quot;,&quot;; \n    }\n  }\n\n  \/\/ open the file. note that only one file can be open at a time,\n  \/\/ so you have to close this one before opening another.\n  File dataFile = SD.open(&quot;data.txt&quot;, FILE_WRITE);\n\n  \/\/ if the file is available, write to it:\n  if (dataFile) {\n    dataFile.println(dataString);\n    dataFile.close();\n    \/\/ print to the serial port too:\n    Serial.println(dataString);\n  }  \n  \/\/ if the file isn't open, pop up an error:\n  else {\n    Serial.println(&quot;error opening datalog.txt&quot;);\n  } \n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/SD_card_datalogger.c\" target=\"_blank\">View raw code<\/a><\/p>\n<p>I hope this tutorial can help you with your projects!<\/p>\n<p><strong>Support my work<\/strong> by <strong>sharing this video<\/strong> with a friend that also likes electronics.<\/p>\n<p>News: I&#8217;m currently working on a project that I&#8217;m really excited about. I won&#8217;t tell exactly what It is. But I&#8217;ll share with you in a few weeks as soon as It&#8217;s finished. So stay tuned for more.<\/p>\n<p>Thanks for reading, you can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my\u00a0<a href=\"https:\/\/www.facebook.com\/RandomNerdTutorials?ref=hl\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Facebook Page.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project I&#8217;m going to create a simple Datalogger with my Arduino and an Ethernet shield.<\/p>\n","protected":false},"author":1,"featured_media":1535,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303,267,2,264,10],"tags":[],"class_list":["post-1523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino-project","category-arduino","category-project","category-a-tutorials"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/thumbnaildatalogger.jpg?fit=956%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/1523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=1523"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/1523\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/1535"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=1523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=1523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=1523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}