Go Down

Topic: Problems with different voltages (Read 148 times) previous topic - next topic

blacklotus1990

Hi everyone 

I tried to recreate the puzzle from the following YouTube video:
https://www.youtube.com/watch?v=Fa_JP8u2bVc


In my version of the puzzle i hooked up an DC-motor that opens a sliding door as soon as the puzzle is solved (when all wires are connected correctly). The sliding door stops as soon as the limit switches are touched. In the initialization-state, the door closes.
Also, i added a button which has to be pressed to get the puzzle running. 

Here is a drawing of what my wiring looks like:


Everything is working as planned when the Arduino is running on 5 Volts. As soon as I hook it up to 9 Volts weird things happen. The LEDs flicker as soon as I touch the aluminum plate where everything is mounted to:

According to my multi meter everything on the aluminum plate is isolated correctly

I have no clue why this is happening only when I hook up 9 volts in stead of 5 volts.
Does anybody have an idea?

here's the code i'm using:
Code: [Select]
//KABEL---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define DEBUGKabel
const int kabelButton = A5;
const byte anzahlBuchsen = 8;
const byte signalPins[anzahlBuchsen] = {7, 8, 9, 10, A0, A1, A2, A3};
const byte numVerbindungen = 4;
const byte verbindungen[numVerbindungen][2] = {{0, 7}, {1, 4}, {2, 6}, {3, 5}};
bool letzterStatus[numVerbindungen] = {false, false, false, false};
enum PuzzleStatus {Initialisierung, Betrieb, Fertig};
PuzzleStatus puzzleStatus = Initialisierung;
unsigned long timeBegin;
bool timeRunning = 0;
int LEDKabel = A4;
const byte dcPin[2] = {11, 5};
const byte stopPin = 12;
bool KabelFertig = 0;
const byte stopPinOpen = 3;//Braun zu Blau von arduino aus
const byte stopPinClosed = 4;//Gelb zu GrĂ¼n von Arduino aus

void setup() {



  //KABEL----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  for (int i = 0; i < anzahlBuchsen; i++) {
    pinMode(signalPins[i], INPUT_PULLUP);
  }
  pinMode(LEDKabel, OUTPUT);
  pinMode(kabelButton, INPUT_PULLUP);
#ifdef DEBUGKabel
  Serial.begin(9600);
  Serial.println(F("Serial communication started"));
#endif
  puzzleStatus = Initialisierung;
  digitalWrite(LEDKabel, HIGH);
  for (int i = 0; i < 1; i++) {
    pinMode(dcPin[i], OUTPUT);
  }
  pinMode(stopPinOpen, INPUT_PULLUP);
  pinMode(stopPinClosed, INPUT_PULLUP);
}

void loop() {

  if (puzzleStatus == Initialisierung) {
    while (digitalRead(stopPinClosed) == 1) {
      analogWrite(dcPin[0], 0);
      analogWrite(dcPin[1], 255);
    }
    analogWrite(dcPin[0], 0);
    analogWrite(dcPin[1], 0);
    puzzleStatus = Betrieb;
  }
  if (puzzleStatus == Fertig) {
    while (digitalRead(stopPinOpen) == 1) {
      analogWrite(dcPin[0], 255);
      analogWrite(dcPin[1], 0);
    }
    analogWrite(dcPin[0], 0);
    analogWrite(dcPin[1], 0);
  }
 else {
  if (digitalRead(kabelButton) == LOW) {
    bool alleKabelKorrekt = true;

    bool statusVeraendert = false;

    for (int i = 0; i < numVerbindungen; i++) {
      byte pin1 = signalPins[verbindungen[i][0]];
      byte pin2 = signalPins[verbindungen[i][1]];
      bool jetztStatus = istVerbunden(pin1, pin2);
      if (jetztStatus != letzterStatus[i]) {
        statusVeraendert = true;
        letzterStatus[i] = jetztStatus;
      }

      if (jetztStatus == false) {
        alleKabelKorrekt = false;
      }
    }
    if (statusVeraendert) {
#ifdef DEBUGKabel
      for (uint8_t i = 0; i < numVerbindungen; i++) {
        Serial.print(F("Pin#"));
        Serial.print(signalPins[verbindungen[i][0]]);
        Serial.print(F(" - Pin#"));
        Serial.print(signalPins[verbindungen[i][1]]);
        Serial.print(F(" : "));
        Serial.println(letzterStatus[i] ? "CONNECTED" : "NOT CONNECTED");
      }
      Serial.println(F("---"));
#endif
    }
    if (timeRunning == 0 && puzzleStatus == Fertig) {
      timeBegin = millis();
      timeRunning = 1;
    }
    if (millis() > timeBegin + 100) {
      if (digitalRead(LEDKabel) == HIGH) {
        digitalWrite(LEDKabel, LOW);
      }
      else {
        digitalWrite(LEDKabel, HIGH);
      }
      timeRunning = 0;
    }
    if (alleKabelKorrekt && puzzleStatus == Betrieb) {
      puzzleStatus = Fertig;
#ifdef DEBUGKabel
      Serial.print(F("The puzzle has been solved!"));
#endif
      digitalWrite(LEDKabel, LOW);
    }
  }
  else {
    digitalWrite(LEDKabel, LOW);
  }
}
}


bool istVerbunden(byte OutputPin, byte InputPin) {
  pinMode(OutputPin, OUTPUT);
  pinMode(InputPin, INPUT_PULLUP);

  digitalWrite(OutputPin, LOW);

  bool istVerbunden = !digitalRead(InputPin);
  pinMode(OutputPin, INPUT_PULLUP);
  return istVerbunden;
}



Thanks in advance and let me know if you need further information.

WattsThat

You absolutely need a current limiting resistor in series with any LED.

When you say it works with 5 volts, is that powered through the USB port? Is the motor working under that condition?

What is the source of the 9 volts? A small block battery?

Vacuum tube guy in a solid state world

MarkT

Small 9V batteries aren't up to powering motors or servos.
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

blacklotus1990

The LEDs have one 220 ohm resistor each. Never had problems with that.

Everything works fine when the Arduino is connected to the PC via USB or if i use a 5v power supply.
The 9volts are from a 12v power supply which i stepped down to 9v via step down converter.

slipstick

So why not step the 12V down to 5V and save all the trouble?

Steve

WattsThat

Quote
The LEDs have one 220 ohm resistor each. Never had problems with that.
Then the schematic should reflect that fact.

Sounds like a bad 12v power supply or something is oscillating. If you have a multimeter, put it on the AC range and measure the output of the stepdown regulator. You should have less than 100 millivolts of ac floating on the dc level.
Vacuum tube guy in a solid state world

MarkT

Which 12V supply?  Which step-down converter?  Which motor?  Details are very important for
electronics...  The stall-current of the motor is a key piece of information for instance.

BTW powering a motor and the Arduino from the same supply is a common cause of problems,
since motors are rough loads at the best of times.
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

blacklotus1990

thanks everyone.

Because I'm just tinkering, I usually buy my electronic components from Ali Express.

The problem is solved:

First I tried another 12v 2A power supply.
Somehow it did work with this one. After that i saw, that one of the wires was broken. After fixing the broken wire i tried it again with the other power supply and it worked.
This could still be the reason:
Quote
Sounds like a bad 12v power supply or something is oscillating. If you have a multimeter, put it on the AC range and measure the output of the stepdown regulator. You should have less than 100 millivolts of ac floating on the dc level.
unfortunately, I don't have a multimeter that can measure AC under 200V... But i have to test that when I have the possibility to.

Thank you guys for your help!


Go Up