For this lab assignment, I created a "Smart Coaster". This device will be used in gatherings and party situations. It may also be used in a club/bar scene. The FSR is attached to the coaster, and the LEDs and Piezo speaker can also be attached. When the drinker has finished his or her drink, he or she will place the empty glass on the coaster. The weight of the empty glass will be sensed by the FSR and translated to LED and Piezo Speaker Output. This is the simultaneous input and output device that the assignment was specifying.
Components:
Arduino Microprocessor
LEDs
Piezo Speaker
FSR
Coaster
Arduino programming environment
Code:
int sensorPin = 0; // select the input pin for the sensor
int speakerPin = 7; //select the input for the speaker
int ledPin1 = 9; // select the output pin for the LED
int ledPin2 = 10;
int ledPin3 = 11;
int val = 0; // variable to store the value coming from the sensor
int FSRPin = 0; //to store value from FSR
void setup() {
beginSerial(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(speakerPin, OUTPUT);
}
void loop() {
FSRPin = analogRead(FSRPin); //read value from FSR
analogWrite(ledPin1, val/4); // analogWrite (dimming the LED) can be between 0-255
analogWrite(ledPin2, val/4);
analogWrite(ledPin3, val/4);
if(FSRPin>50){
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
}
Comments
nice, I hope some day I will
nice, I hope some day I will never see an empty beer glass again with this!