I’m very new to Arduino but I’m trying to use it for a research project for school. I’m trying to record the resistance through a force sensitive resistor (FSR) on a micro sd card while also displaying that current resistance value on a 16x2 LCD screen.
I started at with these two attached diagrams, I used pin 10 instead of 4 for the sd card. I can get the LCD to display the resistance (and force with a calibration curve) on its own, but when I try to add the SD card & code, the LCD displays ‘ffffffffff’ or ‘333333’.
I think the problem has something to do with trying to use pins 11 & 12 for both the LCD and micro sd card, but I don’t know how else to set it up. Please help!!! Here is my current code;
// include the library code:
#include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>
const int chipSelect = 10;
const int FSR_PIN = A0; // Pin connected to FSR/resistor divider
// Measure the voltage at 5V and resistance of your 3.3k resistor, and enter
// their value's below:
const float VCC = 4.98; // Measured voltage of Ardunio 5V line
const float R_DIV = 3230.0; // Measured resistance of 3.3k resistor
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
Serial.begin(9600);
Serial.print("Initializing SD card...");
if (!SD.begin()) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
pinMode(FSR_PIN, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Start");
}
void loop() {
int fsrADC = analogRead(FSR_PIN);
// If the FSR has no pressure, the resistance will be
// near infinite. So the voltage should be near 0.
File myFile;
myFile = SD.open("test.txt", FILE_WRITE);
if (fsrADC != 0) // If the analog reading is non-zero
{
// Use ADC reading to calculate voltage:
float fsrV = fsrADC * VCC / 1023.0; // Volts
// Use voltage and static resistor value to
// calculate FSR resistance:
float fsrR = R_DIV * (VCC / fsrV - 1.0) / 1000; // kOhms
// calculate weight based on calibration
float fsrW = 401.58 * (1 / (fsrR)) - 1.35; // lbs
// print resistance & weight detected to LCD
lcd.print("R = " + String(fsrR) + " kOhms");
lcd.setCursor(0, 1);
lcd.print("W = " + String(fsrW) + " lbs");
// print weight to monitor
Serial.println(String(fsrW));
myFile.println(String(fsrW));
myFile.close();
delay(500);
lcd.clear();
}
else
{
//No pressure detected
lcd.print("No Resistance;");
lcd.setCursor(0, 1);
lcd.print("No Weight");
Serial.println("No Weight");
myFile.println("0");
myFile.close();
delay(500);
lcd.clear();
}
}