กลับไปหน้ารวมไฟล์
log-temperature-data-to-google-sheets-0f9e99.md

วิธีใหม่ในการบันทึกอุณหภูมิ

ถึงจุดนี้ น้องคงอยากได้เซ็นเซอร์วัดอุณหภูมิในบ้านสักตัว - ตัวที่ราคาน้อยกว่า 25 ดอลลาร์ ถ้ามีอยู่แล้ว น้องก็คงอยากได้ตัวที่ดีกว่านี้ จัดไปวัยรุ่น นี่คือทางออกง่ายๆ สำหรับปัญหานี้

สร้างและติดตั้งสคริปต์

สร้างสเปรดชีตใหม่ตามที่แสดงด้านล่าง:
พอสร้างเสร็จแล้ว ให้ไปที่ เครื่องมือ > สคริปต์แก้ไข
สร้างสเปรดชีตใหม่ตามที่แสดงด้านล่าง:
ตั้งชื่อชีตด้านล่างว่า TempSheet
พอสร้างเสร็จแล้ว ให้ไปที่ เครื่องมือ > สคริปต์แก้ไข จากนั้นก็อปปี้และวางโค้ดที่เตรียมไว้ให้ จากนั้นแก้ไข Script ID ในโค้ด Script ID นี้จะอยู่ตรงตำแหน่งที่เขียนว่า "vbn" ใน URL ตัวอย่าง:
https://docs.google.com/spreadsheets/d/vbn/edit#gid=0
ทีนี้ไปที่ เผยแพร่ > ติดตั้งเป็นเว็บแอป ในช่อง "Project version" ให้เลือก "New" ในช่อง "Execute the app as" ให้เลือก "your email id" ในช่อง "Who has access to the app" ให้เลือก "Anyone, even anonymous" แล้วคลิก "Deploy" หมายเหตุ: เวลาติดตั้งใหม่ ให้เลือกเวอร์ชันล่าสุดแล้วกด Deploy อีกครั้ง ในช่อง "Project Version" ให้พิมพ์ "New Script Created"
น้องจะต้องให้สิทธิ์ Google เพื่อติดตั้งเป็นเว็บแอป แค่คลิกที่ "Review Permissions" แล้วเลือก Email ID ที่ใช้สร้างสเปรดชีตนี้
คลิกที่ "Advanced"
แล้วคลิกที่ "Go to 'your_script_name'(unsafe)" ในกรณีของพี่ มันคือ "TempLog_Script"
คลิกที่ "Allow" เพื่อให้สิทธิ์ติดตั้งเป็นเว็บแอป
ตอนนี้จะเห็นหน้าจอใหม่ที่มีลิงก์ที่กำหนดมา พร้อมชื่อว่า "Current web app URL” URL นี้มี Google Script ID อยู่ แค่คัดลอก URL นี้แล้วเก็บไว้ให้ดี

ระบบ Telemetry แบบคลาวด์สำหรับ Big Data

โปรเจกต์นี้ให้โซลูชันระดับมืออาชีพสำหรับการบันทึกข้อมูลสิ่งแวดล้อมลงในสเปรดชีต **Google Sheets** โดยตรง เพื่อการวิเคราะห์ในระยะยาว - **Google Apps Script Webhook**: Arduino (ที่เชื่อมต่อ WiFi) จะส่งคำขอ HTTP POST ไปยัง URL **Google Apps Script** เฉพาะ ซึ่งสคริปต์นี้ทำหน้าที่เป็นสะพาน เชื่อมต่อด้วยคีย์ "Macro" ที่ไม่ซ้ำใคร - **การเพิ่มแถวอัตโนมัติ**: Apps Script จะดักจับข้อมูลอุณหภูมิและความชื้นจาก Arduino และเพิ่มเป็นแถวใหม่ในสเปรดชีตโดยอัตโนมัติ พร้อมกับ Timestamp จากฝั่งเซิร์ฟเวอร์

การโต้ตอบ

