0% found this document useful (0 votes)
10 views6 pages

10 Arduino Coding Tips - 2nd Edition

This document provides 10 essential coding tips for beginners using Arduino, emphasizing the importance of planning algorithms, memorizing key functions, and incremental design. It also highlights effective troubleshooting methods and the value of clear naming conventions and using functions to improve code readability. The tips aim to enhance the programming experience and success of Arduino projects.

Uploaded by

royaljillobalesa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

10 Arduino Coding Tips - 2nd Edition

This document provides 10 essential coding tips for beginners using Arduino, emphasizing the importance of planning algorithms, memorizing key functions, and incremental design. It also highlights effective troubleshooting methods and the value of clear naming conventions and using functions to improve code readability. The tips aim to enhance the programming experience and success of Arduino projects.

Uploaded by

royaljillobalesa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10 ARDUINO

CODING
TIPS
FOR
PROGRAMMING
BEGINNERS

Welcome
Are you a new programmer getting started with Arduino? Or maybe programming is
old hat, but you’re looking for a couple tips specific to the Arduino ecosystem?

Either way, you’re in the right place! The tips you’ll find here are designed to make your
Arduino programming journey easier, faster, and more fun.

We’re here to help


Since 2012, Programming Electronics Academy has been the premier online resource
for learning to program and build with Arduino. Thousands of members have trusted us
to guide them, and we’re proud to share the knowledge and best practices that make
Arduino projects successful.

We love hearing from our community! If you have a coding tip of your own, we’d be thrilled
to share it with our audience. Just send it to: contact@[Link].

Best of luck on your Arduino projects!


Michael J. Cheich
BEFORE CODING

1 Algorithm first
Every new programmer wants to start typing code. I get it, I love writing code too!
But the best place to start your new program is with a pencil and paper. Write down what
your program will do in a step by step fashion - you’ll be writing the algorithm if you do
this! Once you know what it is you need to code, now you can go implement that algorithm
in your Arduino program. But you say, “This is SUCH an easy sketch, I don’t need to waste
my time with an algorithm!” True, it may be a simple sketch you have in mind, but you’ll be
amazed what pops out when you take the time to write out the simple algorithm.

2 Know these Arduino Input/Output


and Serial Functions cold
There is a place for rote memorization. These are the Arduino functions
whose use you should have memorized:

Digital I/O: digitalRead(), digitalWrite(), pinMode()


Analog I/O: analogRead(), analogWrite()
Serial: [Link](), [Link](), [Link]()

3 Find an example sketch


There are so many example sketches out there - find one similar to what you want
to do, and study it! A great place to find example code is right inside the Arduino
IDE under File > Examples. Here you can find examples for all the basic Arduino
functions and most of your installed Arduino libraries.

3
WHILE YOU CODE

4 Incremental Design - always!


One small thing at a time! That goes for code and circuits. Don’t wire up two circuits and then test that they
both work. Wire up one circuit, and test that it works. Then, add the second circuit and test that it works
too! Are you building a wireless temperature sensor? Great. First use a simple example sketch to test that
you can actually read the temperature probe all by itself. Then, in a separate example sketch, see if you can
establish the simplest WiFi connection with your microcontroller. Don’t try doing it all at once - you’ll give
yourself a headache quickly and spend more time hunting errors than actually building your project!

5 Verify, verify, verify


How can you code better? Find your errors faster! You should verify your sketches
frequently. I verify after every line of code I write. Every line. Why? Because I screw up all
the time and I have been programming Arduino for years. If you verify frequently, you may
catch your errors more quickly, and end up with better code.

6 Naming is more important than you think


Any time you’re going to give something a name, pretend you’re naming a baby. What will your friends
say if you name your baby “dip”? Wouldn’t a more proper name be “David Isac Powers”? The same is true
of the names you give your code. What does the variable name tsBT mean to your friends? Wouldn’t
tempSensorBottomTank be a whole lot more descriptive? The latter sure gives a whole lot more detail,
and your friends might not accidentally think it means tankSensorBottomThreshold. A great resource for
thinking about naming is Robert C. Martin’s book Clean Code.

7 Use functions
If you’re brand new to programming and Arduino, you may not be writing your own functions.
Writing functions can make your code more concise, easier to read, and simpler to update.
What code should you turn into functions? Look for sections of code that are repeated often
in your sketch, could this code be turned into a function?

4
TROUBLESHOOTING

8 Hardware vs Software
The age old query of Arduino users after a prototype fails to work…”Is it my circuit
or my code?” This is a very legitimate question - and the quicker you answer it, the
quicker you’ll find your error. First, can you get your circuit to work with the simplest
possible code (remember the incremental design step from above!)? Upload a simple
sketch and check. Still not working? Double check all your hardware connections.
If your hardware works with a simple sketch, it is likely not a circuit, or an Arduino
board issue, and more likely a code/algorithm issue.

9 Print that thing


Wondering why an if statement doesn’t seem to work? Or why your while loop
only runs once? The Serial library print function is a great tool for seeing what’s
up with your code. Write out a simple [Link](valueThatIWantToKnow)
inside the offending code block, open your serial monitor window, and see
where your code took a misstep.

10 Tell a duck
Get a rubber duck. Put it next to your computer. When you run into
an issue with your code, tell your duck exactly what you are doing.
Go through your code in excruciating detail with the duck. At some
point while explaining to your duck what your code is doing, you’ll be
surprised to realize maybe your code isn’t doing what you think after all.
Apparently ducks are real smart coders - go figure!
[Link]

5
Copyright © 2025 by Programming Electronics Academy

You might also like