1_soft_sensor.jpg2_soft_sensor.jpg3_soft_sensor.jpg

4_soft_sensor.jpg

MAP PRESSURE SENSOR
ARDUINO CODE


/* circuit:
weaving pressur sensor making sounds :
DO = C4 (262) / RE = D4 (294) / MI = E4 (330) / FA = F4 (349) /
SOL = G4 (392) / LA = A4 (440) / SI = B4 (494) / DO = C4 (523)

8 - ohm speaker on digital pin 8

ATtiny =
sensor : A3
speaker : 2
led : 0

*/


#define sensorPin A3
#define ledPin 0

int speakerPin = 2;

int threshold0 = 155; threshold for turning the lamp on
int threshold1 = 135;
int threshold2 = 120;
int threshold3 = 105;
int threshold4 = 85;
int threshold5 = 70;
int threshold6 = 58;
int threshold7 = 43;
int sensorValue = 0;
variable to store the value coming from the sensor

void setup() {
pinMode(sensorPin, INPUT); use digital pin number here
pinMode(speakerPin, OUTPUT);
pinMode(ledPin, OUTPUT); } void loop() {
read the value from the sensor:
sensorValue = analogRead(sensorPin);
sensorValue = map(sensorValue, 0, 1023, 0, 255);

if (sensorValue < threshold0) {
turn the LED on
tone(2, 262, 300);
digitalWrite(ledPin, HIGH);
stop the program for <sensorValue> milliseconds:
delay(sensorValue);
turn the ledPin off:
digitalWrite(ledPin, LOW);
stop the program for for <sensorValue> milliseconds:
delay(sensorValue);

}

if (sensorValue < threshold1) {
turn the LED on tone(2, 294, 300);

} if (sensorValue < threshold2) {
turn the LED on
tone(2, 330, 300);
}

if (sensorValue < threshold3) {
turn the LED on
tone(2, 349, 300);
}
if (sensorValue < threshold4) {
turn the LED on
tone(2, 392, 300);
}
if (sensorValue < threshold5) {
turn the LED on
tone(2, 440, 300);
}
if (sensorValue < threshold6) {
turn the LED on
tone(2, 494, 300);
}
if (sensorValue < threshold7) {
turn the LED on
tone(2, 523, 300);
}
delay(700);
}