- **สร้างกราฟแบบเรียลไทม์ในสเปรดชีต**: ด้วยการใช้เครื่องมือสร้างแผนภูมิในตัวของ Google Sheets ผู้ใช้สามารถเห็นภาพข้อมูลจาก Arduino แบบเรียลไทม์บนอุปกรณ์ใดก็ได้ที่มีเว็บเบราว์เซอร์

ทดสอบ DHT22

ใช้แผนภาพวงจรและโค้ดที่ให้ไว้:
แผนภาพ:
โค้ด:

#include "DHT.h"

#define dht_apin A0

DHT dht;

#define DHTTYPE DHT22 //Change this to any type of DHT Sensor you're Using!

DHT(dht_apin, DHTTYPE);

void setup() {

// put your setup code here, to run once:

Serial.begin(9600); //Starts serial

delay(5000); //Waits before reading from sensor

Serial.println("DHT22 Temp. And Humi. Test"); //Prints the intro

}

void loop() {

// put your main code here, to run repeatedly:

dht.read11(dht_apin); //Reads from the sensor

Serial.println("Humi. ---------- "); //Prints humidity

Serial.print(DHT.humidity); //Prints humidity

Serial.print("% "); //Marks the humidity as %

Serial.print("Temp. ------------ "); //Prints temperature

Serial.print(DHT.temperature); //Prints temperature

Serial.print("℃") //Marks the temperature unit

delay(2000); //Waits 2 seconds before doing the loop again fastest is once evrey 2 seconds

} //end loop

โค้ดนี้ควรจะปริ้นท์ค่าอุณหภูมิกับความชื้นออกมาให้เราเห็นนะน้อง ถ้ามันเงียบกริบ ไม่มีอะไรขึ้นเลย ลองรันโค้ดทดสอบด้านล่างนี้ดูก่อน ตั้งค่า Serial ไว้ที่ 9600 เหมือนกัน มันจะส่ง "Hello!" ทุกวินาที เอาไว้เช็คว่าเราติดต่อกับบอร์ดได้มั้ย:

#define one_second 1000

#define the_word_hello "Hello!"

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

delay(5000);

}

void loop() {

// put your main code here, to run repeatedly:

Serial.print(the_word_hello);

delay(one_second);

}

โอเค ถ้าทดสอบแล้วได้ผล งั้นเรามาต่อกันเลยดีกว่า สู้งานนะน้อง!

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x Arduino IDE"
  - "1x Google Sheets"
author: "24Ishan"
category: ""
components:
  - "1x Micro-USB to USB Cable (Generic)"
  - "1x Breadboard (generic)"
  - "1x NodeMCU ESP8266 Breakout Board"
  - "1x DHT22 Temperature and Humidity Sensor"
description: "โปรเจค Log อุณหภูมิแบบ Real-time ด้วย ESP8266 ต่อเซนเซอร์วัดค่าแล้วส่งขึ้นชีตแบบจัดไป งานง่ายแต่หล่อ วัยรุ่นต้องลอง!"
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX19MU5zo7Z6qh5PUkCA+4WKDLmA4qKvr4yuxqares7ezxYGEYR0URZq2ww6sqeJbxJXbQ8wAe3mfeYQ23E9/K1aGNm/LKH73R4RQ6NASzRLRCLqI/u0KuNem"
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/log-temperature-data-to-google-sheets-0f9e99_cover.jpg"
lang: "en"
likes: 14
passwordHash: "3838061c69d69d0f6650435813148fb454e3aff00757c32b3346f8ade71e07ff"
price: 1499
seoDescription: "Learn how to log Temperature data to Google Sheets using ESP8266 for simple IoT projects."
tags:
  - "environmental sensing"
  - "home automation"
  - "smart appliances"
  - "communication"
  - "data collection"
  - "internet of things"
  - "monitoring"
title: "เก็บข้อมูลอุณหภูมิขึ้น Google Sheets ง่ายๆ งานเทพๆ!"
tools: []
videoLinks: []
views: 28850