Author Archives: Melissa Felderman

Interactive Spooky Halloween Cat

via SparkFun: Commerce Blog

As we approach the end of October, the spooky Halloween energy is starting to find its way into my world. I’m not much of a Halloween-er myself, but I have always felt that Halloween is an excellent excuse to show off your killer maker skills, creativity and maybe even scare some folks. This week I made a little interactive Halloween decoration that activates when someone walks by.

My Interactive Spooky Halloween Cat consists of a plastic skeleton cat I found at Michaels and an enclosure that I laser cut from black acrylic. Inside the enclosure is a SparkFun BlackBoard as the brains of the project, an Ultrasonic Sensor for distance sensing, a Qwiic MP3 Trigger Board to add some hissing sound effects, a small hamburger speaker for the sound, a small servo motor to create motion in the cat’s jaw, 16 WS2812 LEDs to create the red light and a small breadboard to make the circuit building quick and easy. A full list of parts used in this project can be found here.

interactive halloween cat

Let's take a look at how this project interacts with the world around it. When a user enters within 100 cm of the ultrasonic sensor, the skeleton and eye sockets light up, it makes a loud, angry hissing sound, and the jaw begins moving up and down.

In order to accomplish this interaction (in addition to the circuitry described further down), the servo motor is connected to a clear strand of fishing line tied to the bottom of the cat’s jaw bone, so when the servo pulls back, the jaw opens up. I also added some white elastic tied to the top and bottom part of the jaw, kind of like a rubber band on braces, ensuring the jaw closes when the servo pushes back forward. I cut small sound holes in the enclosure above where the speaker is to get the best out of the sound.

I also made some modifications to the WS2812 LEDs. First, I cut two individual LEDs from the strip and soldered them together with hook-up wire at a distance of about one half-inch. Then, I connected these via hook-up wire to the remaining 14 LEDs on the rest of the strip. I unscrewed the cat’s skull to remove it from the body and open it up, then carefully drilled holes in the eye sockets, behind which I glued my two individual LEDs. Then I put the head back together and onto on the rest of the skeleton. Finally, I carefully hot glued the remainder of the LEDs down the inside of the cat's spine.

Below is a photograph of the circuit I used in this project. Because some of the parts I used are not available for frtizing diagrams, and because it is hard to see all the connections, I created the table below the image to outline each connection used in this project.

interactive cat circuit

PART / PIN CONNECTION
WS2812 Strip VCC 5V on SparkFun BlackBoard
WS2812 GND GND on SparkFun Black Board
WS2812 DIN Pin 6 on SparkFun BlackBoard
Small Servo VCC 5V on the SparkFun BlackBoard
Small Servo GND GND on SparkFun BlackBoard
Small Servo Data Pin Pin 9 on SparkFun BlackBoard
UltraSonic Sensor GND GND on SparkFun BlackBoard
UltraSonic Sensor VCC 5V on the SparkFun BlackBoard
UltraSonic Sensor Echo Pin Pin 12 on SparkFun BlackBoard
UltraSonic Sensor Trig Pin Pin 13 on SparkFun BlackBoard
Qwiic MP3 Trigger Connect to Qwiic connector on SpakrFun BlackBoard via Qwiic Cable
Hamburger Speaker Jack Audio Jack on Qwiic MP3 trigger

My program for this project can be found below. You will notice there are two programs included. The first is the program specific for this project’s interaction. The second is written for interfacing with the MP3 Trigger Shield and should be pasted into a second tab in your Arduino IDE. The MP3 Trigger code has all been picked up from Nate’s example code for this board, which allowed me to add sound incredibly easily!

Interaction Code:

/*Interactive Halloween Cat Sketch by Melissa Felderman for SparkFun Electrnoics October 2018
MP3 trigger control taken from example code by Nathan Seidle:                 https://cdn.sparkfun.com/assets/d/d/e/a/1/Qwiic_MP3_Trigger_Examples.zip */

#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <Servo.h>

byte mp3Address = 0x37; //Unshifted 7-bit default address for Qwiic MP3

