/* How to use a Force sensitive resistor to fade an LED with Arduino More info: http://www.ardumotive.com/how-to-use-a-force-sensitive-resistor-en.html Dev: Michalis Vasilakis // Date: 22/9/2015 // www.ardumotive.com */ #include //Constants: const int ledPin = 3; //pin 3 has PWM funtion const int sensorPin = 4; //pin 4 to read analog input SoftwareSerial mySerial(ledPin, sensorPin); //Variables: int value = 100; //save analog value int t_ON; int t_OFF; void setup() { pinMode(4, INPUT); pinMode(ledPin, OUTPUT); //Set pin 3 as 'output' mySerial.begin(9600); } void loop() { int pressureSensor = analogRead(2); // Set sensorPin to analog t_ON = map(pressureSensor, 0, 1023, 0, 10); t_OFF = 10 - t_ON; digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level) delay(t_ON); // wait for a second digitalWrite(3, LOW); // turn the LED off by making the voltage LOW delay(t_OFF); //Small delay mySerial.write((byte)sensorPin); //delay(100); }