Mazda 3 Rear Hatch Control with Arduino

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);
  }
}

My suggestion is to a button/switch directly, it is much less trouble prone. Here is something you might want to consider and partially explain my suggestion. There is a good app note AN2689 by ST on automotive electronics. reading it will help you a lot.
https://www.st.com/resource/en/application_note/cd00181783-protection-of-automotive-electronics-from-electrical-hazards-guidelines-for-design-and-component-selection-stmicroelectronics.pdf
Also take a look at this: Distilled Automotive Electronics Design | Analog Devices

Using a micro controller seems like overkill along with the problems of working with the noisy electrical environment of a car. 2 relays and a switch would seem to be all you need.

Thanks for your help! Those links are very helpful for working in the automotive environment.

One side of the motor is wired to ground in the lock actuator, so you mean using the microcontroller to switch on a relay connecting the other side of the motor to 12V? Basically don't use the motor shield to drive the motor directly and replace it with a relay?

Given the fluctuations in the power line I assume I still need the buck-boost to provide power to the motor through the relay so it doesn't see the fluctuations on the power line? And the arduino to run everything given I still need to read the lock state, know when to shut off the relay when the lock is open, and read the input from the button.

You had mentioned doing this without a microcontroller at all. Without a microcontroller how would you know when to shut off the motor and if the car was locked or unlocked?

Thanks!

Why not just take 12V through a push button to the motor. Push the button and motor turns on. Release the button and motor turns off. No Arduino needed and the only parts you need are a push button and some wire.

1 Like

Yeah I initially thought of that, but my concerns were two fold.

First, I don't know much about the motor itself in the actuator and searching the printed text on the motor didn't help much beyond that seems to be 12V. The power line is ~12.5V when the car is off and ~14.5V when the car is on. My concerns were supplying this directly to the motor would be over the rated voltage. The transients i assume wouldn't be an issue given no one should be pressing the button when starting the car etc.

Second, I was hoping to not compromise security if possible. If I wire the button in series then whenever you press it the trunk will open, regardless of if the car is locked or unlocked.

Thanks!

It is a motor in an automotive setting. 12V and automotive mean it can take 14.5 just fine. We call it 12V, but nothing in a car is going to break at just a little more. A 12V automotive system is always assumed to put out 14.5V because that's what you get when the alternator is running.

That's a little stickier. You could wire it so that it's only hot when the car is on. Interacting with the door locks is going to be tricky even with the Arduino.

A simple idea, if it was part of the original vehicle it ran on 12 volts, why not now? That vehicle is probably rated to take a 24V surge or more via a low dump.

Without more details I can't answer that, but I pretty much agree with @Delta_G 's comment in reply #5.

It would help to know what the connections to the actuator really are, by which I mean a diagram / drawing / schematic, not more words. What contacts does it have? When do they operate? What are you hoping to use to control the actuator? An existing button? What contacts does it have? A new button / switch or something? How do you propose to tell the actuator to lock / unlock? As for the rest of the car's locking system how does that work?

At the very least you need to know exactly how it works in terms of what voltage* you apply where to what effect, what contacts there are and what they do when.

*As others have noted, don't worry about whether it's 12V or 13V or 14V or whatever, it's designed to work in a car, it'll be OK.

I appreciate everyone's help! I'm clearly not as used to working in an automotive environment.

This gets at the core of an issue I have been struggling with as it is very difficult to find any documentation about the wiring of the car and what signals the BCM actually is sending to the lock actuator. As mine is clearly not working, I can't study the output response when I press the button as nothing happens.

I can detail what I have learned so far though. All parts are original to the car so should be rated to whatever tolerances were originally required.

There is a button pictured below that is in the trunk door that you press to pop the trunk so you can open it. It is active low and the two wires connect to a harness that feeds all of the wires back through the car I assume to the BCM. It is not wired directly to the lock actuator.

The lock actuator is also wired directly to this harness. It has a 4 pin connector pictured below and I have mapped where each wire goes and will detail this below:

image

Green is ground, white is power, and there are two black wires.

Below is the disassembled lock actuator:

There is a DC motor that powers a worm gear and turns the larger and therefore the smaller gears. This rotates that larger white plastic lever, which is what physically pushes the lock open and releases the hatch.

Below is the right side with gears and motor removed:

One of the larger black wires maps to one side of the motor and ground to the other side. Since my BCM doesn't work, I don't know what signal is sent to the motor through this wire, I assume 12V from the BCM. Nothing happens to this wire in my car when I press the button.

In the original image of the lock actuator there is a white lever in the bottom left. This lever is spring loaded and has contacts on the bottom as shown below:

When the motor is activated and the lock has moved all the way open, this secondary lever gets pushed by the lock mechanism and rotates these contacts. Here is a picture of channels below the contacts:

Normally, the spring holds the lever and contacts all the way to the left, which bridges the gap between the channels and connects them. These wires map to the white power line and the other black wire. When the lever is pushed, it moves the contacts down and to the right, moving one contact onto the black plastic and opening the circuit. My assumption is this is signaling the BCM when the motor has fully unlached the lock so the BCM knows when to stop the motor as this circuit is opened only when the lock has been fully unlached.

As for the lock and unloack status of the car, I assume that is something the BCM already knows as it is also controlling all non-engine components of the car including the door locks.

I apologize as I know this isn't a clear circuit diagram per se, but it is all of the info I have been able to deduce.

Given the button isn't originally wired in series with the motor I didn't know what it is rated to handle and replacement parts don't detail those specs. I assume the motor automatically stops when the lock is open to prevent burning it out, which is why I had wanted to duplicate this and have it stop when the contacts open as someone other than me (e.g. my wife or son) might just hold it down and damage it. Maybe this isn't as important.

The larger issue is I don't actually know what signal is sent to the motor when activated, which is why I was playing it safe as I didn't know if it just gets connected to the power line or not.

Thanks!

Did you try to get a wiring diagram for the car? You should be able to find one easily and possibly for free. With a wiring diagram you should have a better idea of how the motor works.

Yeah this is another issue. I have tried for a while to find the wiring diagram for the rear trunk, but I haven't been able to find it yet.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.