ESP32 and Arduino UNO CAN Bus Motor Controller with Integrated Encoder
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit integrates an ESP32 microcontroller, an Arduino UNO, two MCP2515 CAN controllers, a 7805 voltage regulator, a potentiometer, an L298N DC motor driver, a gear motor with an integrated encoder, a 12V battery, and a diode. The ESP32 and Arduino UNO communicate with the MCP2515 CAN controllers, which are used for CAN bus communication. The L298N motor driver controls the gear motor, and the 7805 voltage regulator provides a stable 5V supply. The potentiometer is used for analog input, and the diode ensures correct polarity for the power supply.
Component List
ESP32 38 PINS
- Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: GND, G23, G22, TXD, RXD, G21, G19, G18, G5, G17, G16, G4, G0, G2, G15, SDI, SD0, CLK, 3V3, EN, SP, SN, G34, G35, G32, 33, G25, G26, G27, G14, G12, G13, SD2, SD3, 5V
Arduino UNO
- Description: A popular 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
MCP2515
- Description: A CAN controller used for CAN bus communication.
- Pins: INT, SCK, SI, SO, CS, GND, VCC, H, L
7805
- Description: A voltage regulator that provides a stable 5V output.
- Pins: Vin, Gnd, Vout
Potentiometer
- Description: A variable resistor used for analog input.
- Pins: GND, Output, VCC
L298N DC Motor Driver
- Description: A dual H-bridge motor driver used to control DC motors.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
Gear Motor with Integrated Encoder
- Description: A DC motor with an integrated encoder for position feedback.
- Pins: MOTOR -, MOTOR+, Encoder -, Encoder +, Encoder A, Encoder B
12V Battery
- Description: A power source providing 12V.
- Pins: VCC, GND
Diode
- Description: A component that allows current to flow in one direction only.
- Pins: cathode, anode
Wiring Details
ESP32 38 PINS
- G27 connected to MCP2515 INT
- G18 connected to MCP2515 SCK
- G23 connected to MCP2515 SI
- G19 connected to MCP2515 SO
- G5 connected to MCP2515 CS
- GND connected to MCP2515 GND, 12V Battery GND, Gear Motor with Integrated Encoder Encoder -, L298N DC Motor Driver GND, 7805 Gnd
- 3V3 connected to Gear Motor with Integrated Encoder Encoder +, MCP2515 VCC
- G32 connected to Gear Motor with Integrated Encoder Encoder B
- 33 connected to Gear Motor with Integrated Encoder Encoder A
- G25 connected to L298N DC Motor Driver IN3
- G26 connected to L298N DC Motor Driver IN4
- G14 connected to L298N DC Motor Driver ENB
- 5V connected to 7805 Vout
Arduino UNO
- D3 connected to MCP2515 INT
- D13 connected to MCP2515 SCK
- D11 connected to MCP2515 SI
- D12 connected to MCP2515 SO
- D10 connected to MCP2515 CS
- GND connected to MCP2515 GND, Potentiometer GND
- 5V connected to MCP2515 VCC, Potentiometer VCC
- A0 connected to Potentiometer Output
MCP2515
- INT connected to ESP32 G27, Arduino UNO D3
- SCK connected to ESP32 G18, Arduino UNO D13
- SI connected to ESP32 G23, Arduino UNO D11
- SO connected to ESP32 G19, Arduino UNO D12
- CS connected to ESP32 G5, Arduino UNO D10
- GND connected to ESP32 GND, Arduino UNO GND
- VCC connected to ESP32 3V3, Arduino UNO 5V
- H connected to MCP2515 H
- L connected to MCP2515 L
7805
- Vin connected to L298N DC Motor Driver 12V, Diode cathode
- Gnd connected to ESP32 GND, 12V Battery GND, Gear Motor with Integrated Encoder Encoder -, L298N DC Motor Driver GND
- Vout connected to ESP32 5V
Potentiometer
- GND connected to Arduino UNO GND
- Output connected to Arduino UNO A0
- VCC connected to Arduino UNO 5V
L298N DC Motor Driver
- IN3 connected to ESP32 G25
- IN4 connected to ESP32 G26
- ENB connected to ESP32 G14
- GND connected to ESP32 GND, 12V Battery GND, Gear Motor with Integrated Encoder Encoder -, 7805 Gnd
- 12V connected to 7805 Vin, Diode cathode
- OUT4 connected to Gear Motor with Integrated Encoder MOTOR -
- OUT3 connected to Gear Motor with Integrated Encoder MOTOR+
- 5V-ENA-JMP-I connected to 5V-ENA-JMP-O
Gear Motor with Integrated Encoder
- Encoder + connected to ESP32 3V3
- Encoder - connected to ESP32 GND, 12V Battery GND, L298N DC Motor Driver GND, 7805 Gnd
- Encoder B connected to ESP32 G32
- Encoder A connected to ESP32 33
- MOTOR - connected to L298N DC Motor Driver OUT4
- MOTOR+ connected to L298N DC Motor Driver OUT3
12V Battery
- VCC connected to Diode anode
- GND connected to ESP32 GND, Gear Motor with Integrated Encoder Encoder -, L298N DC Motor Driver GND, 7805 Gnd
Diode
- cathode connected to 7805 Vin, L298N DC Motor Driver 12V
- anode connected to 12V Battery VCC
Documented Code
Arduino UNO Code
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
This code is a basic template for the Arduino UNO. The setup function is called once when the program starts, and the loop function runs continuously. You can add your specific functionality within these functions.