For my entire life I have loved dogs and only wanted the best for them. I always love seeing those videos of dogs being happy when they get adopted. I realized I should probably do something dog related so I decided that I should have a little cutout of a dog convey anger when dogs are not being adopted.
ForewarningI am sad to admit and do not take pride from this fact, but the project did not end up working in the end. The API that I used was deeply flawed with many issues that include not being updated regularly, incomplete data, and even dogs that were somehow adopted in the future. Sadly, I could only find one other API that could possibly work with my project, but it required me to make a new request for a new authentication key every 6 minutes. I will expand on all of these issues later, I just thought it would be important to give a forewarning.
ElectronicsThe electronics for this project are extremely simple. They consist of a single micro servo, a particle argon, a breadboard, and a couple of wires.
I plugged the red wire into VUSB, the orange wire into D5 and the black wire into ground.
The APIThe API that I used was https://rescuegroups.org/. At face value it is very promising and appeared like the ideal choice for my project. Looking deeper into the actual API it is very flawed.
Before I go into any of the issues with the API I will display an example of one of their responses that I will be referencing. I am purposefully only pulling the date that the last dog was adopted on.
The first issue that I had encountered, and a more minor one compared to the rest, was the fact that they do not include times that dogs were adopted. As you may see there is a portion of the response that is set up specifically for the time, but for some reason it is not in use.
Another one of the issues that I encountered within the API is that it is most definitely not updated "regularly". On the website it is stated that the API is constantly in use with new information going through it all the time, but that is very clearly not the case.
The biggest, and most mind boggling issue is that people are saying that dogs are being adopted in the future. As you may have seen when you first looked at the image the API states that the dog was adopted on December 18th, 2090. I would like to remind you that we are still in the year 2021 and this API is posting that dogs are being adopted almost 70 years into the future. This happens consistently and this example is not the only one. This also leads to many issues. I have no idea if these dogs are legitimately being adopted and are being entered in incorrectly or if people are purposefully entering adoptions that have not happened so I have no way of knowing if I should use these or not. This leads to me doubting the entire API's legitimacy because I have no way of knowing if the dogs that were "adopted" yesterday were actually entered in yesterday or if they were entered in 5 years ago and time has just caught up to them.
I also looked into using other APIs, but the only other one that I could find that could work with my project would be PetSmart's API, but that requires a new authentication key every 6 minutes and I could not figure out how to request an authentication key in the Particle Web IDE for the life of me.
Code BreakdownThe first thing I did was set up my variables and my void setup.
Servo myservo;
int servPin = 5;
int angle = 0;
int timercheck = 0;
double retainer = 0;
void setup()
{
myservo.attach(servPin);
myservo.write(angle);
Particle.subscribe("hook-response/Dog_Update2", myHandler, MY_DEVICES);
}
I started by setting up what I need to to use my servo and created other variables that will be used later. I created a variable called "angle" that is used to assign a new angle to the servo. I also created the variable "timercheck" that is used in a makeshift timer. I also created the variable "retainer" that is used to hold onto the last result from calling the API.
In setup I set up the servo and made it go to an angle of 0 at the beginning in order to return it to its original position. I also subscribed to a webhook I had created to access the API.
Then I set up my loop function.
void loop()
{
Particle.publish("Dog_Update2");
timercheck++;
delay(10000);
}
In my loop function I published "Dog_Update2" to trigger my webhook and get a response. Then I added one to my makeshift timer and did a 10 second delay.
Then, finally, I set up what would happen when I published "Dog_Update2".
void myHandler(const char *event, const char *data) {
{
double adoptedDate = atof(data);
if (timercheck == 10){
if (adoptedDate == retainer){
if (angle != 90){
angle = angle + 90;
}
myservo.write(angle);
delay(1000);
timercheck = 0;
}} else if (adoptedDate != retainer){
timercheck = 0;
angle = 0;
myservo.write(angle);
delay(1000);
retainer = adoptedDate;
}
}
}
The first thing I did was set adoptedDate to the value that I was receiving from the API. Then I checked to see if timercheck was 10. If it was that would mean that 100 seconds had passed and it would check to see if adoptedDate was the same as the adaoptedDate from the previous loop. If it was it would set the servo's angle to 90, trigger a 1 second delay, and set timercheck back to 0 to start another 100 second timer. It would also check to see if adoptedDate was different from the last loop through. If it was it would set timercheck to 0, set the angle of the servo to 0, trigger a 1 second delay and update the previous adoptedDate.
FabricationI used a servo for my project which produces circular motion, but I need to create linear motion in order to complete my goal. To convert circular motion to linear motion I used pontentprintables' design on thingiverse. In his design he places a gear on the servo and uses it to push a bar that has teeth on it in and out.
After I had found this solution all I had to do was construct the the dog and the holding for the electronics. I glued a picture of a dog to a piece of cardboard and glued that to another piece of cardboard that acts as a background/wall the separates the front from where the electronics are.
The image above is what is shown when people are consistently adopting dogs.
The image above is what is shown when people are not consistently adopting dogs. The dog is angry and showing his teeth.
The electronics are all held behind the cardboard shown below.
I used a combination of cardboard, glue, and tape to hold everything together.
Comments
Please log in or sign up to comment.