#define PIN 6
#define numPix 16
#define trigPin 13
#define echoPin 12

bool state = true;


Servo myservo;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPix, PIN, NEO_GRB + NEO_KHZ800);


void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  Wire.begin();
  strip.begin();
  myservo.attach(9);

  myservo.write(180);
  mp3ChangeVolume(31); //Volume can be 0 (off) to 31 (max)
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  //  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;

 if (distance < 100) {  // This is where the LED On/Off happens


    mp3PlayTrack(1);
    for (int i = 0; i < numPix; i++) {
      strip.setPixelColor(i, 255, 0, 0);
    } strip.show();

    for (int i = 0; i < 8; i++){
    myservo.write(90);
    delay(1000);
    myservo.write(180);
    delay(1000);
    }
  }

  else {
    for (int i = 0; i < numPix; i++) {
      strip.setPixelColor(i, 0, 0, 0);
    } strip.show();
    myservo.write(180);


  }
  if (distance >= 100 || distance <= 0) {
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
  delay(500);
}

MP3 Trigger Code by Nate:

//These are the commands we can send
#define COMMAND_STOP 0x00
#define COMMAND_PLAY_TRACK 0x01 //Play a given track number like on a CD: regardless of file names plays 2nd file in dir.
#define COMMAND_PLAY_FILENUMBER 0x02 //Play a file # from the root directory: 3 will play F003xxx.mp3
#define COMMAND_PAUSE 0x03 //Will pause if playing, or starting playing if paused
#define COMMAND_PLAY_NEXT 0x04
#define COMMAND_PLAY_PREVIOUS 0x05
#define COMMAND_SET_EQ 0x06
#define COMMAND_SET_VOLUME 0x07
#define COMMAND_GET_SONG_COUNT 0x08 //Note: This causes song to stop playing
#define COMMAND_GET_SONG_NAME 0x09 //Fill global array with 8 characters of the song name
#define COMMAND_GET_PLAY_STATUS 0x0A
#define COMMAND_GET_CARD_STATUS 0x0B
#define COMMAND_GET_VERSION 0x0C
#define COMMAND_SET_ADDRESS 0xC7

//Checks the status of the player to see if MP3 is playing
//Returns true if song is playing
boolean mp3IsPlaying()
{
  mp3Command(COMMAND_GET_PLAY_STATUS);

  delay(20); //Give the QMP3 time to get the status byte from MP3 IC before we ask for it

  //01: play, 02: stop, 03: pause
  byte playStatus = mp3GetResponse();
  if(playStatus == 0x01) return(true);
  return(false);
}

//Plays a given track number
//Think of this like a CD. The user can arrange the order of MP3s
//however. playTrack(4) will play whatever is in the 4th file.
void mp3PlayTrack(byte trackNumber)
{
  mp3Command(COMMAND_PLAY_TRACK, trackNumber); //Play track  
}

//Plays a file that has been named specifically. 
//For example: passing in 6 will play F006xxx.mp3
void mp3PlayFile(byte fileNumber)
{
  mp3Command(COMMAND_PLAY_FILENUMBER, fileNumber); //Play file number  
}

//Stop playing the current track
void mp3Stop()
{
  mp3Command(COMMAND_STOP);
}

//Change the equalizer to one of 6 types
void mp3ChangeEQ(byte eqType)
{
  //0-normal, 1-pop, 2-rock, 3-jazz, 4-classical, 5-bass
  mp3Command(COMMAND_SET_EQ, eqType); //Change equalizer to bass
}

//Get the current status of the Qwiic MP3
byte mp3Status()
{
  return(mp3GetResponse());
}

//Checks to see if MP3 player has a valid SD card
boolean mp3HasCard()
{
  mp3Command(COMMAND_GET_CARD_STATUS);

  delay(20); //Give the QMP3 time to get the status byte from MP3 IC before we ask for it

  return(mp3GetResponse());
}

