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

Arduino UNO and MPU-6050 Controlled DC Motor with nMOS Transistor

View and Edit Project In Cirkit DesignerImage of Arduino UNO and MPU-6050 Controlled DC Motor with nMOS Transistor

Circuit Documentation

Summary

This circuit is designed to control a DC motor using an nMOS transistor and an Arduino UNO. The motor is switched off if the x-axis value obtained from the MPU-6050 sensor exceeds 135. The MPU-6050 communicates with the Arduino via I2C.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. MPU-6050

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

    • Description: A standard 9V battery used to power the circuit.
    • Pins: -, +
  4. Motor amarillo motorreductor hobby

    • Description: A small DC motor with a gearbox.
    • Pins: vcc, GND
  5. nMOS Transistor (MOSFET)

    • Description: A type of transistor used for switching and amplifying electronic signals.
    • Pins: gate, drain, source

Wiring Details

Arduino UNO

MPU-6050

9V Battery

Motor amarillo motorreductor hobby

nMOS Transistor (MOSFET)

Code Documentation

/*
 * This Arduino Sketch controls a DC motor using an nMOS transistor. The motor
 * is switched off if the x-axis value obtained from the MPU-6050 sensor
 * exceeds 135. The MPU-6050 communicates with the Arduino via I2C.
 */

#include <Wire.h>

const int MPU_ADDR = 0x68; // I2C address of the MPU-6050
const int motorPin = 9;    // Pin connected to the gate of the nMOS transistor

void setup() {
  Wire.begin();
  Serial.begin(9600);
  pinMode(motorPin, OUTPUT);
  digitalWrite(motorPin, LOW); // Ensure motor is off initially

  // Initialize MPU-6050
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x6B); // PWR_MGMT_1 register
  Wire.write(0);    // Set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
}

void loop() {
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x3B); // Starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_ADDR, 2, true); // Request only X-axis registers

  int16_t accelX = Wire.read() << 8 | Wire.read(); // Read X-axis

  Serial.print("Accel X: ");
  Serial.println(accelX);

  if (accelX > 135) {
    digitalWrite(motorPin, LOW); // Turn off motor
  } else {
    digitalWrite(motorPin, HIGH); // Turn on motor
  }

  delay(100); // Small delay to avoid overwhelming the sensor
}

This code initializes the MPU-6050 sensor and reads the x-axis acceleration value. If the value exceeds 135, the motor is turned off; otherwise, the motor is turned on. The motor is controlled via an nMOS transistor connected to pin D9 of the Arduino UNO.