❏ Do not dismantle this circuit since it will be reused in
Lab 4: Store Dial Data
if(c == 's') // show the calibration values
if(c == 'r') // read the dial angle
int val = analogRead(sensorPin);
val = map(val,zero,oneeighty,0,180);
// show the angle
// show calibration values on power up
// get zero from EEPROM by multiplying by 4
// to restore the 16 bit value (induces some
zero = retrieveIntEEPROM(ZERO_ADDRESS);
Serial.print("zero = ");
We will now use the potentiometer dial circuit to
generate some test data that we will use in Lab 6 to
display on the PC. The source code will allow us to slowly
move the potentiometer from zero to 180 and back again
several times over 10 seconds. We will record the sensor
data 10 times a second, giving us 100 data points. If you
move the potentiometer smoothly, you should get an
approximation of a sine wave in this data set. This lab
reuses the code from Lab 3, adding the steps to read the
dial for 10 seconds and send the data to the PC. Since all
the code is the same except for these two things, only the
newly added code will be shown.
1 USB cable
1 Arduino proto shield and jumper wires
// get oneeighty from EEPROM
oneeighty = retrieveIntEEPROM
Serial.print("oneeighty = ");
1 100 Ω resistor
1 Pot dial angle image
Estimated time for this lab: 15 minutes
Check off when complete:
❏ We will reuse the circuit we built for Lab 3.
❏ Compile and upload the code.
❏ Open the serial monitor.
❏ Note that the start-up calibration values are random
reads from the EEPROM.
❏ Set the pot angle to degrees and enter 'z' in the serial
❏ You can either modify the
A101_ch12_EEPROM_dial_calibration.ino from Lab 3 as
will be shown below or you can load the full source
code by opening the
❏ To modify the
❏ Set the pot angle to 180 degrees and enter 'o' in the
A101_ch12_EEPROM_dial_calibration.ino code, we first
add this to the top:
❏ Enter 's' to view the date stored in the EEPROM.
❏ Enter 'r' and note the angle displayed.
❏ Move the dial several times entering 'r' each time and
verify that the results are similar to those in Figure 10.
#define DATA_ADDRESS 4 // start address after
the calibration values
In the setup() function we add:
In the loop() function in the commands list we
58 January 2015