So, my youngest brother got me in the gift exchange that we brothers do every Christmas. He’s been listening to me gab about the Glowforge since I made the pre-purchase. He got me a couple of sheets of 12"x12" acrylic after scouring the Glowforge sales site for info on what it could do. He even accidentally got cast rather than extruded.
I have had an Arduino, an ultrasonic sensor, some female jumper wires sitting around for a couple of years. I recently ordered a relay board to add on. Finally, I’ve come up with a project with some help and inspiration from the acrylic. Also note that I am an absolute beginner and have next to no programming or electronics experience to speak of. Thank goodness for the internet.
I want to use the sensor to create virtual “buttons.” Using a “WHILE” statement, I tell it to do different things depending on the distance detected by the sensor. Here’s the relay switching a different number of times based on how far away my hand is.
It’s a bit more obvious with sound and the last one is 4 quick blips on purpose, just for experimental purposes. You’ll see a light that stays powered on the Arduino and turns off when the relay is switch and it’s light blinks. For whatever reason, sending a “low” signal is what makes the relay go. I’ve got it all plugged in to the header for ICSP (AKA ISP?) so that I can use the female jumpers I have. The relay is on pin 13, which is also the on board LED, which is also available through the ICSP header. The only place I had to use loose wire was to power the relay board. That’s the red and black wires going to the normal 5V and ground. I can use this with an extension cord wired through one of the relays to turn on and off anything with a plug.
Initially, I didn’t have the relay board and was just blinking the light. Here’s my test setup:
Each rectangle is 10cm. Touch the circled number 1, one blink. 2, you get two. Et Cetera. The sensor is in the bottom of the picture.
Here’s the acrylic my brother got me:
I’ve sketched out distances on here to get a feel for their size. There’s a protective covering that will be removed before cutting, of course. There will be rectangular dividers separating each “button” with smaller rectangles cut out of the inside to allow the sensor to pass through but provide definite spaces for a user to “press.”
I’ll create a housing around the sensor and put the Arduino in an enclosed area underneath. Probably will add LEDs to light the “button” from the top or bottom to provide indication of a detected “press.” Could be a version of the game Simon. Could have cards in each space to show what sound will play. Don’t really care at this point. Kinda like Glowforge, I’ll put together some good hardware, then worry about finishing the software.
Here’s the code:
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 45 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
int led = 13; //pin for built-in LED
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
pinMode(led, OUTPUT);
// Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
while ((sonar.ping_cm() > 32) && (sonar.ping_cm()) < 38)
{
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
while ((sonar.ping_cm() > 22) && (sonar.ping_cm()) < 28)
{
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
while ((sonar.ping_cm() > 12) && (sonar.ping_cm()) < 18)
{
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
while ((sonar.ping_cm() > 2) && (sonar.ping_cm()) < 18)
{
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
I know there’s probably better ways to do that, but it’s my first project. Any tips, especially on code, are welcome. I used the NewPing library to run the sensor.