Who doesn’t love a classic game of hot or cold? Simple yet so fun and played for generations. Which is exactly why I felt like it was time for an update. Inspired by the apple AirTag and its precision proximity, I created my own little simpler version of it.
Inspiration:
My version:
In Action:
Process:
Before settling down with this idea as my final one I went through a period of many trial and error as I played around with other sensors and other ideas that unfortunately all failed me somehow but in the end I went back to what I was familiar with and created something that I really love and is fun to play and test its limits with an UltraSonic Sensor.
To make this I first added the different level of closeness LED to resemble the app’s screen and lighting up levels of LED to show how hot or cold you are from the object and then I added the ultrasonic sensor to be able to detect the closeness of the object, following that I added a piezo buzzer to make it give audio feedback as to how close “hot” you are to the object. For the code I just wrote several if else statements that change the LED based on it’s distance and plays a tone on the buzzer and builds up on each other depending on the amount of LED you have on which makes them sound louder.
Code:
// Define the connection pins for the ultrasonic sensor const int trig = 11; const int echo = 12; // Define the pins for the LED indicators const int LED1 = 5; const int LED2 = 4; const int LED3 = 3; const int LED4 = 2; // Define the pin for the piezo buzzer const int piezoPin = A0; // Variables to store the duration of the echo pulse and the calculated distance int duration = 0; int distance = 0; void setup() { // Set the ultrasonic sensor pins pinMode(trig , OUTPUT); // Trigger pin will send the pulse pinMode(echo , INPUT); // Echo pin will receive the pulse // Set the LED pins as outputs pinMode(LED1 , OUTPUT); pinMode(LED2 , OUTPUT); pinMode(LED3 , OUTPUT); pinMode(LED4 , OUTPUT); // Set the piezo buzzer pin as an output pinMode(piezoPin, OUTPUT); // Start serial communication at 9600 baud rate Serial.begin(9600); } void loop() { // Trigger the ultrasonic sensor to send a pulse digitalWrite(trig , HIGH); delayMicroseconds(10); // Ultrasonic pulse is 10 microseconds long digitalWrite(trig , LOW); // Measure the duration of the incoming echo pulse duration = pulseIn(echo , HIGH); // Calculate the distance based on the duration of the echo pulse distance = (duration/2) / 28.5; // Print the distance to the Serial Monitor Serial.println(distance); // Light up LED1 and sound buzzer if distance is 10 cm or less if (distance <= 10) { digitalWrite(LED1, HIGH); tone(piezoPin, 1000); // Emit a 1000Hz tone } else { digitalWrite(LED1, LOW); noTone(piezoPin); // Stop the buzzer if condition is not met } // Light up LED2 and sound buzzer if distance is 30 cm or less if (distance <= 30) { digitalWrite(LED2, HIGH); tone(piezoPin, 1000); // Emit a 1000Hz tone } else { digitalWrite(LED2, LOW); noTone(piezoPin); // Stop the buzzer if condition is not met } // Light up LED3 and sound buzzer if distance is 50 cm or less if (distance <= 50) { digitalWrite(LED3, HIGH); tone(piezoPin, 1000); // Emit a 1000Hz tone } else { digitalWrite(LED3, LOW); noTone(piezoPin); // Stop the buzzer if condition is not met } // Light up LED4 and sound buzzer if distance is 60 cm or less if (distance <= 60) { digitalWrite(LED4, HIGH); tone(piezoPin, 1000); // Emit a 1000Hz tone } else { digitalWrite(LED4, LOW); noTone(piezoPin); // Stop the buzzer if condition is not met } }
Future Changes and reflection:
In the future I would love to make it more aesthetic and maybe even be able to have a way to make it detect only something specific by adding a magnet to it and making it only sensitive to that magnet for example but i’m not really sure how feasible that is. I’d also love to add an LCD screen that says how close you are to the object. But overall as a first time working with sensors and Arduino I do think that this is an amazing start and I can’t help but be proud of myself for it especially with the amount of times my circuits failed or the idea just wasn’t it when I was trying out with the other sensors and how frustrating that was to deal with.