Lab 4 — Sensing: Force sensors and photocells

J M
5 min readOct 2, 2021

Joanne Ma. Professor Kimiko Ryokai. Info C262, Fall 2021

Description

I was really looking forward to working on this week’s lab because I’ve been wanting to learn how to use a force sensor for a potential final project application (or just a fun chaotic project where force is applied to a vessel and used to control a video playback speed).

Components Used

  • arduino
  • breadboard
  • jumper wires
  • resistors, 10k and 200k
  • photocell
  • force-sensitive resistors (fsr)

Part 1 — Photocells

I spent way too long on this section. I first tried to modify last week’s lab by replacing the potentiometer with the photocell, but for some reason, the LEDs were not working correctly. This made me worried that I added the photocell incorrectly and somehow ruined the circuit even after following the circuit diagram. I reconstructed my circuit and changed the pins to make sure it was not because there were loose connections, and that the LEDs haven’t been damaged. It seems like I’ve been pretty unlucky with my breadboard’s QC. After taking a dinner break, the LEDs decided to light up and I knew my circuit was wired correctly.

For whatever reason, when you need electronics to work the most, they will always find weird ways to fail you. I’ve narrowed down the issue to the breadboard, which I will be either using a multimeter to find bad connections (thank you to my friend Michelle for this suggestion!) or replacing the breadboard entirely. Luckily, I was able to see changes in the serial monitor when I hovered my finger over the photocell, which meant things should be working. However, it still seems like the photosensor is not being really responsive to hovering fingers or phone flashlights. My goal this weekend is to troubleshoot this with either Tonya or Zeke if they have surprise lab hours.

Photcell circuit setup

Part 2 — Force Sensitive Resistor (FSR)

I used the same setup and swapped out the photocell with the FSR. I ran the example code provided by the lab. I ran into the same issue, where the FSR barely registers on the analog monitor, but the LED does not change.

FSR Setup w/ LED to dim

Part 3 — Processing

I downloaded Processing, which was the part of the lab I was looking forward to the most. The idea that we can create really beautiful visuals with a relatively lower learning curve is really exciting to me. I tried out the RadialGradient and Brightness example.

Part 4 — More Processing

I downloaded Firmata and made sure to move the Arduino folder into the libraries sub-folder of processing. Then, I uploaded the StandardFirmata sample code to make sure Arduino and Processing were talking to each other! Unfortunately, it seems like the USB port was not being detected by Arduino, so running StandardFirmata was not successful. I tried to run it again by closing the sample code I had open on Processing, to no success. I swapped the USB port, to again, no success. I guess all pieces I needed to verify in lab didn’t work out, so I hope to be able to continue working on this so I can have fun with all the cool sensors. Onwards!

Part 4.1

Annnnd we’re back! Turns out, my sensors were having trouble reading properly. Thanks to Zeke for making sure that my photocell and my force sensor were reading in correctly, and for letting me borrow his force sensor — it turns out that both were not at the correct sensitivity, which is why when I was trying to make sure my circuit and sensors worked with the LED, the LED did not really dim or brighten correctly. We basically went through parts 1–4 to make sure everything was in working order before attempting modifying the code to make a new processing visualization.

Photocell working

FSR working

Processing code for pulsing circle that changes hues

/*
arduino_input
Demonstrates the reading of digital and analog pins of an Arduino board
running the StandardFirmata firmware.
To use:
* Using the Arduino software, upload the StandardFirmata example (located
in Examples > Firmata > StandardFirmata) to your Arduino board.
* Run this sketch and look at the list of serial ports printed in the
message area below. Note the index of the port corresponding to your
Arduino board (the numbering starts at 0). (Unless your Arduino board
happens to be at index 0 in the list, the sketch probably won't work.
Stop it and proceed with the instructions.)
* Modify the "arduino = new Arduino(...)" line below, changing the number
in Arduino.list()[0] to the number corresponding to the serial port of
your Arduino board. Alternatively, you can replace Arduino.list()[0]
with the name of the serial port, in double quotes, e.g. "COM5" on Windows
or "/dev/tty.usbmodem621" on Mac.
* Run this sketch. The squares show the values of the digital inputs (HIGH
pins are filled, LOW pins are not). The circles show the values of the
analog inputs (the bigger the circle, the higher the reading on the
corresponding analog input pin). The pins are laid out as if the Arduino
were held with the logo upright (i.e. pin 13 is at the upper left). Note
that the readings from unconnected pins will fluctuate randomly.

For more information, see: http://playground.arduino.cc/Interfacing/Processing
*/
import processing.serial.*;import cc.arduino.*;Arduino arduino;// Change this pin number to match where you actually have an LED in your
// circuit
int ledPin = 9;
// Change this pin number to match where you actually have a pot in your
// circuit. Note that pin 0 is the same as pin A0, pin 1 is same as A1, etc.
int potPin = 0;
void setup() {
size(500, 500);
colorMode(HSB, 1023, 100, 100);
// Prints out the available serial ports.
println(Arduino.list());

// Modify this line, by changing the "0" to the index of the serial
// port corresponding to your Arduino board (as it appears in the list
// printed by the line above).
arduino = new Arduino(this, Arduino.list()[2], 57600); //modified to change serial port to usb

// Alternatively, use the name of the serial port corresponding to your
// Arduino (in double-quotes), as in the following line.
//arduino = new Arduino(this, "/dev/tty.usbmodem1411", 57600);

arduino.pinMode(ledPin, Arduino.OUTPUT);
}
void draw() {
// We can control the Arduino from Processing
int potVal = arduino.analogRead(potPin);
//int ledBrightness = int(map(potVal, 0, 1023, 0, 255));
// arduino.analogWrite(ledPin, ledBrightness);

// We can also draw to the Processing window
// setting the background to black (red = 0, green = 0, blue = 0)
background(0,0,0);
// pick up the white paintbrush (red = 255, green = 255, blue = 255)
// the next shape we draw will have white color fill
//fill(255, 255, 255);
// potentiometer 0-123,
fill(potVal, 80, 100, 85);

// try setting fill to hue saturation lightness value; make the hue equal to value read from force sensor
// Draw a circle at the center of the window, whose size changes with the potVal
ellipse(width/2, height/2, potVal/3, potVal/3);
}

--

--

J M

Grad student @ UC Berkeley’s School of Information. Interests include social computing, usable security, Being Online™️ and reflective tech.