Arduino Lesson 6: Reading From the Serial Port

So far in our programming we have set the variables inside of the program, usually up at the top. In order to change the number of times the LED’s blink, we would change the lines of code that set those variables. This is OK for playing around, but you can see that if you want other people to use your programs you can not have them playing around with your code. You need to be able to get input from the user without modifying the code. We can do that using the Serial Port. Just like we can print information to the user using the Serial Port, we can also get information from the user using the serial port.

In these exercises we will continue to use the circuit created in Arduino Lesson 3. If you need help in putting the circuit together, go back and review that lesson. Here is a diagram of the circuit we are working with.

LED Schematic
This circuit will allow you to independently control two Light Emitting Diodes from the arduino microcontroller

Also, as a reminder, here is the code we have been working with that incorporates all the things we have learned so far. I am including this code so you can look at it if you get stuck, and to serve as an example for the work you do. To learn programming though, you need to be typing in your own code, making mistakes, and then finding an correcting your mistakes. You will not learn programming if you simply go through these lessons copying and pasting my code.

OK, look over this code and review what we have learned so far. At the top of the program we declare our variables, and we assign values to them. So far we have worked with variables of type int and type String.  Then in the void loop we start our serial port, and we set our two arduino pins to OUTPUT.  In the void loop we have built two for loops .  .  . one to blink the red LED and then one to blink the yellow LED. The parameters used in the for loop like how many times to blink and how long each blink should be are all defined at the top of the program.

As we mentioned at the beginning, it is OK to start out doing things this way, but at some point you need to be getting your parameter values from the user, and not hard coding them into the program. You would like the program to ask the user how many times he would like to blink the red LED, and then ask how many times he would like to blink the yellow LED. This is really pretty easy to do, and we do it over the serial port, very similar to how we learned to print in lesson 5.

In order to get input from the user, you need to make sure that you have turned your serial port on in your void setup. You do that with a Serial.begin(9600); command, as seen in the code above. You always need to have this command in your void setup() if you are going to print to the serial port or read from it. Now, in order to get input from the user, you need to do three things:

    • Prompt the User for the Input
    • Wait for the User to Enter the Input
    • Read the information from the serial port

In the program above,  lets say that in our void loop each time through the loop we want to prompt the user for how many times he wants the red LED to blink and then after that prompt him for how many times he wants the yellow LED to blink. In this scenario, we are now getting the parameters from the user instead of hard wiring them into the program. In this case, we still have to declare our varialbes, but we do not need to assign values to them. Hence in the example above the code:

Should be taken out and replaced with:

You see, now we are only declaring our variables. We are not assigning values to them, because we will be getting the values from the user. It is important, however, that any variables that we will use still need to be declared.

Now in our void loop() this would be the code to get from the user the number of times he would like to blink the LED.

There is a lot going on in these few lines of code, and lots of new things for you to learn, so lets unpack it pretty carefully. The first line should be familiar to you. You are just printing to the serial monitor a message to the user that you are waiting for input. In this case he will see a message asking him to put in a number. Now, we have to remember that the computer can work much faster than a person, so when a computer asks a person to do something, it is important for the computer to sit and wait for the person to complete it. This is done in the second and third lines of code above. This is an example of a while loop. You can see the while loop has a clause associated with it that starts and ends with the curly brackets. The program will continue to execute what is between these curly brackets as long as the condition that is in the parenthesis is true. So a while loop is sort of like a for loop, except the while loop can continue to loop forever as long as the condition in the parenthesis is true. So, we need to understand the ‘condition’ part of the code above, which is Serial.available()==0.  This is not as confusing as it looks. Serial.available() is a function that when you call it, it returns a ‘1’ if the user has input data, and a ‘0’ if the user has not input data. So, if the user has not input data, Seraial.available() will be 0, the condition will be true, and the program will stay in the while loop.

So the bottom line is that

 will sit and loop forever waiting for the user to input the data. When the user inputs the data, it will them move on to the next lines of code. Notice that we do not do anything in the while loop because there are no commands between the two curly brackets. The purpose of this line of code is simply to get the program to stay at that point until the user inputs his data.

Now at the point the user does input the data, Serial.avaialbe() will become ‘1’, and the program moves to the next line of code. The next line of code,

is the line that actually reads the data. Serial.parseInt() reads the number the user input, and then that number is assigned to the variable numRedBlinks. When you are reading an integer from the serial port, you use Serial.parseInt(). There are different commands for reading other variable types. You can imagine that if you were reading a floating number, you would user Serial.parseFloat(). To read a string you would user Serial.readString(). The important point is that you need to use the correctly precise command for the type of data you are trying to read.

OK, so put that code into your program at the start of the void loop() and also make a similar sequence of code to get from the user the numYellowBlinks. After you have that working also get other parameters from the user like the various blink time variables. You should play around with this and get comfortable getting input from the user. When you run the code, remember to click the icon in the upper right of the arduino IDE to get the serial monitor to pop up. You should see the prompt in the Serial Monitor, and you should enter your number in the small box, and then click send, or press the enter key.

