Circuit Documentation
Summary
The circuit in question is designed to interface an Arduino UNO microcontroller with a KY-015 DHT11 temperature and humidity sensor, an MPU-6050 accelerometer and gyroscope module, and two pushbuttons. The circuit is powered by the Arduino's 5V output and includes a 10kΩ pull-up resistor for one of the pushbuttons. The Arduino UNO is programmed to read data from the DHT11 and MPU-6050 sensors and to detect button presses, which trigger immediate sensor readings. The sensor data is then output to the Serial Monitor.
Component List
KY-015 DHT11 Temperature and Humidity Sensor
- Pins: 5V, S, GND
- Description: A basic, low-cost digital temperature and humidity sensor.
MPU-6050 Accelerometer and Gyroscope
- Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
- Description: A motion-tracking device with a 3-axis accelerometer and a 3-axis gyroscope.
Pushbutton (x2)
- Pins: Pin 1, Pin 2, Pin 3, Pin 4
- Description: A simple switch mechanism for control of a machine or some type of process.
Arduino UNO
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13
- Description: A microcontroller board based on the ATmega328P, widely used for building digital devices and interactive objects.
Resistor
- Pins: pin1, pin2
- Description: A passive two-terminal electrical component that implements electrical resistance as a circuit element.
- Properties: 10kΩ resistance
Wiring Details
KY-015 DHT11
- 5V: Connected to the 5V power supply from the Arduino UNO.
- S: Connected to digital pin D2 on the Arduino UNO.
- GND: Connected to the ground (GND) on the Arduino UNO.
MPU-6050
- VCC: Connected to the 5V power supply from the Arduino UNO.
- GND: Connected to the ground (GND) on the Arduino UNO.
- SCL: Connected to analog pin A5 on the Arduino UNO.
- SDA: Connected to analog pin A4 on the Arduino UNO.
Pushbutton 1
- Pin 1: Connected to one terminal of the 10kΩ resistor.
- Pin 2: Not connected.
- Pin 3: Connected to the ground (GND) on the Arduino UNO.
- Pin 4: Connected to the ground (GND) on the Arduino UNO.
Pushbutton 2
- Pin 1: Not connected.
- Pin 2: Not connected.
- Pin 3: Not connected.
- Pin 4: Not connected.
Arduino UNO
- 5V: Provides power to the KY-015 DHT11 and MPU-6050.
- GND: Common ground for the circuit.
- D2: Receives the signal from the KY-015 DHT11 sensor.
- A4: Connected to the SDA pin of the MPU-6050.
- A5: Connected to the SCL pin of the MPU-6050.
- D3: Connected to one terminal of the 10kΩ resistor (other terminal connected to Pushbutton 1).
Resistor
- pin1: Connected to digital pin D3 on the Arduino UNO.
- pin2: Connected to Pin 1 of Pushbutton 1.
Documented Code
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MPU6050.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2 // DHT11 data pin connected to digital pin 2
#define DHTTYPE DHT11
#define BUTTON_PIN 3 // Push button connected to digital pin 3
DHT dht(DHTPIN, DHTTYPE);
Adafruit_MPU6050 mpu;
volatile bool buttonPressed = false;
void setup() {
Serial.begin(9600);
dht.begin();
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
pinMode(BUTTON_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonISR, FALLING);
}
void loop() {
static unsigned long lastReadTime = 0;
unsigned long currentTime = millis();
if (buttonPressed || (currentTime - lastReadTime >= 2000)) {
readSensors();
lastReadTime = currentTime;
buttonPressed = false;
}
}
void readSensors() {
// Read DHT11 sensor
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Read MPU6050 sensor
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
// Print sensor data to Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.print(" %, Acceleration: ");
Serial.print("X: ");
Serial.print(a.acceleration.x);
Serial.print(" m/s^2, Y: ");
Serial.print(a.acceleration.y);
Serial.print(" m/s^2, Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
}
void buttonISR() {
buttonPressed = true;
}
This code initializes the DHT11 and MPU6050 sensors and sets up an interrupt to detect when Pushbutton 1 is pressed. When the button is pressed or every 2 seconds, the readSensors function is called to read and print the temperature, humidity, and acceleration values to the Serial Monitor.
