Maker.io main logo

Your First Arduino Project with Becky Stern

2023-03-14 | By bekathwia

XIAO

After you’ve tried a bunch of the built-in and downloadable examples, as we’ve covered in previous ‎episodes, the next step in your Arduino journey is to combine Arduino sample sketches to make a ‎working prototype of your idea. In this guide, you’ll learn how to build your own unique Arduino ‎project for the first time.

The board I recommend starting with is the Arduino Uno or compatibles such as the Adafruit Metro, ‎Sparkfun Redboard, or Seeeduino.

To build the circuits in this guide, you will need:

The additional components you’ll need will depend on what you want your unique Arduino project ‎to do, but here is what I used for mine:

Figuring out how to write the code for your project can be super intimidating, but here’s a process ‎you can use to break it down.

Your First Arduino Project with Becky Stern

First, write out the primary project purpose. If it has numerous features, you’ll have to decide which ‎are necessary versus those that would be nice but aren’t needed at first. You can always add your ‎‎“nice to have” features later, but as a beginner, you should start with the simplest version.

Your First Arduino Project with Becky Stern

Next, list the project’s inputs and outputs. A passkey lock might have a keypad input, some kind of ‎LED display output, and a solenoid output. Internet projects might have a cloud service as an input, ‎output, or both, but if it’s really your first time building an Arduino project, I recommend saving the ‎IoT stuff for projects two or three.

Your First Arduino Project with Becky Stern

The project I’m building today is a webcam privacy device that uses a button and real-time clock ‎inputs and outputs to a servo motor.

Your First Arduino Project with Becky Stern

The next step is to write out an outline of your program’s main loop. This is called pseudocode, and ‎it should map out the cause-and-effect relationships you want to have in your program.

Your First Arduino Project with Becky Stern

When it comes to choosing the electronic components for your project, ask yourself if each of your ‎inputs and outputs needs to be digital (“on” or “off”), analog (along a scale), or something else. The ‎servo motor that I’m using requires a code library to get it working.

Not all product documentation is created equal, so my best advice to beginners is to shop for ‎components that have good tutorials and sample code, such as those mentioned in the built-in ‎examples, to start or from reputable library sample code. Look up examples and tutorials for each ‎component of your project and build and run each one at a time before attempting to combine their ‎code.

Your First Arduino Project with Becky Stern

So, for example, in my webcam privacy device project, I’ve got a momentary pushbutton input to ‎manually operate the device, a potentiometer to adjust the time it stays open, and a real-time clock ‎to keep accurate track of that time. Then there’s the servo motor. So I’ve got three inputs and one ‎output.

Your First Arduino Project with Becky Stern

So, I’ll start with the built-in Arduino example DigitalReadSerial and wire up my pushbutton, then ‎observe the serial output to confirm my button is working and wired correctly.

Your First Arduino Project with Becky Stern

It’s easier to discover that something is wired incorrectly at this stage when you’re working with ‎code that’s known to work with the component at hand rather than trying to debug wiring and new ‎code at the same time.

Your First Arduino Project with Becky Stern

Then I’ll add the potentiometer and open up a different example, AnalogReadSerial, and observe ‎that serial output to confirm my knob circuit works.

Your First Arduino Project with Becky Stern

As we’ve covered in a previous episode, basic digital and analog code can be used with a variety ‎of different sensors, many times with little to no modification. So I could substitute the pushbutton ‎for a PIR motion sensor, for example, or the knob for a slider or force-sensitive resistor. Having ‎that serial output can help figure out if the logic needs to be reversed or the sensor range mapped ‎to suit the output.

Your First Arduino Project with Becky Stern

For the real-time clock, a library needs to be downloaded to communicate with the device, and that ‎library comes with example code, found in the Examples menu after you’ve installed the library.

Your First Arduino Project with Becky Stern

Lastly, it’s time to test the servo motor, which requires a library that happens to come pre-installed ‎with the Arduino software.

Now it’s time to create a new sketch that will operate all the inputs and outputs and apply the logic ‎that makes the features work.

Your First Arduino Project with Becky Stern

Sometimes there’s an example that does something similar to what you want already, and you can ‎build on that, or you can start with any one of the basic testers you ran in the last step.

The basic idea is to add together all the required bits like library includes and setup stuff, then write ‎something that performs the actions described in the pseudocode. It’s a smart thing to paste your ‎pseudocode into your program as comments. That way you can always see in plain language what ‎you are trying to do. Comments also make it easy for somebody to pick up where you left off later, ‎even if that somebody is you.

Your First Arduino Project with Becky Stern

You’ll want to compile your new program after every important change. Just like testing the ‎hardware one component at a time, compiling often will catch and isolate errors as you make them, ‎like a misplaced semicolon or curly brace. If you keep making changes and try to fix all the errors ‎later, it will be harder to isolate and fix each issue. I’ll go into more error troubleshooting detail in a ‎future episode.

When your program achieves important milestones, save your code as a new version to preserve ‎your last working state. It’s like preserving your last save at an important checkpoint in a video ‎game.

Your First Arduino Project with Becky Stern

You might end up changing some elements of your project as you progress, and that’s natural. ‎Once you get a good basic prototype working, then you can start adding extra features you wrote ‎down earlier.

This process of incrementally building up your project will make it come together more easily, and ‎most importantly, it’ll be more fun and less frustrating. And if you do get frustrated, take a break. ‎So, if you are a student, don’t wait until the last minute. You’d be surprised what fresh eyes can do ‎to improve your code.

Check out the rest of this series for even more information on building with Arduino.

制造商零件编号 A000066
ARDUINO UNO R3 ATMEGA328P BOARD
Arduino
制造商零件编号 2488
METRO ATMEGA328 W/HDR EVAL BRD
Adafruit Industries LLC
制造商零件编号 DEV-15123
REDBOARD QWIIC ATMEGA328 EVAL BD
SparkFun Electronics
制造商零件编号 102010026
SEEEDUINO V4.3 ATMEGA328P DEV BD
Seeed Technology Co., Ltd
制造商零件编号 FIT0096
BREADBRD TERM STRIP 3.20X2.00"
DFRobot
制造商零件编号 1449
SERVOMOTOR RC MICRO ANALOG PLAST
Adafruit Industries LLC
制造商零件编号 FIT0033
SERVO EXTENSION CABLE 300MM
DFRobot
制造商零件编号 P160KNP-0EC15A10K
POT 10K OHM 1/10W PLASTIC LOG
TT Electronics/BI
制造商零件编号 3013
EVAL BOARD FOR DS3231
Adafruit Industries LLC
制造商零件编号 102010428
SEEED STUDIO XIAO RP2040 ARDUINO
Seeed Technology Co., Ltd
制造商零件编号 FIT0624
INCLINED ELECTROMAGNETIC LOCK-12
DFRobot
制造商零件编号 4282
PIRTC - PRECISE DS3231 REAL TIME
Adafruit Industries LLC
制造商零件编号 TS14-1212-43-BK-160-SCR-D
SWITCH TACTILE SPST-NO 0.05A 12V
Same Sky (Formerly CUI Devices)
制造商零件编号 356
TRIMMER 10K OHM PC PIN TOP ADJ
Adafruit Industries LLC
制造商零件编号 30-81794
SENSOR RESISTIVE 3US ANALOG
Interlink Electronics
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum