0

I am new on Arduino. I am trying to use the board to generate a PWM to control a IGBT switch. The following is my code. I didnt get the pulse I expected. Does anyone have idea of what's going on? Thanks

int pinOut = 13;

void setup() {
  pinMode(pinOut, OUTPUT);
}

void loop() {
    digitalWrite(pinOut,HIGH);
    delay(1000);
    digitalWrite(pinOut,LOW);
    delay(1000);

}
Suzy.W
  • 1
  • Please check out my edited answer. I think it will solve your problem, Suzy. – TomServo Jul 13 '17 at 12:06
  • If I might ask, what about my answer was insufficient for you to accept it (by checking the check mark icon)? I want to post the best answers possible to help others now and into the future. – TomServo Jul 17 '17 at 15:16

1 Answers1

0

Your code is doing great at simply turning on and off pinOut pin with a 1000-millisecond delay between toggling. But PWM is a method of turning the pin on and off fast enough to create the illusion of an analog voltage. So instead you need this sort of code, using analogWrite():

int pinOut = 3; // use pin 3, 5, 6, 9, 10, or 11 for this application on an Uno

void setup() {
// no need for setup for this
}

void loop() {
    analogWrite( pinOut, 128 ); // 50% duty cycle, value goes from 0 to 255   
}

Reference this Arduino documentation page.

TomServo
  • 7,248
  • 5
  • 30
  • 47