Microcontroller acts weird after changing to a different power supply

Hello everyone,
I'm making a simple arduino powered blinds controller.
The idea is - there is a single push-button, which makes the motor turn CW/CCW alternately for a set amount of time, but stops if button pushed mid-operation. A LDR monitors light levels outside, and if it gets too dark for a set amount of time, the blinds close. (video of operation here)
I am using a 12V 2A wall plug for breadboarding my projects, but I will solder the components on a perfboard later.
So when I tried using the power supply I ordered for this project (also 12v 2a) the microcontroller started acting weird - when i touch the supply chassis it turns for a bit. when I press the button it also turns for a random, small amount of time. (video) (video)
I suspect the problem is with the motor somehow interrupting the microcontroller by using too much power?
Ofcourse the obvious solution is to use the power supply that works, however I am curious of what is causing the problem, can it be fixed with some diodes or caps, or should I maybe use transistors and ditch the H-bridge altogether?
I am new to this stuff, so please try to explain in laymans terms.
Schematic attached below
Thanks! :slight_smile:

Code: (ignore the stuff related to LDR, I only had just started it)

const int in1Pin = 5; // H-Bridge input pins
const int in2Pin = 4;
const int buttonPin = 7;
const int sensorPin = 1;

int buttonPushCounter = 3;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
//int currentBrightness;
//int previousBrightness;

unsigned long previousMillis = 0;
unsigned long currentMillis;
int timeDown = 18500;
int timeUp = 24000;

void setup() {

  pinMode(in1Pin, OUTPUT);
  pinMode(in2Pin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.println("Press button to move blinds");

int readButton() {
  int buttonState;
  buttonState = digitalRead(buttonPin);
  return buttonState;
//int readSensor() {
//  int currentBrightness = analogRead(sensorPin);
//  currentBrightness = map(currentBrightness, 0, 1023, 1, 100);

void loop() {
     not yet finished

    currentBrightness = analogRead(sensorPin);
    if (readSensor() != previousBrightness) {
      Serial.print("Brightness: ");
    previousBrightness = currentBrightness;

  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      delay (200);
    lastButtonState = buttonState;
  if (buttonPushCounter % 4 == 0) {
    Serial.println("Going Down");
    previousMillis = millis();
    while (millis() - previousMillis <= timeDown && readButton() == LOW) {
      digitalWrite(in1Pin, LOW);
      digitalWrite(in2Pin, HIGH);
    Serial.println("Blinds Stopped");
  else if (buttonPushCounter % 4 == 1) {
    digitalWrite(in1Pin, LOW);
    digitalWrite(in2Pin, LOW);
  else if (buttonPushCounter % 4 == 2) {
    Serial.println("Going Up");
    previousMillis = millis();
    while (millis() - previousMillis <= timeUp && readButton() == LOW) {
      digitalWrite(in1Pin, HIGH);
      digitalWrite(in2Pin, LOW);
    Serial.println("Blinds Stopped");
  else {
    digitalWrite(in1Pin, LOW);
    digitalWrite(in2Pin, LOW);

So when I tried using the power supply I ordered for this project (also 12v 2a) the microcontroller started acting weird - when i touch the supply chassis it turns for a bit.

Is the power supply the only thing you changed? What happens when you switch back to the old power supply?

It sounds like you need to ground the chassis, but it also sounds like "something's loose" somewhere else, like maybe the pull-down resistor to the pushbutton is not making good contact?

First, I'd try wiggling wires. If that doesn't help to track-down the problem, add some serial.Print() statements so you can "watch" the button state on the serial monitor. It's also sometimes helpful to add some print statements that say things like "Opening Blinds", "Stopping Motor", etc., so you can track-down where the error is getting-in.

Same thing when you add the LDR code - Watch what's going on with the serial monitor until your program is fully developed & debugged.

You've got a readButton() function which it looks like you're not using, and you don't need a function for this since it's only one line of code to read the digital pin.

Yes, the power supply is the only thing I changed, and when I connect the previous one, everything works great.
On the power supply there are connections L, N, ground, V+, V-.
I connected L and N to the wall outlet, and V+ to positive V- to ground (red and blue wires in the diagram). Should I connect the ground to V- to sorta ground the chassis?
I have some Serial.print statements to let me see what's going on (going down, going up, blinds stopped), I had more concerning time, but I deleted them when I figured out how to make it work.
I made readButton() because I couldn't put digitalRead(buttonPin) in the while function, don't know why.
Thanks for the advice!
So is it safe to ground the chassis to the "ground" of the circuit? I don't really know how this stuff works to be honest - what is the difference between ground and V- in this case?