Introduction: Inventory Drawer "Smart Cities Hackathon Qualcomm17"

In the next document, you can see the
process of construction and programming of an intelligent drawer. This drawer was programmed in a Dragon Board 410c, with the purpose of improving the quality of cities. The project is part of the contest “smart cities hackathon Qualcomm 17”.

The idea of this project began with a problem that very few people see, which is the lost and bad manage of tools and material that is provided by companies such as factories and even hospitals. In these places, some materials and tools are provided to the workers to do activities, this material and tools must be reused because they are expensive or the lack of economic resources to replace them.

In hospitals, there are people who take control of the materials that are removed, but when there is a human intervention there is the error, which can lead to unnecessary expenses. The best solution to this problem is an intelligent drawer capable to maintain an inventory of objects that are borrowed and returned and at the same time know who is the responsible.

Step 1: Materials

The material needed for the project is the next:
1 x Dragon Board 410c

1 x Sensor Mezzanine 96 Boards for Dragon Board 410c

1 x Breadboard

1 x MDF (Medium Density Fiberboard) sheet 61 x 122 cms

5 x sensor CNY 70

1 X TIP31B

1 x electromagnet

1 x 7408

1 x Keyboard

1 x screen

3 x screws

Resistances (variety)

Copper wires

Glue

Drill

Step 2: Cut the Pieces for the Drawer in the MDF. (For Better Results Use a Laser Cutter)

Step 3: Paste All the Pieces Together to Form a Drawer With Two Little Drawers and a Big One.

Step 4: Screw the Screws in the Middle of Each Drawer.

Step 5: With the Drill Make Holes Through the Drawer in the Back Side, the Hole Must Be the Size of the Sensor.

Step 6: Weld Each Sensor CNY 70 With the Copper Wires. (repeat 4 Times More)

Step 7: An Especial Circuit Is Used for the Sensor.

Step 8: Connect the Sensor Mezzanine to the Dragon Board 410c. (used to Access the GPIO)

It is very important that this step be done with the dragon board off, if not it can burn, besides all the PIN need to be placed correctly.

Step 9: Connect the Circuit From the Breadboard to the Mezzanine

Step 10: Write or Copy the Code.

