India Automation Challenge 2021
OR
Hello Everyone Myself Mohit and i have created this Automatic Library Book Management System Project. Let me first tell you how this Project Play an Important role in Real World as you all aware about the Current Pandemic Situation and now colleges/schools have been Re-opened it is important to maintain Social Distancing. Till Now in Some Colleges or schools Book are being Issued to Student Manually by using barcode Reader and excel sheet. All of the book and Student Library ID Card have barcode. To Issue book student have to give there book to Library teacher along with there Library ID Card and the Library teacher issue the book by scanning the barcode on book and student library ID card. If Teacher/Student is Sick then there might be chances that germs will be transferred to the Book or Library card. My project help in maintaining Social Distancing and also reduce close contact between people.
Through this project student can easily Issue/Return book they just have to wave there hand on the right/left side(IR sensors) of the project and place there book and library ID card then the book will be issue/Return.
Each Book and Library ID card are being provided with the barcode.
Instead of barcode reader in this project i'm using a camera and using open CV to detect the barcode value.
Book and Libary ID card Details are Stored in an Remote MySql Database.
I have also Created an App and a Website using python-Flask and Hosted it online on Heroku for free.
Student can see there details on website by entering there University Enrollment Number or Library ID Card Barcode Number.
Advantage of Website in Worst case scenario if Hardware stopped working for some reason then the Teacher can manually issue/return book to student.
App is created Using MIT app inventor can only access by Library person for Security purpose So that no one to who the book belong not steal the book from library. Will explain it in more detail below.
Thing you should know about the Projects:-
As it's a prototype that's why i have created it in cardboard but in practical world a 3-D printed box or sheet metal box can be created.
Raspberry pi 3 B+ Model, IR Sensors, Raspberry Pi TFT Display, Usb web-cam, usb sound card, Transformer, capacitor, diode, resistor,7805 voltage rectifier, LED, power adaptor , jumper wire, pcb, box, LED Light, Usb Speaker
Python, Open-cv, Pyzbar library, gtts library, Python-Flask, mysql, MIT App Inventor(app), PHP, pysimplegui
Here i have used raspberry pi 3 b+ model which has 1.4ghz processor with built-in wifi and bluetooth functionality. In this project i have opt-out for raspberry because the need for high processing power also it's easy to use, cheaper and it support usb web camera.
Raspberry pi also provide Gpio pins through that i was able to interface IR Sensor easily.
To Make the User GUI (Graphical user interface ) i have used pysimplegui library through this i was able to display text (instructions) on TFT Display.
Instead of normal LCD i have used TFT Display (3.5 inch) to make the project more user friendly.
Power supply -
Created a Ac to Dc full bridge rectifer power supply which output 12v and 5v. This giving power to our both IR sensor and LED Light(12v).
To giving power to raspberry pi i have used 5v, 3A Adaptor and for Speaker i have used a anothter usb adaptor. i have connected all the input power to a single power cable.
We two option to read(detect) barcode of books or student ID card either we go for normal usb Barcode Reader or Usb web-camera. Here i have used Usb Web- camera for detecting barcode instead of normal barcode reader because it's cheaper as compare to barcode reader.
Software-
website which you see here( https:/ /librarybookmanager.herokuapp.com/ ) is being created using python-flask because through this i was able to use mysql connector library which allow me to connect to my database and also issue/return/re-issue book manaully or make changes in database.
App-
App will play an important role as it prevents the books from getting stolen. As the system is automatic that why there might chances that some students try to take books without issuing.
so to prevent this the library person will sit at the exit door of the library along with the mobile application and by scanning student the library person will able to see all the student detail like how many books issued to them or which are those books and there total fine.
Circuit Diagram Image
In hardware side there are two IR sensor which are connected to Raspberry pi gpio. Right sensor output pin is connected to raspberry pi gpio pin 20 and Left side Sensor output pin is connected to Raspberry pi gpio pin 21.
VCC of both Sensors are connected to the 5v output of the power supply and ground to power supply ground.
Raspberry pi Gnd pin also connected to power supply ground side.
i have given seperate power to raspberry pi using 5v 3a adaptor and speaker have been connected on seperate usb adaptor but all the power input are connected to a single power cord (plug).
Speakers are connected to raspberry pi through Sound card so that we hear loud sound it boost volume of the speaker.
USB web-camera is connected to the usb port of the raspeberry pi.
LED Light is used to give our usb web camera better lighting so that the camera was able to get clear view of the barcode.
LED Light positive side is connected to power supply 12v output and ground is connected to power supply ground.
#!/usr/bin/python3 import time import datetime import mysql.connector as c import cv2 from pyzbar.pyzbar import decode import RPi.GPIO as GPIO from gtts import gTTS from mpyg321.mpyg321 import MPyg321Player import PySimpleGUI as sg sg.LOOK_AND_FEEL_TABLE['MyCreatedTheme'] = {'BACKGROUND': '#34495E', 'TEXT': '#FFCC66', 'INPUT': '#339966', 'TEXT_INPUT': '#000000', 'SCROLL': '#99CC99', 'BUTTON': ('#003333', '#FFCC66'), 'PROGRESS': ('#D1826B', '#CC8019'), 'BORDER': 1, 'SLIDER_DEPTH': 0, 'PROGRESS_DEPTH': 0, } sg.theme('MyCreatedTheme') layout1 = [[sg.Text('Welcome to Library book manager',justification='center',size=(80,4),font=("Helvetica", 20))], [sg.Text(size=(100,3),justification='center',key='-OUTPUT-',font=("Helvetica", 15))], [sg.Text(justification='center',size=(100,4),key='-LEFT-',font=("Helvetica", 13))]] window = sg.Window(title="Library book manager",layout=layout1,size=(600,700),resizable=True,use_custom_titlebar=True, alpha_channel=.5,right_click_menu = None, grab_anywhere=False,no_titlebar=True).finalize() window.Maximize() sensor1 = 20 sensor2 = 21 language = 'en' #welcometext = 'Welcome to Automatic Library book management system!' #myobj = gTTS(text=welcometext, lang=language, slow=False) #myobj.save("welcome.mp3") ##placebooktext = 'Please Place Book which you want to issue or re issue!' #myobj1 = gTTS(text=placebooktext, lang=language, slow=False) #myobj1.save("placebook.mp3") #placereturnbooktext = 'Please Place Book which you want to Return!' #myobj1 = gTTS(text=placereturnbooktext, lang=language, slow=False) #myobj1.save("placereturnbook.mp3") #placecardtext = 'Please Place Your LIBRARY ID CARD!' #myobj2 = gTTS(text=placecardtext, lang=language, slow=False) #myobj2.save("placecard.mp3") #bookissuetext = 'Book has been issued to you!' #myobj3 = gTTS(text=bookissuetext, lang=language, slow=False) #myobj3.save("bookissue.mp3") #bookreissuetext = 'Book has been re issued to you!' #myobj4 = gTTS(text=bookreissuetext, lang=language, slow=False) #myobj4.save("bookreissue.mp3") #bookreturntext = 'Book has been succesfully Returned!' #myobj5 = gTTS(text=bookreturntext, lang=language, slow=False) #myobj5.save("bookreturn.mp3") #morebooktext = 'YOU CANNOT ISSUE BOOKS MORE THAN 5' #myobj6 = gTTS(text=morebooktext, lang=language, slow=False) #myobj6.save("morebook.mp3") #nobooktext = 'Book Not Registered in Database' #myobj7 = gTTS(text=nobooktext, lang=language, slow=False) #myobj7.save("nobook.mp3") #nousertext = 'Book Not Registered in Database' #myobj8 = gTTS(text=nousertext, lang=language, slow=False) #myobj8.save("nouser.mp3") #errortext = 'You can only Return book after 7 Days' #myobj9 = gTTS(text=errortext, lang=language, slow=False) #myobj9.save("error.mp3") #error2text = 'Book is not isued to you or something went wrong' #myobj10 = gTTS(text=error2text, lang=language, slow=False) #myobj10.save("error2.mp3") player = MPyg321Player() player.play_song("welcome.mp3") GPIO.setmode(GPIO.BCM) GPIO.setup(sensor1,GPIO.IN) GPIO.setup(sensor2,GPIO.IN) cap = cv2.VideoCapture(0) cap.set(3, 320) cap.set(4, 240) flag1 = True flag2 = False flag3 = True flag4 = False con = c.connect(host="hostname", user="username", passwd="password", database="database name", port=3306 ) def mohit(frame): global flag1 global flag2 global bookname global bookuid global bookissuedto global cursor con.commit() if flag1 == True: for code in decode(frame): print(code.type) print(code.data.decode('utf-8')) id = code.data.decode('utf-8') cursor.execute("Select uid, bookname , available , issuedto FROM bookdatabase WHERE uid="+str(id)) result = cursor.fetchone() #print(result[2]) if result is not(None): if result[2] == 1: bookname = result[1] bookuid = result[0] bookissuedto = result[3] #cv2.destroyAllWindows() flag2= True function2(result[2]) flag1= False elif result is None: flag1=False print("Book not Registered!!") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Is Not Registered !!") window.finalize() player.play_song("nobook.mp3") def function2(res): if res == 1: print("Place Your LIBRARY ID CARD!!") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Place Your LIBRARY ID CARD !!") window.finalize() player.play_song("placecard.mp3") count = 0 maurya(count) def maurya(count): global flag1 global flag2 time.sleep(10) count_f_stop = 0 while count <= 100: if count_f_stop == 0: while count_f_stop <= 10: success, frame1 = cap.read() count_f_stop = count_f_stop + 1 count = count + 1 success, frame1 = cap.read() read(frame1) #cv2.imshow('test', frame) #cv2.waitKey(1) flag1 = True main() def read(frame1): global flag1 global flag2 global bookname global bookuid global intissuefine global cursor con.commit() if flag2 == True: for code1 in decode(frame1): print(code1.type) print(code1.data.decode('utf-8')) uid = code1.data.decode('utf-8') if uid == bookissuedto or bookissuedto == str(0): cursor.execute("Select lid, name , issued,fine FROM usersdatabase WHERE lid="+str(uid)) result1 = cursor.fetchone() if result1 is not(None): flag2 = False usedlid = result1[0] username = result1[1] userissued = result1[2] issuefine1 = result1[3] intissuefine = int(issuefine1) if userissued == 0: tday = datetime.date.today() tdelta = datetime.timedelta(days=14) returndate = tday + tdelta newuserissued = userissued + 1 query = """ UPDATE usersdatabase SET b1name = %s,b1uid = %s,b1issuedate=%s,b1returndate=%s,issued=%s WHERE lid = %s """ data = (bookname,bookuid,tday,returndate,newuserissued,uid) cursor.execute(query, data) con.commit() bquery = """ UPDATE bookdatabase SET issuedto=%s WHERE uid = %s """ bdata = (uid,bookuid) cursor.execute(bquery,bdata) con.commit() print("Book Has been issued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been issued to "+str(username)+"\nReturn Date : "+str(returndate)) window.finalize() player.play_song("bookissue.mp3") if userissued == 1: tday = datetime.date.today() tdelta = datetime.timedelta(days=14) returndate = tday + tdelta cursor.execute("Select lid, name ,b1returndate,b1issuedate,issued FROM usersdatabase WHERE b1uid="+str(bookuid)) result2 = cursor.fetchone() if result2 is not(None): m1 = result2[2] ynew1 = m1[0:4] yint1 = int(ynew1) mnew1 = m1[5:7] mint1 = int(mnew1) dnew1 = m1[8:10] dint1 = int(dnew1) previousreturndate1 = datetime.date(yint1,mint1,dint1) tday = datetime.date.today() remainderdate=previousreturndate1 - tday remainderday = remainderdate.days #print(remainderday) if remainderday < 7 and remainderday >= 0: reissuequery1 = """ UPDATE usersdatabase SET b1name = %s,b1uid = %s,b1issuedate=%s,b1returndate=%s WHERE b1uid = %s """ newreturndate = returndate + remainderdate data1 = (bookname,bookuid,tday,newreturndate,bookuid) cursor.execute(reissuequery1,data1) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date :"+str(newreturndate)) window.finalize() player.play_song("bookreissue.mp3") elif remainderday < 0 : absremainderday = abs(remainderday) fine = intissuefine + 2 * absremainderday reissuequery2 = """ UPDATE usersdatabase SET b1name = %s,b1uid = %s,b1issuedate=%s,b1returndate=%s,fine=%s WHERE b1uid = %s """ newreturndate = returndate + remainderdate data2 = (bookname,bookuid,tday,returndate,fine,bookuid) cursor.execute(reissuequery2,data2) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date : "+str(newreturndate)+"\nTotal Fine: "+str(fine)) window.finalize() player.play_song("bookreissue.mp3") cursor.execute("Select lid, name ,b2returndate,b2issuedate,issued FROM usersdatabase WHERE b2uid="+str(bookuid)) result17 = cursor.fetchone() if (result17 is not(None)) and (result2 is None): m1 = result17[2] ynew1 = m1[0:4] yint1 = int(ynew1) mnew1 = m1[5:7] mint1 = int(mnew1) dnew1 = m1[8:10] dint1 = int(dnew1) previousreturndate1 = datetime.date(yint1,mint1,dint1) tday = datetime.date.today() remainderdate=previousreturndate1 - tday remainderday = remainderdate.days if remainderday < 7 and remainderday >= 0: reissuequery3 = """ UPDATE usersdatabase SET b2name = %s,b2uid = %s,b2issuedate=%s,b2returndate=%s WHERE b2uid = %s """ newreturndate = returndate + remainderdate data3 = (bookname,bookuid,tday,newreturndate,bookuid) cursor.execute(reissuequery3,data3) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date :"+str(newreturndate)) window.finalize() player.play_song("bookreissue.mp3") elif remainderday < 0 : absremainderday = abs(remainderday) fine = intissuefine + 2 * absremainderday reissuequery4 = """ UPDATE usersdatabase SET b2name = %s,b2uid = %s,b2issuedate=%s,b2returndate=%s,fine=%s WHERE b2uid = %s """ newreturndate = returndate + remainderdate data4 = (bookname,bookuid,tday,returndate,fine,bookuid) cursor.execute(reissuequery4,data4) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date : "+str(newreturndate)+"\nTotal Fine: "+str(fine)) window.finalize() player.play_song("bookreissue.mp3") cursor.execute("Select lid, name ,b3returndate,b3issuedate,issued FROM usersdatabase WHERE b3uid="+str(bookuid)) result18 = cursor.fetchone() if (result18 is not(None)) and (result17 is None) and (result2 is None): m1 = result18[2] ynew1 = m1[0:4] yint1 = int(ynew1) mnew1 = m1[5:7] mint1 = int(mnew1) dnew1 = m1[8:10] dint1 = int(dnew1) previousreturndate1 = datetime.date(yint1,mint1,dint1) tday = datetime.date.today() remainderdate=previousreturndate1 - tday remainderday = remainderdate.days if remainderday < 7 and remainderday >= 0: reissuequery5 = """ UPDATE usersdatabase SET b3name = %s,b3uid = %s,b3issuedate=%s,b3returndate=%s WHERE b3uid = %s """ newreturndate = returndate + remainderdate data5 = (bookname,bookuid,tday,newreturndate,bookuid) cursor.execute(reissuequery5,data5) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date :"+str(newreturndate)) window.finalize() player.play_song("bookreissue.mp3") elif remainderday < 0 : absremainderday = abs(remainderday) fine = intissuefine + 2 * absremainderday reissuequery6 = """ UPDATE usersdatabase SET b3name = %s,b3uid = %s,b3issuedate=%s,b3returndate=%s,fine=%s WHERE b3uid = %s """ newreturndate = returndate + remainderdate data6 = (bookname,bookuid,tday,returndate,fine,bookuid) cursor.execute(reissuequery6,data6) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date : "+str(newreturndate)+"\nTotal Fine: "+str(fine)) window.finalize() player.play_song("bookreissue.mp3") cursor.execute("Select lid, name ,b4returndate,b4issuedate,issued FROM usersdatabase WHERE b4uid="+str(bookuid)) result19 = cursor.fetchone() if (result19 is not(None)) and (result2 is None) and (result17 is None) and (result18 is None): m1 = result19[2] ynew1 = m1[0:4] yint1 = int(ynew1) mnew1 = m1[5:7] mint1 = int(mnew1) dnew1 = m1[8:10] dint1 = int(dnew1) previousreturndate1 = datetime.date(yint1,mint1,dint1) tday = datetime.date.today() remainderdate=previousreturndate1 - tday remainderday = remainderdate.days if remainderday < 7 and remainderday >= 0: reissuequery7 = """ UPDATE usersdatabase SET b4name = %s,b4uid = %s,b4issuedate=%s,b4returndate=%s WHERE b4uid = %s """ newreturndate = returndate + remainderdate data7 = (bookname,bookuid,tday,newreturndate,bookuid) cursor.execute(reissuequery7,data7) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date :"+str(newreturndate)) window.finalize() player.play_song("bookreissue.mp3") elif remainderday < 0 : absremainderday = abs(remainderday) fine = intissuefine + 2 * absremainderday reissuequery8 = """ UPDATE usersdatabase SET b4name = %s,b4uid = %s,b4issuedate=%s,b4returndate=%s,fine=%s WHERE b4uid = %s """ newreturndate = returndate + remainderdate data8 = (bookname,bookuid,tday,returndate,fine,bookuid) cursor.execute(reissuequery8,data8) &nbs