Log data with a DHT22 temp sensor & a Pi to Google Spreadsheet

Sdílet
Vložit
  • čas přidán 4. 09. 2024
  • Hey there!
    In this video I'll connect a DHT 22 sensor to a Raspberry Pi. We'll read the temperature & humidity out of it, write the data to a Google Spreadsheet and display it in a nice look line chart.
    Preparations
    All you need is a Raspberry Pi and the DHT 22 sensor I used in the video. You'll find for around 5 Euro/Dollar at your favorite dealer. With these little preassembled sensor boards you are ready to go. If you only buy the sensor it self you may need some resistor to get it working.
    Libraries/Links
    We're using the Adafruit DHT lib. In the meantime it's declared deprecated. This means the vendor doesn't actively support it. I created an unmodified fork of it so that you can still use it in the future like in this video.
    AdafruitDHT lib: github.com/dat...
    Temperature Chart lib: github.com/dat...
    Google Developer Console: console.develo...
    Google Docs: docs.google.com
    Feel free to comment if you have any questions or suggestions.
    Thanks for watching!

Komentáře • 53

  • @mikerush9283
    @mikerush9283 Před 2 lety +3

    I enjoyed following this video and getting my Google Sheet set up with its accompanying chart in my browser - thanks for sharing this, Datort.
    I noticed that the chart X-axis increments the same amount for each reading so that a reading taken eight hours ago is spaced the same as one taken a minute ago if it was the one taken before the current reading. This is because the X-axis values written to the sheet are strings and not date-time values. So the sheet looks nice but the chart derived from it does not necessarily reflect the slopes of the temperature changes as the time between each reading is not necessarily the same (though it will be fine if the pi runs continuously with no breaks).
    After a bit of experimentation, I got the app.js file to write a date-time value, not a string, by adding valueInputOption="USER_ENTERED" into the original insert_rows statement that uses isoformat. This meant that the Sheet stored the date and time in the first column, the temperature in the second and the humidity in the third. I had to fiddle with the index file too to plot columns A and B (I didn’t plot humidity) and to remove the reverse direction statement as the values are plotted in time order now with the latest being at the far right.
    I think it gives a truer representation of the rate of change of temperature and just thought I’d share it here. Cheers!

  • @neilirvine7129
    @neilirvine7129 Před 2 lety

    Excellent video!

  • @electricalcoder3025
    @electricalcoder3025 Před 4 lety

    GOOD and cool job DATORT.👌👍👌..liked it too.....as we share the same intrests and channel
    content... i will encourage and suppourt you as much as i can....and i SUBSCRIBED yours tooo. IAM YOUR 54TH SUBSCRIBER...anyways...let this be
    good begiining and All the very best from Electrical coder.👍

  • @kickflipz
    @kickflipz Před 3 lety +1

    What about a history tab? That'd all I'm looking for... Looked for hoouuuurs

  • @mherrerap87
    @mherrerap87 Před 3 lety +1

    Great project!! I got it up and working, i was wondering if there is anyway to do 2 separate charts, i live in Costa Rica and we have such humidity that the temperature is always a flat line😅

  • @etobigrow5092
    @etobigrow5092 Před 4 lety +1

    great video. thank you!

  • @ermannobiffi2498
    @ermannobiffi2498 Před 2 lety

    Very interesting. Thank a lot !

  • @miyokichuro799
    @miyokichuro799 Před rokem

    Is there a way to just overwrite one row of cells ever update?

  • @accesser
    @accesser Před 2 lety

    Neat idea
    Is there a limit now far the cable to sensor can push 5v and data ? Might be interesting to put a sensor in the ceiling cavity and other places

  • @tonygun77
    @tonygun77 Před rokem

    Nice nice nice, thank you

  • @jason_x_90
    @jason_x_90 Před 2 lety

    Hi. I connected the DH22. Getting "failed to get reading, try again!" Any idea what the issue is? Thanks!

  • @matiasmedina9373
    @matiasmedina9373 Před 2 lety

    Error accessing GPIO. Make sure program is run as root with sudo! help me please

  • @Harometras
    @Harometras Před 2 lety

    Is this still working? I triple checked everything.
    I'm getting this error:
    Unable to login and get spreadsheet. Check OAuth credentials, spreadsheet name, and make sure spreadsheet is shared to the client_email address in the OAuth .json file!
    Google sheet login failed with error: Invalid control character at: line 1 column 160 (char 159)

  • @WilliamBurlingame
    @WilliamBurlingame Před 4 lety

    When I ran "sudo pip install gspread oauth2client", I got the error message "google-auth 1.19.2 has requirement rsa

  • @dandorr6330
    @dandorr6330 Před 3 lety +1

    good method. very happy to be able to log to online spreadsheet. that's exactly what I was wanting. I have a problem trying to run my python script at boot up on a raspberry pi 3. The script works fine in Thoney and from the terminal window. However, I have tried numerous times to configure /etc/rc.local to run my script at startup and am unable. it appears that it does not locate the *.json file. Although, my .json file is in the very same subdirectory as the script. Or could be another problem. idk. Could you help with runny this as a startup script?

    • @oussamagouzaouia6631
      @oussamagouzaouia6631 Před 2 lety

      did you find a solution for this problem because i'm having troublke with it too

    • @lyingriotman2220
      @lyingriotman2220 Před rokem

      Why not set up a cron job to do it? There's an option to run things at startup

  • @johanneswollinger1321

    hy! very helpful video! How can I implement two or more temperature sensors?

  • @gem-it7419
    @gem-it7419 Před 3 lety

    Hi can you help me with this problem Please:
    json.decoder.JSONDecodeError: Invalid control character at: line 3 column 38 (char 165)
    I have done everything you did but I face that Error. It drives me crazy

  • @this_is_not_miami
    @this_is_not_miami Před 4 lety +1

    Excellent tutorial, worked like a charm thank you!
    Do you know how to edit the script so that I can take readings from 2 DHT22 sensors?

    • @datort
      @datort  Před 4 lety +3

      Hey and thanks for your feedback! There is for sure a way to extend the script for this. Unforunately I can‘t code something down right now, cause I‘m sitting here with a broken shoulder after an accident 😔 For a „quick fix“ you could copy the script, change the parameters and run it twice. Should work...

    • @this_is_not_miami
      @this_is_not_miami Před 4 lety +3

      I did just that, works for now. Thanks again :)

  • @E2ESolutionsDIY
    @E2ESolutionsDIY Před 4 lety

    Nice work Dear 👍 All the very best from #E2Esolutions .

    • @E2ESolutionsDIY
      @E2ESolutionsDIY Před 4 lety

      How's your shoulder now Dear .. Wishing you a speedy recovery ☺

    • @datort
      @datort  Před 4 lety +1

      Thanks very much! Can‘t use one of my arms for another 3 weeks. That‘s annoying but it could be worse. Slowly but surely recovering. 💪🏻😊

    • @E2ESolutionsDIY
      @E2ESolutionsDIY Před 4 lety

      @@datort Take care Buddy, will discuss your new Post. till then support my posts☺

  • @Frissdas1207
    @Frissdas1207 Před 2 lety

    Is there a way to make it so you get a text or email if it goes above a certain temp?

  • @mikerush9283
    @mikerush9283 Před 2 lety

    Followed this and it all worked great except for the chart right at the end. The spreadsheet is updating fine and the raspberrypi.local tab is entitled Temperature Monitor but it just times out saying "Error in query: request timed out". Any suggestions? Thanks for the video!

    • @mikerush9283
      @mikerush9283 Před 2 lety

      Just found that I hadn't added 'spreadsheets/d' in front of the Google Sheets ID so all working well now - thanks again!

  • @vishwanathasardeshpande7092

    Sir can you help me how to configure moisture sensor to raspberry Pi

  • @taylorkissinger5004
    @taylorkissinger5004 Před 2 lety

    Hi, so I have one question. I had no issues in the video up until I did ./google_spreadsheet.py right before the sensor actually input readings into the spreadsheet. When it tried to run this script, I got an ImportError: No module named gspread. I did the sudo pip install gpread oauth2client line, and it says gspread is installed. Why does it say the module gspread is not installed though? Do you know how to fix this issue? Thank you for any help you could give me!

    • @taylorkissinger5004
      @taylorkissinger5004 Před 2 lety

      Nevermind, fixed the error. Really good video!

    • @tonygun77
      @tonygun77 Před rokem

      @@taylorkissinger5004 i have same error, what can i do?

    • @justindungog4401
      @justindungog4401 Před rokem

      @@tonygun77 import gspread in your python file

  • @97Syahmie
    @97Syahmie Před 4 lety

    whats the exact model of the DHT22 sensor that you used?

  • @thesambajaj
    @thesambajaj Před 4 lety

    Whats this error I recd when installing google auth.. "google-auth 1.18.0 has requirement rsa

    • @datort
      @datort  Před 4 lety

      Hey, what type of Linux Distribution and Python version are you using? I was on the default Raspian/RaspberryPi OS with it's Python 2.7 (for that time). Maybe it has something todo with this. The tutorial was based on plain and clean installation of that distribution.

    • @thesambajaj
      @thesambajaj Před 4 lety

      ​@@datort But, all worked inspite of that. Thanx for the video. Very helpful.

  • @giuseppe.buccheri
    @giuseppe.buccheri Před 2 lety

    Can anyone help me?
    I don't know why after "./google_spreadsheet.py" I have as answers "sudo: unable to execute ./google_spreadsheet.py: No such file or directory".
    Obviously the file is present and I modified the code as in the video.
    I have installed Python 3.7.3
    (
    sudo apt-get install python3
    &
    sudo apt-get install python3-pip
    )
    Please help me

    • @giuseppe.buccheri
      @giuseppe.buccheri Před 2 lety

      I managed to solve by changing google_spreadsheet.py in the first few lines of code from usr/bin /python to usr/bin/python3. Now I have another problem:
      pi@raspberrypi001:~/Adafruit_Python_DHT/examples $ ./google_spreadsheet.py
      File "./google_spreadsheet.py", line 119
      worksheet.insert_row((datetime.datetime.now().strftime('%Y-%m-%d'), datetime.datetime.now().strftime('%H:%M')temp, humidity), 1)
      ^
      TabError: inconsistent use of tabs and spaces in indentation

    • @taylorkissinger5004
      @taylorkissinger5004 Před 2 lety

      @@giuseppe.buccheri Did you ever get the error that gspread was not defined? After running "./google_spreadsheet.py"

    • @taylorkissinger5004
      @taylorkissinger5004 Před 2 lety

      I just tried changing the first line of google_spreadsheet.py to the usr/bin/python3 like you did, and now Im not getting the gspread error. I'm getting the same TabError you are getting. I have no idea if you ever found a solution, but I'll let you know if I figure something out

  • @lzr1839
    @lzr1839 Před 4 lety

    When I tried running the program, there was an error :ImportError: cannot import name Beaglebone_Black_Driver. Can anyone help me?