//Get the 8 characters of the song currently playing
String mp3SongName()
{
  String thisSongName = "";
  mp3Command(COMMAND_GET_SONG_NAME);

  delay(50); //Give the QMP3 time to get the name from MP3 IC before we ask for it

  Wire.requestFrom(mp3Address, 8); //Song names are max 8 chars

  while(Wire.available())
  {
    thisSongName += (char)Wire.read();
  }
  return(thisSongName);
}

//Get the number of songs on the SD card (in root and subfolders)
//Limited to 255
byte mp3SongCount()
{
  mp3Command(COMMAND_GET_SONG_COUNT); //Get current song count

  delay(50); //Give the QMP3 time to get the count from MP3 IC before we ask for it

  return(mp3GetResponse());
}

//Change volume to zero (off) to 31 (max)
void mp3ChangeVolume(byte volumeLevel)
{
  mp3Command(COMMAND_SET_VOLUME, volumeLevel); //Change volume
}

//Play the next track
//Think of this like a CD. The audio files can be in any order. The user
//sets the file order. This plays the next one.
void mp3PlayNext()
{
  mp3Command(COMMAND_PLAY_NEXT);
}

//Play the previous track
//Think of this like a CD. The audio files can be in any order. The user
//sets the file order. This plays the previous one.
void mp3PlayPrevious()
{
  mp3Command(COMMAND_PLAY_PREVIOUS);
}

//Checks to see if Qwiic MP3 is responding over I2C
boolean mp3IsPresent()
{
  Wire.beginTransmission(mp3Address);
  if (Wire.endTransmission() != 0)
    return(false); //Sensor did not ACK
  return(true);
}

//Pause a currently playing song, or begin playing if current track is paused
boolean mp3Pause()
{
  mp3Command(COMMAND_PAUSE);
}

//Change the I2C address
//If you forget what address you've set the QMP3 to then close the
//ADR jumper. This will force the I2C address to 0x36
boolean mp3ChangeAddress(byte address)
{
  mp3Command(COMMAND_SET_ADDRESS, address);
  mp3Address = address; //Change the global variable to match the new address
}

//Send command to Qwiic MP3 with options
boolean mp3Command(byte command, byte option)
{
  Wire.beginTransmission(mp3Address);
  Wire.write(command);
  Wire.write(option);
  if (Wire.endTransmission() != 0)
    return(false); //Sensor did not ACK
  return(true);
}

//Send just a command to Qwiic MP3
boolean mp3Command(byte command)
{
  Wire.beginTransmission(mp3Address);
  Wire.write(command);
  if (Wire.endTransmission() != 0)
    return(false); //Sensor did not ACK
  return(true);
}

//Ask for a byte from Qwiic MP3
//The response depends on what the last command was
//It is often the system status but can be song count or volume level
byte mp3GetResponse()
{
  Wire.requestFrom(mp3Address, 1);

  if (Wire.available())
    return (Wire.read());

  Serial.println("Error: Sensor did not respond");
  return(0);
}

//Returns the firmware version as a float
float mp3GetVersion()
{
  mp3Command(COMMAND_GET_VERSION);

  Wire.requestFrom(mp3Address, 2); //2 bytes for Version

  if (Wire.available() == 0) return 0;
  float versionNumber = Wire.read();
  versionNumber += (float)Wire.read() / 10.0;

  return (versionNumber);
}

I hope you enjoyed reading about this project and that it inspired you to get spooky with your projects this Halloween. Let us know your thoughts in the comments below!

comments | comment feed

Distance Sensing: 7 Amazing Projects that Use Distance Sensors

via SparkFun: Commerce Blog

Distance sensing can open up limitless opportunities when it comes to project building. From assistive tech to experiencing echolocation like our dolphin friends, we’ve collected some of the coolest distance sensing projects from the maker community!

1. Vibrating Distance Sensor

vibrating distance sensor

One extremely exciting use of distance sensors is as a visual aid for visually-impaired individuals. With the Vibrating Distance Sensor, the user holds a flashlight embedded with a distance sensor, vibration motor and Arduino, and points it forward. When the distance sensor catches an object in the user’s path, it will provide haptic feedback to let the user know.

