Figure 1: Force Sensor
Step 1: >Connection from Sensor to Arduino Mega 2560.
- Connect the sensor first pin to the Analog pin of Ao to the board
- Connect the sensor second pin to the 5v of the board.
Step 2: Connection from LED to Arduino Mega 2560.
- Connect the positive pin to the digital pin of 03 to the board.
- Connect the negative pin to the Gnd of the board.
Programming
- int ledpin = 3;
- int sensorPin = A1;
- int value;
- void setup()
- {
- pinMode(ledpin, OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- value = analogRead(sensorPin);
- Serial.println(Force: );
- value = map(value, 0, 1023, 0, 255);
- Map value 0 - 1023 to 0 - 255(PWM)
- analogWrite(ledpin, value);
- delay(100);
- }