Arduino 101: Using a Force sensitive resistor to adjust an LED

in #utopian-io6 years ago (edited)

What Will I Learn?

  • You will learn the basic working principle of a force sensitive resistor and how to use it properly.
  • You will learn how to integrate the force sensitive resistor with the arduino.
  • You will learn how to program the arduino board with this sensor using the arduino IDE.

Requirements

Hardware

  • Arduino Uno

image.png

Image source

  • Force sensitive resistor

image.png

Image source

  • LED

image.png

Image source

  • Resistors (220 & 10k ohms)

image.png

Image source

  • Breadboard

image.png

Image source

  • Computer

image.png

Image source

  • Jumper wires

image.png

Image source

  • USB cable type A to B

image.png

Image source

Software

  • Arduino software / Arduino IDE

Knowledge

  • Basic electronics and programming knowledge

Difficulty

  • Basic

Project description

  • This is a simple project uses a force sensitive resistor that is controlled by the arduino uno board to adjust the brightness of the LED. Once force is exerted in the FSR, its resistance value would change thus changing the brightness of the LED. If the FSR is not pressed, its resistance is infinite meaning no voltage and current could pass through it thus the LED will not light up but when a force is applied to the FSR, its resistance will decrease depending on how strong the force is, if it is applied with minimum force the LED's light will be dim but when it is applied with greater force its resistance would decrease a lot and would brighten up the LED.

Component description

Arduino Uno - a type of arduino board that is regularly used by specialist and hobbyist because of its robust design. It is equipped with a microcontroller board that is based on ATMega328P with 14 advanced I/O pins (6 are PWM outputs), 6 analog inputs, 16 Mhz quartz crystal, a power jack, a USB port, an ICSP header and a reset button.

Force sensitive resistor - is sensor that allows you to detect physical pressure, squeezing and weight. It is simple to use and low cost. It is basically special type resistor that will change its resistance value once force is applied to it.

Tutorial Contents

Using a Force sensitive resistor to adjust an LED

Step 1: Gather the parts

  • You can buy the components in your local electronics shop or you can order them online.

image.png

Step 2: Construct the circuit

Connect the Sources

  • Connect the 5V pin of the arduino uno board into the top/bottom slot of the breadboard. The connections here are horizontally connected making it an ideal spot for the sources.
  • Connect the GND pin of the arduino uno board into the top/bottom slot of the breadboard but make sure not to short them out to avoid damage to the board.

image.png

Connect the sensor

  • Connect the other end of the sensor to the voltage source(+) in the breadboard.
  • Connect a 10 kilo ohms pull-down resistor to the other end of the sensor and connect it to the ground. This pull-down resistor will help give a reasonable amount of range over the operation of the sensor.
  • Connect that same connection into the analog pin A0 of the arduino uno board.

image.png

Connect the LED

  • Connect the anode(+) of the LED to a 220 ohm resistor that is connected to pin number 5 of the arduino uno board. This resistor will protect the LED from over supply of current.
  • Connect the cathode(-) of the LED to the common ground.

image.png

Step 3: Programming

  • Connect the arduino uno board to the computer using a USB type A to B cable.
    image.png

Image source

  • Once connection is established, open the arduino IDE and go to Tools > Board: > then select Arduino/Genuino Uno.
    image.png

  • Copy the codes below into your sketch in the arduino IDE.


const int led = 5;     //sets the led pin @pin 5 
const int FSRanalogpin = A0; //sets the FSR analogpin A0 to read analog input
int value; //saves the analog value
void setup(){
  pinMode(led, OUTPUT);  //Sets led @pin 5 be the OUTPUT 
}
void loop(){ 
  value = analogRead(FSRanalogpin);       //This will read and save the analog value from potentiometer
  value = map(value, 0, 1023, 0, 255); //This will map the value from 0-1023 to 0-255 (PWM)
  analogWrite(led, value);          //Sends the PWM value to led
  delay(100);                          //Delay of 100 milliseconds 
}

What this code does is very simple, first is sets the pins of the LED and FSR. Then it sets the LED as the OUTPUT. In the loop command, it sets the 'value' to read the inputs from the FSRanalogpin and map those values from 0-1023 to 0-255 then the analogWrite will send the PWM values to the LED with a delay of 100 milliseconds.

  • After typing the code into your sketch, click the Verify button to save and compile the code. This will also check for any errors in the code.
    image.png

  • If no errors were found, press the Upload button to start the installation to the board.

image.png

Step 4: Testing

  • After the installation has finished, remove the arduino uno board from the computer and connect it with a battery pack to power it up.
  • Now, after the arduino boots up and no force was applied to the FSR then the LED should not light up because the resistance of the FSR is at its maximum.
  • Apply a little force to the FSR by squeezing it a bit, this should light up the LED slightly.
  • Now squeeze it even more, this should brighten up the LED as you continue to squeeze the FSR.
  • If nothing is working, redo the previous steps carefully and make sure to follow the instructions correctly.

Curriculum

Here are my other Arduino tutorials that you might find interesting:



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thanks a lot man😄

Hey @ted7 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.030
BTC 70971.83
ETH 3830.80
USDT 1.00
SBD 3.41