2. Arduino Distance Meter

This distance sensing box is designed to help you measure distance across the walls of your home or office. This can help greatly with hanging photographs, shelving, artwork and other wall decor. It’s such a cool DIY solution for measuring space!

3. The DolphinView

the dolphinView

This incredibly creative project by deep sea ecologist Andrew David Thaler allows users to experience vision like a dolphin. While dolphins have amazing eyesight, they also use echolocation to navigate their way through the deep seas. This biomechanism is in the dolphin’s jaw, where it creates a clicking sound. Vibrations are then sent back to the jaw based on objects in the vicinity, letting the dolphin know what’s up. This project uses a LIDAR sensor and small speakers on wearable glasses to send vibrations to the human ear and head, similar to the experience of dolphins!

4. The Screaming Cauldron

Just in time for the spooky season, we have the screaming cauldron - a fun project to add a little extra ‘AHHH’ to your Halloween. This candy filled cauldron for trick-or-treaters is embedded with a distance sensor and microcontroller so that when candy is taken, a scary scream is played! This is bound to shock and delight trick-or-treaters. Get ready to be known as the spookiest house on the block!

5. Distance Measurer for Bocce Ball

bocce ball distance measurer

Holy smokes, it has been a long time since I’ve played bocce ball, which may be why I was so delighted with this project. For those unfamiliar with the game, the aim of bocce ball is to get your colored ball as close as possible to the pallino, or target ball. The distance measurer for bocce ball takes away all the guess work and makes sure you’ll always know for sure whose ball is closest. The fabrication of this project makes it super easy to check the distance at ground level while still standing upright because of the handy, cane-like configuration. A display up top will let you know the results, so you can be sure that your bocce ball games will forever be fair!

6. Car Parking Assistant

Long gone are the days of hanging a tennis ball in your garage for perfect parking. Now you can make your very own digital car parking assistant using an Arduino and distance sensor. I love a good home automation project because they always address a real problem. I will absolutely be making one of these when I eventually have a house and garage. How about you?

7. PopPet

PopPet

I have seen a good number of DIY robots over the past few year, and PopPet may be the most adorable one yet. This little dude is full of character and is designed as an educational tool for all ages. Full, open source plans are available for you to get started with your very own PopPet, which include several different faceplates to express different personalities and moods!

I hope you found these projects as inspiring and exciting as I did. Finding these projects has certainly piqued my interest in distance sensing, and I’m excited to start using LIDAR and ultrasonic sensors in my projects. Let us know your thoughts in the comments below!

comments | comment feed

SIK Project Ideas: Locker Alarm

via SparkFun: Commerce Blog

A few weeks ago I began to share some projects using parts from the SIK v4.0 to inspire users beyond the guide book. Today’s project was most certainly inspired by all of the cool back-to-schoool projects I wrote about last week – ladies and gentlemen, I introduce the Locker Alarm!

The locker alarm is a project using parts found in the SIK v4.0, so if you happen to have one at home, you are all set. The project includes a SparkFun Redboard, a breadboard, the SparkFun baseplate, the piezo speaker, a momentary pushbutton and photocell, a 330 ohm resistor, a 10k ohm resistor, and a AA battery pack and jumper wire.

locker alarm project

The diagram below illustrates the circuit. As you can see, the piezo speaker has two leads that are NOT polarized, meaning either can go to power or ground. In this circuit, one of the leads should go directly to ground, with the other connected to pin 6. Our next component, the button, also has two non-polarized leads. One lead will go directly to power and the second will go both to ground, via a 10k ohm resistor, and directly to pin 2. Finally we have the photocell. This guy has two non-poloraized leads as well. One will go to power, and the other to both ground, via a 330 ohm resistor, and directly to pin A0.

locker alarm circuit

Having a hard time seeing the circuit? Click on the wiring diagram for a closer look.



