user48276: So we were asked to do something with a force sensitive resistor so naturally i thought of a project which takes the name of the main component which is force and applies it ,mine works by as  you apply more and more pressure to the sensor it takes this value and displays it on an lcd but the display should be a bar graph which increases as the pressure increases. the problem is i dont really know how to do a bar graph on a 16x2 lcd. Please help. (my lcd has an I2c) 
here is my code for the pressure sensor so far
int fsrAnalogPin = 0; // FSR is connected to analog 0
int fsrReading;      // the analog reading from the FSR resistor divider

void setup(void) {
  Serial.begin(9600);  
}

void loop(void) {
  fsrReading = analogRead(fsrAnalogPin);
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
  delay(100);
}

ok so i improved my code and i finally got it this code displays the force detected by the fsr into a bar graph 
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LcdBarGraphX.h>
#include<LcdBarGraph.h>

byte lcdNumCols = 20; // -- number of columns in the LCD

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);   // -- creating LCD instance

int fsrAnalogPin = 0; // FSR is connected to A0

// -- creating a 4 chars wide bars
LcdBarGraphX lbg0(&lcd, 16, 0, 0); // -- First line at column 0 and row 0 with 16 columns

void setup(void) {
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
  lcd.begin(4, lcdNumCols); // start lcd with 2 rows and 16 columns
  lcd.clear();
  delay(100);
}

void loop(void) {
  lbg0.drawValue( analogRead(fsrAnalogPin), 9); // the 9  is the maximum range you want for pressure
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
  delay(100);
}


user39225: From the Library Manager, install the LcdBarGraphX library by Balazs Kelemen.
There are several examples there as well.

user4143: There's two ways you can do it: the easy way, and the fancy way.
The easy way really is easy.  Since the display can only display characters you just display characters - enough to represent a bar graph.
If you have a display with "Rom Code A00"* then character 255 is a solid block (▇) so you just print between 0 and 16 of them in a row.  0 is 0% and 16 is 100%. (If you have ROM Code A02 then you could just use #, or custom design a character - see below).
Force:▒▒▒▒▒▒▒▒▒▒
▇▇▇▇▇▇▇▇▇▒▒▒▒▒▒▒

Or with #:
Force:▒▒▒▒▒▒▒▒▒▒
#########▒▒▒▒▒▒▒

The fancy way is to use the programmable characters facility.  You would create 4 new characters that partially fill a block.  Each character is 5 pixels wide, so creating a character with 1 column of pixels set (▏), one with 2 set (▍), 3 set (▌) and 4 set (▋) (you already have all 5 set on in character 255 if you have ROM Code A00 - otherwise define a 5th with all 5 columns on).  Now you can be clever and work out:

How many full characters to print, and 
Which of the extra characters to print on the end.

That gives you effectively 16*5 (80) pixels of horizontal resolution (albeit with a small gap between each set of 5 pixels).
Exactly how you do whichever of those methods you choose is now up to you.

*: ROM Code A00 is the character ROM with Japanese characters in the characters 128-255.  ROM Code A02 has European accented characters instead.

48276: <p>So we were asked to do something with a force sensitive resistor so naturally i thought of a project which takes the name of the main component which is force and applies it ,mine works by as  you apply more and more pressure to the sensor it takes this value and displays it on an lcd but the display should be a bar graph which increases as the pressure increases. the problem is i dont really know how to do a bar graph on a 16x2 lcd. Please help. (my lcd has an I2c) </p>

<p>here is my code for the pressure sensor so far</p>

<pre><code>int fsrAnalogPin = 0; // FSR is connected to analog 0
int fsrReading;      // the analog reading from the FSR resistor divider

void setup(void) {
  Serial.begin(9600);  
}

void loop(void) {
  fsrReading = analogRead(fsrAnalogPin);
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
  delay(100);
}
</code></pre>

<p>ok so i improved my code and i finally got it this code displays the force detected by the fsr into a bar graph </p>

<pre><code>#include &lt;Wire.h&gt;
#include &lt;LiquidCrystal_I2C.h&gt;
#include &lt;LcdBarGraphX.h&gt;
#include&lt;LcdBarGraph.h&gt;

byte lcdNumCols = 20; // -- number of columns in the LCD

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);   // -- creating LCD instance

int fsrAnalogPin = 0; // FSR is connected to A0

// -- creating a 4 chars wide bars
LcdBarGraphX lbg0(&amp;lcd, 16, 0, 0); // -- First line at column 0 and row 0 with 16 columns

void setup(void) {
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
  lcd.begin(4, lcdNumCols); // start lcd with 2 rows and 16 columns
  lcd.clear();
  delay(100);
}

void loop(void) {
  lbg0.drawValue( analogRead(fsrAnalogPin), 9); // the 9  is the maximum range you want for pressure
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
  delay(100);
}
</code></pre>
 39225: <p>From the Library Manager, install the <a href="https://platformio.org/lib/show/681/LcdBarGraphX" rel="nofollow noreferrer">LcdBarGraphX</a> library by Balazs Kelemen.</p>

<p>There are several examples there as well.</p>
 4143: <p>There's two ways you can do it: the <em>easy</em> way, and the <em>fancy</em> way.</p>

<p>The easy way really is easy.  Since the display can only display characters you just display characters - enough to represent a bar graph.</p>

<p>If you have a display with "Rom Code A00"<sup>*</sup> then character 255 is a solid block (▇) so you just print between 0 and 16 of them in a row.  0 is 0% and 16 is 100%. (If you have ROM Code A02 then you could just use <code>#</code>, or custom design a character - see below).</p>

<pre><code>Force:▒▒▒▒▒▒▒▒▒▒
▇▇▇▇▇▇▇▇▇▒▒▒▒▒▒▒
</code></pre>

<p>Or with <code>#</code>:</p>

<pre><code>Force:▒▒▒▒▒▒▒▒▒▒
#########▒▒▒▒▒▒▒
</code></pre>

<p>The fancy way is to use the programmable characters facility.  You would create 4 new characters that partially fill a block.  Each character is 5 pixels wide, so creating a character with 1 column of pixels set (▏), one with 2 set (▍), 3 set (▌) and 4 set (▋) (you already have all 5 set on in character 255 if you have ROM Code A00 - otherwise define a 5th with all 5 columns on).  Now you can be clever and work out:</p>

<ol>
<li>How many full characters to print, and </li>
<li>Which of the extra characters to print on the end.</li>
</ol>

<p>That gives you effectively 16*5 (80) pixels of horizontal resolution (albeit with a small gap between each set of 5 pixels).</p>

<p>Exactly how you do whichever of those methods you choose is now up to you.</p>

<hr>

<p>*: ROM Code A00 is the character ROM with Japanese characters in the characters 128-255.  ROM Code A02 has European accented characters instead.</p>