75 thoughts on “Arduino Lesson 6: Reading From the Serial Port”

  1. The “while” loop is clearly explained but when I tried, it seems to jump out of the loop even though Serial.available is zero. I have written a short sketch to try to track down the problem but I can not see where it is going wrong.

    void setup(){
    Serial.begin(9600);

    }

    void loop(){
    Serial.println(“Enter a number”);//prompt

    while(Serial.available()==0) {}//wait for input
    int num=Serial.parseInt();//transfer number to num
    Serial.println(Serial.available());//print Serial.available valu
    Serial.println(num);//print number

    }

    1. Rob, Not sure what is wrong, the code looks right, and it runs on my arduino uno properly. Make sure baud rate is same on your serial monitor. I have my arduino serial monitor set on 9600 baud, and “carriage return” and it works as expected.

      1. am having the same issue. it seems impossible to figure out. may be its an hardware issue.

  2. Thanks for the quick reply. It must be something to do with the hardware. I am using a cheap import. I have added a line which reads the contents of the monitor again and this seems to clear it out and then the program continues correctly. It is a bit strange.

    1. The same issue, to solve it I just selected “No line Ending” option on the serial monitor and 9600.. and now it’s ok.. but the question is why.. we should dig deeper to figure out ….

  3. these are awesome tutorials and im enjoying them. rob , i think u shuldnt use int num=Serial.parseInt(); bt instead use num=Serial.parseInt() without the int part and make sure u did declare your num as int at the top of your program.

  4. Hello Paul,
    I am having a problem similar to Rob’s. The RED serial send routine works fine but the YELLOW serial send routine simply prints out the first ‘prompt’ line, delays about a half second and then falls through to the ‘void loop()’.
    I have tried copy/paste from the red routine to the yellow routine to no avail. I am using an Arduino MEGA 2560 R3. The serial monitor is as you suggested: Carriage Return, 9600 baud.

    *********************************************
    int redLEDPin=9; //Declare redLEDPin an int, and set to pin 9
    int yelLEDPin=10; //Declare yellowLEDPin an int, and set to pin 10
    int redOnTime=250; //Declare redOnTime an int, and set to 250 mseconds
    int redOffTime=250; //Declare redOffTime an int, and set to 250
    int yelOnTime=250; //Declare yellowOnTime an int, and set to 250
    int yelOffTime=250; //Declare yellowOffTime an int, and set to 250
    int numRedBlinks; //Number of times to blink red LED
    int numYelBlinks; //Number of times to blink yellow LED
    String redMsg=”The Red LED is Blinking”;
    String yelMsg=”The Yellow LED is Blinking”;
    String st1=”Welcome to “; //Create a String st1 and set to “Welcome to ”
    String st2=”Lesson 6″; //Create a String st2 and set to “Lesson 6″
    String st3; //Declare a String st3 but dont assign value to it yet.

    void setup() {
    Serial.begin(9600);
    pinMode(redLEDPin, OUTPUT); // Tell Arduino that redLEDPin is an output pin
    pinMode(yelLEDPin, OUTPUT); // Tell Arduino that yellowLEDPin is an output pin

    st3=st1+st2; // Concatenate st1 and st2 into a new variable st3
    Serial.println(st3); // Print out st3
    Serial.println(” “); // Skip a line

    Serial.println(“How many times do you want the RED LED to blink? “); // Prompt for User Input
    while (Serial.available()==0) {} // Wait for User Input
    numRedBlinks = Serial.parseInt(); // Read User Input

    Serial.println(“How many times do you want the YELLOW LED to blink? “); // Prompt for User Input
    while (Serial.available()==0) {} // Wait for User Input
    numYelBlinks = Serial.parseInt(); // Read User Input
    }

    thanks in advance for any help

    1. Rob great classes i am going to do them all ,but i am having the same problem as others were as soon as i enter red value into the serial monitor it asks for yellow input but doesn’t wait and starts the cycle , preventing me from making the yellow blink at all , i hope this can be figured out as i hate to move on with learning when their is a problem .. ugh!

        1. Got the solution! set serial monitor to “no line end” and it worked like a charm (after two hours).

          BIG THANKS to Ed C

          1. Thanks Daniel
            I had the same problem and your idea worked for me. I thought that Serial.avaliable may have to be set back to 0, but it appears that reading Serial.parseInt does this for you.

  5. Had a problem with this one but managed to solve it by reducing the BAUD rate from 115200 to 9600 (both matched initially).

  6. sir i have been watching ur tutorials all are really awesome. i need one help from you. currently i am working on a project which consists of 3 analog gas sensors which senses the data and sends the data in the integer format to the another arduino board through xbee.
    i have a big problem at the reciever side. the problem is i have to read the integer values which are obtained through serial buffer. how can i do that?
    how can i terminate one reading after the other through the buffer?
    how can i get integer data for example 1234 ,2341,2345,5678 etc like that randomly variable values?
    plz help me asap.

  7. Am wondering why the for and while etc. do not change color, even though the loops work correctly. Cannot figure it out.
    Apart from that, this stuff is soooo challenging to play around with!
    Thanks

  8. These tutorials have been a Godsend for me. I’m self taught so these tutorials are extremely valuable to me. Thank you for all these tutorial series.

  9. I have change the code NumYellowblinks in NumRedblinks and it works for me.
    Serial.println(” “);
    Serial.println(yellowMessage);
    for (int j=1; j<=numRedBlinks; j=j+1) {

  10. There tutorials on programming Arduino are superb. Who need books, I don’t, I got a few to my disgust. Then I discovered this site. Thanks a lot

  11. Dear Sir;

    Greetings;

    Please suggest:
    This is my code for this tutorial
    But the problem is it is not responding as it should be,
    it is not stopping itself for the input of the Blue led only taking it for the red LED .I think I am doing something wrong with the while loop,please help.

    the code:

    int redpin=12; // to define the red led pin on circuit
    int blupin=13; //to define the blue ledpin on circuit
    int redon=1000; //red led on time
    int redoff=1000; //red led off time
    int bluon=800; //blue led on time
    int bluoff=800; // blue led off time
    int redblink; // number of times red led wil blink
    int blublink; // number of times blu led will blink
    String redmessage=”the red Led is blinking”;
    String blumessage=”the blue Led is blinking”;
    void setup(){

    Serial.begin(9600);
    pinMode(redpin,OUTPUT);
    pinMode(blupin,OUTPUT);
    }

    void loop(){
    Serial.println(“HOW MANY TIMES YOU WANT TO BLINK RED LED ?”); //to ask foe input about the number of blinks of red led.
    while(Serial.available()==0);{ } //wait for the input value
    redblink=Serial.parseInt(); //to take value of number of red blinks from the serial monitor

    Serial.println(“HOW MANY TIMES YOU WANT TO BLINK BLUE LED ?”); //to ask for input about the number of blinks of blue led.
    while(Serial.available()==0);{ } //wait for the input value
    blublink=Serial.parseInt(); //to take value of number of blue blinks from the serial monitor

    Serial.println(redmessage);
    for(int j=1;j<=redblink;j=j+1){
    Serial.println(j);
    digitalWrite(redpin,HIGH);
    delay(redon);
    digitalWrite(redpin,LOW);
    delay(redoff);

    Serial.println(blumessage);
    for(int k=1;k<=blublink;k=k=1){
    Serial.println(blumessage);
    Serial.println(k);
    digitalWrite(blupin,HIGH);
    delay(bluon);
    digitalWrite(blupin,LOW);
    delay(bluoff);
    }
    }

    }

    1. It is your line:

      while(Serial.available()==0);{ } //wait for the input value

      There should be no colon between the closing parenthesis and the open curly bracket. So, this line is incorrect, and it never enters the while loop, just goes to the next step.

      1. Thanks a lot for the help.
        But still it is only asking about red led and waits for red led input.once entered it is asking for blue led input but not waiting for input instead goes for the red led blinking as entered.

        my new corrected code:

        int redpin=12; // to define the red led pin on circuit
        int blupin=13; //to define the blue ledpin on circuit
        int redon=1000; //red led on time
        int redoff=1000; //red led off time
        int bluon=800; //blue led on time
        int bluoff=800; // blue led off time
        int redblink; // number of times red led wil blink
        int blublink; // number of times blu led will blink
        String redmessage=”the red Led is blinking”;
        String blumessage=”the blue Led is blinking”;
        void setup(){

        Serial.begin(9600);
        pinMode(redpin,OUTPUT);
        pinMode(blupin,OUTPUT);
        }

        void loop(){
        Serial.println(“HOW MANY TIMES YOU WANT TO BLINK RED LED ?”); //to ask foe input about the number of blinks of red led.
        while(Serial.available()==0){ } //wait for the input value
        redblink=Serial.parseInt(); //to take value of number of red blinks from the serial monitor

        Serial.println(“HOW MANY TIMES YOU WANT TO BLINK BLUE LED ?”); //to ask for input about the number of blinks of blue led.
        while(Serial.available()==0){ } //wait for the input value
        blublink=Serial.parseInt(); //to take value of number of blue blinks from the serial monitor

        Serial.println(redmessage);
        for(int j=1;j<=redblink;j=j+1){
        Serial.println(j);
        digitalWrite(redpin,HIGH);
        delay(redon);
        digitalWrite(redpin,LOW);
        delay(redoff);

        Serial.println(blumessage);
        for(int k=1;k<=blublink;k=k=1){
        Serial.println(blumessage);
        Serial.println(k);
        digitalWrite(blupin,HIGH);
        delay(bluon);
        digitalWrite(blupin,LOW);
        delay(bluoff);
        }
        }

        }

          1. ——— thanks for clearing this up, just spent 2 hours trying to figure out why the code wouldnt work , so happy now!!!!!!!!!!!!!!!!!!!!!

          2. I really desire to get more meticulous in this whole Arduino programming tutorial and I would like to know what each “line option” in the serial monitor next to the BAUD rate options mean…and an example of situations where we might prefer the other option than the others. Thank you very much!

          3. Thank you. Your solution worked for me.
            I assume No Line End, New Line, Carriage Return will be explained later?

  12. Looking for a program for the Arduino
    Reading a value from the A to D converter (pot).
    every second into the serial window – this is easy…
    Then compare it to an Excel column of values. Every second with the next value in the column.
    Then write the original value of the read value from excel and the value of the pot on the ADC into two Excel columns – Then have three LEDS on the o/p port of the Arduino, to indicate if the value read in from the ADC is bigger, equal or smaller than the value in the original excel column.

  13. Hi, thanks for the great tutorial.

    I am using this code to obtain user input for the number of minutes that a relay is turned on for. However, the code you provide asks for user input every time the loop starts again.

    I would like to ask for the user input once, during the setup, then convey that user input to another variable named eMin (end minute). eMin is calculated by sMin (start minute) + the user input e.g. 1.

    I tried moving the user input to the void setup {} but although the code uploads ok, the relay doesn’t turn on for some reason. Without the user input then it works fine (e.g. looking at code below if int eMin = (sMin+1); thenit works fine. I think it’s something to do with the user input coming after the variable has been defined but I’m not sure.

    Here’s the code:
    #include
    #include //real-time clock library
    #include
    #include
    #include
    // iowa https://www.iowa-aquaponics.com/learn/automation/p?Project=6754692986044416&n=Toggle%20Pump%20Control&c=Automation
    //sourceA Real-Time Clock – Part II: Grow Light Controller http://iowa-aquaponics.blogspot.co.nz/2013_07_01_archive.html
    RTC_DS1307 RTC;

    #define RELAY1 2 // relay connected on pin x
    #define DS3231_I2C_ADDRESS 0x68
    #define dht_dpin 8 // define the temp sensor pin number

    // Convert normal decimal numbers to binary coded decimal
    byte decToBcd(byte val)
    { return( (val/10*16) + (val%10) );}
    // Convert binary coded decimal to normal decimal numbers
    byte bcdToDec(byte val)
    { return( (val/16*10) + (val%16) );}

    //iowa stuff
    // Pump
    int relay = 2; // Relay pin
    int state = LOW; // Initial relay state – off
    //end iowa

    //iowa time-based events from https://www.iowa-aquaponics.com/learn/automation/p?Project=5114542350663680&n=Real-Time Clock&c=Automation
    // Start time: 0 mins past every hour
    //int sHour = 21;
    int sMin = 27;

    //define variable for pump time on
    int pumpTimeOn;

    // Off time: ontime plus x mins
    //int eHour = 21;
    int eMin = (sMin+pumpTimeOn);

    // Time variables
    time_t turn_on;
    time_t turn_off;
    //endiowa time-based events

    //temp sensor
    dht DHT; //call the temp sensor DHT

    void setup()
    {
    Wire.begin();
    Serial.begin(9600);

    //start user input pump time
    Serial.println(“How many minutes do you want the pump to turn on for?”); //Prompt User for Input
    while(Serial.available()==0) { // Wait for User to Input Data
    }
    pumpTimeOn=Serial.parseInt(); //Read the data the user has input
    //- See more at: http://www.toptechboy.com/arduino/arduino-lesson-6-reading-from-the-serial-port/#sthash.nqaGLrjg.dpuf
    //end user input pump time

    // set the initial time here:
    // DS3231 seconds, minutes, hours, day, date, month, year
    //setDS3231time(00,35,21,4,9,9,15);//uncomment to set time again
    // Relay – Initialise the Arduino data pins for OUTPUT
    pinMode(RELAY1, OUTPUT);
    // iowa
    RTC.begin();
    Serial.println(“Initializing….”);
    pinMode(relay, OUTPUT);
    digitalWrite(relay, state);
    // Notify if the RTC isn’t running
    if (! RTC.isrunning()) {
    Serial.println(“RTC is NOT running”);
    }
    //end iowa
    //start iowa time-based events
    DateTime current = RTC.now();
    // Use the RTC time to set the start time
    //setTime(sHour, sMin, 00, current.day(), current.month(), current.year());
    setTime(current.hour(), sMin, 00, current.day(), current.month(), current.year());
    turn_on = now();

    // Use RTC time to set the end time
    // setTime(eHour, eMin, 00, current.day(), current.month(), current.year());
    setTime(current.hour(), eMin, 00, current.day(), current.month(), current.year());
    turn_off = now();

    // Reset system time to now
    setTime(current.hour(), current.minute(), current.second(), current.day(), current.month(), current.year());
    //end iowa time-based events

    //start temp sensor events
    delay(300);//Let system settle
    Serial.println(“Humidity and temperature\n\n”);
    delay(700);//Wait rest of 1000ms recommended delay before accessing sensor
    //end temp sensor

    }

    void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
    dayOfMonth, byte month, byte year)
    {
    // sets time and date data to DS3231 – only needed when adjusting the time
    Wire.beginTransmission(DS3231_I2C_ADDRESS);
    Wire.write(0); // set next input to start at the seconds register
    Wire.write(decToBcd(second)); // set seconds
    Wire.write(decToBcd(minute)); // set minutes
    Wire.write(decToBcd(hour)); // set hours
    Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
    Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
    Wire.write(decToBcd(month)); // set month
    Wire.write(decToBcd(year)); // set year (0 to 99)
    Wire.endTransmission();
    }

    void readDS3231time(
    byte *second,
    byte *minute,
    byte *hour,
    byte *dayOfWeek,
    byte *dayOfMonth,
    byte *month,
    byte *year)
    {
    Wire.beginTransmission(DS3231_I2C_ADDRESS);
    Wire.write(0); // set DS3231 register pointer to 00h
    Wire.endTransmission();
    Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
    // request seven bytes of data from DS3231 starting from register 00h
    *second = bcdToDec(Wire.read() & 0x7f);
    *minute = bcdToDec(Wire.read());
    *hour = bcdToDec(Wire.read() & 0x3f);
    *dayOfWeek = bcdToDec(Wire.read());
    *dayOfMonth = bcdToDec(Wire.read());
    *month = bcdToDec(Wire.read());
    *year = bcdToDec(Wire.read());
    }

    void displayTime()
    {
    byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
    // retrieve data from DS3231
    readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
    &year);
    // send it to the serial monitor
    Serial.print(hour, DEC);
    // convert the byte variable to a decimal number when displayed
    Serial.print(“:”);
    if (minute<10)
    {
    Serial.print("0");
    }
    Serial.print(minute, DEC);
    Serial.print(":");
    if (second<10)
    {
    Serial.print("0");
    }
    Serial.print(second, DEC);
    Serial.print(" ");
    Serial.print(dayOfMonth, DEC);
    Serial.print("/");
    Serial.print(month, DEC);
    Serial.print("/");
    Serial.print(year, DEC);
    Serial.print(" Day of week: ");
    switch(dayOfWeek){
    case 1:
    Serial.println("Sunday");
    break;
    case 2:
    Serial.println("Monday");
    break;
    case 3:
    Serial.println("Tuesday");
    break;
    case 4:
    Serial.println("Wednesday");
    break;
    case 5:
    Serial.println("Thursday");
    break;
    case 6:
    Serial.println("Friday");
    break;
    case 7:
    Serial.println("Saturday");
    break;
    }
    }

    void loop()
    {
    displayTime(); // display the real-time clock data on the Serial Monitor,
    //start temp sensor code
    DHT.read11(dht_dpin);
    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("% ");
    Serial.print("temperature = ");
    Serial.print(DHT.temperature);
    Serial.println("C ");
    Serial.println("");
    //end temp sensor code
    //start pump timer code
    DateTime current = RTC.now();
    // Reset system time to now
    setTime(current.hour(), current.minute(), current.second(), current.day(), current.month(), current.year());
    time_t n = now();

    if (turn_on <= n && n < turn_off) {
    // Execute "on" code
    digitalWrite(RELAY1,LOW);
    } else {
    digitalWrite(RELAY1,HIGH); // Execute off code
    }
    //end pump timer code
    Alarm.delay(1000); // wait one second between clock display

    }

    Your advice would be much appreciated.

    Thanks again!

  14. I managed to fix this problem with changing Serial.available()==0 to 1. See below:
    int redLEDPin=9; //Declare redLEDPin an int, and set to pin 9
    int yellowLEDPin=10; //Declare yellowLEDPin an int, and set to pin 10
    int redOnTime; //Declare redOnTime an int, and set to 250 mseconds
    int redOffTime=250; //Declare redOffTime an int, and set to 250
    int yellowOnTime; //Declare yellowOnTime an int, and set to 250
    int yellowOffTime=250; //Declare yellowOffTime an int, and set to 250
    int numYellowBlinks=5; //Number of times to blink yellow LED
    int numRedBlinks=5; //Number of times to blink red LED
    String redMessage=”The Red LED is Blinking”; //Declaring a String Variable
    String yellowMessage=”The Yellow LED is Blinking”; //Declaring a String Variable

    void setup() {
    Serial.begin(115200); // Turn on the Serial Port
    pinMode(redLEDPin, OUTPUT); // Tell Arduino that redLEDPin is an output pin
    pinMode(yellowLEDPin, OUTPUT); //Tell Arduino that yellowLEDPin is an output pin

    Serial.println(“How Many Times Do You Want the Red LED to blink?”); //Prompt User for Input
    while(Serial.available()==0) { // Wait for User to Input Data
    }
    numRedBlinks=Serial.parseInt(); //Read the data the user has input

    Serial.println(“How Many Times Do You Want the Yellow LED to blink?”); // Here was the problem for some reason. When serial.available changed to 1 it seems to be working fine.
    while(Serial.available()==1) { // Wait for User to Input Data
    }
    numYellowBlinks=Serial.parseInt(); //Read the data the user has input

    Serial.println(“How Long Do You Want the Red LED to be On?”);
    while(Serial.available()==1) { // Wait for User to Input Data
    }
    yellowOnTime=Serial.parseInt(); //Read the data the user has input

    Serial.println(“How Long Do You Want the Yellow LED to be On?”);
    while(Serial.available()==1) { // Wait for User to Input Data
    }
    yellowOnTime=Serial.parseInt(); //Read the data the user has input
    }

    void loop() {

    Serial.println(redMessage);
    for (int j=1; j<=numRedBlinks; j=j+1) { // Start our for loop
    Serial.print(" You are on Blink #: ");
    Serial.println(j);
    digitalWrite(redLEDPin,HIGH); //Turn red LED on
    delay(redOnTime); //Leave on for redOnTime
    digitalWrite(redLEDPin,LOW); //Turn red LED off
    delay(redOffTime); //Leave off for redOffTime
    }
    Serial.println(" ");
    Serial.println(yellowMessage);
    for (int j=1; j<=numYellowBlinks; j=j+1) { // Start our for loop
    Serial.print(" You are on Blink #: ");
    Serial.println(j);
    digitalWrite(yellowLEDPin,HIGH); //Turn yellow LED on
    delay(yellowOnTime); //Leave on for yellowOnTime
    digitalWrite(yellowLEDPin,LOW); //Turn yellow LED off
    delay(yellowOffTime); //Leave off for yellowOffTime
    }
    Serial.println(" ");
    }

  15. Nice tutorial.
    The detailed explanation of everything works perfectly for beginners like me.
    Please continue that video tutorial series and expand on more advanced circuits.

  16. in my code it do not wait for the input of blue LED.
    Please help:

    float redPin=9;
    float rlagOn=100;
    float rlagOf=200;
    float bluPin=12;
    float blagOn=150;
    float blagOf=180;
    float r_blink;
    float b_blink;
    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(redPin,OUTPUT);
    pinMode(bluPin,OUTPUT);
    }

    void loop() {
    int j=r_blink;

    // put your main code here, to run repeatedly:
    Serial.println(” “);
    Serial.println(“HOW MANY TIME YOU WANT TO BLINK RED LED ?”);
    while (Serial.available()==0)
    { }
    r_blink=Serial.parseFloat();
    for (j=1;j<=r_blink;j=j+1)
    {
    Serial.println(j);
    digitalWrite(redPin,HIGH);
    delay(rlagOn);
    digitalWrite(redPin,LOW);
    delay(rlagOf);
    }

    int k=b_blink;
    Serial.println(" ");
    Serial.println("HOW MANY TIME YOU WANT TO BLINK BLUE LED ?");//prompt for input
    while (Serial.available()==0)//do the input
    {}
    b_blink=Serial.parseFloat();
    for(k=1;k<=b_blink;k=k+1)
    {
    Serial.print(k);
    digitalWrite(bluPin,HIGH);
    delay(blagOn);
    digitalWrite(bluPin,LOW);
    delay(blagOf);
    }
    }

  17. how can i read signal fom the slave mmicrocontroller of same integer datatype from the master microcontroller while communication b/w 2 microcontroller in arduino?

  18. /*this module reads sensors converts float to string and sends data actually over a RS485 pair of lines to another arduno*/

    #include “Adafruit_BMP085.h”
    #include
    #include
    //* —-Declare constants and Pin mumbers —-*/
    #define SSerialRx 10
    #define SSerialTx 11
    #define SSerialTxControl 4
    #define RS485Transmit HIGH
    #define RS485Receive LOW
    #define Pin13LED 13

    /* — Declare Objects —*/
    Adafruit_BMP085 mySensor;
    SoftwareSerial RS485Serial(SSerialRx,SSerialTx);

    /* — Declare Varibles –*/
    long Start;
    float tempC;
    float pressure;
    void setup() {
    Serial.begin(9600);
    mySensor.begin();
    pinMode (SSerialTxControl, OUTPUT);
    pinMode (Pin13LED, OUTPUT);
    RS485Serial.begin(9600);
    digitalWrite(SSerialTxControl, RS485Receive);

    }

    void loop() {
    tempC = mySensor.readTemperature();
    delay(150);
    pressure = mySensor.readPressure();
    delay(150);
    char tempC1[6];
    char pressure1[10];
    dtostrf (tempC,6,2, tempC1);// converting to string necessary to send over serial
    Serial.println(tempC1);
    delay(100);
    pressure=(pressure/100);
    delay(100);
    dtostrf(pressure,8,2,pressure1);
    delay(100);
    digitalWrite(SSerialTxControl, RS485Transmit);
    RS485Serial.write(“$ Temperature is:”);// using$ as start of text
    delay(1);
    RS485Serial.write(‘#’);
    delay(10);
    RS485Serial.write(‘$’);
    delay(1);
    RS485Serial.write(tempC1);
    delay(10);
    RS485Serial.write(pressure1);
    delay(10);
    RS485Serial.write(‘#’);// # as end of text
    digitalWrite(SSerialTxControl, RS485Receive);
    Start = millis();
    while(millis() – Start<100){
    delay(1);
    if(RS485Serial.read()=='$'){
    delay(1);
    char tempC2=RS485Serial.read();
    delay(1);
    char pressure2=RS485Serial.read();
    Serial.print(pressure2);// for debugging
    delay(2000);
    Serial.println(tempC2);// just for debugging
    break;
    }
    }
    digitalWrite(SSerialTxControl, RS485Transmit);
    }
    /*———————————————————————-
    This is main module with lcd, reading data from sensor arduino and using string/char to successfully read over serial –*/
    #include
    #include
    /* —-Declare constants and Pin mumbers —-*/
    char tempC1;
    #define SSerialRx 11
    #define SSerialTx 10
    #define SSerialTxControl 12
    #define RS485Transmit HIGH
    #define RS485Receive LOW
    #define Pin13LED 13
    LiquidCrystal lcd(36,38,40,42,44,46);
    SoftwareSerial RS485Serial(SSerialRx, SSerialTx);
    int i, MessageLength, Message[100];
    int j, MsgLgth,Msg[100];
    void setup() {
    // start serial
    Serial.begin(9600);
    //initiate LCD
    lcd.begin(16,2);
    lcd.clear();
    lcd.setCursor(0,0);
    Serial.println(“Temperature:-“);
    lcd.print(“Temperature:”);
    delay(100);
    pinMode(Pin13LED, OUTPUT);
    pinMode(SSerialTxControl, OUTPUT);
    digitalWrite(SSerialTxControl, RS485Receive);
    RS485Serial.begin(9600);

    }

    void loop() {
    lcd.clear();
    lcd.setCursor(0,0);
    if(RS485Serial.read() ==’$’){
    for (i=0; i<100; i++){
    delay(10);
    // Serial.print(i);
    Message[i] = RS485Serial.read();
    delay(10);
    if (Message[i] =='#')
    break;
    }
    if(RS485Serial.read() =='$'){
    for (j=0; i<100; j++){
    delay(10);
    // Serial.print(j);
    Msg[j] = RS485Serial.read();
    delay(10);
    if (Msg[j] =='#')
    break;
    }
    lcd.clear();
    lcd.setCursor(0,0);
    MessageLength = i;
    MsgLgth = j;
    //Serial.print(i);
    delay(10);

    Serial.print(tempC1);
    }

    for(i=0; i<MessageLength; i++){
    // lcd.print(Message[i]);
    lcd.print(char(Message[i]));//here we printing Temperature is:
    delay(200);
    Serial.print('a');
    }
    lcd.setCursor(0,1);
    for (j=0; j<MsgLgth; j++){
    Serial.print(char(Msg[j]));
    lcd.print(char(Msg[j]));//here we print temp and pressure
    delay(2000);
    }
    }

    digitalWrite(SSerialTxControl, RS485Transmit);
    RS485Serial.print('$');// just sending anything for the moment
    delay(10);// you can send something more meaningful
    RS485Serial.print('a');
    delay(10);
    RS485Serial.print('b');
    delay(10);
    RS485Serial.print('#');
    Serial.println('b');
    digitalWrite(SSerialTxControl, RS485Receive);

    }

  19. strange…noticed two “includes” being blank..they should be include SoftwareSerial.h and Wire.h with BMP_085.h.
    The other two missing are: LiquidCrystal. h and
    SoftwareSerial.h

  20. Hey there! Really enjoying the videos and I am learning so much!!
    I souped up this lessons code using some of the tricks you taught me. Had to make it a little more, you know, exciting. Add some flare! Add a green LED to Pin 11 and check it out!! (Best if arranged like a stop light!)

    [code]
    //To get user input, there are three things to do
    //Prompt the user for the input
    //Wait for the user to enter the input
    //Read the information from the serial port

    //Global int variables:
    int red = 9; //Declare red as int, set to pin 9
    int yellow = 10; //Declare yellow as int, set to pin 10
    int green = 11;
    int redOn; //Declare redOn as int, set delay (ms) NO VALUE, will get from UI
    int redOff = 250; //Declare redOff as int, set delay (ms)
    int yellowOn; //Declare yellowOn as int, set delay (ms)NO VALUE, will get from UI
    int yellowOff = 250; //Declare yellowOff as int, set delay (ms)
    int redLoop; //Declare redLoop as int, no value assigned. Will get from user input in serial port.
    int yellowLoop; //Declare yellowLoop as int, no value assigned. Will get from user input in serial port.
    //Global String Variables:
    String redMessage = “The Red LED is Blinking!”; //String variable. Editing text changes serial output
    String yellowMessage = “The Yellow LED is Blinking!”;

    void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200); //Turns Serial Port On
    pinMode(red, OUTPUT); //Set red as output
    pinMode(yellow, OUTPUT); //Set yellow as output
    pinMode (green, OUTPUT);

    Serial.println(“Make it Blink Program 2.0 – Chris Brantley”);
    Serial.println(” “);
    delay(500);
    digitalWrite(red, HIGH);
    Serial.println(“Ready “);
    Serial.print(“. “);
    delay(500);
    Serial.print(“. “);
    delay(500);
    Serial.println(“. “);
    delay(500);
    digitalWrite(red, LOW);
    Serial.println(“Set “);
    digitalWrite(yellow, HIGH);
    Serial.print(“. “);
    delay(500);
    Serial.print(“. “);
    delay(500);
    Serial.println(“. “);
    delay(500);
    digitalWrite(yellow, LOW);
    Serial.println(“Go!! “);
    for (int j = 1; j <= 4; j = j + 1) { //Blink 4 times rapidly to emulate excitement!
    digitalWrite(green, HIGH);
    delay(125);
    digitalWrite(green, LOW);
    delay(125);
    }
    Serial.println(" ");

    Serial.println("How many times should Red blink? "); //Step 1: Prompt the user for input.
    while (Serial.available() == 0) { } //Step 2: Wait for user input
    redLoop = Serial.parseInt(); //Step 3: Read Input. Match what you expect. int, float, script.

    Serial.println("How fast should Red blink? (1-1000) ");
    while (Serial.available() == 0) { }
    redOn = Serial.parseInt();

    Serial.println("How many times should Yellow blink? "); //Step 1: Prompt the user for input.
    while (Serial.available() == 0) { } //Step 2: Wait for user input
    yellowLoop = Serial.parseInt(); //Step 3: Read Input. Match what is expected.

    Serial.println("How fast should Yellow blink? (1-1000) ");
    while (Serial.available() == 0) { }
    yellowOn = Serial.parseInt();
    }

    void loop() {
    // put your main code here, to run repeatedly:

    Serial.println(redMessage);
    for (int j = 1; j <= redLoop; j = j + 1) { //For loop to repeat code
    Serial.print(" Blink #: ");
    Serial.println(j);
    digitalWrite(red, HIGH);
    delay(redOn);
    digitalWrite(red, LOW);
    delay(redOff);
    }

    Serial.println(" ");
    Serial.println(yellowMessage);
    for (int j = 1; j <= yellowLoop; j = j + 1) {
    Serial.print(" Blink #: ");
    Serial.println(j);
    digitalWrite(yellow, HIGH);
    delay(yellowOn);
    digitalWrite(yellow, LOW);
    delay(yellowOff);
    }
    Serial.println(" ");
    }
    [/code]

  21. Hey there! Really enjoying the videos and I am learning so much!!
    I souped up this lessons code using some of the tricks you taught me. Had to make it a little more, you know, exciting. Add some flare! Add a green LED to Pin 11 and check it out!! (Best if arranged like a stop light!)

  22. Sent the wrong code. This one includes the green LED I mentioned before. It’s just for a bit of fun!

  23. I’ve watched first 7 lessons till now.All are good but especially lesson 6 is extraordinary.The way you teach those 3 lines,is simply mindblowing.After seeing that,I feel you should now look for the other areas of electronics,electrical and computer science(obviously select those topics which you love).

  24. hii sir,
    sir i have one problem in arduino please guide me
    how to convert ACSII value into int.
    actually i am using esp8266 and their output comes in ACSII form so give particular i have to convert into int.

  25. i have tried all user suggestions but my code is still not working right , the program still wont wait for user input on yellow led even when i put the code into the setup loop it still wont wait and jumps into the void loop and my code looks perfectly matched to yours and i even tried switching arduinos?????? driving me nuts??? this should work

    1. Try setting serial monitor to “no line ending” (box next to baud rate), I had the same issue and this fixed it.

  26. Thanks for Lesson -6 … i was make my own sketch with help of your video..i just buy it 4 days ago for understand how to work arduino. i am a fresher in arduino project but with your each and every lessons help me a lot… Thanks to Mr.Paul McWhorter

    My project done …

    int redPin=9;
    int greenPin=10;
    int redOn=250;
    int redOff=250;
    int greenOn=250;
    int greenOff=250;
    int redTime;
    int greenTime;

    void setup() {
    Serial.begin(9600);
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    Serial.println(“Aries Computer Solutions”);
    Serial.println(“Welcome to my new Program”);

    Serial.println(” Please Input DATA for RED LED “);
    while(Serial.available()==0); {}
    redTime=Serial.parseInt();

    Serial.println(” Please Input DATA for GREEN LED “);
    while(Serial.available()==0); {}
    greenTime=Serial.parseInt();

    }

    void loop() {
    Serial.println(“Red LED Start”);
    for (int x=1; x<=redTime; x=x+1) {
    Serial.print(" Red LED Blinking = ");
    Serial.println(x);
    digitalWrite(redPin, HIGH);
    delay(redOn);
    digitalWrite(redPin, LOW);
    delay(redOff);

    }
    Serial.println("Green LED Start");
    for (int x=1; x<=greenTime; x=x+1) {
    Serial.print(" Green LED Blinking = ");
    Serial.println(x);
    digitalWrite(greenPin, HIGH);
    delay(greenOn);
    digitalWrite(greenPin, LOW);
    delay(greenOff);
    }

    }

  27. Paul, great great training video. Suggest (if it is not in your instructions some where I missed), you add a note for serial monitor to be set to “no line ending”, just spent several hours (not wasted) challenging my coding, and this turned out to be the issue. Just loaded Python and started thru your videos, question can one build a Python GUI (toggle and push buttons)interface to Arduino? Just spent 6 months building a large CNC Plasma cutter using Arduino, CNC Shield, GRBL and Universal GCode Sender. Ran 3500 lines of Gcode last weekend without a hiccup.

  28. Thanks for a great intro into programming. I have not done anything with code for a very long time and I was tempted to skip a bit. I am so glad I did not and I have taken your advice. All the errors so far have been typo type and each time I make an error it takes a little less time to find and fix.
    I am looking forward to the next videos on the PI and integrating the two platforms into real world problems.
    Regards
    Lee

  29. I’m having and issue with getting the Led to blink the correct number of times. I have (j=1; j<RedBlink; j=j+1 ) but no matter what I do when I set it to blink 10 (or any other amount) times in the Serial monitor it will only blink 9 or one less than the number I set…. The only fix I have found to this is is setting j=0. I must be doing something wrong but I have also copied the text directly from this site and still the same issue. Any help would be appropriated. Thanks

  30. instead of (j=1; j<RedBlink; j=j+1 ) try (int j = 1; J< RedBlink; j ++);

    You should be fine from there. The first variable set 'int' to j and the j++ is the same as j = j+1 but a bit easier. You can google C++ conventions and get excellent further study.

  31. Thank you for your tutorials…VERY helpful. However, when I try to use Serial.parseInt it says it is “class ‘HarwareSerial’ has no member named parseInt.

    My guess it is it isn’t in the library…can you tell me how to fix it?

  32. I had the same problem with this skipping the yellow number input. I am at 9600 and all I did to fix this was change the serial monitor from “no line ending” to something else, then back to “no line ending. then it works as intended.
    I stumbled upon this by just trying different things. this after switching boards, cables, computer, and messing with code. crazy. I hope this helps someone.

  33. I have tried several times to move the code around and no matter what I have done I still get

    Lesson6:7: error: expected primary-expression before ‘;’ token

    int numRedBlinks=; //Number of red blinks

    ^

    Lesson6:8: error: expected primary-expression before ‘;’ token

    int numYellowBlinks=; //Number of yellow blinks

    ^

    exit status 1
    expected primary-expression before ‘;’ token

    I int redLEDPin=9; //Declares a variable for red LED
    int yellowLEDPin=10; //Declares a variable yellow LED led
    int redOnTime=250; //Red time on
    int redOffTime=250; //Red time off
    int yellowOnTime=250; //Yellow time on
    int yellowOffTime=250; //Yellow time off
    int numRedBlinks=; //Number of red blinks
    int numYellowBlinks=; //Number of yellow blinks
    String redMessage=”The Red LED is Blinking”; //Declaring a string message
    String yellowMessage=” The Yellow LED is Blinking”; //Declaring a string message

    void setup() {

    Serial.begin(115200);

    pinMode(redLEDPin,OUTPUT); //Tell Arduino that redLedPin is an output
    pinMode(yellowLEDPin,OUTPUT); //Tell Arduino that yellowLEDPin is an output
    numRedBlinks=Serial.parseInt();
    numYellowBlinks=Serial.parseInt();
    Serial.println(“How Many Times Do You Want the RED LED To Blink ?”);
    while (Serial.available()==0){} //Wait for user input

    Serial.println( );

    Serial.println(“How Many Times Do You Want the Yellow LED To Blink ?”);
    while (Serial.available()==0){ //Wait for user input

    }

    }

    void loop() {
    Serial.println(redMessage);
    for (int j=1; j<=numRedBlinks;j=j+1){ //Start for loop
    Serial.print(" You are on Blink#: ");
    Serial.println(j);
    digitalWrite(redLEDPin,HIGH); //Turn on Red led
    delay(redOnTime); // Wait time on
    digitalWrite(redLEDPin,LOW); //Turn off time
    delay(redOffTime); //Leave off for redOffTime

    }
    Serial.print(" ");
    Serial.println(yellowMessage);
    for (int j=1; j<=numYellowBlinks;j=j+1){ //Start our for loop
    Serial.print(" You are on Blink#: ");
    Serial.println(j);
    digitalWrite(yellowLEDPin,HIGH); //Turn yellow LED on
    delay(yellowOnTime); //Wait time on
    digitalWrite(yellowLEDPin,LOW); //Turn yellow LED off
    delay (yellowOffTime); //Leave off for yellowOffTime

    }
    Serial.println(" ");

  34. I’m an old retired geezer, fast approaching 70 y/o. Have always been one to piddle and tinker with various things; mechanical, electrical, woodworking etc. I have been a pretty extensive computer user since the middle 80’s but never got into the writing code end of it. I’m wanting to build a laser engraver for some of the woodworking that I do; that’s how I got into this Arduino thing. Stumbled across your instructional video on the net and have been working through them one at the time. Lessons 1 – 5 were not much of a problem but 6 was a different story. I have spent 20 plus hours on that one (I am a man of great patience and perseverance), I would go back to lesson 1 each time and start over.; each time I reviewed I would pick something else up. Most of my problems were typos which the debugging took care of finally. Once my code was correct I had to change a setting on the serial monitor to no line ending (thanks to all who gave that tip in the comments) and the program worked as designed. I’m off to #7 after I rest these old tired eyes a bit.
    Mr. McWhorter (I hope I spelled that right) I would like to thank you for your time and efforts sir, you are a great teacher. Your lessons have been easy to follow for the most part and your examples and explanations have been easy to understand. I am looking forward to completing the series and possibly going on to others that you offer. Now I’m off to rest these old tired eyes.
    Please edit this post as you see fit.

    1. [“I would like to thank you for your time and efforts sir, you are a great teacher. “]

      100% agree with Robert.

      And for the issue with New Line not being No Line Ending – I’ll need some schooling on these options – I used “Serial.println();” to track progress to find an error with no success. As a last resort I came here. I replaced my code with yours and received same outcome. I never thought to scroll below your lesson and read the comments. It wasn’t my coding after all! The time spent debugging was well spent. Helped reinforce the use of what I have learned so far, and to troubleshoot in various ways.

      Serial.println(“Professor Paul, Thank you. “); // the Top Tech Boy!

  35. Hi this is the best guide i have ever followed.
    after a day i am able to greate a program that i can call in other programs.
    sorry i did not make comments one the commands so im not a good boy :(.
    looking forward to make more arduino with you. just need the parts from lesson 10 and after 😀

    >>> Main Code << high) {
    wait();
    Serial.println(“The number is to high – Please try again”);
    Serial.println();
    }
    ////////////////////////////////////
    if (program >> Funktions <<< next page

    void wait() {
    Serial.print("you have pushed – ");
    Serial.println(program);
    Serial.println(waitMsg);
    Serial.println();
    delay(waitDelay);
    }

    void program1(){
    Serial.println("there is no program here");
    delay(programDelay);
    }

    void program2(){
    Serial.println("there is no program here");
    delay(programDelay);
    }

    void program3(){
    Serial.println("there is no program here");
    delay(programDelay);
    }

    void program4(){
    Serial.println("there is no program here");
    delay(programDelay);
    }

  36. after getting all the inputs, the serial.println or print is not printing the text messages fully

    For example: Serial.println(“your input is “+input1);

    I am getting the below
    “put is ”

    I’m not getting the full text (“your in” is missing at the starting message) or the input as well

    I tried different baud too, but the same result, not showing fully.

    1. It must have worked as i see.
      Serial.println(“bla bla” + variable); should make you see;
      bla bla variable(depends on your variable, integer, string etc)

      Have you solved your problem? i wonder about it.

      Hello from Turkey

    2. Go to “Arduino web Editor” and set on the serial monitor “No Line End” and 9600.

      if the problem continues try by using a different computer .. or a different Arduino board…

  37. A great place to learn.
    Here is my code
    ____________________
    Here I am taking input of numRedBlinks from user and numGreenBlinks is defined in Global Variable.

    According to the program. Once we input the value of numRedBlinks through serial input it should follow for loop of Red LED and the the Green LED and Prompt again for the input for numRedBlinks value. But it is behaving .. as follows. Where I am doing mistake ?

    How many times do you want red LED to blink?
    Red LED is blinking
    1
    2
    3
    4
    5

    Green LED is blinking
    1
    2
    3
    4
    5
    How many times do you want red LED to blink?
    Red LED is blinking

    Green LED is blinking
    1
    2
    3
    4
    5
    How many times do you want red LED to blink?

    int redLEDPin=9; //Declare redLEDPin as int, set to pin 9
    int greenLEDPin=10; //Declare greenLEDPin as int, set to pin 10
    int redOnTime=250; //Declare redOnTime an int and set to 250ms
    int redOffTime=250; //Declare redOffTime an int and set to 250ms
    int greenOnTime=250; //Declare greenOnTime an int and set to 250ms
    int greenOffTime=250; //Declare greenOffTime an int ans set to 250ms
    int numRedBlinks; //Declare numRedBlinks as an int and set 5 times
    int numGreenBlinks=5; //Declare numGreenBlinks as an int and set 5 times

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

    pinMode(redLEDPin,OUTPUT);
    pinMode(greenLEDPin,OUTPUT);

    }

    void loop() {
    // put your main code here, to run repeatedly:
    Serial.println(“How many times do you want red LED to blink? “);
    while (Serial.available ()==0) { }
    numRedBlinks = Serial.parseInt();

    Serial.println(“Red LED is blinking”);

    for (int j=1; j<=numRedBlinks; j=j+1) {
    Serial.println(j);
    digitalWrite(redLEDPin,HIGH);
    delay(redOnTime);
    digitalWrite(redLEDPin,LOW);
    delay(redOffTime);
    }
    Serial.println(" ");

    Serial.println("Green LED is blinking");
    for (int j=1; j<=numGreenBlinks; j=j+1) {
    Serial.println(j);
    digitalWrite(greenLEDPin, HIGH);
    delay(greenOnTime);
    digitalWrite(greenLEDPin,LOW);
    delay(greenOffTime);
    }

    }

    1. No issue with coding, just enabling no line ending on serial monitor solved the issue. Thank you again for wonderful lessons.

Comments are closed.