Now it s time to program our Arduino. The photocell is constantly checking the light level. If it is dark, then nothing should happen because the locker is closed. If the locker is opened, the photocell will register the light and trigger an alarm tone on the piezo speaker. The button will turn off the alarm, so it might be a good idea to hide the button somewhere discreet. Once the button is hit, the Arduino stops playing the alarm tone. The alarm will not be triggered again until the locker has been closed and reopened.

You can use the program below to get the alarm running, or you can challenge yourself to write it on your own! In any case, I have added some comments to my code to explain some of the logic!

//Locker Alarm by Melissa Felderman for SparkFun Electronics September 2018

int photoCell = A0; //declare photocell to pin A0
int photoVal; //declare variable to hold photocell value
int momBut  = 2; //declare momentary pushbutton to pin 2 (interrupt pin)
int butVal; //variable to hold the value of the momentary pushbutton
int piezo = 6; //declare piezo speaker to pin 6

//the below booleans are used for the alarm logic in the if statements in the loop. Both should be set to false at the top of the program
bool turnOnAlarm = false;
bool state = false;



void setup() {

  pinMode(6, OUTPUT); //let the arduino know that the piezo pin is an output
  pinMode(momBut, INPUT); //let the arduino know that the button is an input
  attachInterrupt(digitalPinToInterrupt(momBut), alarmOff, HIGH); //attach an interrupt to pin 2(the button) we do this so the button will register even during a delay

}

void loop() {

  photoVal = analogRead(photoCell); //read the photocell value and store it in the photoVal variable

  //the if statements below create the logic for the alarm. If the photocell reads a high light value and the state boolean is false, trigger the alarm
  //this will then change the booleans 'state' and 'turnOnAlarm' to true. While 'turnOnAlarm' is true, the alarm sound will play (funtion alarm();)
  //if the button is pressed(per the attach interupt in the setup), a function will be triggered 'alarmOff();' which turns the
  //boolean 'turnOnAlarm' back to false, so the alarm will stop playing. The alarm will not turn back on even though the photocell is
  //recieveing light because the boolean 'state' is still true. This boolean will remain true until the locker is closed and the
  //photocell is recieveing no light again, essentially resetting it for the next time.
  if (photoVal > 300 && state == false) {
    turnOnAlarm = true;
    state = true;
  } if (turnOnAlarm == true) {
    alarm();
  } if (turnOnAlarm == false) {
    noTone(piezo);

  }
  if (photoVal < 300) {
    state = false;

  }



}

//below is an alarm function this uses the tone fucntion to make the alarm sound on the piezeo. This function is called while 'turnOnAlarm' is true
void alarm() {

  for (int hz = 440; hz < 1000; hz += 25) {
    tone(piezo, hz, 50);
    delay(5);
    for (int i = 3; i <= 7; i++);

  }
  // Whoop down
  for (int hz = 1000; hz > 440; hz -= 25) {
    tone(piezo, hz, 50);
    delay(5);
    for (int i = 3; i <= 7; i++)
    {

    }
  }
}


//This function is triggered when the interrupt button is hit. If changes the value of 'turnOnAlarm' so that the user
//can stop the alarm while the locker is still open and the photocell is recieving light.
void alarmOff() {
  turnOnAlarm = !turnOnAlarm;

}


That’s all it takes to make your very own alarm locker. As is, you can stick this bad boy with the AA battery pack on the inside of your locker door with some 3M foam tape, and it’s ready to go. However, there is still plenty of room to take it a step further. If you have access to digital fabrication tools like a 3D printer or laser cutter, try to make an enclosure for your alarm. I made one on the 3D printer, hoping to amplify the sound of the piezo using an inverted cone shape.

locker alarm 3d printed enclosure

For even more advanced makers, try setting an alarm that wirelessly sends you a notification of the breach. Maybe you could turn it off remotely too! This project is not limited to students with lockers - it will work in any small enclosed space, like a desk drawer or closet. There is a ton of room to build, expand and improve upon this project! Tell us know your thoughts and ideas in the comments below!

comments | comment feed

10 Back-To-School Projects to Celebrate Fall!

via SparkFun: Commerce Blog

