Why Won't my Serial Read value stay the sameWhy does starting the serial monitor restart the sketch?Arduino read PWM duty cycle value with input (analog / digital)Why does the serial monitor output show some unidentified symbols?Fade sketch stuck in mathematical loopHow to read a PWM OUTPUT PIN value?why data value is 0

Levenshtein Neighbours

Have only girls been born for a long time in this village?

Why is su world executable?

Which basis does the wavefunction collapse to?

How can I train a replacement without letting my bosses and the replacement knowing?

Polar contour plot in Mathematica?

Are there any OR challenges that are similar to kaggle's competitions?

Do predators tend to have vertical slit pupils versus horizontal for prey animals?

Does C++20 mandate source code being stored in files?

Starships without computers?

Vegetarian dishes on Russian trains (European part)

Can sulfuric acid itself be electrolysed?

Hiker's Cabin Mystery | Pt. XV

Why do balloons get cold when they deflate?

How do neutron star binaries form?

Can the front glass be repaired of a broken lens?

Why did St. Jerome use "virago" in Gen. 2:23?

Just one file echoed from an array of files

Why don't politicians push for fossil fuel reduction by pointing out their scarcity?

Is recepted a word?

Unbiased estimator of exponential of measure of a set?

Angles between vectors of center of two incircles

How do you call it when two celestial bodies come as close to each other as they will in their current orbits?

What causes burn marks on the air handler in the attic?



Why Won't my Serial Read value stay the same


