Flex sensors problem with arduino uno without breadboard

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);
}

Welcome to the forum

Why did you start a topic in the Uncategorised category of the forum when its description is

:warning: DO NOT CREATE TOPICS IN THIS CATEGORY :warning:

Your topic has been moved to the Programming category

1 Like

arduino is not power source. connect LCD proper.

1 Like

I moved it, it still doesn't work. the display is off and does not turn on

show

why you try to invent new combination of wrong connection?
you able to use ISP pins, they contain +5V and GND too.

I don't know what the pins are


what do I change in the code?

try that sketch now, with all current connections. is LCD still show proper ?
and if you want i look into your code - embed it as code.

1 Like

it still doesn't work, the display stays on but doesn't show anything
`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);
}`

go to ide, right click> point "copy for Forum"> left click
edit your post > delete everything > right click> point "paste"> left click

1 Like

disconnect usb, connect usb, do you see one line full of blocks on LCD?

1 Like

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);
}

yes

lcd.init();

Thank you! now it lights up and displays the LCD correctly, only it doesn't measure anything no matter how much I move the sensors and it only shows -63 degrees. do you think you could help me with this too?

now it looks like this, but no matter how much I move the sensors, nothing changes

#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
const int FLEX_PIN_1 = A0; // Pin connected to voltage divider output
const int FLEX_PIN_2 = A1; // Pin connected to voltage divider output

void setup() {
  lcd.init();
}

void loop() {
  lcd.setCursor(0, 0);
  lcd.print(analogRead(FLEX_PIN_1));
  lcd.print("   ");
  lcd.setCursor(0, 1);
  lcd.print(analogRead(FLEX_PIN_2));
  lcd.print("   ");
  delay(200);
}

show schematic how you wired that sensors.

1 Like

black wires-gnd
white wires- , the signal -a1,10
and the brown wires are for 5v