Hi everyone
I tried to recreate the puzzle from the following YouTube video:
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:
//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.