Why does starting the serial monitor restart the sketch?Arduino read PWM duty cycle value with input (analog / digital)Why does the serial monitor output show some unidentified symbols?Fade sketch stuck in mathematical loopHow to read a PWM OUTPUT PIN value?why data value is 0






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am trying to write to serial to control the brightness of an LED. When I initially type in a value such as '50' or '100', the LED lights up, but then the 'ppm' value drops down to '10' and just stays there (regardless of what I enter in initially. Any idea why this is occurring?



int ledpin1 = 3;
int pwm = 0;

void setup()
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(ledpin1, OUTPUT);


// the loop routine runs over and over again forever:
void loop()
// reads input to serial monitor
if (Serial.available() > 0)
pwm = Serial.read();


analogWrite(ledpin1, pwm);
Serial.print("PWM value is: ");
Serial.println(pwm);
delay(1000);











share|improve this question









New contributor



s_barb_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    1















    I am trying to write to serial to control the brightness of an LED. When I initially type in a value such as '50' or '100', the LED lights up, but then the 'ppm' value drops down to '10' and just stays there (regardless of what I enter in initially. Any idea why this is occurring?



    int ledpin1 = 3;
    int pwm = 0;

    void setup()
    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
    pinMode(ledpin1, OUTPUT);


    // the loop routine runs over and over again forever:
    void loop()
    // reads input to serial monitor
    if (Serial.available() > 0)
    pwm = Serial.read();


    analogWrite(ledpin1, pwm);
    Serial.print("PWM value is: ");
    Serial.println(pwm);
    delay(1000);











    share|improve this question









    New contributor



    s_barb_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      1












      1








      1








      I am trying to write to serial to control the brightness of an LED. When I initially type in a value such as '50' or '100', the LED lights up, but then the 'ppm' value drops down to '10' and just stays there (regardless of what I enter in initially. Any idea why this is occurring?



      int ledpin1 = 3;
      int pwm = 0;

      void setup()
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
      pinMode(ledpin1, OUTPUT);


      // the loop routine runs over and over again forever:
      void loop()
      // reads input to serial monitor
      if (Serial.available() > 0)
      pwm = Serial.read();


      analogWrite(ledpin1, pwm);
      Serial.print("PWM value is: ");
      Serial.println(pwm);
      delay(1000);











      share|improve this question









      New contributor



      s_barb_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am trying to write to serial to control the brightness of an LED. When I initially type in a value such as '50' or '100', the LED lights up, but then the 'ppm' value drops down to '10' and just stays there (regardless of what I enter in initially. Any idea why this is occurring?



      int ledpin1 = 3;
      int pwm = 0;

      void setup()
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
      pinMode(ledpin1, OUTPUT);


      // the loop routine runs over and over again forever:
      void loop()
      // reads input to serial monitor
      if (Serial.available() > 0)
      pwm = Serial.read();


      analogWrite(ledpin1, pwm);
      Serial.print("PWM value is: ");
      Serial.println(pwm);
      delay(1000);








      serial pwm






      share|improve this question









      New contributor



      s_barb_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      s_barb_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 8 hours ago









      VE7JRO

      1,8676 gold badges14 silver badges24 bronze badges




      1,8676 gold badges14 silver badges24 bronze badges






      New contributor



      s_barb_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 9 hours ago









      s_barb_27s_barb_27

      61 bronze badge




      61 bronze badge




      New contributor



      s_barb_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      s_barb_27 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























          1 Answer
          1






          active

          oldest

          votes


















          3














          When you type "100" you aren't sending the number 100. You're sending the characters "1", "0", "0", and whatever selected line ending you have (CR, LF, or CR and LF).



          So if you have CR+LF for your line ending you're reading the numbers 49, 48, 48, 13 then 10.



          You need to read the characters as they arrive and group them into a representation of the number (up until you get the line ending), then convert that representation into an actual number.



          • Reading Serial on the Arduino





          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("schematics", function ()
            StackExchange.schematics.init();
            );
            , "cicuitlab");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "540"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            s_barb_27 is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f68022%2fwhy-wont-my-serial-read-value-stay-the-same%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            When you type "100" you aren't sending the number 100. You're sending the characters "1", "0", "0", and whatever selected line ending you have (CR, LF, or CR and LF).



            So if you have CR+LF for your line ending you're reading the numbers 49, 48, 48, 13 then 10.



            You need to read the characters as they arrive and group them into a representation of the number (up until you get the line ending), then convert that representation into an actual number.



            • Reading Serial on the Arduino





            share|improve this answer





























              3














              When you type "100" you aren't sending the number 100. You're sending the characters "1", "0", "0", and whatever selected line ending you have (CR, LF, or CR and LF).



              So if you have CR+LF for your line ending you're reading the numbers 49, 48, 48, 13 then 10.



              You need to read the characters as they arrive and group them into a representation of the number (up until you get the line ending), then convert that representation into an actual number.



              • Reading Serial on the Arduino





              share|improve this answer



























                3












                3








                3







                When you type "100" you aren't sending the number 100. You're sending the characters "1", "0", "0", and whatever selected line ending you have (CR, LF, or CR and LF).



                So if you have CR+LF for your line ending you're reading the numbers 49, 48, 48, 13 then 10.



                You need to read the characters as they arrive and group them into a representation of the number (up until you get the line ending), then convert that representation into an actual number.



                • Reading Serial on the Arduino





                share|improve this answer













                When you type "100" you aren't sending the number 100. You're sending the characters "1", "0", "0", and whatever selected line ending you have (CR, LF, or CR and LF).



                So if you have CR+LF for your line ending you're reading the numbers 49, 48, 48, 13 then 10.



                You need to read the characters as they arrive and group them into a representation of the number (up until you get the line ending), then convert that representation into an actual number.



                • Reading Serial on the Arduino






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 9 hours ago









                MajenkoMajenko

                73.5k4 gold badges38 silver badges85 bronze badges




                73.5k4 gold badges38 silver badges85 bronze badges























                    s_barb_27 is a new contributor. Be nice, and check out our Code of Conduct.









                    draft saved

                    draft discarded


















                    s_barb_27 is a new contributor. Be nice, and check out our Code of Conduct.












                    s_barb_27 is a new contributor. Be nice, and check out our Code of Conduct.











                    s_barb_27 is a new contributor. Be nice, and check out our Code of Conduct.














                    Thanks for contributing an answer to Arduino Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f68022%2fwhy-wont-my-serial-read-value-stay-the-same%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

                    Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

                    19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу