I might have bitten off more than I can chew here with my somewhat limited skills, but I would appreciate any help if possible!
The short summary is I have a 2012 Mazda 3 hatchback and the trunk lock suddenly stopped working. I checked the button, which works, and replaced the actuator, with no improvement. Took it to the dealership and they said it is an issue with the body control module, which would need to be replaced costing around $1500. Given this is an old car and everything else works perfectly, I thought I could use an arduino to replace this singular task and save a significant amount of money.
I took apart the old actuator and there is a small DC motor inside. Very hard to find specs, but similar models appear to be 12V. Power line to the trunk sits around 12.5V with the car off and 14.5V with the car on. Given the hostile environment of the car (e.g. power surges with cranking, voltage changes etc.) I opted to run the Arduino uno power through a buck converter, which outputs 5V to the Vin pin. I am using the adafruit motor shield v2.3 to run the DC motor, which receives power separately (Vin jumper removed) from the car power line through a buck-boost converter as I was worried the input and output voltages were too close together to use the buck when the car is off. Trying to do this quickly I bought both off Amazon, which maybe was my first mistake. All output voltage were tested prior to anything being connected to the arduino.
Wiring is very simple. In addition to above, button is connected to digital pin 2 and ground and is active low. There are a few other inputs for assessing lock/unlock status for security, and to know when to stop the motor (when the lock opens two contacts in the actuator are bridged to signal to stop the motor), but I removed these from the code for now to simplify things.
This was working fine when I was running a 12V power supply directly to the motor shield. After wiring up the buck-boost and buck and connecting the power supply to the inputs of those, it still works, but when I first press the button everything flashes for a second like there is a drop in voltage or something and the motor jitters slightly. If you keep holding it the motor will then spin up until you release the button. Then when I went to upload the code with additional above features the Arduino is no longer recognized by the device manager and despite extensive troubleshooting I can't connect to it. I assume I fried something on the board, though it will still run the code that is currently on the board.
Before I bought a new board I figured I should ask for help. Is this an issue with EMI when the motor turns on? Have I missed something big here? Debating on if I should just scrap this completely and go back to a cord I rigged to the manual actuator release.
Thanks in advance!!
Code is below:
#include <Wire.h>
#include <Adafruit_MotorShield.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Connect the motor to port M4
Adafruit_DCMotor *motor = AFMS.getMotor(4);
// Button pin
const int buttonPin = 2;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - Button Controlled Motor Test!");
AFMS.begin(); // create with the default frequency 1.6KHz
pinMode(buttonPin, INPUT_PULLUP); // Set up the button pin with internal pull-up resistor
motor->setSpeed(255); // Set the motor speed (0 to 255)
}
void loop() {
// Read the button state
int buttonState = digitalRead(buttonPin);
// Check if the button is pressed (active low)
if (buttonState == LOW) {
Serial.println("Button pressed, turning on motor!");
// Turn on the motor at full speed
motor->run(FORWARD);
} else {
// If the button is not pressed, stop the motor
motor->run(RELEASE);
}
}