Arduino Mega 2560 Controlled Motor System with I2C Communication and Hall Effect Sensing
View and Edit Project In Cirkit DesignerCircuit Documentation
Summary
The circuit in question is a complex system that includes an Arduino Mega 2560 microcontroller as the central processing unit, interfacing with various sensors, motor drivers, and power supply components. The circuit utilizes I2C communication, PWM control, and digital I/O for sensor interfacing. It is designed to control multiple DC motors, read from Hall effect sensors and rotary encoders, and manage power distribution from a 12V battery and a power supply module.
Component List
Microcontroller
- Arduino Mega 2560: A microcontroller board based on the ATmega2560, with a wide range of I/O pins including PWM, digital, and analog inputs.
Motor Drivers
- MD03: Motor drivers capable of driving DC motors with I2C communication for speed and direction control.
Sensors
- HALL SENSOR: Magnetic field sensors that provide digital output signals.
- HEDS ENCODER: Optical encoders for detecting the position and speed of a motor shaft.
- ME22 ROTARY ENCODER: Mechanical encoders that provide feedback on the position of a rotating shaft.
- SR02: Ultrasonic sensors for distance measurement.
Power Components
- 12v Battery: A 12V power source for the circuit.
- POWER SUPPLY: A module that provides various voltage outputs including 12V, 5V, and 3.3V.
Logic Level Converters
- Adafruit 4-channel I2C-safe Bi-directional Logic Level Converter: A device that safely steps down 5V signals to 3.3V and steps up 3.3V to 5V at the same time.
- SparkFun Voltage-Level Translator Breakout - TXB0104: A 4-bit non-inverting level shifter that can be used for bidirectional voltage-level translation.
Passive Components
- Resistor: Various resistors used for pull-ups, pull-downs, and current limiting.
- Mosfet: Transistors used for switching high current loads.
Actuators
- DC Motor: Electric motors that convert electrical energy into mechanical energy.
- brake: Electromechanical devices used to slow or stop the motion of the DC motors.
Wiring Details
Arduino Mega 2560
- 3.3V connected to logic level converters and power supply (3.3V FROM ARDUINO).
- GND connected to various GND pins of sensors, encoders, and power supply.
- Digital I/O pins (D4 PWM to D10 PWM) connected to level translators and Mosfets for control signals.
- I2C pins (SDA, SCL) connected to I2C devices and pull-up resistors.
- 5V connected to resistors, sensors, encoders, and power supply (5V FROM ARDUINO).
MD03 Motor Drivers
- SCL and SDA connected to I2C bus with pull-up resistors.
- Gnd connected to system ground.
- Vin connected to 12V from the battery and power supply.
- Motor + and Motor - connected to corresponding DC motor terminals.
HALL SENSOR
- Ground connected to system ground.
- Vin connected to 5V from Arduino.
- Signal connected to digital I/O pins on Arduino (D51, D53).
HEDS ENCODER
- GND connected to system ground.
- CHANNEL A connected to level translator outputs.
- Vin connected to 5V from Arduino.
ME22 ROTARY ENCODER
- GND connected to system ground.
- CHANNEL A connected to level translator outputs.
- Vin connected to 5V from Arduino.
SR02 Ultrasonic Sensors
- Connected to 5V and GND from the power supply.
- Signal lines connected to level translators.
Power Components
- 12v Battery provides power to MD03 motor drivers and brakes.
- POWER SUPPLY distributes 12V, 5V, and 3.3V to various components in the circuit.
Logic Level Converters
- Adafruit and SparkFun level translators used to interface 3.3V and 5V logic signals.
Passive Components
- Resistors used for pull-up on I2C lines and other signal conditioning.
- Mosfets used for controlling brakes with PWM signals from Arduino.
Actuators
- DC Motors connected to MD03 motor drivers.
- brakes connected to Mosfets for activation and deactivation.
Documented Code
#define TRIG_PIN 8
#define ECHO_PIN 7
void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
void loop() {
long duration, distance;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = (duration / 2) / 29.1; // Convert duration to distance
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000);
}
Filename: sketch.ino
Description: This Arduino sketch is designed to measure distance using an ultrasonic sensor. It triggers the sensor and reads the echo to calculate the distance to an object. The distance is then printed to the serial monitor every second.