Running 24 volts motor through arduino

JCA34F:
And ANOTHER thing :slight_smile: , you are powering the HESs with 5V and connecting the signal to 3.3V (I think) inputs. Those HESs MAY be the kind you need, I can't say, 'cause I don't know how your project / device is supposed to work.

Oh, you are right, may that's the reason two of my MKR boards are not functional anymore.
The problem is sensors need 5V and the pins to the MKR board need to be 3.3 V. I think it is not a problem for UNO. However, relays can be powered by 3.3 V.

@Aarg and JCA34F thank you so very much guys for your help. After your handy comments and suggestions, I have finally made it work the way I wanted it to be.

@JCA34F regarding the sensors, I checked the voltage difference between ground and data pin of the sensor and it was 2.6 volts, so, I think that's fine and therefore, it is working even though I am powering it with 5 V. The minimum I can provide is 4.5 V to the sensor.

Regarding the 2 MKR boards, I thought they have been burned or something as they were not flashing and the computer was not recognizing them anymore. I am thankful to the guys on this forum because I learned in previous posts that if I put the board in bootloader mode, and flash a program it might work. And luckily it worked for me. So, my 2 MKR boards are working again :slight_smile:

Will keep you guys posts regarding the progress and will let you know if I confront any issue again :stuck_out_tongue:

#define sensor1 A1
#define sensor2 A3
#define sensor3 A6
#define buttonPin_blue 1
#define buttonPin_red 7
#define relayPin1 3
#define relayPin2 5

bool enableS1= true;
bool enableS2= false;
bool enableS3= false;
bool deParking = false;
bool motorInMotion1 = false;
bool motorInMotion2 = false;

void setup() {

  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);
  pinMode(buttonPin_blue, INPUT);
  pinMode(buttonPin_red, INPUT);
  pinMode(relayPin1, OUTPUT);
  pinMode(relayPin2, OUTPUT);

}

void loop() {

    int val1 = analogRead(sensor1);
    int val2 = analogRead(sensor2);
    int val3 = analogRead(sensor3);
    int val4 = digitalRead(buttonPin_blue);
    int val5 = digitalRead(buttonPin_red);
    int Relay1 = digitalRead(relayPin1);
    int Relay2 = digitalRead(relayPin2);

    if (val1 <= 400 && enableS1 && !deParking){
    enableS1 = false;
    enableS2 = true;
    digitalWrite(relayPin1, HIGH);
    motorInMotion1 = true;
    }
    else if (val1 > 300 && deParking){
       deParking = false;
       enableS1 = true;
    }
    
    if (val2 <= 400 && enableS2){
    enableS2 = false;
    enableS1 = false;
    enableS3 = true;
    digitalWrite(relayPin1, LOW);
    motorInMotion1 = false;
    }

    if (val4 == 1 && val3 > 300){
    digitalWrite(relayPin2, HIGH);
    enableS3 = true;
    motorInMotion2 = true;
    }

    if (val3 <= 400 && enableS3){
    enableS3 = false;
    deParking = true;
    digitalWrite(relayPin2, LOW);
    motorInMotion2 = false;
    delay(5000);
    }

    if (val5 == 1 && val2 > 300){
      if (motorInMotion1){
        digitalWrite(relayPin1, LOW);
        motorInMotion1 = false;
      }
      else if (motorInMotion2){
        digitalWrite(relayPin2, LOW);
        motorInMotion2 = false;
      }
      else{
        digitalWrite(relayPin1, HIGH);
        motorInMotion1 = true;
        enableS2 = true;
      }
    }
}

Hello everyone,

Regarding my current project, I have an additional task to add to this project. I have a second button (red_button) that will turn ON or OFF the motor at any time, in other words, it would be the manual rotation of the motor. With the code that has to drive the motor automatically works fine. But the addition of the red_button is not working properly. I have attached the schematic of it to this comment.

What is the purpose of the red_button? Generally, when I press the red_button and the motor is not in motion, it should start rotation of the motor in the forwarding direction. And if it is already in rotation either forward or reverse direction, pressing the red button should stop the motor. So, pressing the button will stop the forward and the reverse motion, but it only allows the motor to rotate in the forwarding direction.

The issue I face is when I press the button it will start the motor in the forwarding direction. But when I want to stop the forward rotation the relay ticks very fast and makes that abrupt ticking sound. Sometimes it will stop and sometimes it won't the motor. Regarding the reverse rotation, if I press the red_button, it will stop the reverse rotation but (SOMETIMES) at the same time it starts the forward rotation.

Can you guys please tell me if I have done something wrong in the code or in the hardware?

Thank you very much.

schematic1.jpg

schematic1.jpg

Hi,
I am currently using this schematic in my current project. I want to know the limitations of this schematic. Additionally, can it affect the operation of Arduino and my code? Any tips to improve it. Currently, I have only 5 VDC and 24 VDC available.
Thank you!