 programming code

hi,
i need to generate pwm of 30 hz and turn it off at 20 minutes in arduino nano,
so i used a code to generate 30 hz which is given below but i need code to turn it off

int pin =3;
void setup() {
pinMode(3, OUTPUT);
}
void loop() {
digitalWrite(pin, HIGH);
delay(16.66);
digitalWrite(pin, LOW);
delay(16.66);
}

interesting:

delay(16.66);

FYI, because delay() only takes integers (unsigned long), your float is being cast to an uint32_t.

How much precision is needed? A very simple but not very elegant solution is to add a while. 20 minutes is 1200 seconds is 1,200,000 millis.

int pin =3;
void setup() {
pinMode(3, OUTPUT);
}
void loop() {
while (millis()<1200000){
digitalWrite(pin, HIGH);
delay(16.66);
digitalWrite(pin, LOW);
delay(16.66);
}
}

What is the point of defining pin as 3 and then doing pinMode(3, OUTPUT) ?

The cast of 16.66 is probably truncating to the integer 16.

You might try:

const byte pin = 3;
void setup()
{
pinMode(pin, OUTPUT);
}
void loop()
{
while (millis()<1200000)
{
digitalWrite(pin, HIGH);
delay(16);
delayMicroseconds(660);
digitalWrite(pin, LOW);
delay(16);
delayMicroseconds(660);
}
// the stop part
while(1); // press the reset button to repeat
}

Note: The maximum value for delayMicroseconds is 16383.