ARDUINO #Tutorial 14 Reading #Strings from the Serial Monitor

25 Просмотры
ARDUINO #Tutorial 14 Reading #Strings from the Serial Monitor
#arduino #serial #data
Why, do We need to read strings from the Serial monitor? This allows US to get input from a User. This allow the ARDUINO to read words or sentences also known as strings.
In Our previous ARDUINO’s lessons We learned how to read integers, and floating-point numbers over the serial monitor. Today We learn how to interact with the ARDUINO where by the end of it, You will be able to send commands to the Arduino, in a way that it understand.
We start with this Question for the User to answer. Then We give the user to choose which LED He wants to turn ON.
We start By with the question as string We declare it, with “MSG” This is asking “What Is Your Name? “Without any value attached to it, because We are going to get that from the User. We then have, another string named “MSG2” is equals to “Hello ”. Lastly We added a string “MSG3” which is “ , & Welcome to Arduino! “.
We are not using any pins yet so all We need to do is to start the “serial.begin” with a 9600 BAUD rate. Naturally We need the USER’s name. We ASK, We WAIT and We READ, so let's ask!
For that We use this“SERIAL.PRINTLN”. Then in the parenthesis, We have “MSG” also remember that when You put Your message it must be without the quotes but enclosed in brackets.
After We have asked, We wait, OK. For that We have this “WHILE LOOP” with a“serial.available “ open and close the parenthesis and EQUAL EQUAL to 0 for that see From Our previous TuTos. With hereafter We have clause with a curly bracket. We do absolutely nothing in this loop. Because We are waiting as long as “serial.available” is Equal to 0 or as long as nothing is sent.
But then when, something is available, when the USER, has responded then it will drop out of, this loop to READ, this “myName” here. It is equal to “serial.readString”. Then We have The empty Parenthesis to end this line, because We will use them to store the User’s input.
After We have “serial.print (MSG2);”followed by a, “serial.print (myName);” and Finally We have this “serial.print (MSG3);” This will give Us “hello, ANSWER & Welcome to, Arduino!” You can compile this and open up the serial monitor to test this.
Let’s continue with Our Void loop, We Again have to ASK Our question. Here with this “serial.printLN” and then “MSG”. With this loop HERE We wait until the User send something.
We then have “userChoice” is equal to “serial.readString” with nothing inside those Brackets here.
After that We have an IF Statement to figure out and set the User’s options, as We can have Red, Yellow, Green or it could be blue. Then, with the User’s choses it is easy for Us to use those Ifs statements. So IF “userChoice” equal equal
Then if the “userChoice” is red then We set Our (MSG2); and turn on the LED in this section with a “digitalWrite and the Red Pinis HIGH);” We loop this. That is why We turn all the other LEDs OFF, by turning the other colors to LOW. The last 2 We add the USER’s choice and the (MSG3);.
Let me know in the comment down below if You wish me to teach You how to do that? So in today’s video We learn how to
I, would love to hear Your comments about the video down below, I really like to know how You use this maybe it helped You understand or if also people are actually watching these things?

Link to Sites:

Arduino getting started with serial monitor: How to use the Serial Monitor with the Arduino IDE 2.0 | Arduino
SERIAL - Arduino Reference: Serial - Arduino Reference
Serial.readString() - Arduino Reference: https://www.arduino.cc/reference/en/language/functions/communication/serial/readstring/
10kTech: https://sites.google.com/view/10ktech

You guys can help me out over at PATREON: and that will keep this content coming:

Link to My Most Watched Video:

Recover You r lost data With DISK DRILL even with the free Version

I find the Best Calculator Ever & it is free.

How to Change from Microsoft Edge to Google Search Instead (UPDATED)

Link to the other CYBERPUNCK 2077 Video:

Feel Free to leave a comment, Please, or a remark maybe even a request or question in the comment section bellow may You have any, and, If You LIKE this video, please do HIT the SUSCRIBE Button and, OR, the bell Icon.

????Your 1 Subscription to My Channel Can Make My Day ????

THANKS a MILLION for YouR time.
Комментариев нет.