Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP8266 NodeMCU-Based Wi-Fi Temperature and Motion Sensor

View and Edit Project In Cirkit DesignerImage of ESP8266 NodeMCU-Based Wi-Fi Temperature and Motion Sensor

Circuit Documentation

Summary

This circuit involves an ESP8266 NodeMCU microcontroller interfaced with a temperature sensor and an MPU6050 accelerometer + gyroscope. The ESP8266 reads data from both sensors and prints the values to the serial monitor.

Component List

  1. ESP8266 NodeMCU

    • Description: A low-cost Wi-Fi microcontroller with GPIO, ADC, and other features.
    • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
  2. Temperature Sensor

    • Description: A digital temperature sensor.
    • Pins: Temp GND Black, Temp VDD Red, Temp DQ Data Yellow
  3. MPU6050 Accelerometer + Gyroscope

    • Description: A 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer.
    • Pins: INT, AD0, XCL, XDA, SDA, SCL, GND, VCC

Wiring Details

ESP8266 NodeMCU

Temperature Sensor

MPU6050 Accelerometer + Gyroscope

Code Documentation

/*
 * ESP32 MPU TEMP
 * This Arduino sketch reads data from a temperature sensor and an MPU6050
 * accelerometer + gyroscope, and prints the values to the serial monitor.
 */

#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Pin definitions
#define TEMP_PIN D6
#define MPU_SDA D2
#define MPU_SCL D1

// Temperature sensor setup
OneWire oneWire(TEMP_PIN);
DallasTemperature tempSensor(&oneWire);

// MPU6050 setup
Adafruit_MPU6050 mpu;

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  while (!Serial) delay(10); // Wait for serial port to connect

  // Initialize temperature sensor
  tempSensor.begin();

  // Initialize MPU6050
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  mpu.setAccelerometerRange(MPU6050_RANGE_2_G);
  mpu.setGyroRange(MPU6050_RANGE_250_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
}

void loop() {
  // Request temperature readings
  tempSensor.requestTemperatures();
  float temperatureC = tempSensor.getTempCByIndex(0);

  // Get MPU6050 readings
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  // Print temperature sensor data
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" *C");

  // Print MPU6050 data
  Serial.print("Accel X: ");
  Serial.print(a.acceleration.x);
  Serial.print(" m/s^2");
  Serial.print(" | Accel Y: ");
  Serial.print(a.acceleration.y);
  Serial.print(" m/s^2");
  Serial.print(" | Accel Z: ");
  Serial.print(a.acceleration.z);
  Serial.println(" m/s^2");

  Serial.print("Gyro X: ");
  Serial.print(g.gyro.x);
  Serial.print(" rad/s");
  Serial.print(" | Gyro Y: ");
  Serial.print(g.gyro.y);
  Serial.print(" rad/s");
  Serial.print(" | Gyro Z: ");
  Serial.print(g.gyro.z);
  Serial.println(" rad/s");

  delay(1000); // Delay for a second before next reading
}

This code initializes the temperature sensor and MPU6050, reads data from both sensors, and prints the values to the serial monitor every second.