Arduino 101: Using a Force sensitive resistor to adjust an LED
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
- Force sensitive resistor
- LED
- Resistors (220 & 10k ohms)
- Breadboard
- Computer
- Jumper wires
- USB cable type A to B
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
Step 1: Gather the parts
- You can buy the components in your local electronics shop or you can order them online.
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.
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.
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.
Step 3: Programming
- Connect the arduino uno board to the computer using a USB type A to B cable.
Once connection is established, open the arduino IDE and go to Tools > Board: > then select Arduino/Genuino Uno.
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.
If no errors were found, press the Upload button to start the installation to the board.
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:
- Arduino 101: Using a Gas sensor module
- Arduino 101: Controlling a solenoid lock
- Arduino 101: Alcohol sensor circuit using MQ-3 module
- Arduino 101: Using 2 ultrasonic sensors and servo motor
Posted on Utopian.io - Rewarding Open Source Contributors
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
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
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