Early fall marks a very special time of year: back-to-school. As a total nerd and learning enthusiast, this time of year has always been particularly magical and exciting for me. Growing up, nothing made me happier than heading to the office supply store in late August to pick out my new folders, notebooks, and binders.

I was feeling that back-to-school nostalgia over the past few weeks and decided to see if anyone else shared my enthusiasm who maybe devised some interesting back-to-school projects. Lo and behold, a quick google search led me to countless brilliant and inspiring projects for back-to-school. Below are a bunch of my favorite finds!

1. Homework Writing Machine

Is your handwriting causing issues with your homework? Well, fear not, because you can build your very own homework writing machine that will assist you in completing your work with impeccable lettering.

2. Backpack Alarm

Worried that your backpack might get stolen this semester with all of your assignments inside? Ease your fears with the backpack alarm project!

3. Hover board

If the bus is not your thing but you don’t have a car, don’t sweat too much because you can build your very own hover board, which can get you to and from school. No adults necessary!

4. Illuminated Pencil Box

We know you want to stand out with you school accessories, which is why this illuminated pencil box is so cool! Impress the socks off of your classmates with this project!

5. Light Up Pennants

Show off your school spirit AND amazing electronics skills with these e-textile pennants. Perfect to put up in your locker or dorm room!

light up pennants

6. Arduino Calculator

Stand out with this homemade Arduino calculator. Sure, you could buy one, but what fun would that be? Challenge yourself to make your own with this great project!

Arduino Calculator

7. School Bus Heads Up

If you or your kids struggle with making the bus in the morning, this project is definitely for you. Get a notification when the school bus is approaching your stop to make sure you make it without having to stand out waiting in the cold!

school bus heads up

8. SmartWay Backpack

This project is for all the nervous parents out there! We know sending your kid to school can cause some anxiety, especially if your kid is walking to or from school alone. This SmartWay Backpack includes a GPS so parents can know where their child is at all times during the commute to and from school, offering a great deal of peace of mind.

SmartWay Backpack

9. LilyPad Safety Scarf

Another project aimed towards creating a safer environment for kids walking to and from school alone, the safety scarf will keep you warm AND light up when it gets dark outside. Weather you are walking to school before sunrise, or heading home after sunset, this scarf will keep you visible to cars on the road!

safety scarf

10. Chibitronics Trapper Keeper

Add some swag to your trapper keeper by adding LEDs that turn on when the binder is opened. Check out this super cool back-to-school project from Becky Stern!

I hope these projects both inspire you and get you excited about back-to-school! Let us know what you think in the comments below!

comments | comment feed

SIK Project Ideas: Vote Counter

via SparkFun: Commerce Blog

The SparkFun Inventor’s Kit is an awesome beginner’s kit for Arduino. It comes with a handy guide book that teaches users how to take advantage of all the components included in the kit. Through a series of cumulative projects, you can learn the fundamentals of working with Arduino and programmable electronics and start designing your own projects! But what happens when you finish the book and don’t know what to do next? There are endless projects to be made using the SparkFun Inventor’s Kit, so we decided to show off some of our favorite project ideas that didn’t make it into the guidebook.

vote counter

This week I made a digital vote counter. The project uses a SparkFun ReadBoard, a breadboard, the SparkFun Base Plate, four buttons, four 330 ohm resistors, the USB cable and jumper wire. Each button is a different color: green, blue, red and yellow. These each can represent a different person or item to vote for. By pressing a button of a certain color, the vote count for the color will increase by one. Results are displayed on the Arduino serial monitor. Let’s take a look at the circuit!

vote counter circuit

Having a hard time seeing the circuit? Click on the wiring diagram for a closer look.

