no output serial monitor

Hi guys!

Why doesn't this code result in any sort of output in the Serial Monitor window? I just want it to state the frequency and duty cycle once.

int Gate = 8;
int on = 10;
int off = 5;
int frequency = 1000000* (1/(on + off));

void setup() {
  pinMode(Gate, OUTPUT);
  
  Serial.write('Duty cycle:');Serial.write((100*on/(on+off)));Serial.write('%'); 

  Serial.write('Frequency: ');Serial.write(frequency);Serial.write('Hz'); 


}
void loop() { 
  digitalWrite(Gate, LOW);
  delayMicroseconds(on);
  digitalWrite(Gate, HIGH);
  delayMicroseconds(off);

}

:slight_smile:

You need to initialize the serial connection before using it.

Serial.begin(9600);  // initialize serial bus
while(!Serial);      // wait for serial connection

You should also use the Serial.print() and Serial.println() functions instead of Serial.write() for printing text.

in your setup-function the first thing that must be executed to make serial work is a

Serial.begin(baudrate);

where baudrate should be a typical common value like 9600 or 115200.

In the serial monitor you have to adjust the baudrate to the value you have chosen in your program

instead of Serial.write use

Serial.print();

or Serial.println();
best regards Stefan

Also, you need to use double quotes for strings, not single quotes.