Hannah Jiang



Get in touch if you want to chat about design or just simply want to say HI!

haiyuanj@gmail.com

Week 2 – The Analog Sensor

The Concept

Different colors sometimes can be used to indicate different feelings. For example, blue can mean sadness and red passion. For this week’s project, I want to use a distance sensor and led lights in different colors to demonstrate how emotions change when a loved one leaving us or getting closer to us.

I use red light for happiness and blue for sadness, yellow and green for states in between.

The Circuit


The Enclosure

The code:

int ledPinB = 8; // blue
int ledPinR = 6; //red
int ledPinG = 5; //green
int ledPinY = 3; //yellow
int duration, distance; //to measure the distance and time taken

void setup() {
Serial.begin (9600);
//Define the output and input objects(devices)
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPinR, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinG, OUTPUT);
pinMode(ledPinY, OUTPUT);
}

void loop() {

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;

if (distance >= 30 || distance <= 0)
{
Serial.println(“no object detected”);
Serial.print(“distance= “);
Serial.println(distance);
digitalWrite(ledPinB,HIGH);
digitalWrite(ledPinR,LOW);
digitalWrite(ledPinG,LOW);
digitalWrite(ledPinY,LOW);

}
else if(distance >= 20 && distance < 30) {
Serial.println(“object detected \n”);
Serial.print(“distance= “);
Serial.println(distance);
digitalWrite(ledPinG,HIGH);
digitalWrite(ledPinR,LOW);
digitalWrite(ledPinB,LOW);
digitalWrite(ledPinY,LOW);
}
else if(distance >= 10 && distance < 20) {
Serial.println(“object detected \n”);
Serial.print(“distance= “);
Serial.println(distance);
digitalWrite(ledPinY,HIGH);
digitalWrite(ledPinR,LOW);
digitalWrite(ledPinB,LOW);
digitalWrite(ledPinG,LOW);
}
else {
Serial.println(“object detected \n”);
Serial.print(“distance= “);
Serial.println(distance);
digitalWrite(ledPinR,HIGH);
digitalWrite(ledPinG,LOW);
digitalWrite(ledPinB,LOW);
digitalWrite(ledPinY,LOW);
}
}