Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Mahmoud Ahmed
Published

DIY Vending Machine using Arduino & 1Sheeld

Simply the machine has four types of candies and each type has it's special code, you should tweet with this special code to get your candy.

IntermediateFull instructions provided19,450
DIY Vending Machine using Arduino & 1Sheeld

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
1Sheeld
1Sheeld
×1
SMPS (5V - 5A)
×1
Standard Metal Servo Motor (7.5 kg.cm)
×8
Bolt (M4 x 10mm)
×1
Small breadboard
×1
Jumper wires (generic)
Jumper wires (generic)
Male-Male and Male-Female
×1
3mm Acrylic Sheet
×1
3mm Plywood Sheet
×1
Screws & Nuts
×1

Software apps and online services

Twitter
Twitter

Hand tools and fabrication machines

Screwdriver
Pliers
Flush cutter
Digital multimeter
Double-sided glue or tape
Copper spacers
6mm, Male-Female
Duct tape

Story

Read more

Schematics

Vending%20Circuit.fzz

Code

Vending Machine.ino

C/C++
#define CUSTOM_SETTINGS
#define INCLUDE_TWITTER_SHIELD
#define INCLUDE_TERMINAL_SHIELD

#include <OneSheeld.h>
#include <Servo.h>

Servo BlockColoumn1;          // create servo object to control a servo
Servo BlockCandy1;            // create servo object to control a servo

Servo BlockColoumn2;          // create servo object to control a servo
Servo BlockCandy2;            // create servo object to control a servo

Servo BlockColoumn3;          // create servo object to control a servo
Servo BlockCandy3;            // create servo object to control a servo

Servo BlockColoumn4;          // create servo object to control a servo
Servo BlockCandy4;            // create servo object to control a servo

void setup()
{
  OneSheeld.begin();

  BlockColoumn1.attach(3);     // attaches the servo on pin 3 to the servo object
  BlockCandy1.attach(4);       // attaches the servo on pin 4 to the servo object
  
  BlockColoumn2.attach(5);     // attaches the servo on pin 5 to the servo object
  BlockCandy2.attach(6);       // attaches the servo on pin 6 to the servo object
  
  BlockColoumn3.attach(7);     // attaches the servo on pin 7 to the servo object
  BlockCandy3.attach(8);       // attaches the servo on pin 8 to the servo object
  
  BlockColoumn4.attach(9);     // attaches the servo on pin 9 to the servo object
  BlockCandy4.attach(10);      // attaches the servo on pin 10 to the servo object

  /* Subscribe to setOnSelected event for the Twitter shield. */
  Twitter.setOnSelected(&shieldSelection);
  /* Subscribe to onNewTweet event. */
  Twitter.setOnNewTweet(&myTweet);
}

void loop()
{

}

void shieldSelection()
{
  /* Track keyword 1Sheeld on Twitter. */
  Twitter.trackKeyword("C111");
  Twitter.trackKeyword("C112");
  Twitter.trackKeyword("C113");
  Twitter.trackKeyword("C114");
}

void myTweet(char * userName , char * userTweet)
{
  /* Check if the tweet has 1Sheeld keyword. */
  if (strstr(userTweet, "C111") != 0)
  {
    BlockCandy1.write(90);
    OneSheeld.delay(400);
    BlockCandy1.write(180);
    OneSheeld.delay(20);
    BlockColoumn1.write(90);
    OneSheeld.delay(400);
    BlockColoumn1.write(180);
    Terminal.println(" C111 Detected");
  }
  else if (strstr(userTweet, "C112") != 0)
  {
    BlockCandy2.write(90);
    OneSheeld.delay(400);
    BlockCandy2.write(180);
    OneSheeld.delay(20);
    BlockColoumn2.write(90);
    OneSheeld.delay(400);
    BlockColoumn2.write(180);
    Terminal.println(" C112 Detected");
  }
  else if (strstr(userTweet, "C113") != 0)
  {
    BlockCandy3.write(90);
    OneSheeld.delay(400);
    BlockCandy3.write(180);
    OneSheeld.delay(20);
    BlockColoumn3.write(90);
    OneSheeld.delay(400);
    BlockColoumn3.write(180);
    Terminal.println(" C113 Detected");
  }
  else if (strstr(userTweet, "C114") != 0)
  {
    BlockCandy4.write(90);
    OneSheeld.delay(400);
    BlockCandy4.write(180);
    OneSheeld.delay(20);
    BlockColoumn4.write(90);
    OneSheeld.delay(400);
    BlockColoumn4.write(180);
    Terminal.println(" C114 Detected");
  }
  else
  {
    BlockCandy1.write(180);
    BlockColoumn1.write(180);
    
    BlockCandy2.write(180);
    BlockColoumn2.write(180);
    
    BlockCandy3.write(180);
    BlockColoumn3.write(180);
    
    BlockCandy4.write(180);
    BlockColoumn4.write(180);
    
    Terminal.println(" Nothing Detected");
  }
}// void my tweet

Credits

Mahmoud Ahmed
6 projects • 46 followers
Building new products is my favourite hobby :D

Comments