element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino Projects
  • Products
  • Arduino
  • Arduino Projects
  • More
  • Cancel
Arduino Projects
Blog Arduino temperature logger which saves data on SD card and sends it to Ubidots IOT application
  • Blog
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dragonboliero
  • Date Created: 16 Dec 2015 2:34 PM Date Created
  • Views 3785 views
  • Likes 3 likes
  • Comments 8 comments
  • logger
  • c
  • python
  • ardintermediate
  • temperature
  • ubidots
  • card
  • arduino
  • sd
Related
Recommended

Arduino temperature logger which saves data on SD card and sends it to Ubidots IOT application

dragonboliero
dragonboliero
16 Dec 2015

Hello,

 

Today I would like to share with you my second little project. Its an Arduino temperature logger which saves data on micro SD card and thanks to a short Python script it can also send data to Ubidots IOT application. The circuit itself is very simple, in order to complete it all you need is:

 

11 - jumper wires

1 - 4.7K ohm resistor

1 - DS18B20 temperature sensor

1 - SD card reader

1 - Arduino UNO

 

Here's the circuit's schematic:

 

image

Here's a video showing how assemble the circuit:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Arduino sketch for this project:

#include <OneWire.h> //library for communication with temperature sensor
#include <DallasTemperature.h> //temperature sensor library
#include <SD.h> //sd card reader library available in every Arduino IDE
#include <SPI.h> //library for communication with SD card reader

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

File logs;  // variable responsible for writing to file 
float temp; //variable storing the current temperature
int number = 0; //variable holding the number indicating current entry in csv file

unsigned int hour = 20; //variable storing current hour
unsigned int minute = 45; //variable storing current minute 
unsigned int day = 2; //variable storing current day of the week
unsigned int date = 15; //variable storing current day of the month 
unsigned int month = 12; //variable storing current month
unsigned int year =  2015; //variable storing current year

unsigned int leap_year = 0; //variable for checking whether it's a leap year or not

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  SD.begin(10);
  // Start up the library
  sensors.begin();
} //end of void setup

