Workshop 4 plan

  • Take a look at unit and see where this links up to Arduino stuff
  • A few words on IoT, beacons, RFID, OSC and linking to other software
  • A few words on digital LED strip
  • A few words on servo motors
  • A few words on 7 segment displays

'IF' control structures

  • paste the following code into your Arduino IDE and follow the instructions:

/* This code simply prints out the value of a potentiometer
 * on an analog pin. The potentiometer should have one side
 * to 5V, one side to GND, and the middle to analog in
 * pin 0. Once the sketch is uploaded, open the serial monitor
 * (top right button) to view the reading.
 * Look at the Arduino site reference page and the description of
 * the 'if...else' operator under the 'Structure' section. Use
 * this operator to also print 'left' or 'right' if the pot is
 * turned either side of the halfway mark:
 * The code is heavily commented to describe exactly what is going on
 * and all the other bits you need are there. Watch out for getting your
 * curly brackets in the right place and making sure you close them correctly. 
 * Check the error messages if things don't work!
 *  Luke Woodbury 17th March 2016

const int potPin = 0;  //define our pin for our pot, it won't change so is a const(ant) integer
int potVal;  //define a variable integer (whole number) to hold the value from the pot reading

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);  //start serial communication with the computer

void loop() {
  // put your main code here, to run repeatedly:
  potVal = analogRead(potPin);  //read the pot pin and store the incoming value in potVal

Serial.print("Pot Value = "); //print actual text with quotation marks
Serial.println(potVal);  //print out the value of potVal and follow with a line break (println)

  • Again, look at the Arduino Reference page, this time under the 'Math' section at the 'map' operator. This page gives you an example of how to scale one value to another, in this case an analogue input value to to a PWM output value. We used this in the fade example in Week 2, insert this into the code above and scale your pot output from 0 - 1023 to 0 - 255. 


Click on a link 

Exercise 1 - Digital LED strip and the 'for' loop

Exercise 2 - Servo motor and the 'if' statement

Exercise 3 - 7 segment display and the 'switch case' statement