Saturday, June 4, 2016

Force Sensor: Code and Wiring



Code:


int pressurePin = A0;
int force;
int LEDpin = 12;
void setup() {
Serial.begin(9600);
pinMode(LEDpin, OUTPUT);
}
void loop() {
  force = analogRead(pressurePin);
  Serial.println(force);
if(force > 500)
{
  digitalWrite(LEDpin, HIGH);
}
else
{
  digitalWrite(LEDpin, LOW);
}
delay(100);
}





Wiring Diagram:


8 comments:

  1. Hey Sam I want it to trigger a tone... any suggestions...

    ReplyDelete
    Replies
    1. If you still need help on this problem instead of the led you would just create a variable for the tone. Instead in the if then statement you would use your tone, hope this helps.

      Delete
  2. Hello sam, thanks for the video its crisp and clear.
    I am a beginner and i would be very grateful if you could help me out here, I want to connect 4 FSR's and 4 led's to the arduino just like you did for one.
    Can you give a code for that please.

    ReplyDelete
  3. Dude, you are my hero! Thank you for the video and the blog post!!!!

    ReplyDelete
  4. Hi, Can you send me a link of the parts you used in this project?

    ReplyDelete
  5. i plug program in and its saying there is a problem

    ReplyDelete
  6. Is there a way to set the project up with more LEDS? I want to be able to measure the different levels of force by three different colors coming on. EX:if(force > 500){ write.LEDpin,Red) BUT if(force < 500){digitalwrite. LEDpin,Yellow) BUT if(force < 250) {digitalwrite. LEDpin, Green). Also, is there a way to extend the force sensor so that its able to connect to something? (how can I correctly write the example code listed above)

    ReplyDelete