Buzz Wire Game
Read moreIn this tutorial we will be going over how to make a game where the goal is to bring a hoop through a course without touching the hoop to the center wire with a Wia Dot One
Figure 1
Requirements- Wia Dot One Buy yours here
- Servo Motor Buy yours here
- MicroUSB cable Buy yours here
- Account on Wia
- Account at WiaYou will need to be registered and /or logged in to your Wia account athttps://www.wia.io/.
- Set up your Dot OneYou will need to have a set up Dot One and you can find the tutorial on how to do that Here.
- Set up your code projectNow you will need to create a space and then a block project on your Wia Dashboard
- Now you need to set up a code project so we can code the the pins that detect the wires touching and the pins that control the buzzer.
- You can follow along the code below and read the comments for a better understanding.
- Feel free to try and write this code yourself and reference my code if needed!
#include <WiFi.h>
#include <Wia.h>
const int inputWirePin = 19;
const int outputWirePin = 18;
const int buzzerPin = 26;
int previousTime1 = 0;
int previousTime2 = 0;
int timeElapsed1 = 0;
int timeElapsed2 = 0;
bool stop;
Wia wiaClient = Wia(); // this is necessary for the Dot One to funtion properly
void setup()
{
WiFi.begin(); // this connects the Dot One to the wifi
delay(2500); // this pin is the wire that detects if they have touched
pinMode(inputWirePin,INPUT_PULLDOWN); // this pin is the hot wire meaning it has voltage and will supply current when the two wires touch
pinMode(outputWirePin,OUTPUT); // this pin controls the buzzer
pinMode(buzzerPin, OUTPUT);
}
void loop()
{
stop = false;
digitalWrite(outputWirePin, HIGH); // set the hotwire to high
if(digitalRead(inputWirePin) == HIGH) // check if the wires have touched
{ // this loop allows you to start a run
previousTime2 = millis();
while(digitalRead(inputWirePin) == HIGH)// this is responsible for the start run
{
delay(1);
if(millis()-previousTime2 > 4000) // checks that the wires have been connected for 4000ms
{
delay(2000); // delay to give time for the user to start
previousTime2 -= 2000; // deduct the delay form their time
stop = true;
break; // break out of the while loop
}
}
timeElapsed2 = millis()-previousTime2; // calculate the time elapsed
if(timeElapsed2 >= 4000)
{
for(int i = 0; i < 5; i++)
{
digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(buzzerPin, LOW);
delay(100);
}
}
if(stop) // this indicates if the run should be started or if the user made a mistake
{
wiaClient.createEvent("Start run");
}
else
{
timeElapsed1 = millis() - previousTime1; // calculate run time
previousTime1 = millis();
wiaClient.createEvent("End run", timeElapsed1); // print run time
digitalWrite(buzzerPin, HIGH); // buzz when the user touched
delay(100);
digitalWrite(buzzerPin, LOW);
delay(3000);
}
}
}
Making your course and wire- To start off we need the Dot One to know when the wires have touched so we are going to have one wire do a digital read while the other is doing a digitalwrite high. This means one is supplying 3.3V and one is looking for 3.3V so if the it finds it then the wires have touched.
- To start off find a coat hanger which is plain with no paint on it. This is important because the paint could make it hard for the two wires to make contact and not register because the paint insulates the wires.
- Then bend the coat hanger out to be as straight as you cann and cut off about 1/3 of it. The smaller bit is your handle while the larger bit is the course.
- Now bend the course into a shape you would like for your game as seen in figure 2 and a handle into a small loop at one end and larger oval at the other.
Figure 2
Connecting your course and the buzzer to the Dot One- To start off this portion you will need to wire up the buzzer to the Dot One and you if you look in figure 3, figure 4 and figure 5 to see how it is connected.
- First figure 3 illustrates how everything is connected in words and matching to colors
Figure 3
Figure 4
Figure 5
Setting up your flow (optional)- For this project I wanted to be able to track my times and see compare them so I added on a component where I would receive notifications on my phone displaying when I start and stop a run and my time.
- To start off you’ll need to go to flows and create a new flow
- Then drag an Event Created node, found in the Trigger tab under Wia, into the workspace and put End run in for the Name
- Then select your Dot One from the list as seen in figure 6.
Figure 6
- Now drag a Notification node, found in the Action tab under Wia, into the workspace and for the message enter the following:
End run! Time: ${input.body.data/1000} seconds
- This sends a notification which displays the elapsed time in seconds.
Figure 7
- Now drag another Event Created node, found in the Trigger tab under Wia, into the workspace and put Start run in for the Name
- Then select your Dot One from the list as seen in figure 8.
Figure 8
- Now drag a Notification node, found in the Action tab under Wia, into the workspace and for the message enter the following:
Start run
- This sends a notification whenever you start a new run but holding the handle to the puzzle for a few seconds as seen in figure 9.
Figure 9
- Lastly connect the nodes as seen in figure 10.
Figure 10
- Now you’re all set and your game is ready to go!
Jack Duff
32 projects • 8 followers
Man of the people. Champion of the downtrodden. Marketing magic @ Wia.
Becoming a maker by learning, building, and exploring
Spivey
82 projects • 59 followers
Tourist in a Tutu || US Born || Melbourne/Mexico/California Raised || New Yorker at ❤️ || SF to Dublin to be COO of Wia the best IoT startup
Comments