Arduino Mega 2560 Controlled Motor System with I2C Communication and Hall Effect Sensing
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to interface with various sensors and actuators through an Arduino Mega 2560 microcontroller. It includes motor drivers (MD03), rotary encoders (ME22 ROTARY ENCODER), Hall sensors, DC motors, and ultrasonic sensors (SR02). The circuit also features logic level converters for voltage level translation between devices operating at different logic levels. A 12V battery and a power supply unit provide the necessary power for the components. The Arduino Mega 2560 is programmed to handle sensor inputs and control outputs to the motors.
Component List
Microcontroller
- Arduino Mega 2560: A microcontroller board based on the ATmega2560, with numerous digital and analog I/O pins.
Motor Drivers
- MD03: A high-current motor driver designed to control DC motors with I2C communication capability.
Sensors
- HALL SENSOR: A sensor that detects magnetic fields and provides a digital output signal.
- HEDS ENCODER: An optical encoder providing feedback on the position and speed of a motor shaft.
- ME22 ROTARY ENCODER: A mechanical encoder that provides feedback on angular position through two output channels.
- SR02: An ultrasonic sensor used for measuring distance to an object.
Actuators
- DC Motor: An electric motor that runs on direct current (DC) electricity.
Power Sources
- 12v Battery: A 12-volt battery providing power to the circuit.
- POWER SUPPLY: A unit that supplies various voltage levels for the circuit components.
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 translator with automatic direction sensing.
Passive Components
- Resistor: A passive two-terminal electrical component that implements electrical resistance as a circuit element.
Wiring Details
Arduino Mega 2560
- Connected to various sensors, actuators, and logic level converters through its I/O pins.
- Provides 3.3V and 5V to logic level converters and sensors.
- Communicates with motor drivers via I2C (SCL, SDA).
- Controls ultrasonic sensors using digital pins for trigger and echo signals.
MD03 Motor Drivers
- Receive power from the 12V battery.
- Control DC motors by connecting to the motor terminals.
- Interface with the Arduino Mega 2560 via I2C for motor control commands.
HALL Sensors
- Powered by the 5V supply from the power supply unit.
- Ground connected to the common ground in the circuit.
- Signal pins connected to logic level converters for interfacing with the microcontroller.
HEDS Encoders
- Powered by the 5V supply from the power supply unit.
- Ground connected to the common ground in the circuit.
- Channel A and B outputs connected to logic level converters for interfacing with the microcontroller.
ME22 Rotary Encoders
- Powered by the 5V supply from the power supply unit.
- Ground connected to the common ground in the circuit.
- Channel A and B outputs connected to logic level converters for interfacing with the microcontroller.
DC Motors
- Connected to the motor outputs of the MD03 motor drivers.
Power Supply
- Provides 12V to the motor drivers and 5V to the logic level converters and sensors.
- Ground connected to the common ground in the circuit.
Logic Level Converters
- Step down 5V signals from the Arduino Mega 2560 to 3.3V and step up 3.3V to 5V for safe communication with 3.3V devices.
Resistors
- Used for pull-up/pull-down resistances or current limiting in the circuit.
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);
}
Code Description
- The code is written for the Arduino Mega 2560 microcontroller.
- It initializes the serial communication and configures the trigger and echo pins for the ultrasonic sensor.
- In the loop function, it triggers the ultrasonic sensor and reads the echo to calculate the distance to an object.
- The calculated distance is then printed to the serial monitor every second.