Why isn't this working

nothing is wrong with my code, it's just my motor won't turn on, while in the same exact code, i hooked the output pin to a train crossing signal and works flawlessly, is there anything i could do, and here is the code

const int SensorPin2 = 2;
const int Motor = 4;

void setup() {
  pinMode(SensorPin2, INPUT);
  pinMode(SignalPin, OUTPUT);
}

void loop() {
  bool sensor2State = digitalRead(SensorPin2) == LOW;
  

  digitalWrite(Motor, sensor2State ? HIGH : LOW);
}

My guess would be that you need a motor driver and adequate power supply.

Post a schematic, let's see.

a7

2 Likes

i don't have a motor driver

“Well, there’s your problem”

1 Like

Assuming you are using an Arduino Uno R3, an output pin can deliver 5V at up to 20mA under normal operating conditions.

How many volts and mA does your train crossing signal need?

And how many volts and mA does your motor need?

Oh, and regardless of its voltage and current requirements, if you have connected a motor directly to an output pin without a flyback diode across it, you will not have a working pin for very long.

1 Like

which i am, and i'm not entirely for sure how much V is required for the signal, but all i know, is that's using an eve model flasher board

ok, i'll just think of something else, because, i obviously don't have everything i need to make what i wanna do work, so yeah, but thank's for the help, i just might use it another day

s-l1600

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.