void loop(void)
{ 
  //checking whether it's leap year or not
  if (year % 4 == 0)
  leap_year = 1;
  else
  leap_year = 0;
  
  
  //changing minutes
  if (minute < 55)
  minute +=5;
  else
  minute = 0;
  
  //changing hour
  if ((minute == 0) && (hour < 24))
  hour++;
  if ((minute == 0) && (hour == 24))
  hour = 0;
  
  //changing day of the week
  if((minute == 0) && (hour == 0) && (day <8))
  day +=1;
  if((minute == 0) && (hour == 0) && (day == 8))
  day = 1;
  
  //changing day of the month  
  //formula for 30 day months
  if ((date < 31) && ( (month == 4) || (month == 6) || (month == 9) || (month == 11)) && (hour == 0) && (minute ==0))
  {
   date++; 
  }
  if ((date == 31) && ( (month == 4) || (month == 6) || (month == 9) || (month == 11)) && (hour == 0) && (minute ==0))
  {
   date = 0;
   month++; 
  }
  
  //formula for February 
  if ( ((date < 29) && (month == 2) && (hour == 0) && (minute == 0) && (leap_year == 0)) || ((date < 30) && (month == 2) && (hour == 0) && (minute == 0) && (leap_year == 1)) )
  {
   date = date +1; 
  }
  if ( (date == 29) && (month == 2) && (hour == 0) && (minute == 0) && (leap_year == 0) || ((date == 30) && (month == 2) && (hour == 0) && (minute == 0) && (leap_year == 1)) )
  {
   date = 0;
   month = 3;
  }
  
  //formula for 31 day months
  if ((date < 32) && ( (month == 1) || (month == 3) || (month ==5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) && (hour == 0) && (minute ==0))
  {
    date++;
  }
  if ((date == 32) && ( (month == 1) || (month == 3) || (month ==5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) && (hour == 0) && (minute ==0))
  {
   date = 1;
   if(month <12)
   month++; 
   else
   month = 1;
  }
  
  
  //changing year
  if( (hour == 0) && (minute == 0) && (date == 1) && (month == 1))
  year++;
  
  
  sensors.requestTemperatures(); // Send the command to get temperatures
  temp =  sensors.getTempCByIndex(0); //assigning sensor's vale to the variable
  Serial.println(temp);
  
  
  logs = SD.open("logs.csv", FILE_WRITE); //assigning file to which we want to write the data
  if(logs) //if opening of the file was successful
  {
    
   if (number == 0)
   logs.println("sep=,"); //we add this line to the file so that excel 2013 and newer software knows that this is coma separated file
   
   //then we write entry number, date and sensor read
   logs.print(number);
   logs.print(",");
   
   logs.print(temp); //finally we add temperature read from sensor
   logs.print(",");
   
   if (hour < 10)
   logs.print("0"); //we add 0 is hour is lower than 10
   logs.print(hour);
   logs.print(":");
   if(minute <10) 
   logs.print("0"); //we add 0 if minute is lower than 10
   logs.print(minute);
   logs.print(" ");
   
   switch(day) //we add day of the week appropriately
   {
    case 1:
     logs.print("Monday");
     break;
    case 2:
     logs.print("Tuesday");
     break;
    case 3:
     logs.print("Wednesday");
     break;
    case 4:
     logs.print("Thursday");
     break;
    case 5:
     logs.print("Friday");
     break;
    case 6:
     logs.print("Saturday");
     break;
    case 7:
     logs.print("Sunday");
     break;
   }
   logs.print(" ");
   logs.print(date);
   logs.print(" ");
   
   switch(month)
   {
    case 1:
     logs.print("January");
     break;
    case 2:
     logs.print("February");
     break;
    case 3:
     logs.print("March");
     break;
    case 4:
     logs.print("April");
     break;
    case 5:
     logs.print("May");
     break;
    case 6:
     logs.print("June");
     break;
    case 7:
     logs.print("July");
     break;
    case 8:
     logs.print("August");
     break;
    case 9:
     logs.print("September");
     break;
    case 10:
     logs.print("October");
     break;
    case 11:
     logs.print("November");
     break;
    case 12:
     logs.print("December");
     break;
   }
   
   logs.print(" ");
   logs.println(year); //printing year to the file
   Serial.println("Saving successful");
   logs.close();//we close and save the file
  }
  logs.flush();
  
  
  delay(300000); // we delay program for 5 minutes and then take another read
  //delay(60000); //for testing purposes 1 minute
  //delay(2000);//for testing purposes 2 seconds
  number = number + 1; // we add 1 to the entry counter
}

 

Python script which allows communication between Arduino and Ubidots application:

from ubidots import ApiClient #importing ubidots api
from time import * #importing standard time library
import serial #importing pyserial library

api = ApiClient ('your_account_key') #key of our ubidots account
ser = serial.Serial('COM6', 9600, timeout = 0) #establishing communication with Arduino serial port

temp_val = api.get_variable('your_variable_key') #ubidots variable's key with which we want to communicate


while True:
    current_temp = ser.readline(6) #reading first 6 characters from serial port
    if ( (current_temp[:1] == '-')or(current_temp[:1] == '1') or (current_temp[:1] == '2') or (current_temp[:1] == '3') or (current_temp[:1] == '4') or (current_temp[:1] == '5') or (current_temp[:1] == '6') or (current_temp[:1] == '7') or (current_temp[:1] == '8') or (current_temp[:1] == '9') ):
            
            float_current_temp = float(current_temp[:5]) #converting value read from the serial port a float
            new_value = temp_temp.save_value({'value':float_current_temp}) #sending value to ubidots
            print ("sending successful")

 

Video explaining Arduino sketch and Python script, as well as providing introduction to Ubidots:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Please comment. Any feedback is very valuable for me, especially constructive criticism. If you like what I'm doing you can subscribe my channel on YouTube (https://www.youtube.com/user/W0j45), follow me on Twitter (https://twitter.com/milczarekw) and Instagram (https://www.instagram.com/milczarekw/).

 

Thank you for reading!

  • Sign in to reply

Top Comments

  • dragonboliero
    dragonboliero over 9 years ago in reply to neilk +1
    Hello Neil, Did you share your project somewhere? I would really like to see it if its possible. I'm really happy that you liked my entry. Best regards, Wojtek
  • Former Member
    Former Member over 9 years ago

    I am trying to work on an idea much like this as I have several grocery stores that have many refrigeration/ freezer needs. Something like this that could be accessed remotely would be very useful.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neilk
    neilk over 9 years ago in reply to dragonboliero

    You're most welcome, Wojciech.

     

    Good luck with your future developments.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dragonboliero
    dragonboliero over 9 years ago in reply to neilk

    Thank you for the post Neil! I've added SD.remove function to my program. Finally I'll not have to manually remove previous files on my computer image. The idea of connecting Arduino with Excel is also interesting and I might use it in the future.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neilk
    neilk over 9 years ago in reply to dragonboliero

    Hello Wojciech,

     

    Here is the link to my Blog post about my Data Logger:

     

    http://www.element14.com/community/people/neilk/blog/2013/10/14/arduino-data-logger-sending-data-to-excel-via-a-web-server-on-ethernet-shield

     

    See also my post no 4 at if you want to download the sketch:

     

    http://www.element14.com/community/thread/27515/l/arduino-data-logger-sending-data-to-excel-via-a-web-server-on-ethernet-shield

     

    I hope you find it useful

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dragonboliero
    dragonboliero over 9 years ago in reply to neilk

    Hello Neil,

     

    Did you share your project somewhere? I would really like to see it if its possible. I'm really happy that you liked my entry.

     

    Best regards,

     

    Wojtek

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube