Using the Recipes

The example recipes in the Physical Computing section provides a set of suggested usage scenarios, along with wiring and code samples to get going.

Recipes have been written primarily for the Arduino UNO R3 platform in mind. Additional platforms may be available for some of these projects, found under the tabs of each recipe page.

Each recipe has two core sections – Wiring and Coding. Where appropriate, a Libraries section provides a list of code libraries needed to be installed for the code to compile.

Wiring

For Wiring, breadboard diagrams are provided, and where available, a link to the source Fritzing file is shared. If you are familiar with the Arduino, you will find that it translates easily to other ‘Arduino-like’ variants. More recipes will slowly get restored from the older build over time.

These images can be enlarged by clicking on them. In addition, download links to the Fritzing file are also available via blue download buttons that look like this:

Download Sample Fritzing file

Libraries

If a component requires that you install one or more code libraries before you can compile and upload the code to your microcontroller, it will be listed here, for example:

  • Sparkfun Ambient Light Sensor Arduino Library

For the Arduino IDE, follow these instructions to learn how this is done. Generally, copy and paste the library name into the search field of the Library Manager and click on the Install button for the found library.

Code

The Code section details the actual code – you can do a copy and paste directly into the IDE to test. When you move your mouse pointer to the upper right corner of the code box, click the clipboard icon to copy all of the code.

Most sections have been commented – read along and try things out.

Where possible, parameters have been made available using C preprocessor statements (those #define lines) and/or other variables, these are declared at the top of the sketch for easy access. Experiment and adjust these values – read the comments to know the valid ranges!


Example of Sample Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// SKETCH COMMENTS etc

// [BEGIN PARAMETERS]
#define SOME_PIN       A0           // analogue input pin A0
#define ANOTHER_PIN    2            // digital pin 2
int sensorVal = 0;                  // this is a variable; we use this to keep track of numerical values in our code (see line 18)
bool isReadyForCoffee = true;       // another comment to describe what this does
// [END PARAMETERS]

void setup() {                      // runs once at startup
    ...
}

void loop() {                       // runs forever
    // sometimes there might be customisable options here – read the comments
    ...
}

Serial Port Printouts

In addition, most recipes use the Serial port to print out relevant readings.

You can use built-in Serial utilities such as the Arduino IDE’s Serial Monitor / Plotter, or any Serial port monitoring software such as Roger Meier’s CoolTerm.

Generally, the Serial baud rate is set to 115200bps – check the code to find out what to use.


This page was last updated: 23 Sep 2024