🤩 How much Arduino can you learn in 7 Days? 👇
bit.ly/7_Day_Arduino_Challenge
**If you like this, I think you'll like the premium Arduino training we offer. Check it out here** bit.ly/3nSBPUs
Click Below to Read About This Topic on Our Website
programmingelectronics.com/tu...
We designed this circuit board for beginners!
Kit-On-A-Shield: amzn.to/3lfWClU
SHOP OUR FAVORITE STUFF! (affiliate links)
---------------------------------------------------
We use Rev Captions for our subtitles
bit.ly/39trLeB
Arduino UNO R3:
Amazon: amzn.to/37eP4ra
Newegg: bit.ly/3fahas8
Budget Arduino Kits:
Amazon:amzn.to/3C0VqsH
Newegg:bit.ly/3j4tISX
Multimeter Options:
Amazon: amzn.to/3rRo3E0
Newegg: bit.ly/3rJoekA
Helping Hands:
Amazon: amzn.to/3C8IYXZ
Newegg: bit.ly/3fb03X1
Soldering Stations:
Amazon: amzn.to/2VawmP4
Newegg: bit.ly/3BZ6oio
AFFILIATES & REFERRALS
---------------------------------------------------
►Audible Plus Free trial: amzn.to/3j5IGrV
►Join Honey- Save Money bit.ly/3xmj7rH
►Download Glasswire for Free:bit.ly/3iv1fql
FOLLOW US ELSEWHERE
---------------------------------------------------
Facebook: / programmingelectronics...
Twitter: / progelecacademy
Website: www.programmingelectronics.com/
In the last lesson we learned about the "If statement". The "If statement" was the perfect choice for setting up instructions to run only when certain conditions are met. "If 30 seconds has passed - stop the heating element" or "If the sensor perceives a wall - turn 180 Degrees". This lesson will expand on this amazingly useful function and show you how to stack different conditions to meet the flexibility you will want in your designs.
You Will Need
Potentiometer (doesn't matter what resistance range)
220 Ohm Resistor
LED (any color)
Jumper Wires (3)
solder-less breadboard
Alligator Clip
Dull machete with wooded handle
Step-by-Step Instructions
Place your potentiometer in the breadboard.
Place a jumper wire from one of the outside leads of the potentiometer to the 5V pin on Arduino.
Place a jumper wire from the other outside lead of the potentiometer to one of the GND pins.
Place the final jumper wire from the center pin of the potentiometer to the A0 pin.
Connect either side of the 220-Ohm resistor to pin 13.
Connect the short leg of the LED to the GND (the GND pin next to pin 13 is the most convenient).
Attach the other leg of the resistor to the long leg of the LED.
Plug your Arduino into your computer with the USB cable.
Open the Arduino IDE.
Go to File, Examples, 05.Control, IfStatementConditionals
Click the Verify button (Top Left). The button will turn orange and then blue once finished.
Click the Upload button. The button will turn orange and then blue when finished.
Open up the Serial Monitor window. Tools, Serial Monitor.
Adjust the potentiometer and watch as the LED turns on and off based on the knob position.
Circuit Talk
If you recall from the previous lessons, a potentiometer is a voltage divider. You have 5 volts at one side of the potentiometer and 0 volts at the other side - you are using the 5volt pin and the GND pin. As you adjust the knob on the potentiometer the amount voltage that will be applied to the center pin changes. The voltage is being divided. This means that the voltage at pin A0 where the center pin is attached will be somewhere between 0 and 5 volts based on where you have the potentiometer knob adjusted.
Discuss the Sketch
Below is the sketch in its entirety from the Arduino IDE. The basic concept of the sketch is this - we measure voltage at an analog pin from 0 to 1023 - this voltage changes based on where the knob of the potentiometer is set. Then we define a threshold value somewhere in this range, lets pick the number 400. When the value measured at the analog pin is above 400, we turn on the LED at pin 13, when the voltage is below 400 we turn the LED off. It's as easy as that.
Make sure you read this sketch and try to figure out what is taking place before moving on.
This program might look kind of long to you - the previous ones were a bit shorter. A good way to approach any program long or short is to cut it up into chunks and only consider pieces of it at a time. The first chunk is this sketch is the multi-line comments that clearly describe:
What the program will do
Generally how the program will accomplish it
How to set up the circuit and the components you will need
Any pertinent notes
The license the program is released under (if any)
Негізгі бет Tutorial 11: If Statement Conditionals: Arduino Course for Absolute Beginners (ReM)
Пікірлер: 144