Introduction: Control Servo Arm Using Force Sensitive Resistor
Hello Makers,
I'm back with another cool Instructable.
This Instructable is part of a series of Instructables with the NodeMCU, my previous Instructables shows you how to Interfacing FSR with NodeMCU, and lots more. So make sure, you check that first before trying out this.
So, let's get started !!
Step 1: Components Needed
All That You Need.
Hardware Required
- NodeMCU
- FSR (Force Sensitive Resistor)
- Servo Motor
- 10K ohm resistor
- Bread Board
- Micro USB cable
- Connecting Wires
Software Required
- Arduino IDE (with ESP8266 Library installed)
Step 2: Descriptions
Servo motors are great devices that can turn to a specified position.
Usually, they have a servo arm that can turn from 0 - 180 degrees.
Generally FSR's are resistors that changes its resistance value (in ohms) depending on how much its force / pressure is applied on it.
Therefore, using NodeMCU, we control a servo arm to a specified position by applying force on FSR. As simple as that!
Step 3: Circuit Wiring
No soldering skills are required as we will be using a breadboard.
FSRconnections are pretty easy, see the circuit diagram.
Servo connections :
Orange wire connects to Digital pin D2.
Brown wire connects to GND pin.
Red wire connects to 3v3 pin.
Step 4: Coding Time
CODE
#include <Servo.h>
Servo servo; const int sensorOut = A0; // Pin A0 to read analog input //Variables: int pressure; //To store analog value
void setup(){ Serial.begin(9600); // Begin serial communication servo.attach(4); //D2 servo.write(0); delay(1000); }
void loop(){ pressure = analogRead(sensorOut); //Read and store analog value from Force Sensitive Resistance Serial.println(pressure); //Print value pressure = map(pressure, 0, 1023, 0, 180);//Map value 0-1023 to 0-255 (PWM) servo.write(pressure); delay(100); }
Download the "Control servo arm_FSR.ino" file and open it up in the Arduino IDE.
Then Create a new sketch and paste the code below in the Arduino IDE and hit Upload. You can tinker with it if you like based on the application, or just use it as it is.
Attachments
Step 5: Output
Using Serial monitor you can check the output from the analog pin connected to FSR.
Depending upon the pressure applied the Servo arm is turned.
That's all makers!
I hope you liked this, Stay Tuned for more Projects!