Run Switch Case with multiple buttons over serial monitor

Hej Guys,
maybe someone can help me to figure out my switch case for my cableway project (see picture) on a island in Sweden.

Everything works fine, so fare. The cableway runs up and down even with 400kg load.
Only the start and stop is quite violently (to quick).
Since i could control the speed from the 380V motor with a 10k ohm pot, i try to use a MCP4131 - Digital Potentiometer and control it over arduino (uno). Also the buttons soft-start, soft-stop, emergency-stop over a remote-control with buttons as well a end-top and a end-down over end-switches.

The Switch Case seems the best solution for me..

But i`m stuck with the problem, after writing some numbers in serial monitor with push-buttons, to catch them afterwords with the serial read to address the switch case.. see below:

const int pin_LED1 = 8;
const int pin_LED2 = 13;

// all buttons gona be later "deboucend"
const int pin_ButtonSoftStart = 2; // Start-Buttton
const int pin_ButtonSoftStop = 3; // Stop-Button
//etc.

int ButtonState_SoftStart = 0;
int ButtonState_SoftStop = 0;
//etc.

int lastButtonState_SoftStart;
int lastButtonState_SoftStop;
//etc.

void setup() {
  Serial.begin(9600);

  pinMode(pin_LED1, OUTPUT);
  pinMode(pin_LED2, OUTPUT);
  //etc.

  pinMode(pin_ButtonSoftStart, INPUT);
  pinMode(pin_ButtonSoftStop, INPUT);
  //etc.
}

void loop() {

  // press the button stop to get in serial monitor the Nr.1
  ButtonState_SoftStart = digitalRead(pin_ButtonSoftStart);
  if (ButtonState_SoftStart == HIGH) {
    if (ButtonState_SoftStart != lastButtonState_SoftStart)
      Serial.println('1');
    lastButtonState_SoftStart = ButtonState_SoftStart;
  }

  // press the button stop to get in serial monitor the Nr.2
  ButtonState_SoftStop = digitalRead(pin_ButtonSoftStop);
  if (ButtonState_SoftStop == HIGH) {
    if (ButtonState_SoftStop != lastButtonState_SoftStop)
      Serial.println('2');
    lastButtonState_SoftStop = ButtonState_SoftStop;
  }
  delay(10);


  // read what`s in the serial monitor..
  if (Serial.available() > 0) {
    int ReadPushButton = Serial.read();

    // switch Cases: if number 1 ore 2 etc. showes up in serial monitor (next line),
    // than switch to case 1 ore 2 etc.. and light up LED 1 ore 2 etc.
    switch (ReadPushButton) {

      case '1':
        digitalWrite(pin_LED1, HIGH);
        delay(500);
        digitalWrite(pin_LED1, LOW);
        break;

      case '2':
        digitalWrite(pin_LED2, HIGH);
        delay(500);
        digitalWrite(pin_LED2, LOW);
        break;

        //case 3 etc.
    }
    delay(1);
  }
}

When you write to Serial, the information goes out of your Arduino. Unless you wire the transmit pin directly to the receive pin, you don't get that information back.

Why would you send a number or a letter and expect to read it again?

Hi,
Welcome to the forum.

Since i could control the speed from the 380V motor with a 10ohm pot,

How does that work, do you have a VSD?
10 Ohms sounds very low.

Can you please post a copy of the motor control circuit you propose, in CAD or a picture of a hand drawn circuit in jpg, png?

What are the specs of the 380V motor, AC or DC.
What is the power source, mains supply or a generator?

Thanks.. Tom.. :slight_smile:

Hej Morgan and Tom,
thank you for your fast feedbacks and welcoming me as a newbie =)
cool..

So far I have not understood that arduino can`t read the monitor over serial.read, only the input from the pc. Thank you for this feedback. Somehow I need a solution with the switch case, so that the individual buttons could trigger a case.
Do you have an idea how i could solve it with the switch case?

Sorry, its of course a 10k Ohms.. I have summarized a schematic, which shows the course of the cableway and the arduino .. see the picture (jpg).

hejdå Marco

I like the idea of your project...
What happens if the motor doesn’t stop?
Wrecked towers, broken cable, dropped cargo?

Before tuning up the motor control, i’d be exploring some redundancy or fail-safe mechanisms to ensure the motor (and complete system) is doing what is expected (not what is commanded!)
Perhaps second sensor at each end - either wired differently, or a different type to verify all is working properly. A tachsensor on the motor that you can use to get feedback from the driven load...

This project looks simple, and if it was for a hobby layout - ok, but
i suspect this has serious consequences, and should be designed with that in mind.

Sorry to be a bit damp on your plans, but get it right the first time, and you’ll never look back.

Hi,
Thanks for the overall connection image.

Do you have a user/installation manual for the VSD unit on the motor.

The easiest way to use a digital pot is if the original pot you are replacing is referenced to gnd/0V on the VSD control input.

Tom... :slight_smile: