Intermediate
4 hours
ESP8266 IoT Temperature Logger to Google Sheets
This project uses the ESP8266 (NodeMCU) to post sensor readings to a Google Sheets spreadsheet via the Google Sheets API every 5 minutes. The spreadsheet automatically timestamps and plots a chart of readings over time. It’s a great introduction to REST APIs, JSON, and IoT data pipelines without needing a server.
What You’ll Need
- NodeMCU ESP8266 development board
- DHT22 temperature and humidity sensor
- 10 kΩ resistor (DHT22 pull-up)
- Micro-USB cable
- Google account (for Sheets + Apps Script)
- WiFi network credentials
Step-by-Step Instructions
- Set up Google Sheets: Create a new Google Sheet. Name columns: Timestamp, Temperature (°C), Humidity (%). Note the spreadsheet ID from the URL.
- Create an Apps Script webhook: In the Sheet, go to Extensions → Apps Script. Paste a doGet(e) function that appends a new row using SpreadsheetApp.openById() with data from URL parameters. Deploy as Web App (Anyone can access). Copy the deployment URL.
- Install Arduino tools: Add ESP8266 board to Arduino IDE. Install “DHT sensor library” and “ESP8266HTTPClient”.
- Wire the DHT22: VCC → 3.3 V, Data → D4 (GPIO2) with 10 kΩ pull-up to 3.3 V, GND → GND.
- Write the sketch: Connect to WiFi using WiFiClientSecure. Every 5 minutes, read DHT22. Build the URL: your Apps Script URL + “?temp=” + temp + “&hum=” + humidity. Call HTTPS GET with the built URL.
- Test: Upload, open Serial Monitor. You should see WiFi connected, readings taken, and HTTP 200 responses. Check the Sheet for new rows appearing.
Safety Notes
- Do not hardcode WiFi passwords in code you share publicly or commit to a public repository.
- The Apps Script “anyone can access” setting means the URL acts as an API key — keep it private.
Tips & Troubleshooting
- If HTTPS calls fail with certificate errors, use WiFiClientSecure with setInsecure() temporarily for testing, then add the correct fingerprint for production.
- Add multiple sensors (CO2, pressure) by adding more URL parameters to the same Apps Script endpoint.
- Use Google Sheets built-in chart feature to auto-plot temperature vs time with no extra code.