Hi. I have a big problem and I need help. my project is a collar that includes 2 flexion sensors placed on the neck inside the collar and connected to the arduino uno board. I would like the angles to be displayed on the i2c lcd. I wrote the code but when I run it nothing happens, the display stays off and nothing happens. I checked the cables, the power supply and the display. the lcd display works without the sensors connected to the board. can you help me ? this is how they are connected and this is the code.
const int FLEX_PIN_1= A0; // Pin connected to voltage divider output
const int FLEX_PIN_2= A1; // Pin connected to voltage divider output
// Measure the voltage at 5V and the actual resistance of your
// 47k resistor, and enter them below:
const float VCC = 4.70; // Measured voltage of Ardunio 5V line
const float R_DIV_1 = 10000.0; // Measured resistance of 3.3k resistor
const float R_DIV_2 = 10000.0; // Measured resistance of 3.3k resistor
// Upload the code, then try to adjust these values to more
// accurately calculate bend degree.
const float STRAIGHT_RESISTANCE = 37300.0; // resistance when straight
const float BEND_RESISTANCE = 90000.0; // resistance at 90 deg
const int LCD_Vcc = 11;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(FLEX_PIN_1, INPUT);
pinMode(FLEX_PIN_2, INPUT);
pinMode(LCD_Vcc, OUTPUT);
digitalWrite(11, HIGH);
}
void loop()
{
// Read the ADC, and calculate voltage and resistance from it
int flexADC_1 = analogRead(FLEX_PIN_1);
int flexADC_2 = analogRead(FLEX_PIN_2);
float flexV_1 = flexADC_1 * VCC / 1023.0;
float flexV_2 = flexADC_2 * VCC / 1023.0;
float flexR_1 = R_DIV_1 * (VCC / flexV_1 - 1.0);
float flexR_2 = R_DIV_2 * (VCC / flexV_2 - 1.0);
Serial.println("Resistance: " + String(flexR_1) + " ohms");
Serial.println("Resistance: " + String(flexR_2) + " ohms");
digitalWrite(LCD_Vcc, HIGH);
lcd.setCursor(0,0);
// Use the calculated resistance to estimate the sensor's
// bend angle:
float angle_1 = map(flexR_1, STRAIGHT_RESISTANCE, BEND_RESISTANCE,
0, 90.0);
Serial.println("Bend: " + String(angle_1) + " degrees");
Serial.println();
// bend angle:
float angle_2 = map(flexR_2, STRAIGHT_RESISTANCE, BEND_RESISTANCE,
0, 90.0);
Serial.println("Bend: " + String(angle_2) + " degrees");
Serial.println();
lcd.print("Bend: " + String(angle_1) + " degrees");
lcd.setCursor(2,1);
lcd.print("Bend: " + String(angle_2) + " degrees");
lcd.setCursor(0,2);
delay(500);
}