Copy and paste the code below into a blank Arduino sketch. Then compile and upload it to your Metro.
/* * Force Sensitive Resistor Test Code * * The intensity of the LED will vary with the amount of pressure on the sensor */ int sensePin = 2; // the pin the FSR is attached to int ledPin = 9; // the pin the LED is attached to (use one capable of PWM) void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT } void loop() { int value = analogRead(sensePin) / 4; //the voltage on the pin divded by 4 (to //scale from 10 bits (0-1024) to 8 (0-255) analogWrite(ledPin, value); //sets the LEDs intensity proportional to //the pressure on the sensor Serial.println(value); //print the value to the debug window }
LED Not Lighting Up?
LEDs will only work in one direction. Try taking it out and twisting it 180 degrees. (no need to worry, installing it backwards does no permanent harm).
Fading to Fast/Slow
This is a result of the FSR’s response to pressure not being quite linear. But do not fear it can be changed in code (check out the details in the Making it Better section)
Page last edited January 22, 2025
Text editor powered by tinymce.