Tutorial 07: digitalRead() and the Serial Port: Arduino Course for Absolute Beginners (ReM)

Tutorial 07: digitalRead() and the Serial Port: Arduino Course for Absolute Beginners (ReM)

297,190 View

***If you like this, I think you'll like the premium Arduino training we offer. Check it out here*** https://bit.ly/3nSBPUs

We designed this circuit board for beginners!
Kit-On-A-Shield: https://amzn.to/3lfWClU

SHOP OUR FAVORITE STUFF! (affiliate links)
---------------------------------------------------


Get your Free Trial of Altium PCB design Software
https://www.altium.com/yt/programmingelectronicsacademy
We use Rev Captions for our subtitles
https://bit.ly/39trLeB


Arduino UNO R3:
Amazon: https://amzn.to/37eP4ra
Newegg: https://bit.ly/3fahas8

Budget Arduino Kits:
Amazon:https://amzn.to/3C0VqsH
Newegg:https://bit.ly/3j4tISX

Multimeter Options:
Amazon: https://amzn.to/3rRo3E0
Newegg: https://bit.ly/3rJoekA

Helping Hands:
Amazon: https://amzn.to/3C8IYXZ
Newegg: https://bit.ly/3fb03X1

Soldering Stations:
Amazon: https://amzn.to/2VawmP4
Newegg: https://bit.ly/3BZ6oio

AFFILIATES & REFERRALS
---------------------------------------------------
►Audible Plus Free trial: https://amzn.to/3j5IGrV

►Join Honey- Save Money https://bit.ly/3xmj7rH
►Download Glasswire for Free:https://bit.ly/3iv1fql


FOLLOW US ELSEWHERE
---------------------------------------------------
Facebook: https://www.facebook.com/ProgrammingElectronicsAcademy/
Twitter: https://twitter.com/ProgElecAcademy

*Click Below to Read About This Topic on Our Website*
https://www.programmingelectronics.com/tutorial-07-digitalread-and-serial-port-communication/

*Description:*

As simple as it may seem, knowing when something is either on or off can be a great tool to designing something useful. Answers to the following questions are what this lesson plans to tackle:

Is a button being pressed?
Has a switch been turned on?
What is my on/off sensor status?
When you can answer questions like these, you can implement actions based on the current status - if the button is pressed do this - otherwise, do that. If the sensor is HIGH take this action, otherwise do nothing. You get the gist. But before we can implement the actions, we have to be able to track the status and the changes of the digital pins.

You Will Need

A momentary push button - this is a button that is spring loaded, so when you press it, it pops back out
Jumper wires - at least three
A 10,000 Ohm resistor AKA 10K resistor
A solder-less breadboard
A very ripe banana, with one peel removed (not completely useful, but nutritious)
Step-by-Step Instructions

Connect your push button to the breadboard.
Connect one side of the push button to the 5-volt pin on the Arduino board using a jumper wire.
Connect one side of the 10K resistor to the other side of the pushbutton.
Connect the other side of the resistor to the ground pin on your Arduino. You may have to use a jumper wire to make this reach.
The same side you have your resistor connected to the pushbutton, connect a jumper wire and run this to pin 2 on your Arduino board.
Connect your Arduino to your computer with the USB cable.
Go to File, Examples, 01.Basics, digitalReadSerial
Click the Verify button in the top left corner. The verify button will turn orange and then back to blue when it has completed compiling.
Click the Upload Button (to the immediate right of the verify button). This button will also turn orange and then back to blue once you sketch is uploaded to your Arduino board.
Now go to the menu bar at the top and select Tools, Serial Monitor. You could use the short cut key of Shift + Control + M.
The serial monitor window will open and will be spotting off numbers. It should be a bunch of 0's.
Press and hold the pushbutton - watch the serial monitor window, the numbers should now be 1.
If the numbers are not scrolling, make sure you click scrolling at the bottom left of the serial monitor window.

This sketch opens up with a multi-line comment containing a short description of the program and circuit. The first block of code is where we declare and initialize variables. From the last lesson we are familiar with the int data type.

int pushButton = 2; //This is the pin that our push button is connected to.

Notice how on one line the variable pushButton is declared and initialized. Also notice the descriptive name of the pushButton - this is how it ought to be - variable name with meanings.

So let's consider what we have done so far - we have made a variable that will store the pin number that our push button is connected to.


Did you miss our previous article...
https://learningvideos.club/computer-technology/introduction-to-programming-for-beginners