Latest / CyberSecurity Summary / Arduino programming: the ultimate beginner's guide to learn Arduino programming step by step
Transcript
- 0:00Speaker 1: Ever wanted to control a light, make a motor spin,
- 0:02Speaker 1: or read the temperature in your room, not just with
- 0:05Speaker 1: a switch, but with code. If the idea of building
- 0:08Speaker 1: little gadgets that interact with the physical world using simple
- 0:11Speaker 1: programming sounds intriguing, well, you are absolutely in the right place.
- 0:16Speaker 2: Welcome to a deep dive based on a fantastic beginner's
- 0:19Speaker 2: guide you shared with us.
- 0:20Speaker 1: Yeah, great source.
- 0:22Speaker 2: We're pulling out the most important nuggets from the source
- 0:24Speaker 2: material to give you a real shortcut into the fundamental
- 0:28Speaker 2: world of Urdueno programming.
- 0:30Speaker 1: Our mission today is to quickly get you up to
- 0:33Speaker 1: speed on what our Dueno is, why it's become this
- 0:36Speaker 1: go to tool for makers and hobbyists everywhere, and walk
- 0:41Speaker 1: through the absolute essentials of how it works so you
- 0:45Speaker 1: can start bringing your own project ideas to life without
- 0:48Speaker 1: feeling totally lost.
- 0:49Speaker 2: At its heart, Arduino is an open source electronic platform.
- 0:53Speaker 2: Think of it as having two key components. There's the
- 0:56Speaker 2: physical circuit board, the hardware that you can program okay,
- 0:59Speaker 2: and then there's the coding software, the ide that you
- 1:02Speaker 2: use on your computer to write those instructions.
- 1:04Speaker 1: And I love this detail from the source. Unlike traditional programming,
- 1:07Speaker 1: where your first success is often printing Hello World on
- 1:11Speaker 1: a screen. In the microcontroller world, that rite of passage
- 1:15Speaker 1: is getting an LED light to blink. The blinking LED
- 1:19Speaker 1: it's your basic confirmation that the code got onto the
- 1:22Speaker 1: chip and the board is alive. It's a small thing,
- 1:25Speaker 1: but surprisingly satisfying.
- 1:28Speaker 2: That blinking LED is really the signal that you've successfully
- 1:31Speaker 2: bridged the digital and physical worlds. Your code is now
- 1:34Speaker 2: making something happen electrically.
- 1:37Speaker 1: Okay, so it's a programmable board, but drill down a bit,
- 1:40Speaker 1: what exactly is it doing on that board.
- 1:42Speaker 2: It's essentially a small specialized computer called a micro controller.
- 1:47Speaker 2: Unlike your desktop or phone, which can do a million things,
- 1:50Speaker 2: a micro controller is typically designed to execute one specific
- 1:53Speaker 2: program repeatedly and interact directly with electronic components.
- 1:58Speaker 1: And the history as laid out than the source. It's
- 2:00Speaker 1: actually pretty cool. It didn't start because some tech giant
- 2:03Speaker 1: wanted to build I don't know, smart toasters.
- 2:05Speaker 2: No, not at all. It originated back in two thousand
- 2:08Speaker 2: and three at the Interactive Design Institute in Ivrea, Italy.
- 2:12Speaker 2: Right Hernando Barragan had this practical goal simplify micro controllers.
- 2:17Speaker 2: At the time, boards like the basic stamp were really
- 2:20Speaker 2: expensive over one hundred dollars.
- 2:22Speaker 1: Wow.
- 2:23Speaker 2: That put them out of reach for students, especially those
- 2:25Speaker 2: in design who needed to incorporate interaction into their projects
- 2:28Speaker 2: but weren't deep into electrical engineering.
- 2:31Speaker 1: So it was fundamentally about lowering the barrier to entry,
- 2:35Speaker 1: making this tech accessible exactly.
- 2:37Speaker 2: That accessibility is crucial to its story. The platform was
- 2:40Speaker 2: further developed by key figures like Masimo Bonzi, David Mellis,
- 2:44Speaker 2: David Cortils, Tom Ego, and gen Luca Martino, building on
- 2:47Speaker 2: that initial vision and earlier work like the Wiring Project.
- 2:52Speaker 1: And that accessibility focus really defines who uses it today. Right,
- 2:56Speaker 1: It's not just engineers.
- 2:57Speaker 2: Absolutely, The source emphasizes it was intention only designed for everyone.
- 3:01Speaker 2: You see it pop up with artists creating interactive installations,
- 3:04Speaker 2: architects building dynamic models, musicians experimenting with electronic instruments, hobbyists
- 3:10Speaker 2: inventing gadgets in their garage, and yes, it's a fantastic
- 3:13Speaker 2: tool for introducing kids to coding and electronics.
- 3:16Speaker 1: That broad appeal makes perfect sense when you look at
- 3:19Speaker 1: the advantages that source highlights. There are what six big
- 3:23Speaker 1: reasons Ardweno became such a phenomenon.
- 3:25Speaker 2: Yeah, six key ones.
- 3:26Speaker 1: Let's unpack the why behind its popularity.
- 3:29Speaker 2: Number one, and perhaps the most impactful initially, was cost efficiency.
- 3:33Speaker 2: The source contrasts the price starkly, older boards costing one
- 3:38Speaker 2: hundred dollars plus lo o versus pre assembled ardwenos often
- 3:42Speaker 2: less than fifty dollars or even less if you assemble
- 3:44Speaker 2: a kit yourself. Making it affordable was a primary driver.
- 3:48Speaker 1: That changes everything for a student or hobbyist. Okay, what's
- 3:51Speaker 1: number two?
- 3:51Speaker 2: The development environment. The Ardueno ID, that's the software where
- 3:55Speaker 2: you write your code is cross platform. Doesn't matter if
- 3:58Speaker 2: you're on Windows, mac Os, or Linux.
- 4:00Speaker 1: The ID works on all of them, no operating system
- 4:03Speaker 1: lock in. That's a big plus. And related to that software.
- 4:07Speaker 2: The software is open source. This means the coding tools
- 4:09Speaker 2: are completely free, no licenses, no fees.
- 4:12Speaker 1: That's huge.
- 4:13Speaker 2: This is massive for education and collaboration. Anyone can download it,
- 4:17Speaker 2: use it, modify it, teach with it. It really fosters a
- 4:20Speaker 2: culture of sharing and learning.
- 4:22Speaker 1: So it's free and you can see how it works
- 4:24Speaker 1: under the hood. How about for people who aren't just beginners?
- 4:27Speaker 1: Does it scale up?
- 4:28Speaker 2: That's the fourth point? Extendability. While it's simple for beginners.
- 4:32Speaker 2: The software allows more experienced programmers to delve deeper using
- 4:36Speaker 2: C plus plus libraries and AVRC for more complex tasks.
- 4:40Speaker 2: It scales with your skill level.
- 4:42Speaker 1: It grows with you as you learn.
- 4:44Speaker 2: Fifth advantage, the ide itself is designed for clarity and simplicity.
- 4:48Speaker 2: The coding environment is straightforward, aiming to make the process
- 4:51Speaker 2: of writing and debugging code as easy as possible, particularly
- 4:55Speaker 2: for those new to programming micro controllers.
- 4:58Speaker 1: Makes sense, and the sixth Advance Edge takes the open
- 5:01Speaker 1: source idea beyond the software to the physical board itself exactly.
- 5:06Speaker 2: The hardware designs are also open source under a Creative Commons.
- 5:09Speaker 1: License, so you could technically build your own if you
- 5:11Speaker 1: have the knowledge.
- 5:12Speaker 2: Yeah, you can build your own or do we know
- 5:14Speaker 2: compatible board? The source even points out you can start
- 5:17Speaker 2: building simple circuits on a breadboard, which is a prototyping
- 5:20Speaker 2: tool that doesn't require soldering, further lowering the initial hardware barrier.
- 5:24Speaker 1: Affordable, accessible on any computer, free to use and share, scalable,
- 5:29Speaker 1: easy software, and even open source hardware designs.
- 5:33Speaker 2: Yeah, that list definitely paints a clear picture of why
- 5:36Speaker 2: it took off. Now, as you get started, the source
- 5:39Speaker 2: introduces some key terminology you'll encounter constantly. We talked about
- 5:43Speaker 2: open source right.
- 5:44Speaker 1: Open source means the freedom to use, modify, and share
- 5:48Speaker 1: both the hardware designs and software tools. It's really foundational
- 5:52Speaker 1: to the whole platform.
- 5:53Speaker 2: And the basic distinction hardware versus software. Pretty straightforward.
- 5:57Speaker 1: Yeah. Hardware is the physical board, the chips, the pins,
- 6:00Speaker 1: the wires. Software is the code, the instructions you write
- 6:04Speaker 1: and load onto the hardware to tell it what to do.
- 6:06Speaker 2: The code is the brain. The board is the body.
- 6:08Speaker 1: What about EPROM That sounds a bit intimidating.
- 6:12Speaker 2: E PROM is just a specific type of memory on
- 6:14Speaker 2: the board. The source likens it to a tiny hard
- 6:16Speaker 2: drive because, unlike the main memory, which resets when you
- 6:19Speaker 2: power off. Okay, e PROM can store data persistently even
- 6:23Speaker 2: when the board has no power, useful for saving things
- 6:26Speaker 2: like settings or calibration data.
- 6:28Speaker 1: Like a little non volatile storage. Got it and pwmpins?
- 6:32Speaker 1: I see that mession on the board descriptions what's PWM.
- 6:35Speaker 2: PWM stands for pulsewith modulation. Certain digital pins have this
- 6:39Speaker 2: special capability. Instead of just being fully on in five
- 6:43Speaker 2: volts or fully o off zero volts, they can rapidly
- 6:46Speaker 2: switch between on and all off f By controlling the
- 6:50Speaker 2: ratio of on time to off time within a cycle,
- 6:53Speaker 2: you can simulate varying levels in between.
- 6:56Speaker 1: So like dimming an led not just turning it on or.
- 6:58Speaker 2: Off exactly, or controlling the speed of a motor smoothly.
- 7:01Speaker 2: It gives you analog like control from a digital pin.
- 7:04Speaker 2: It's pretty clever.
- 7:05Speaker 1: That is clever, Okay. Clock speed is that just how
- 7:08Speaker 1: fast it thinks?
- 7:09Speaker 2: Pretty much? That's the speed at which the micro controller
- 7:11Speaker 2: executes instructions measured in megahertz EM hurts. A faster clock
- 7:15Speaker 2: speed means it can crunch numbers and react faster, making
- 7:18Speaker 2: your project more responsive.
- 7:20Speaker 1: But there's a trade off.
- 7:20Speaker 2: Yeah. The trade off, the source notes is usually increased
- 7:23Speaker 2: power consumption. Faster usually means hungrier.
- 7:25Speaker 1: Speed versus battery life. The classic trade off and uh
- 7:29Speaker 1: you aret art.
- 7:31Speaker 2: You art relates to serial communication. It's a measure of
- 7:34Speaker 2: how many serial communication lines aboard has. Serial communication sends
- 7:39Speaker 2: data one bit at a time sequentially. It's a simpler
- 7:42Speaker 2: way to transfer data than say, parallel communication, and is
- 7:46Speaker 2: often used for communication between the arduino and a computer
- 7:49Speaker 2: or other devices, which.
- 7:51Speaker 1: Feels like a good bridge to something everyone's heard of,
- 7:54Speaker 1: Internet of things or IoT. How does our Duena fit
- 7:57Speaker 1: in there?
- 7:57Speaker 2: Absolutely? Our Dueno is a fantastic tool for getting into IoT.
- 8:02Speaker 2: Many projects involve using sensors connected to an arduino to
- 8:05Speaker 2: gather data temperature, light, motion, you name it, right, and
- 8:08Speaker 2: then connecting that arduino to a network to share that information,
- 8:11Speaker 2: becoming part of this interconnected world. The source gives examples
- 8:15Speaker 2: like smart appliances or smartphones as part of the broader
- 8:18Speaker 2: IoT landscape, and Ardueno lets you build your own custom
- 8:21Speaker 2: nodes within that.
- 8:22Speaker 1: Building, your own piece of the smart home. Okay, speaking
- 8:25Speaker 1: of building, If I'm sold on our dueno, how do
- 8:27Speaker 1: I pick which board to start with? There seem to
- 8:29Speaker 1: be quite a few. The source offers some smart questions
- 8:32Speaker 1: to ask yourself.
- 8:33Speaker 2: Yeah, it suggests starting with your project idea. First, consider
- 8:37Speaker 2: how much processing power you'll need.
- 8:39Speaker 1: So is it a simple turn an led on project
- 8:42Speaker 1: or is something complex like crunching sensor data while controlling
- 8:46Speaker 1: multiple motors for a robot arm Right? That points towards
- 8:50Speaker 1: requirements like flash memory, SHRAM and processor.
- 8:52Speaker 2: Speed exactly Second, how many inputs and outputs? How many
- 8:56Speaker 2: digital and analog pins. Will your project require simple project
- 9:00Speaker 2: needs just a few? Complex needs many more?
- 9:03Speaker 1: Makes sense? And third, are you envisioning a wearable device
- 9:07Speaker 1: like something sewn into clothing?
- 9:09Speaker 2: That question immediately narrows down the options to specialized boards
- 9:13Speaker 2: designed for e textiles, like the lily Pads or the Gemma.
- 9:16Speaker 2: As the source points out, they're designed to be sown.
- 9:18Speaker 2: Some are even washable.
- 9:20Speaker 1: Let's highlight a couple of the specific boards mentioned, just
- 9:22Speaker 1: to give a concrete feel for the variety. The Uno
- 9:25Speaker 1: is definitely the classic starting point.
- 9:27Speaker 2: Right it really is. The Source positions the Arduino Uno
- 9:31Speaker 2: as the quintessential beginner board. Flexible and easy to get
- 9:34Speaker 2: started with. It uses a standard Mini USB for connection, which.
- 9:37Speaker 1: Is pretty common, and the specs.
- 9:39Speaker 2: Specs listed are around twenty five dollars, Sixteenminger hurt speed,
- 9:43Speaker 2: fourteen digital pins, six of which can do that PWM
- 9:47Speaker 2: thing we talked about, and six analog input pins. A
- 9:50Speaker 2: good all arounder.
- 9:51Speaker 1: A great general purpose board to learn on. How about Leonardo?
- 9:54Speaker 1: What's special about that one?
- 9:55Speaker 2: The Leonardo is interesting because it's processor design allows it
- 9:59Speaker 2: to show up on your computer as a standard mouse
- 10:01Speaker 2: or keyboard right out of the box. Oh neat Yeah,
- 10:04Speaker 2: which is cool for projects that you know physically control
- 10:06Speaker 2: your computer uses a micro USB port and is also
- 10:10Speaker 2: sixteen megahertz priced a bit lower around twenty dollars.
- 10:13Speaker 1: Controlling your computer with physical inputs cool.
- 10:16Speaker 2: The Esplorer sounds like it's designed specifically for education.
- 10:19Speaker 1: It absolutely is. It's based on the Leonardo, but comes
- 10:22Speaker 1: with multiple common sensors and outputs already built right onto
- 10:24Speaker 1: the board. A joystick, slighter, temperature sensor, light sensor, sound sensor,
- 10:29Speaker 1: even an accelerometer.
- 10:30Speaker 2: Wow. All included YEP.
- 10:31Speaker 1: Plus sound and light outputs. You learn by seeing these
- 10:34Speaker 1: integrated components in action, which removes the initial hurdle of
- 10:38Speaker 1: wiring everything up yourself. It's around forty four dollars, also
- 10:41Speaker 1: sixteen megahertz. That's a smart way to ease people into
- 10:44Speaker 1: the hardware side. For bigger, more complex projects that make it.
- 10:47Speaker 1: Twenty five to sixty is mentioned.
- 10:48Speaker 2: The Mega twenty five to sixty is the workhorse for
- 10:50Speaker 2: when you need more resources, robotics, three D printers, anything
- 10:54Speaker 2: requiring a lot of connections, more pins, basically way more pins.
- 10:58Speaker 2: It dramatically increases the pin count fifty four digital pins,
- 11:02Speaker 2: fifteen of those or PWM capable sixteen analog inputs and
- 11:06Speaker 2: much more memory than the you know still keeps the
- 11:09Speaker 2: sixteen megahertz speed, though around forty six upslers.
- 11:13Speaker 1: More inputs and outputs for more complex systems. Okay, and
- 11:15Speaker 1: the zero sounds like an upgrade.
- 11:17Speaker 2: The Arduino zero is presented as a performance upgrade. It's
- 11:20Speaker 2: a thirty two bit board running at forty eight megaherts.
- 11:23Speaker 2: That's faster, much faster processing. It also has a built
- 11:26Speaker 2: in debugger, the EDBG, which helps you find errors in
- 11:29Speaker 2: your code without needing extra hardware. That's a great feature
- 11:32Speaker 2: for troubleshooting, especially more complex code. It's about forty three dollars.
- 11:36Speaker 1: Faster and easier debugging. Nice and for those specifically targeting IoT,
- 11:40Speaker 1: the Internet of Things stuff.
- 11:41Speaker 2: The Ardueno un is built with IoT in mind. It
- 11:44Speaker 2: actually integrates Wi Fi and thret connectivity right on the board,
- 11:47Speaker 2: so convenient. Yeah, and it even runs a small Linux
- 11:50Speaker 2: operating system linino OS alongside the Arduino microcontroller. This makes
- 11:55Speaker 2: network connectivity much more straightforward than adding shields or external modules.
- 12:00Speaker 2: It's the priceiest of the ones, detailed around sixty eight
- 12:03Speaker 2: dollars running at sixteen milihertz on the micro controller side, So.
- 12:07Speaker 1: The choice really depends on what you want to do,
- 12:09Speaker 1: and the source mentions. There's a whole family beyond these
- 12:12Speaker 1: more powerful thirty two bit do boards, Android integration with
- 12:15Speaker 1: the Meg eighty K, smaller ProBoards for permanent installation, those
- 12:20Speaker 1: lilypads and Gema for.
- 12:21Speaker 2: Wearables, right, and even tiny powerful ones like the Ta.
- 12:24Speaker 2: And it's a whole ecosystem. But honestly, starting with something
- 12:28Speaker 2: like the Uno is perfectly fine for learning the fundamentals.
- 12:30Speaker 2: You can do a lot with an.
- 12:31Speaker 1: Uno okay board in hand. Ide software installed on my computer.
- 12:35Speaker 1: What's the very first step to making it do something?
- 12:37Speaker 1: How do you get your instructions onto the board?
- 12:39Speaker 2: First? You write your program, which in the Arduino world
- 12:42Speaker 2: is called a sketch. You do this in the Ardueno
- 12:44Speaker 2: ide on your computer. The IDE helps you write the
- 12:47Speaker 2: code and importantly helps find errors, what we call debugging.
- 12:50Speaker 1: Got the sketch written, Now I need to get it
- 12:53Speaker 1: from my computer onto the board's little brain.
- 12:55Speaker 2: Right. You connect the board to your computer, usually with
- 12:57Speaker 2: a USB cable. Different boards use different USB ports, you know,
- 13:02Speaker 2: standard USBB like on printers, Mini USB, micro USB okay,
- 13:06Speaker 2: and the source notes some older or specialized boards might
- 13:10Speaker 2: need a separate adapter cable called an FTDI cable, but
- 13:13Speaker 2: most common ones just use USB. The ID should recognize
- 13:17Speaker 2: your board, or you might need to select it from
- 13:19Speaker 2: a list. Then you simply click the upload button and
- 13:23Speaker 2: magic happens, sort of. The IDE compiles your code, turns
- 13:27Speaker 2: it into machine language, the micro controller understands and sends
- 13:30Speaker 2: it over the USB cable to the board's memory. The
- 13:33Speaker 2: source adds a little note that with some older boards,
- 13:36Speaker 2: you might need to hit a reset button right after
- 13:38Speaker 2: clicking upload for it to accept the new code. Modern
- 13:41Speaker 2: ones usually handle it automatically and.
- 13:43Speaker 1: Actually writing the code. It feels like learning a new language,
- 13:46Speaker 1: doesn't it, with all the weird symbols and terms.
- 13:49Speaker 2: It really is just like learning Spanish or French. There's vocabulary,
- 13:53Speaker 2: the keywords like int or void. There's grammar, the rules
- 13:57Speaker 2: about semicolon's and curly braces and structure.
- 14:00Speaker 1: It gets easier, definitely.
- 14:02Speaker 2: Just like spoken language. The more you practice, the more
- 14:04Speaker 2: natural it feels. And learning one programming language gives you
- 14:07Speaker 2: a big head start on others because a lot of
- 14:09Speaker 2: the concepts carry over.
- 14:10Speaker 1: Let's go back to that iconic blinking led sketch. The
- 14:14Speaker 1: source breaks down the basic structure of an Ardueno sketch.
- 14:17Speaker 1: What are the absolutely essential parts.
- 14:20Speaker 2: Every basic sketch. Pretty much every Arduino program you write
- 14:23Speaker 2: has two fundamental functions that are required, void setup and
- 14:27Speaker 2: void loop.
- 14:28Speaker 1: Okay, walk me through setup. The example shows constant pink
- 14:31Speaker 1: le lo o open thirteen before it, and then void
- 14:34Speaker 1: setup pin mode pink le lo otput right.
- 14:37Speaker 2: So first, that constant pinklo thirteen line defines a constant.
- 14:41Speaker 2: Const means the value won't change. Int means it's an integer.
- 14:45Speaker 2: Pinkel is just a name we give it, and thirteen
- 14:47Speaker 2: is the value, meaning pin thirteen. Using names like pinkele
- 14:50Speaker 2: makes the code easier to read than just putting thirteen everywhere.
- 14:53Speaker 1: Okay, good practice. Then set up.
- 14:54Speaker 2: The void setup function runs only once when your Arduino
- 14:57Speaker 2: board powers up or resets. That's where you put code
- 15:00Speaker 2: for initial configuration. The most common thing done here is
- 15:03Speaker 2: setting the pin mode for the pins you'll be using.
- 15:06Speaker 1: So pin mode pink ol l utpe tells the Arduino what.
- 15:10Speaker 2: It tells the Arduino that the pin we named pinkle,
- 15:13Speaker 2: which is pin thirteen, will be used as an otput,
- 15:16Speaker 2: meaning the arduino will send signals out from this pin,
- 15:19Speaker 2: like turning an LED on or off. The other option
- 15:22Speaker 2: is I nput if you're reading a button press for instance.
- 15:26Speaker 1: Okay, setup is for one time tasks when it starts
- 15:28Speaker 1: up and then loop That sounds like where.
- 15:30Speaker 2: The action is wabloop is exactly that. This function runs
- 15:32Speaker 2: repeatedly forever, well as long as the board has power.
- 15:35Speaker 2: Right after the setup function finishes, This is where you
- 15:38Speaker 2: put the code that does the actual work of your project,
- 15:40Speaker 2: whatever you want the arduno to keep doing, over and.
- 15:42Speaker 1: Over, looking at the blinking LED code inside loop. Digital
- 15:45Speaker 1: right pink o l HH delay six hundred, Digital right
- 15:49Speaker 1: pink COLW delay six hundred. What sequence does that create?
- 15:53Speaker 2: Okay? Digital right is a function that sets a digital
- 15:55Speaker 2: pin to either five volts, which we call hegh, or
- 15:58Speaker 2: zero volts, which we call a low Got it so,
- 16:01Speaker 2: Digital right pinkle ahgh sits pin thirteen to five V,
- 16:05Speaker 2: turning the connected LED on. Then delay six hundred pauses
- 16:10Speaker 2: the entire program for six hundred milliseconds that's point six seconds.
- 16:14Speaker 2: Waits for a bit exactly after that pause. Digital rate
- 16:17Speaker 2: pink ors low W sets the pin back to zero V,
- 16:21Speaker 2: turning the LED off, and then another delay six hundred
- 16:24Speaker 2: pauses again for point six seconds with.
- 16:26Speaker 1: The LED off, And because this is inside the loop function,
- 16:29Speaker 1: it just repeats that whole sequence. On for point six
- 16:32Speaker 1: is pause oh off for point six is pause on
- 16:35Speaker 1: for point six is forever.
- 16:37Speaker 2: Precisely that creates the continuous blinking effect. It's simple, but
- 16:40Speaker 2: it demonstrates the core structure.
- 16:42Speaker 1: The source gives some helpful basic trouble shooting tips based
- 16:45Speaker 1: on this simple example, which is smart, like what if
- 16:47Speaker 1: it doesn't blink?
- 16:48Speaker 2: Yeah? Common issues If you wired up an external LED
- 16:50Speaker 2: in the little built in LED on the board blinks
- 16:53Speaker 2: but yours doesn't. The most common issue is wiring your
- 16:55Speaker 2: LED backward. LEDs only let current flow one way. They
- 16:58Speaker 2: are polarized. The longer leg usually goes to the positive side.
- 17:01Speaker 1: The penh easy mistake. What else?
- 17:03Speaker 2: Another simple check? If the built in LED on the
- 17:07Speaker 2: board is blinking, but maybe not at the rate you
- 17:10Speaker 2: programmed like it's blinking slowly once a second instead of
- 17:13Speaker 2: your faster point six second rate. It probably means your
- 17:17Speaker 2: new sketch didn't successfully upload. The board is likely still
- 17:21Speaker 2: running the default blink sketch or whatever was on it last.
- 17:24Speaker 1: Good simple checks for beginners. Now let's look inside those
- 17:27Speaker 1: setup and loop functions at the actual pieces of code
- 17:30Speaker 1: you use. The source covers comments, data types, and operators.
- 17:35Speaker 1: Comments first seem important.
- 17:37Speaker 2: Comments are your best friend. Seriously, theare knows you write
- 17:40Speaker 2: in your code for yourself or other humans to explain
- 17:42Speaker 2: what's happening, why you did something, whatever. The computer completely ignores.
- 17:46Speaker 1: Them, like leaving little sticky notes on your code. What
- 17:49Speaker 1: are the types? How do you write them?
- 17:50Speaker 2: There are two main ways. Starts a single line comment.
- 17:54Speaker 2: Everything after the double slash on that line is ignored
- 17:56Speaker 2: by the compiler, okay. And then there's to start a
- 17:58Speaker 2: multiline comment and to end it. Everything between those two
- 18:00Speaker 2: markers is ignored, even if it spans multiple lines. Good
- 18:03Speaker 2: for longer explanation.
- 18:04Speaker 1: So comments are purely for clarity. What about those lines
- 18:08Speaker 1: that start with the hash sign hashtag like hashtag difine
- 18:11Speaker 1: or hashtag include. Those aren't comments.
- 18:13Speaker 2: Those are called preprocessor directives, their instructions for the compiler
- 18:16Speaker 2: before it actually compiles the main pad. Hashtag define creates
- 18:19Speaker 2: a constant name for a value, like we saw earlier
- 18:22Speaker 2: with hashtag define LEDPM thirteen. The compiler just literally replaces
- 18:26Speaker 2: every instance of LEDPN with thirteen throughout your code before compiling.
- 18:30Speaker 1: Does that save memory or something?
- 18:32Speaker 2: The source notes it can save a tiny bit of
- 18:33Speaker 2: program memory compared to defining a constant variable with constant
- 18:37Speaker 2: because it's just text replacement. And crucially, hashtag define lines
- 18:41Speaker 2: do not end with a semicolon.
- 18:43Speaker 1: Good tip about the missing semicolon and hashtag include.
- 18:47Speaker 2: Hashtag include is used to bring in external libraries of code.
- 18:51Speaker 2: Libraries contain pre written functions that handle common tasks like
- 18:54Speaker 2: controlling specific sensors or communication protocols. So hashtag includes servo
- 18:58Speaker 2: dot oh would let you use functions for controlling servo motors.
- 19:02Speaker 2: These also do not end with a semicolon.
- 19:04Speaker 1: Got it? Okay? Let's talk data types. When we store
- 19:07Speaker 1: values in variables, the source says, the value has a
- 19:10Speaker 1: specific type. Why is that important?
- 19:12Speaker 2: Yes? The data type tells the computer what kind of
- 19:15Speaker 2: information the variable holds, like is it a whole number,
- 19:17Speaker 2: a number with a decimal, a character, and how much
- 19:20Speaker 2: memory it needs to store it. Using the right type
- 19:23Speaker 2: is important for accuracy and efficiency.
- 19:25Speaker 1: What are the common ones we'll see.
- 19:27Speaker 2: You'll see end all the time. That's for whole numbers
- 19:29Speaker 2: positive or negative like ten or mineta five or zero.
- 19:33Speaker 2: Then float for numbers with decimal points like three point one,
- 19:36Speaker 2: four or nan a zero point zero zero one by
- 19:39Speaker 2: exactly U. Char is for a single character like A
- 19:43Speaker 2: or b or even seven stored as a character, and
- 19:46Speaker 2: boolean is super simple. It can only hold one of
- 19:49Speaker 2: two values, true or false.
- 19:51Speaker 1: And there are others mentioned like byte long, unsigned long,
- 19:55Speaker 1: and void.
- 19:55Speaker 2: Right bite is useful for small positive whole numbers from
- 19:59Speaker 2: zero up to two fifty five. It uses less memory
- 20:02Speaker 2: than an int, which is good on these small microcontrollers.
- 20:05Speaker 2: Long and unsigned long are for when you need to
- 20:07Speaker 2: store much larger whole numbers, like maybe counting milliseconds since
- 20:10Speaker 2: the board started.
- 20:11Speaker 1: And void.
- 20:12Speaker 2: Void isn't really a type you store data in. It's
- 20:14Speaker 2: used in function definitions like voids setup to indicate that
- 20:18Speaker 2: the function doesn't return any value when it's done running.
- 20:20Speaker 1: Okay, so we know what kinds of data we can
- 20:23Speaker 1: work with, how do we well operate on that data?
- 20:27Speaker 1: Add things, compare things.
- 20:28Speaker 2: That's where operators come in. They're the symbols that perform actions.
- 20:31Speaker 2: You know, the basic arithmetic ones from school plus for addition,
- 20:35Speaker 2: for subtraction, for multiplication, for division.
- 20:37Speaker 1: Percent, I always forget what modulo does.
- 20:39Speaker 2: Modulo the percent signed percent gives you the remainder after
- 20:43Speaker 2: an integer division. This source gives the example seven percent five. Well,
- 20:47Speaker 2: five goes into seven one time with a remainder of two,
- 20:50Speaker 2: so seven percent five equals too. It's surprisingly useful for
- 20:54Speaker 2: things like checking if a number is even or odd,
- 20:57Speaker 2: or making counters wrap around.
- 20:59Speaker 1: Okay, remainder, got it now. The source points out a
- 21:02Speaker 1: classic beginner pitfall versus that one trips everyone up initially,
- 21:05Speaker 1: doesn't it?
- 21:06Speaker 2: Oh yeah, it's super common. A single equal sign is
- 21:09Speaker 2: the assignment operator. It puts the value on the right
- 21:11Speaker 2: into variable on the left, Like insensor value of equal
- 21:14Speaker 2: five hundred. It's saying, makes sensor value.
- 21:16Speaker 1: Equal five hundred, assigning of value right.
- 21:18Speaker 2: A double equal sign is the comparison operator. It checks
- 21:21Speaker 2: if the two things on either side are already equal.
- 21:24Speaker 2: It asks the question, is sensor value equal to five hundred.
- 21:28Speaker 2: It results in either true or false.
- 21:30Speaker 1: So if sense value is five hundred is wrong because
- 21:34Speaker 1: it tries to assign five hundred. But if sensor value
- 21:37Speaker 1: equals five hundred is right because it checks if it's
- 21:40Speaker 1: already five hundred exactly.
- 21:42Speaker 2: Using inside an if is a very common bug when
- 21:44Speaker 2: you're starting out.
- 21:45Speaker 1: That distinction is vital. Beyond checking for equality, what other
- 21:49Speaker 1: comparison operators are there?
- 21:50Speaker 2: The standard ones you'd expect means not equal to, then
- 21:53Speaker 2: you have for less than, for greater than, for less
- 21:56Speaker 2: than or equal to. And it's for greater than or
- 21:57Speaker 2: equal to.
- 21:58Speaker 1: And these all give back true or false.
- 22:00Speaker 2: Yeap. They all evaluate to a boolean true or false value,
- 22:03Speaker 2: which is perfect for using in if statements or loops.
- 22:06Speaker 1: Which ties directly into boolean or logical operators. How do
- 22:08Speaker 1: those work?
- 22:09Speaker 2: Exactly? These operators let you combine or modify those true
- 22:12Speaker 2: false results. And is the logical A and D operator.
- 22:15Speaker 2: Condition an and condition B is only true if both
- 22:17Speaker 2: condition A and A D condition B are true. Is
- 22:20Speaker 2: the logical OAR operator. That's two vertical bars. Condition A
- 22:25Speaker 2: condition B is true if either condition AOAR condition B
- 22:28Speaker 2: is true, or if both are true. And the exclamation
- 22:31Speaker 2: mark it's the logical not operator. It just reverses the
- 22:34Speaker 2: truth value, so true becomes false and false becomes true.
- 22:39Speaker 2: Useful for flipping conditions.
- 22:41Speaker 1: These are the fundamental tools for calculation and comparison. Now,
- 22:44Speaker 1: how do we make our program smart? How do we
- 22:47Speaker 1: make it decide what to do based on conditions or
- 22:49Speaker 1: repeat actions multiple times?
- 22:51Speaker 2: That's where control structures come in. They direct the flow
- 22:54Speaker 2: of your program, deciding which lines of code get executed
- 22:57Speaker 2: and when. Decision making is typically handled with if statements,
- 23:01Speaker 2: often paired with else, if and else.
- 23:04Speaker 1: How does that sequence work? Like? Does it check all
- 23:06Speaker 1: of them?
- 23:06Speaker 2: It checks them in order and if condition code block
- 23:09Speaker 2: runs the code inside its curly braces only if the
- 23:11Speaker 2: condition evaluates to true.
- 23:13Speaker 1: Okay, if it's true, run the code if it's false.
- 23:16Speaker 2: If the if condition is false, the program can then
- 23:19Speaker 2: optionally check an el sif another condition. If that condition
- 23:23Speaker 2: is true, it's code runs. You can string multiple elsifs together,
- 23:27Speaker 2: one after another. It checks them sequentially until it finds
- 23:30Speaker 2: one that's true, runs its code, and then skips the
- 23:32Speaker 2: rest of the elsifs and any final.
- 23:34Speaker 1: Else and the else at the end.
- 23:35Speaker 2: A final optional else code block runs only if none
- 23:39Speaker 2: of the preceding if or else if conditions were true.
- 23:42Speaker 2: It's the fallback the otherwise case.
- 23:45Speaker 1: So it's how you create those branching paths in your logic.
- 23:47Speaker 1: If the sensor reads high, do this otherwise. If it's
- 23:50Speaker 1: kind of medium, do that otherwise. If it's low, do
- 23:52Speaker 1: this other thing.
- 23:53Speaker 2: Precisely, that's the core of decision making in code. For
- 23:56Speaker 2: repeating actions, you generally use loops. The source details two
- 24:00Speaker 2: main types, while loops and four loops.
- 24:02Speaker 1: What does a wild loop do? How is it different?
- 24:05Speaker 2: A while code to repeat loop is pretty straightforward. It
- 24:09Speaker 2: checks the condition before each potential run. If the condition
- 24:12Speaker 2: is true, it executes the code block inside the curly braces.
- 24:15Speaker 2: Then it goes back, checks the condition again. If it's
- 24:18Speaker 2: still true, it runs the code again. It keeps doing
- 24:21Speaker 2: this as long as the condition remains true.
- 24:23Speaker 1: So it could run zero times if the condition is
- 24:25Speaker 1: false the first.
- 24:26Speaker 2: Time exactly, or it could run forever if the condition
- 24:30Speaker 2: never becomes false. Think of it as a loop that
- 24:32Speaker 2: keeps going while something is true, like processing data while
- 24:36Speaker 2: there is data available, or running a game loop while
- 24:39Speaker 2: the game isn't over.
- 24:41Speaker 1: It keeps checking the condition, and four loops they look
- 24:43Speaker 1: a bit more structured.
- 24:45Speaker 2: Four loops are generally used when you know or can
- 24:49Speaker 2: calculate how many times you want to repeat something, or
- 24:51Speaker 2: when you're iterating through a known sequence like the elements
- 24:54Speaker 2: in an array. The structure looks a bit more complex
- 24:57Speaker 2: for initialization condition, iteration, code repeat.
- 25:00Speaker 1: Okay, break down those three parts in the parentheses. Initialization.
- 25:04Speaker 2: Initialization runs only once at the very beginning of the loop.
- 25:08Speaker 2: It's typically used to declare and set up a counter
- 25:10Speaker 2: variable like into I zero zero got it condition. The
- 25:14Speaker 2: condition is checked before each loop iteration, just like in
- 25:17Speaker 2: a while loop. If it's true, the code inside the
- 25:19Speaker 2: loop runs. If it's false, the loop terminates. A common
- 25:22Speaker 2: condition is something like I ten and iteration. The iteration
- 25:26Speaker 2: part runs after the code block inside the loop executes,
- 25:28Speaker 2: but before the condition is checked again for the next round.
- 25:31Speaker 2: It's usually used to update the counter variable, most often
- 25:34Speaker 2: incrementing it with I plus plus which means i I
- 25:37Speaker 2: plus one, or decrementing it with iis i.
- 25:40Speaker 1: One okay, So for into I zero I five I
- 25:43Speaker 1: plus plus do something would initialize I to zero. Then
- 25:47Speaker 1: it checks is zero less than five yes, runs, the
- 25:49Speaker 1: code increment's e to one checks is one less than
- 25:51Speaker 1: five yes runs the code increment's i all the way
- 25:54Speaker 1: until it becomes five checks is five to eight and
- 25:56Speaker 1: five no, so the loop stops. I ran five times
- 25:59Speaker 1: with I having the values zero, one, two, three, and
- 26:01Speaker 1: four inside the loop.
- 26:03Speaker 2: You got it. That's exactly how it works, and the
- 26:06Speaker 2: source gives that critical warning. Your four loop must have
- 26:10Speaker 2: a condition that will eventually become false. If you accidentally
- 26:13Speaker 2: write a condition that's always true, like I expeol zero
- 26:16Speaker 2: when I only ever increases, the loop runs forever and
- 26:19Speaker 2: your program just gets stuck there. That's another common way
- 26:22Speaker 2: to get stuck when you're starting.
- 26:23Speaker 1: Out, an accidental infinite loop. Yeah, I can see how
- 26:26Speaker 1: that happens. Speaking of iterating through things, that brings us
- 26:29Speaker 1: nicely to a rays. What's an array for? Why not
- 26:32Speaker 1: just use separate variables?
- 26:34Speaker 2: An array is a way to group multiple pieces of
- 26:36Speaker 2: data of the exact same type under a single variable name.
- 26:39Speaker 2: Think of it like a list or sequence of related values,
- 26:42Speaker 2: all stored neatly together in memory. The source uses the
- 26:46Speaker 2: example of wanting to control several LEDs, maybe using pins two, seven, four, six,
- 26:51Speaker 2: five and three instead of six different variables, use one
- 26:53Speaker 2: array exactly. You could declare it like in lead pins seven, four, six,
- 26:57Speaker 2: fy three. Now you have one variable lead pins that
- 27:00Speaker 2: it's all six pin numbers.
- 27:01Speaker 1: The syntax uses those square brackets. What's the potentially tricky
- 27:05Speaker 1: part about getting items out of that list.
- 27:07Speaker 2: The main thing to remember is zero indexing. In our
- 27:10Speaker 2: dwino and C plus plus says and many other programming languages,
- 27:14Speaker 2: you access elements in an array using an index number
- 27:18Speaker 2: that starts at zero.
- 27:19Speaker 1: Not oneh right, zero based.
- 27:21Speaker 2: So the first item in the array is it index zero,
- 27:24Speaker 2: The second item is at index one, the third at two,
- 27:26Speaker 2: and so on.
- 27:27Speaker 1: Okay, So in that lead pins example, leadpin zero would
- 27:30Speaker 1: give you the value two. The first pin number, yeah,
- 27:33Speaker 1: leadpins one would give you seven, and the last one,
- 27:35Speaker 1: which is the sixth element, would be at index five,
- 27:38Speaker 1: giving you the value three.
- 27:39Speaker 2: Exactly right. It feels a little weird at first if
- 27:42Speaker 2: you're used to counting from one in everyday life, but
- 27:44Speaker 2: you get used to zero indexing pretty quickly. It's just
- 27:46Speaker 2: the standard way it's done.
- 27:48Speaker 1: And the source shows how arrays and four loops are
- 27:50Speaker 1: often used together. That makes perfect sense. Now you can
- 27:53Speaker 1: use a four loop with a counter i that goes
- 27:55Speaker 1: from zero up to the size of the array minus one,
- 27:59Speaker 1: and inside the loop you use lead pinc to access
- 28:02Speaker 1: each element in turn, like you could loop through and
- 28:04Speaker 1: set the pin mode for all of them. In setup,
- 28:06Speaker 1: or loop through and turn them all on or off
- 28:08Speaker 1: in loop.
- 28:08Speaker 2: It's a really fundamental and efficient pattern for handling collections
- 28:12Speaker 2: of things in your code, much cleaner than writing the
- 28:15Speaker 2: same line of code six times with different variable names.
- 28:18Speaker 1: Definitely, okay, we've seen the built in functions set up
- 28:22Speaker 1: and loop, But what if you have a specific sequence
- 28:25Speaker 1: of actions, maybe like calculating something complex or controlling a
- 28:29Speaker 1: motor in a certain way, that you need to perform
- 28:31Speaker 1: multiple times throughout your program. Copy pasting that block of
- 28:35Speaker 1: code everywhere seems bad.
- 28:37Speaker 2: Copy pasting is definitely messy and prone to errors. If
- 28:41Speaker 2: you find a bug, you have to fix it in
- 28:43Speaker 2: every single place you pasted it. That's where user defined
- 28:47Speaker 2: functions are incredibly useful. They let you package a block
- 28:50Speaker 2: of code into a named, reusable.
- 28:51Speaker 1: Unit, like creating your own custom command.
- 28:53Speaker 2: Pretty much, you write the code for that task once
- 28:56Speaker 2: inside a function definition, give the function a meaningful name,
- 29:00Speaker 2: and then whenever you need to perform that task in
- 29:02Speaker 2: your main code set up or loop or even another function,
- 29:04Speaker 2: you just call that function by using its name. It
- 29:07Speaker 2: makes your code much neater, easier to read, easier to debug,
- 29:10Speaker 2: and easier to.
- 29:11Speaker 1: Update the source gives the general structure return type, function name, parameters,
- 29:17Speaker 1: code block, return value. Let's unpack that function signature return type.
- 29:23Speaker 2: Return type specifies what type of data, if any, the
- 29:26Speaker 2: function sends back to the place it was called from
- 29:28Speaker 2: when it finishes its job. We saw void earlier, meaning
- 29:32Speaker 2: it returns nothing, but it could be into if it
- 29:35Speaker 2: calculates a whole number, float, if it calculates a decimal number, boolean,
- 29:39Speaker 2: if it returns true or false.
- 29:40Speaker 1: And so on. Okay, function name is just what you
- 29:43Speaker 1: call it.
- 29:43Speaker 2: Yep, you pick the name. Make it descriptive so you
- 29:45Speaker 2: know what it does, like calculated distance or blinkeled sequence.
- 29:48Speaker 1: And parameters inside the parentheses.
- 29:50Speaker 2: Parameters are optional inputs. There are variables declared inside the
- 29:53Speaker 2: parentheses that allow you to pass information into the function
- 29:56Speaker 2: when you call it. So the function has data to
- 29:58Speaker 2: work with. You define them with their data type and
- 30:01Speaker 2: a placeholder name like int, pin number, int, blink delay.
- 30:05Speaker 2: If a function doesn't need any input, the parentheses are
- 30:07Speaker 2: just empty and.
- 30:08Speaker 1: The code block is just the steps the function takes.
- 30:11Speaker 2: Right, the instructions between the curly braces are the actual
- 30:15Speaker 2: work the function performs in that return value line at
- 30:19Speaker 2: the end, The return keyword is used to send a
- 30:21Speaker 2: value back to wherever the function was called from. You
- 30:25Speaker 2: only use it if your function's return type is something
- 30:27Speaker 2: other than void. Using return also immediately stops the function's
- 30:31Speaker 2: execution right there and goes back to the calling code.
- 30:34Speaker 1: The example from the source is float employe yearnings, float
- 30:38Speaker 1: hours worked flow pay rate.
- 30:40Speaker 2: Ye.
- 30:40Speaker 1: So that takes two.
- 30:41Speaker 2: Inputs right That function definition says it's named employee yearnings.
- 30:45Speaker 2: It expects two numbers with decimal points float as input,
- 30:49Speaker 2: which it will call hours worked and pay rate. Inside
- 30:52Speaker 2: the function, it does some calculation inside presumably hours worked,
- 30:56Speaker 2: pay rate, and then returns the result, which must also
- 30:59Speaker 2: be a float, using return statement like return hours worked,
- 31:02Speaker 2: pay rate.
- 31:02Speaker 1: And in your main sketch, maybe in loop you'd use
- 31:05Speaker 1: that function, maybe like float my weekly pay employee earnings
- 31:08Speaker 1: forty point zero twenty five point fifteen er, and the
- 31:10Speaker 1: function would run do the math forty twenty five point
- 31:12Speaker 1: to yo, and that calculated value would get stored in
- 31:15Speaker 1: the my weekly pay variable exactly.
- 31:17Speaker 2: You call the function by name, provide the input values
- 31:19Speaker 2: called arguments in the parentheses, and if it returns something,
- 31:23Speaker 2: you can capture that result in.
- 31:24Speaker 1: A variable where do you actually write these function definitions?
- 31:29Speaker 2: The source points out that any functions you create yourself
- 31:32Speaker 2: need to be defined outside of the standard set up
- 31:34Speaker 2: and loop functions. Usually you put them either before setup
- 31:37Speaker 2: or after loop. And remember they can be simple void
- 31:41Speaker 2: functions that don't return a value, and they might not
- 31:43Speaker 2: need any parameters if they just perform a fixed sequence
- 31:46Speaker 2: of actions.
- 31:47Speaker 1: Got it. Functions are all about organization and reusability. Okay,
- 31:52Speaker 1: moving on from writing our own functions. Our duino gives
- 31:55Speaker 1: us a whole library of built in functions to interact
- 31:58Speaker 1: with the board itself and the outside world it's API
- 32:01Speaker 1: or application programming interface. What are some crucial ones we
- 32:04Speaker 1: absolutely need to know?
- 32:06Speaker 2: We've actually seen some of the most important ones already.
- 32:08Speaker 2: For digital pins, we saw pin mode and set up
- 32:11Speaker 2: and digital right to set a pin HGH or low W.
- 32:14Speaker 2: There's also its counterpart, digital read pin, which checks the
- 32:18Speaker 2: current state of an input pin. Is it reading high
- 32:20Speaker 2: like five V from a press button or LW zero V.
- 32:24Speaker 2: These are your basic digital io input output tools, right.
- 32:28Speaker 1: What about analog? We know boards have those analog input
- 32:30Speaker 1: pins like a zero through a five on the UNO.
- 32:33Speaker 1: How do we read those.
- 32:34Speaker 2: For reading analog inputs. The core function is an allog
- 32:37Speaker 2: read pin. You give it the pin number like a zero.
- 32:39Speaker 2: It reads the voltage level present on that pin, which
- 32:42Speaker 2: could be anything between zero V and five E, and
- 32:44Speaker 2: converts that varying analog voltage into a digital number.
- 32:47Speaker 1: As a condvaria what kind of number do you get?
- 32:49Speaker 2: It performs what's called analog to digital conversion or ADC.
- 32:52Speaker 2: On most standard or do we knows like the UNO,
- 32:54Speaker 2: it's a ten bit ADC. This means it maps the
- 32:56Speaker 2: input voltage range zero V to five V to a
- 32:59Speaker 2: numerical range of zero to ten twenty three. So if
- 33:01Speaker 2: the pin reads zero V and I'll agreed return zero.
- 33:04Speaker 2: If it reads five V, it returns twenty twenty three.
- 33:08Speaker 2: If it reads say two point five V halfway, it
- 33:11Speaker 2: returns around five to twelve AH.
- 33:13Speaker 1: So a sensor like a potentiometer or temperature sensor that
- 33:16Speaker 1: outputs a varying voltage gets turned into a usable number
- 33:19Speaker 1: between zero and ten on twenty three. That's really useful
- 33:22Speaker 1: and analog right. We touched on that with PWM.
- 33:24Speaker 2: Exactly analog right pin value is used on those special
- 33:28Speaker 2: PWM enabled digital pins marked with a tilt on many boards.
- 33:32Speaker 2: It uses pulse width modulation to output an analog like
- 33:35Speaker 2: signal even though it's a digital pin. The value provide
- 33:38Speaker 2: here is typically between zero and two.
- 33:39Speaker 1: Fifty five, not zero to ten twenty three.
- 33:41Speaker 2: Now for analog right, the standard range is zero to
- 33:44Speaker 2: two fifty five, Where zero means the signal is effectively
- 33:47Speaker 2: off zero percent duty cycle, two fifty five means it's
- 33:50Speaker 2: fully on one hundred percent duty cycle, and a value
- 33:53Speaker 2: like one hundred and twenty seven means it's not about
- 33:55Speaker 2: half the time simulating roughly half brightness or half speed.
- 33:58Speaker 2: This is how you smoothly dem LEDs or control the
- 34:01Speaker 2: speed of many DC motors.
- 34:02Speaker 1: Okay, so analog read for getting sensor data in El
- 34:05Speaker 1: de Lando twenty three, anlog ride for controlling things with
- 34:07Speaker 1: varying levels out using PWM zero two five to five.
- 34:11Speaker 1: The source also covers how the Arduino can talk back
- 34:13Speaker 1: to your computer using something called the serial monitor.
- 34:15Speaker 2: Yes, serial communication is fundamental. It's a standard way electronic
- 34:19Speaker 2: devices talk to each other, sending data one bit after another,
- 34:22Speaker 2: usually over a simple connection like the USB cable. The
- 34:26Speaker 2: serial monitor built into the Arduino ide is basically a
- 34:29Speaker 2: simple text window on your computer. That lets your ardueno
- 34:32Speaker 2: send messages to you and lets you type messages from
- 34:35Speaker 2: your computer to the ardweno.
- 34:37Speaker 1: How do you enable that communication in your code?
- 34:40Speaker 2: The first step, usually done inside setup is to start
- 34:43Speaker 2: the serial communication channel using serial dot begin speed. The
- 34:47Speaker 2: speed is the data rate in bits per second, often
- 34:49Speaker 2: called the BOD rate. A very common speed to use
- 34:52Speaker 2: is ninety six hundred, so you'd write serial dot begin
- 34:55Speaker 2: ninety six hundred. You also need to make sure the
- 34:58Speaker 2: serial monitor window in the IDE is set to the
- 35:00Speaker 2: same speed.
- 35:01Speaker 1: Okay, communication started. Now how do I send data like
- 35:04Speaker 1: a sensor reading from the arduino to my computer screen?
- 35:08Speaker 2: You use the serial dot print and serial dot print
- 35:10Speaker 2: ale in functions. Serial dot print data sends whatever data
- 35:14Speaker 2: you give it text in quotes like hello, or the
- 35:17Speaker 2: value of a variable like sensor value to the serial monitor.
- 35:21Speaker 2: Serial dot printal data does the same thing, but it
- 35:23Speaker 2: also adds a new line character at the end, so
- 35:26Speaker 2: the next thing you print will appear on the next
- 35:28Speaker 2: line in the monitor. Print aline is usually what you
- 35:30Speaker 2: want for reading streams of data.
- 35:32Speaker 1: It makes the output readable. And how about the other
- 35:35Speaker 1: way sending commands from my computer to the arduino like
- 35:39Speaker 1: typing something in the serial monitor.
- 35:41Speaker 2: For that, you typically use serial dot read. This function
- 35:44Speaker 2: reads the next available byte character of incoming data that
- 35:48Speaker 2: has been sent from the computer. You usually check first
- 35:51Speaker 2: if data is actually available using serial dot available, which
- 35:54Speaker 2: returns the number of bytes waiting to be read.
- 35:56Speaker 1: Okay, check if something's there, then read it. The source
- 35:59Speaker 1: gives some fantastic practical examples tying these API functions together,
- 36:04Speaker 1: like reading a temperature sensor and showing the actual temperature
- 36:07Speaker 1: on the computer screen.
- 36:08Speaker 2: Right. That example really brings it together. You'd use analog
- 36:11Speaker 2: reed in your loop to get the raw sensor value
- 36:14Speaker 2: zero air zero two three. Then you do a little
- 36:17Speaker 2: math based on the sensor's data sheet to convert that
- 36:19Speaker 2: raw reading into an actual voltage and then maybe into
- 36:22Speaker 2: degrees celsius or fahrenheit. And finally you'd use serial dot
- 36:25Speaker 2: print temperature followed by serial dot print calculated temperature to
- 36:30Speaker 2: display that reading live in the serial monitor.
- 36:32Speaker 1: That's a complete little system. Another one uses a photo
- 36:35Speaker 1: resistor a light sensor and prints text descriptions like dark, dim,
- 36:39Speaker 1: light bright.
- 36:40Speaker 2: Yeah. That one demonstrates combining analog reed to get the
- 36:43Speaker 2: light level again zero one zero two three with a
- 36:46Speaker 2: series of I false iff statements. You check is the
- 36:48Speaker 2: value less than two hundred if yes, Serial dot printaline dark,
- 36:52Speaker 2: else if it's less than five hundred ceial dot print
- 36:54Speaker 2: lan dim else off less than eight hundred, Serial dot
- 36:57Speaker 2: print lin and light L serial dot printline bright categorizes
- 37:00Speaker 2: the numerical reading into meaningful text.
- 37:02Speaker 1: Output, turning numbers into words. And the final example using
- 37:05Speaker 1: serial communication lets you actually control an LED from your
- 37:09Speaker 1: computer keyboard.
- 37:10Speaker 2: Yes, that project shows how you can use serial dot
- 37:13Speaker 2: available and serial dot read inside your loop. You check
- 37:16Speaker 2: if the user has typed something into the serial monitor's
- 37:19Speaker 2: input bar and hit send. If they have, you read
- 37:22Speaker 2: the character they sent. If the character is, say one,
- 37:25Speaker 2: the code sees that and uses digital right to turn
- 37:28Speaker 2: an LED on. If the character is a role on it,
- 37:30Speaker 2: it turns the LED off.
- 37:31Speaker 1: F That's really cool building a simple remote control interface
- 37:35Speaker 1: just using the serial monitor.
- 37:36Speaker 2: It's a simple but powerful demonstration of two way communication
- 37:39Speaker 2: between your computer and the physical world via the arduino.
- 37:42Speaker 1: The source also quickly mentions a couple of other useful
- 37:45Speaker 1: built in math related functions. Yeah, map and constraint.
- 37:49Speaker 2: Yeah, those are super handy. Utility functions map value from
- 37:52Speaker 2: low to high to low. A high takes a number
- 37:54Speaker 2: of value that's within one range from load to from
- 37:56Speaker 2: high and mathematically scales it to fit within a different
- 37:59Speaker 2: range to low to high.
- 38:00Speaker 1: Oh like taking that zero one to two three analog
- 38:02Speaker 1: read result and scaling it down to the zero two
- 38:05Speaker 1: five to five range needed for analog.
- 38:06Speaker 2: Right exactly, that's a perfect use case. Map sensor of
- 38:10Speaker 2: value zero one seria three zero two fifty five saves
- 38:13Speaker 2: you doing the proportional math yourself and constrain value lower
- 38:18Speaker 2: bound upperbound is simple. It just makes sure a number
- 38:20Speaker 2: stays within a specific minimum and maximum limit. If the
- 38:23Speaker 2: value is below lower bound, it returns lower bound. If
- 38:26Speaker 2: it's above upper bound, it returns upper bound. Otherwise it
- 38:29Speaker 2: just returns the original value. Useful for keeping things within
- 38:32Speaker 2: safe operating.
- 38:33Speaker 1: Ranges, handy shortcuts, and it mentions their whole other categories too,
- 38:37Speaker 1: like math character random number functions.
- 38:40Speaker 2: Right, the Arduino API is quite rich. Once you start exploring.
- 38:43Speaker 1: You also touched on the serial communication as dealing with
- 38:47Speaker 1: a stream of data. The source goes a bit deeper
- 38:49Speaker 1: into working with text data, specifically strings and the stream concept.
- 38:54Speaker 1: What's that about?
- 38:55Speaker 2: Conceptually, the stream class in Arduino programming represents a flow
- 38:59Speaker 2: of data coming in or going out sequentially, like a
- 39:01Speaker 2: stream of characters or bites from a source like the
- 39:04Speaker 2: serial port or a file or network connection, and strings
- 39:07Speaker 2: are fundamental when you're dealing with text within that stream
- 39:10Speaker 2: or just in your program.
- 39:11Speaker 1: Generally, what exactly is a string in this context? Is
- 39:15Speaker 1: it like the string object in other languages.
- 39:17Speaker 2: Are Duino supports two main ways of handling strings. There's
- 39:20Speaker 2: the string object, which is easier to use for beginners.
- 39:23Speaker 2: You can concatenate them with plus said, et cetera, but
- 39:26Speaker 2: it can use more memory and potentially cause issues on
- 39:29Speaker 2: small micro controllers. The more fundamental way, inherited from CC
- 39:33Speaker 2: plus plus day is using character arrays, often called Sea
- 39:36Speaker 2: style strings.
- 39:38Speaker 1: So like charm my message hello exactly.
- 39:41Speaker 2: The source defines these Sea style strings as basically a
- 39:45Speaker 2: rays of characters. They are stored one character after another
- 39:48Speaker 2: in memory, and crucially, they end with a special invisible
- 39:51Speaker 2: character called the null character, which is written as zaguro
- 39:54Speaker 2: to mark the actual end of the string within the array.
- 39:57Speaker 1: So text is just stored as a list of character
- 40:00Speaker 1: ending with a special marker.
- 40:01Speaker 2: Essentially yes for seestyle strings, and the serial object we've
- 40:04Speaker 2: been talking about is a practical implementation a derivative class
- 40:08Speaker 2: in programming terms of that general stream concept. It's specifically
- 40:12Speaker 2: tailored for sending and receiving streams of bites or characters
- 40:15Speaker 2: over the serial connection like the USB cable to your computer.
- 40:18Speaker 1: It's the specialized tool that handles that flow of characters
- 40:21Speaker 1: between the board and the computer's serial monitor exactly.
- 40:24Speaker 2: So when the source revisits cerial functions like serial dot begin,
- 40:28Speaker 2: serial dot print, cereal dot printal N, and cereal dot read,
- 40:31Speaker 2: it's helpful to think of them as methods for interacting
- 40:34Speaker 2: with this data stream. It also mentions other useful stream
- 40:37Speaker 2: serial functions like serial dot available, which we discuss checks
- 40:41Speaker 2: if there's data waiting in the incoming stream. Any of
- 40:43Speaker 2: those for reading, Yeah, cereal dot parsent and cereal dot
- 40:47Speaker 2: parsefloat are handy. They try to read through the incoming
- 40:50Speaker 2: stream until they find and parse out a valid integer
- 40:53Speaker 2: or a floating point number, skipping any non numeric characters
- 40:56Speaker 2: of for it saves you reading characters one by one
- 40:59Speaker 2: and converting them yourself, And cereal dot peak lets you
- 41:02Speaker 2: look at the next character in the incoming stream without
- 41:05Speaker 2: actually removing it from the stream, which can sometimes be useful.
- 41:08Speaker 1: So working with text inputs or outputs socially over cereal
- 41:12Speaker 1: really relies on understanding either character arrays c strings or
- 41:17Speaker 1: the string object and using the right ceial stream functions
- 41:20Speaker 1: to read and write that data.
- 41:22Speaker 2: That's the pathway for text communication between your arduino and
- 41:25Speaker 2: another device like your computer. Mastering serial is key for
- 41:29Speaker 2: debugging and for many interactive projects.
- 41:32Speaker 1: Wow, that was a fantastic tour through the essentials of
- 41:35Speaker 1: our dueno. We really covered a lot.
- 41:36Speaker 2: We did cover quite a bit of ground, from understanding
- 41:39Speaker 2: what our dueno is, it's very accessible history and the
- 41:43Speaker 2: key advantages that really made it so popular, the.
- 41:46Speaker 1: Cost, the open source nature, cross.
- 41:47Speaker 2: Platform exactly, then figuring out how to pick your first
- 41:51Speaker 2: board based on what you actually want to do with it.
- 41:53Speaker 1: We dove into setting up the software, writing your first
- 41:56Speaker 1: sketch love that term, with the essential setup and loop functions,
- 41:59Speaker 1: and walking through that fundamental blinking led example line by line.
- 42:04Speaker 1: Even touched on basic troubleshooting if it doesn't work first
- 42:07Speaker 1: time yep.
- 42:08Speaker 2: And we explored the building blocks of writing the code itself,
- 42:12Speaker 2: adding comments for clarity understanding different data types like int, float, boolean,
- 42:17Speaker 2: and using operators for math and comparisons, remembering that crucial
- 42:21Speaker 2: versus difference.
- 42:22Speaker 1: Don't forget controlling the flow of your program with Eiffel's
- 42:25Speaker 1: decisions and wildfoar loops for repetition, and grouping data efficiently
- 42:30Speaker 1: with a raise, always remembering that tricky zero indexing right.
- 42:34Speaker 2: And we saw the power of creating your own reusable
- 42:36Speaker 2: functions to keep your code organized and avoid copy pasting.
- 42:39Speaker 2: Plus how to leverage our duenos built in API functions,
- 42:43Speaker 2: the really important ones like digital read digital right, analog
- 42:47Speaker 2: read for sensors, analog right for PWOM, control.
- 42:50Speaker 1: Sommudicating back and forth of your computer using the serial monitor,
- 42:53Speaker 1: including handling strings, and the whole concept of the serial
- 42:56Speaker 1: data stream.
- 42:57Speaker 2: So, based on this deep dive into your material, I
- 43:00Speaker 2: think the most important takeaway is probably that the absolute
- 43:02Speaker 2: best way to learn this stuff is by doing. Get
- 43:05Speaker 2: your hands on a board, even a cheap clone to start.
- 43:09Speaker 2: Try those examples, tweak the code, mess around with it,
- 43:11Speaker 2: see what happens. Break it. That's honestly how you learn
- 43:14Speaker 2: a lot of the time, and then figure out how
- 43:16Speaker 2: to fix it.
- 43:16Speaker 1: And you are absolutely not alone in this journey. The
- 43:19Speaker 1: source really highlights the incredible Arduino community online forums, websites
- 43:24Speaker 1: packed with projects and tutorials, YouTube channels, plus local resources
- 43:28Speaker 1: like maybe a hobby shop or even books from the library.
- 43:31Speaker 1: Don't ever hesitate to look for health or inspiration.
- 43:34Speaker 2: Definitely and start small. That blinking led is simple for
- 43:39Speaker 2: a reason. Master basic inputs like buttons and simple sensors
- 43:43Speaker 2: and basic outputs like LEDs and maybe small motors or
- 43:46Speaker 2: buzzers before you tackle, you know, complex robotics or network
- 43:51Speaker 2: IoT projects. Build your confidence step by step.
- 43:54Speaker 1: It's true or do we know? Genuinely gives you the
- 43:56Speaker 1: power to take an idea that's just in your head
- 43:58Speaker 1: and make it physically happen in the real world using code.
- 44:01Speaker 1: So thinking about all the different things you could potentially
- 44:03Speaker 1: sense or read from the world around you, light temperature, motion,
- 44:06Speaker 1: button presses, commands from a computer, and all the different
- 44:09Speaker 1: things you could potentially control or make happen in the
- 44:11Speaker 1: world lights, sounds, motors sending data back. What simple, perhaps
- 44:16Speaker 1: unexpected or even playful interaction are you imagining building into
- 44:20Speaker 1: your very first Arduino project.