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:


4 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