I'm building a PWM generator on an UNO r3 as part of a larger project and I'm fairly new to arduino. Currently I'm just trying to test my code but I'm finding that the Serial Monitor stops sending prints very shortly after launching. I checked around and tried to stop the serial from resetting by dropping a resistor between the 5v and reset, a capacitor from 5v to gnd, and from 5v to reset. None of those seemed to help. I also added in 'while (!Serial)' if anyone has any suggestions I'd appreciate it.
The print on the serial monitor only shows:
"Enter Heating Number 0 to 9, followed by a comma
then a four digit time in seconds (012"
int pwmPin = 9; // pwm connected to digital pin 9
int PWMvalue = 0;
void setup() {
//allows serial communication at 9600 baud
Serial.begin(9600);
while (!Serial); // Wait until Serial is communicating
Serial.println("Enter Heating Number 0 to 9, followed by a comma");
Serial.println("then a four digit time in seconds (0120 would be two minutes),");
Serial.println("or simply 'x' to power off");
}
void loop() {
if (Serial.available() > 0){
String in = {Serial.readString()};
int pwr = in[0];
int t = {(in[5] * 1000) + (in[4] * 100) + (in[3] * 10) + in[2]};
if (pwr >= 0 && pwr <= 9)
{
PWMvalue = (pwr + 1) * 25; //255=100%, 127=50%, ect
analogWrite(pwmPin, PWMvalue);
Serial.print("Heating element powered to ");
Serial.print((pwr + 1) * 10);
Serial.println("%");
Serial.println("pwr is currently: ");
Serial.print(pwr);
Serial.println("t is currently: ");
Serial.print(t);
delay((t - '0') * 1000);
PWMvalue = 0;
analogWrite(pwmPin, PWMvalue);
Serial.println("Heating is complete, exiting Program in 10 seconds");
delay(10000);
Serial.println("Goodbye");
exit(0);
}
if (pwr == 'x')
{
PWMvalue = 0;
analogWrite(pwmPin, PWMvalue);
Serial.println("Heating element powered off, exiting Program in 10 seconds");
delay(10000);
Serial.println("Goodbye");
exit(0);
}
else
{
PWMvalue = 0;
analogWrite(pwmPin, PWMvalue);
Serial.println("ERROR: Invalid Input");
Serial.println("Exiting Program in 10 seconds");
delay(10000);
Serial.println("Goodbye");
exit(0);
}
}
PWMvalue = 0;
analogWrite(pwmPin, PWMvalue);
Serial.println("Goodbye");
exit(0);
}