Input-Output Coincidence
2 min readOct 6, 2022
Albert Hodo. Tangible UI, Fall 22
Prompt: Create and Input and Output device with the Arduino. You can use the piezo speakers or any other device.
Components Used
- Bread Board
- RGB LED’s
- Active Buzzer
- Origami Folded Paper
- MQ2 Gas Sensor (to simulate Co2 sensor)
- Jump Wires
- Arduino Uno
Process
I used the Gas sensor to simulate the Co2 sensor to read the presence of gas in the room. I then mde the buzer beep when there was the presence of gas in the room. I also used the RGB as ambient light and made it a bright orange when the buzzer beeps.
Code
#include <Wire.h>
#include <Adafruit_Sensor.h>
int redpin = 11; //select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
int greenpin =9;// select the pin for the green LED
int val;
int buzzPin =3; //Connect Buzzer on Digital Pin3
unsigned i=0;
int redVal = 255;
int greenVal = 1;
int blueVal = 1;
int lightVal=0;
void setup() {
Serial.begin(9600);
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(buzzPin, OUTPUT);}void loop(){
int gasVal;
gasVal=analogRead(A2);//Read Gas value from analog 0
//gasVal = gasV*5.00/1023.00;
//int RS = ((5.00*10000)/gasVal) - 10000;
//int ratio= RS/20000;
//int alcohol= ratio*3616.1 -2.675;i += 1;
if (i < 255) {
redVal -= 1; // Red down
greenVal += 1; // Green up
blueVal = 1; // Blue low
} else if (i < 509) {
redVal = 1; // Red low
greenVal -= 1; // Green down
blueVal += 1; // Blue up
} else if (i < 763) {
redVal += 1; // Red up
greenVal = 1; // Green low
blueVal -= 1; // Blue down
} else {
i = 0;
}if(gasVal>122){//22
analogWrite(redpin, 255);
analogWrite(greenpin, 0);
analogWrite(bluepin, 0);
digitalWrite(buzzPin, HIGH);
delay(500);
digitalWrite(buzzPin, LOW);
delay(500);}
else{
analogWrite(redpin, redVal);
analogWrite(greenpin, greenVal);
analogWrite(bluepin, blueVal);
}Serial.print("Gas level is: ");
Serial.println(gasVal,DEC);//Print the value to serial port
//delay(100);}
Demo