The Basics of Programming for Arduino

The Arduino programming language is based on an open source language called Wiring – it has a syntax similar to C. That fact may not be particularly interesting to a beginner, but for me it’s very significant. The first language I ever learnt was C. As an unguided 16 year old I naively googled “what’s the best programming language to learn first?”. This question illicits wholly different answers to the question “What’s the best programming language for beginners?” but in my ignorance I bought all £22 worth of ‘C for Dummies’, an 800+ page amalgamation of 6 C tutorial books and consumed the thing cover to cover. Since finishing that book, I’ve been looking for ways to apply this knowledge. So you can imagine my excitement to discover Arduino syntax was so similar. Anyway, that’s enough about me. Here’s what you really need to know.

The Arduino requires you use at least two functions in your sketch. These are setup() and loop().

setup()

The setup() does exactly what it says; it sets up the Arduino to do all the tasks you want it. This involves things like setting up pins as inputs and outputs that will later be used to control objects in the physical world. This function runs only once when the code is first loaded onto the board.

loop()

Once setup() has run, the second required function, loop() runs over and over and over until the arduino loses power or a new sketch is uploaded. loop() runs incredibly quickly. For a very simple sketch, it is called at a frequency of 130kHz – that’s 130,000 times each second. This is an important point to note; we’ll consider why when we write our first sketch.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s