#include <br>#include 
#include 
//#include 
#include "libsoc_gpio.h"
#include "libsoc_debug.h"
#include "libsoc_board.h"
/* This bit of code below makes this example work on all 96Boards */
unsigned int LED_1; // electro iman 
unsigned int BUTTON_1;//first sensor
unsigned int BUTTON_2;//second sensor
unsigned int BUTTON_3;// close
unsigned int BUTTON_4;//third sensor
struct User{
    char username[20];
    char password[20];
}User;
struct Database{
    char Article_Name[20];
    char Location[20];
}Database;
int sensor1;
int sensor2;
int sensor3;
int sensor1_last_state;
int sensor2_last_state;
int sensor3_last_state;
char username[50];
char password[50];
char YesNo[40];
FILE *pFILE;
char Yes[20] = {"Yes"};
int running = 1;
__attribute__((constructor)) static void _init()
{
    board_config *config = libsoc_board_init();
    BUTTON_1 = libsoc_board_gpio_id(config, "GPIO-A");//fists sensor 
    BUTTON_2 = libsoc_board_gpio_id(config, "GPIO-C");// second sensor 
    BUTTON_3 = libsoc_board_gpio_id(config, "GPIO-D"); // close rack 
    BUTTON_4 = libsoc_board_gpio_id(config, "GPIO-B"); // third sensor
   // BUTTON_5 = libsoc_board_gpio_id(config, "GPIO-E");
    LED_1 = libsoc_board_gpio_id(config, "GPIO-E"); // electro iman 
    
   libsoc_board_free(config);
}
/* End of 96Boards special code */
int main()
{
    gpio *led_1 ,*button_1 ,*button_2, *button_3, *button_4 ;
    //int touch;
    
    struct User Karina;
    struct User Manager;
    
    
     strcpy( Karina.username, "Karina Valverde");
     strcpy( Karina.password, "Taller Vertical");
     
     
     strcpy( Manager.username, "The Boss");
     strcpy( Manager.password, "ITESM");
    
    
    struct Database Tool;
    struct Database Pen;
    struct Database Case;
    
    strcpy( Tool.Article_Name, "Tool");
        struct Database Tool;
    struct Database Pen;
    struct Database Case;
    
    strcpy( Tool.Article_Name, "Tool");
    strcpy( Pen.Article_Name, "Pen");
    strcpy( Case.Article_Name, "Case");
libsoc_set_debug(0);
    led_1 = libsoc_gpio_request(LED_1,LS_SHARED);
    button_1 = libsoc_gpio_request(BUTTON_1,LS_SHARED);
    button_2 = libsoc_gpio_request(BUTTON_2,LS_SHARED);
    button_3 = libsoc_gpio_request(BUTTON_3,LS_SHARED);
    button_4 = libsoc_gpio_request(BUTTON_4,LS_SHARED);
    //button_5 = libsoc_gpio_request(BUTTON_5,LS_SHARED);
    if((led_1 == NULL) || (button_1 == NULL)|| (button_2 == NULL)|| (button_3 == NULL)||(button_4 == NULL))
    {
        goto fail;
    }
    libsoc_gpio_set_direction(led_1,OUTPUT);
    libsoc_gpio_set_direction(button_1,INPUT);
    libsoc_gpio_set_direction(button_2,INPUT);
    libsoc_gpio_set_direction(button_3,INPUT);
    libsoc_gpio_set_direction(button_4,INPUT);
    //libsoc_gpio_set_direction(button_5,INPUT);
    if((libsoc_gpio_get_direction(led_1) != OUTPUT)
    || (libsoc_gpio_get_direction(button_1) != INPUT)
    || (libsoc_gpio_get_direction(button_2) != INPUT)
       || (libsoc_gpio_get_direction(button_3) != INPUT)
    || (libsoc_gpio_get_direction(button_4) != INPUT))
  {
        goto fail;
    }
    
    sensor1 = libsoc_gpio_get_level(button_1);
    sensor2 = libsoc_gpio_get_level(button_2);
    sensor3 = libsoc_gpio_get_level(button_4);
    
    sensor1_last_state = sensor1;
    sensor2_last_state = sensor2;
    sensor3_last_state = sensor3;
    
    if (sensor1 ==1){
        strcpy( Tool.Location, "Located on Rack");
    } else if (sensor1 == 0){
        strcpy( Tool.Location, "Never placed in this Rack");
    }
    if (sensor2 ==1){
        strcpy( Pen.Location, "Located on Rack");
    } else if (sensor2 == 0){
        strcpy( Pen.Location, "Never placed in this Rack");
    }
   if (sensor3 ==1){
        strcpy( Case.Location, "Located on Rack");
    } else if (sensor3 == 0){
        strcpy( Case.Location, "Never placed in this Rack");
    }
 while(running)
    {
        libsoc_gpio_set_level(led_1,HIGH);
        printf("Please entrer user name: ");
        scanf("%s", username);
        
      
         printf("Please entrer password: ");
         scanf("%s", password);
      
       
        if (strcmp(username, "Karina") == 0 && strcmp(password, "Taller") == 0){
          
            libsoc_gpio_set_level(led_1,LOW);
             libsoc_gpio_set_level(led_1,LOW);
            while(libsoc_gpio_get_level(button_3) != 1 ){
                sensor1 = libsoc_gpio_get_level(button_1);
                sensor2 = libsoc_gpio_get_level(button_2);
                sensor3 = libsoc_gpio_get_level(button_4);
         }
            libsoc_gpio_set_level(led_1,HIGH);
            if (sensor1 == 1 && sensor1 != sensor1_last_state){
                strcpy( Tool.Location, Karina.username);
            }else if (sensor1 == 0 && sensor1 != sensor1_last_state){
                strcpy( Tool.Location, "Located on Rack");
            }
            if (sensor2 == 1 && sensor2 != sensor2_last_state){
                strcpy( Pen.Location, Karina.username);
            }else if (sensor2 == 0 && sensor2 != sensor2_last_state){
                strcpy( Pen.Location, "Located on Rack");
           }
          if (sensor3 == 1 && sensor3 != sensor3_last_state){
                strcpy( Case.Location, Karina.username);
            }else if (sensor3 == 0 && sensor3 != sensor3_last_state){
                strcpy( Case.Location, "Located on Rack");
             }
     }else if (strcmp(username, "Boss") == 0 && strcmp(password, "ITESM") == 0){
                printf(" Do you wish to generate a text file with the database? [Yes/No]");
                scanf("%s", YesNo);
             if ((strcmp(YesNo,Yes) == 0)){
                //Manager_user(pFILE);
            pFILE = fopen("Database.txt","w");
            fprintf(pFILE,"%s", "--------Rack's Database----- \n");
            fprintf(pFILE,"%s", "Article's Name:");
            fprintf(pFILE,"%s", Tool.Article_Name);
            fprintf(pFILE,"%s", "\t");
            fprintf(pFILE,"%s", "Article's Location:");
            fprintf(pFILE, "%s", Tool.Location);
            fprintf(pFILE,"%s", "\n");
   
            fprintf(pFILE, "%s", "Article's Name:");
            fprintf(pFILE,"%s", Pen.Article_Name);
            fprintf(pFILE,"%s", "\t");
            fprintf(pFILE,"%s", "Article's Location:");
            fprintf(pFILE, "%s", Pen.Location);
            fprintf(pFILE,"%s", "\n");
            fprintf(pFILE, "%s", "Article's Name:");
            fprintf(pFILE,"%s", Case.Article_Name);
            fprintf(pFILE,"%s", "\t");
            fprintf(pFILE,"%s", "Article's Location:");
            fprintf(pFILE, "%s", Case.Location);
            fprintf(pFILE,"%s", "\n");
            fclose(pFILE);
          }
        printf("Access Denied \n");
}

    }
    
    fail:
    if(led_1 || button_1|| button_2|| button_3)
    {
        printf("apply gpio resource fail!\n");
        libsoc_gpio_free(led_1);
        libsoc_gpio_free(button_1);
        libsoc_gpio_free(button_2);
        libsoc_gpio_free(button_3); 
    }

Step 11: Run the Program.

Step 12: Conclusions

The project has a future promising, since it can improve in a very effective way, the sensors can be changed for RFID´S tags and at the same time with the RFID is possible to use ID cards to monitorize who is responsible of the material.

Step 13: Video