Need help with code to control a high voltage capacitor

I have a problem were I get the opposite effect then i want.
My LED is always on and then it turns off for the amount of time i have set.
The problem is that is should be the other way around. So off to on.

I't on an UNO.

I have put digitalWrite(Induction, LOW); under VOID LOOP at the top. so i dont get why it does not turn the LED off when you first run the script.

The plan is to use a high voltage capacitor insted of an led. so i can control a spark.

(LED is just to test the script)

My code:

I have an uno and i have the 5v to the + side og the LED and the 8 PIN to the negativ side of the LED.

String command;
#define Induction 8



void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(Induction, OUTPUT);
digitalWrite(Induction, LOW);


Serial.println("type command (test)");
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(Induction, LOW);
if (Serial.available()){
command = Serial.readStringUntil('\n');
    command.trim();
if (command.equals("q")) {
  digitalWrite(Induction, HIGH);

}
delay (2000);

  digitalWrite(Induction, LOW);
}
}

Thank you for taking the time :slight_smile:

That's not the way to operate an LED.

Because of this:

Since the LED is connected to 5V, when the output pin goes low there is voltage across the LED and it turns on.

When the output pin is high with 5V on both LED terminals there is no voltage across the LED and it's off.

...You should have a resistor in series with the LED to prevent excess current.

It's OK because the Arduino can either "source" or "sink" current, but it reverses the logic and either way it needs a resistor.

Thank you :slight_smile:

That works. question. The 8 Pin outputs 5v? and is there a way to make that ground? an or make a passageway from example ( Pin 9 to Pin 10) and control the passageway to only passthrough then some code says so?

And thanks for your help :smiley:
Edit: I have two 220 ohm between the led + and -

When you set the pin HIGH, it is at 5V. When you set the pin LOW, it is at ground.

If you want to turn on a "passageway" that is usually done with a relay. An UNO pin controls the relay to either connect the relay output pins or keep them open.

Thank you so much. this really help alot. Thank you :smiley:

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