As illustrated in the diagram above, one side of each button is connected directly to VCC. The other side is connected to an individual IO pin: the green button to pin 2, blue to pin 3, red to pin 4 and yellow to pin 5. You will also notice that on the IO pin side of the buttons, our leads are also connected to GND via a 330 ohm resistor. This is called a “Pull Down Resistor,” and it helps our Arduino get clean readings when the button is not pressed. Each digital pin will read the voltage of the circuit it is connected to. As electricity follows the path of least resistance, when the button is not pressed, the pin will read LOW or 0 because electricity is traveling via the resistor to GND. However, when the button is pressed, the electricity will travel across the button to the VCC connection because it is not blocked by a resistor, allowing us to get a clear and clean HIGH or 1 reading.

To activate the vote counter, you can use the program that has been provided below. I have added comments throughout the program to demonstrate how it works.

//Vote Counter for by Melissa Felderman for SparkFun Electronics

//declaring the digital IO pin value for each button
int greenBut = 2;
int blueBut = 3;
int redBut = 4;
int yellowBut = 5;

//variable to hold button reading
int greenVal;
int blueVal;
int redVal;
int yellowVal;

//variable to hold the total vote count
int greenTotal = 0;
int blueTotal = 0;
int redTotal = 0;
int yellowTotal = 0;

//variables used in debounce functions to make sure on press = one vote
bool greenBool = false;
bool blueBool = false;
bool redBool = false;
bool yellowBool = false;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 200;

void setup() {
  //initiate the serial moniter
  Serial.begin(9600);

  //let Arduino know that the digital pins are recieveing input
  pinMode(greenBut, INPUT);
  pinMode(blueBut, INPUT);
  pinMode(redBut, INPUT);
  pinMode(yellowBut, INPUT);

}

void loop() {
  //read the value of the buttons and store them in a variable
  greenVal = digitalRead(greenBut);
  blueVal = digitalRead(blueBut);
  redVal = digitalRead(redBut);
  yellowVal = digitalRead(yellowBut);


  //if statements below allow us to press the button and get several HIGH readings with one press, but only register one vote per press
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if ((greenVal == HIGH) && (greenBool == false)) {
      greenBool = true;
      greenTotal++;
      Serial.write(0);
      lastDebounceTime = millis();
    } greenBool = false;


    if ((blueVal == HIGH) && (blueBool == false)) {
      blueBool = true;
      blueTotal++;
      Serial.write(1);
      lastDebounceTime = millis();
    } blueBool = false;


    if ((redVal == HIGH) && (redBool == false)) {
      redBool = true;
      redTotal++;
      Serial.write(2);
      lastDebounceTime = millis();
    } redBool = false;


    if ((yellowVal == HIGH) && (yellowBool == false)) {
      yellowBool = true;
      yellowTotal++;
      Serial.write(3);
      lastDebounceTime = millis();
    } yellowBool = false;
  }

  //serial print commands to show results in the serial monitor
  Serial.print("Green: ");
  Serial.print(greenTotal);
  Serial.print(" ");
  Serial.print("Blue: ");
  Serial.print(blueTotal);
  Serial.print(" ");
  Serial.print("Red: ");
  Serial.print(redTotal);
  Serial.print(" ");
  Serial.print("Yellow: ");
  Serial.println(yellowTotal);

}

Once you have uploaded the code to the Arduino, you can open the serial monitor to see the vote counts!

serial monitor vote counter

We hope this project inspires you to push the boundaries of your SparkFun Inventor’s Kit beyond the guidebook. Share your feedback and ideas in the comments below!

comments | comment feed

The Great Ceramic 3D Printer Experiment: Part IV

via SparkFun: Commerce Blog

Well friends, it’s been a minute since my last ceramic printer update. Today we’re going to continue on the extremely slow journey. Before we jump in, let’s do a quick recap of where we left off. Feel free to also catch up on your own by checking out parts I, II, and III.

As a reminder, this project is based on Jonathan Keep’s OS Delta Ceramic 3D printer, and his documentation has been the main source of guidance as I move through this build. Last we spoke, I had completed the basic structure and was beginning to making things move. First and foremost, I needed to figure out how to make my own linear bearing attachments, which are circled in red below. Keep claims to have developed a custom tool to create that part, without much more information about it, so I knew I was pretty much on my own figuring this out.

linear bearings attachment

