Writing code

Arduino sketches are written in C. Much to the derision of my colleagues, I always resisted learning the C language. I had to learn it for Arduino and now wonder why I was so stupid. Anyone who has ever coded will find the Arduino software really easy.

If you have never written computer code (sometimes called programming) you will need to pick it up. Actually doing it in Arduino is an excellent way to learn it. There is no debugging facility. However you can get the code to send test data to your computer screen, so you get clues when you do something wrong and can see the effects of your code immediately. There are libraries of ready-written code both within the Arduino software and on the website and forums. You will normally need to adapt the sketch to do exactly what you want but this is a great learning experience. The only things you might need to take time out to learn are the code structures such as loops and decision making. If you've got a working brain you'll soon pick it all up.

There are three sections to an Arduino sketch:

define where you name the pins

setup where you say what the pins are to be used for and say what data variables you want

loop where you write the active code



(C) Peter Scott 2012

Last edit 23 December 2015