Link to lab: https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/analog-in-with-an-arduino/
Circuit with a potentiometer and LED setup (220-ohm resistor and LED in series), where the potentiometer’s middle pin is connected to the input to the LED setup.
The same circuit as the one to the left, but this time the potentiometer’s middle (output) pin and the input to the LED setup are both connected to the Arduino, which handles reading the input from the potentiometer and adjusting the output to the LED accordingly
Since I’m not using the IDE, I needed another way to access the serial port output. On the suggestion of the Ardino CLI FAQ, I used screen, which comes build in on my Mac. This article was quite helpful in figuring out how to set it up. I also learned in my searching, from this post, that the port can only be accessed by one thing at a time, so I need to close the screen window (or whatever I am using) before uploading to the board.
For figuring out the range for the force-sensitive resistors, it was hard to read all the numbers flashing by, so after my first try, I modified the code to kept track of the maximum reading and print that out instead (I noticed the minimum was still around 0). I ended up getting 990 as the maximum.
// sketch for determining sensor value range coming from force-sensing resistors
// for lab:<https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/analog-in-with-an-arduino/>
using namespace std;
const int redLED = 9; // pin number for red LED
const int whiteLED = 8; // pin number for white LED
int sensorValA = 0;
int sensorValB = 0;
int brightness = 0;
int highestValue = 0;
void setup() {
Serial.begin(9600);
pinMode(redLED, OUTPUT);
pinMode(whiteLED, OUTPUT);
}
void loop() {
// set analogValue
sensorValA = analogRead(A0);
sensorValB = analogRead(B0);
// when a new high value is detected, reset highestValue
int higherValue = max(sensorValA, sensorValB);
if(higherValue > highestValue) {
highestValue = higherValue;
}
// print current highest value
Serial.println(highestValue);
}
I noticed that the red LED dims when its input varies, but the white just turns on and off — I tried switching the inputs just to check it wasn’t something with the programming, and the result was the same. I wonder why this is.
Using force-sensitive resistors to control two LEDs using an Arduino.
Using force-sensitive resistors to control two LEDs using an Arduino.