Given that I didn't have access to Keep's tools, I decided to 3D model and print this part, which is straightforward enough.

linear bearings attachment print

From here I needed to attach those fresh prints to the bearings, as well as to the belt for movement. I completely forgot to consider this in my model, so I drilled some holes in the prints to accommodate my zip ties.

drilling print

zip ties

That worked well, and it was time to attach the belt. I realized that my belt is not already in a loop, and I had to find a way to not only clamp it into a loop, but also attach it to my linear bearings to create the movement I need. The solution I attempted, a 3D printed belt clamp, did not work very well. The grip on my belt was not strong enough, and it was awkward to attach two 3D-printed parts to each other manually.

GT2 Belt First Try

GT2 belt attachment

That about brings us up to speed. In catching myself up on the project, I took a look at my 3D-printed parts, which I both drilled through and screwed together, and decided that my best bet is probably to re-model and re-print that part with more consideration to its function. Time be damned!

The beauty of 3D printing is that you can make a truly customized part; there’s really no need to start drilling holes or attaching parts together unless you are working against a deadline and literally do not have the time, which I am not. So it was back to the Tinkercad board.

I decided I would model my belt clamp directly on the linear bearings attachment, eliminating the need to connect to parts together manually. I went to Thingiverse for some inspiration and was pleased to find that there are tons of GT2 belt clamps available for download, and the one I was using was not the only option. I found this really nifty square clamp and printed it out to test its strength.

GT2 clamp

It proved to be a much more effective clamp than the one I was working with previously. With this knowledge, I decided to just pop that clamp on to my linear bearing attachment, and then add some holes for my zip ties as seen in the image below.

new model linear bearing attachment

printed model

I was quite pleased with this because it solved three problems:
1. I now have room for zip ties; no need to drill through this print.
2. I now have a belt clamp, which will effectively turn my GT2 belt into a loop.
3. The clamp also effectively attached the belt to the linear bearings, allowing for movement.

In conclusion, I killed three birds with one print. Go me.

Previously, I attached these guys to the linear bearings right away. However, in reviewing Keep’s video, I noticed that before he zip-tied these into place on the linear bearings, he connected them via rods to the extruder holder in order to moved it using the belts on the motors (check out 2:21 in the video linked above). This led me to start looking at the base of my extruder holder more closely so that I could prepare it for the rods.

My initial attempt when I made the structure was cut out of two pieces of MDF, which I sandwiched together with wood glue. Upon further inspection, I noticed that Keep uses a second fabricated part to hold the extruder in place – a ring-like object, connected to the base of the holder via standoffs.

Keep’s printer:

keeps printer head

This is what I overlooked when I made my initial cuts, and I ran into a problem right away. My MDF was too thick for my longest standoff screws. I realized that I should just make these parts again to my own specs and decided to 3D print these parts too.

print head holder

This worked really well. I was able to put together a little holder than keeps my extruder in position without wobbling, which I assume is the desired affect.

print head holder

Now I can begin to work out connecting the rods. This is where I got stuck. In Keep's video, he uses small nails, making a secure but flexible connection between rod and MDF. Nails probably make a heck of a lot more sense if you are using MDF, but I printed my parts and I am concerned that the printed plastic won’t work quite the same way. Now I am pondering a way to move forward.

On one hand I feel like I should make the base of the extruder holder in a thinner MDF and drop the print, but that doesn’t solve how I’ll manage the linear bearing attachments, for which I am pretty committed to my 3D printed parts. Therefore, my next step will be to figure out how exactly I plan to work around that. I’d love to hear any suggestions you may have for this predicament in the comments below!

Before I close this post I want to mention that taking on a project well outside of my comfort zone has been a truly interesting experience. While I knew this would be a bigger project for me from the get go, I think I underestimated just how slowly I need to move through each step to figure out how to make this beast a reality. In the case of this project, I don’t have an intuitive feel about how to solve the problems I run into, but I am figuring it out as I go and learning so much along the way. I appreciate you sticking with me for the ride!

thank you

comments | comment feed