/IDD-Fa19-Lab3

Developing-and-Designing-Interactive-Devices -- template for Lab 3

Primary LanguageC++

Data Logger (and using cool sensors!)

A lab report by Meera Nanda.

In The Report

For this lab, we will be experimenting with a variety of sensors, sending the data to the Arduino serial monitor, writing data to the EEPROM of the Arduino, and then playing the data back.

Part A. Writing to the Serial Monitor

a. Based on the readings from the serial monitor, what is the range of the analog values being read?
0-1023

b. How many bits of resolution does the analog to digital converter (ADC) on the Arduino have?
10 bits.

Part B. RGB LED

How might you use this with only the parts in your kit? Show us your solution.
I used this as an indicator of success or failure in a Whack-A-Mole game. This required one resistor connected to each pin of the RGB LED (except the common anode), and then each RGB pin in turn connected to pins 9, 10 and 11 of the Arduino. I then programmed the Arduino to send values to each pin to turn it red or green depending on whether the user was successful or not. Below is a video of the Whack-A-Mole game running with the RGB LED, and a video of the LED running through all colors.

See Whack-A-Mole Video
See RBG LED Video

Part C. Voltage Varying Sensors

1. FSR, Flex Sensor, Photo cell, Softpot

a. What voltage values do you see from your force sensor?
The range I saw went from 0 to approximately 1000.

Lightly touching ~ 300-400
Pressing ~ 900
Full force ~ 1000

See FSR Video

b. What kind of relationship does the voltage have as a function of the force applied? (e.g., linear?)
The voltage appears to have a logarithmic relationship to the force applied. As the force increases, the resistance decreases and therefore the voltage increases. Below is a graph describing this relationship (sourced from the FSR datasheet).

FSR Voltage by Force Graph

c. Can you change the LED fading code values so that you get the full range of output voltages from the LED when using your FSR?
If we want to change only the brightness of the LED, then the code needs to include a map function to take in the FSR reading and translate it to a value between 0-255, as seen below:

brightnessValue = map(fsrValue, 0, 1000, 0, 255);

If we want to use the FSR to control the colors of the RGB LED, then the mapping needs to translate the FSR reading to a value between 0-765 (255 * 3) in order to write a range of 0-255 per RGB pin, as shown below:

rgbValue = map(fsrValue, 0, 1000, 0, 765);

Then the values from 0-255, 256-510 and 511-765 will be written to the pins for red, green and blue respectively.

See complete code here
See FSR Controlling RBG LED Video

d. What resistance do you need to have in series to get a reasonable range of voltages from each sensor?
Around 10k ohms in series for each sensor allows for a reasonable range of voltages. This was referenced from the datasheets for each sensor.

e. What kind of relationship does the resistance have as a function of stimulus? (e.g., linear?)
Photoresistor - logarithmic: as light increases, resistance decreases.
Flex sensor - linear: as the bending angle increases, the resistance increases.
Soft pot - linear: resistance increases/decreases depending on the direction you move the position in.

See Photoresistor Video
See Flex Sensor Video
See Soft Pot Video

2. Accelerometer

a. Include your accelerometer read-out code in your write-up.
Accelerometer Read-Out Code

See Accelerometer Video
See Accelerometer Controlling RGB LED Video
See Accelerometer Readings on LCD Video

Optional. Graphic Display

Take a picture of your screen working insert it here!
Below is an image of the reading from an FSR on the Graphic Display. Working Screen

See Graphic Display Video
See A0 Readings on Graphic Display Video

Part D. Logging values to the EEPROM and reading them back

1. Reading and writing values to the Arduino EEPROM

a. Does it matter what actions are assigned to which state? Why?
In this example it does matter because the reading, writing and clearing of the EEPROM has to happen in the correct order. If, for instance, you clear something that has been written to the EEPROM before it is read, then your code will not function as planned.

b. Why is the code here all in the setup() functions and not in the loop() functions?
Because we want to perform each action once and not loop through it continuously.

c. How many byte-sized data samples can you store on the Atmega328?
1024 bytes.

d. How would you get analog data from the Arduino analog pins to be byte-sized? How about analog data from the I2C devices?
Analog data from the Arduino analog pins are 10 bits, so in order for it to be byte sized we will need to divide by 4, or use a mapping function to translate the value to a number between 0-255. I2C devices already send only 8 bits (1 byte) of data at a time.

e. Alternately, how would we store the data if it were bigger than a byte? (hint: take a look at the EEPROMPut example)
You could store the data at different addresses in the EEPROM by seperating it into byte sized groups.

Upload your modified code that takes in analog values from your sensors and prints them back out to the Arduino Serial Monitor.

Updated EEPROM Code

Serial Moniter Output: EEPROM Monitor Screenshot

2. Design your logger

For my logger, I created a night light that works with a photoresistor. Below is the state diagram:

a. Insert here a copy of your final state diagram. Night Light State Diagram

3. Create your data logger!

a. Record and upload a short demo video of your logger in action.
Night Light Code
Night Light Video