Ever since professor Sherwood told us about this assignment, I have started to think about how can I use my feet in order to make the LED light go on.
At first, I discovered that I need to use a sensor, which I found in the kit. Then, with a little inspiration from one of my favorite bands ever, Queen, I started to think about interactive ways to make this happen.
This was the result (excuse my PJs and slippers I was sick) :
At first, my right leg is right in front of the sensor. After the first few kicks, I move the right leg right next to the sensor, so that the LED light will turn off.
This was the code that I used:
//declaring the pins of the sensors
const int trigPin = 12;
const int echoPin = 13;
long duration;
int distance;
//declaring the rgb led
int rgb_r = 8;
int rgb_b = 7;
int rgb_g = 4;
void setup() {
// put your setup code here, to run once:
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(rgb_r, OUTPUT);
pinMode(rgb_b, OUTPUT);
pinMode(rgb_g, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
// We check the measured distance and control the RGB LED depending on it
// If distance between 20-50 cm, LED is blue
analogWrite(rgb_r, 0);
analogWrite(rgb_g, 0);
analogWrite(rgb_b, 255);
Serial.println("Led is blue!");
}
delay(1000);
Serial.print("distance = ");
Serial.print(distance);
Serial.print("\n");
delay(1000);
}
It would have been complete if I added the hand claps with the kicks for sound purposes but I did not want to be taxed for that in regards to my grade 🙂 .
Overall, it was fun to make. The sensor is not that strong so in the future I would like to use something stronger maybe. Also, this can become an actual project and I could make it so that the color of the led would change when your feet have different positions.