Introduction: Smart Fridge

Hello, in this instructable for school I'm going to show you how to create your own smart fridge using an Raspberry Pi. The smart fridge counts the drinks you take out by using your personal badge.

All the data will be saved and collected in a Mysql database and put on the website.The website is responsive and useable on smartphones.

Step 1: Tools and Components

Tools:

  • A soldering iron
  • Solder
  • Drill
  • Jigsaw
  • Saw
  • Screwdriver or hammer (if you want to use screws or nails)
  • Sandpaper
  • 2x Hardwood plywood (12mm 122 x 61 cm)

Components:

  • 1x Raspberry pi 3
  • 1x 8GB micro SD
  • 1x Led strip (1m)
  • 3x led's (green, blue and red)
  • 1x Button
  • 1x 6V / 12V elektric lock
  • 1x Relais 5V
  • 6x LDR
  • 9x resistor
  • 1x Breadboard
  • 1x MCP3008
  • 1x GPIO T-cobbler
  • 1x Ethernet cable
  • 1x External power (lock)
  • 1x Universal power (pi)
  • Electronic wires

These are the things that I used, but you can change some parts or add some.

Maximum total cost without tools is about €140

Step 2: Setting Up the Raspberry Pi 3

We will start installing the operating system on our Raspberry Pi.

Download the image "Raspbian Jessie with pixel" from the Raspberry Pi website. You will see that this is a ZIP-file.Extract this ZIP-file to a desired location.

  • Download the tool Win32 Disk Imager, this can be downloaded on Sourceforge.
  • Click on the folder icon to select the image
  • Then select at "Device" your microSD
  • Then click on "Write"

After the image is written on your microSD, you can open the microSD in Windows Explorer.

  • Open the file "cmdline.txt"
  • Add the following line before the word "rootwait": 169.254.10.0
  • Then save the file.

Insert the microSD in the RPi

Apply a voltage to your RPi with 5,2V DC Adapter

Connect the network cable to the RPi and plug it into the network port of your computer.

Your Raspberry is ready to use now.

Step 3: Connect to the Raspberry Pi 3

To connect to our RPi we will use Putty.

  1. Download Putty
  2. Create a SSH connection (see image)
  3. Sign in
    • Username: pi
    • Password: raspberry

SETTING WIFI UP

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf 

Go to the bottom of the file and add the following:

network={	ssid="name of the wireless network"
		psswrd="the password of the network
		psk="password of the wireless network"

}

To see your IP address type:

ifconfig wlan0

Now you can wirelessly connect to your Raspberry Pi Hostname in Putty = IP address

If there is an problem to connect to wifi, you can edit the file like this:

"sudo nano /etc/wpa_supplicant/wpa_supplicant.config"

Step 4: Electric Circuit

In this step we will connect every sensor to the Raspberry pi.

Connect the T-cobbler to the GPIO pins on the raspberry pi and place it on a breadboard. Or you can make your own PCB and make it more durable.

MCP3008:

  • Connect the VDD pin to 3v3Connect
  • the VREF pin to 3v3Connect
  • the AGND pin to GNDConnect
  • the CLK pin to SCLKConnect
  • the Dout pin to MISOConnect
  • the Din pin to MOSIConnect
  • the CS pin to CEOConnect
  • the DGND pin to GND

LDR:

Connect every LDR you use (max 8) to one pin on the MCP3008.

Connect the first pin of the LDR to the 3v3 and the second to an resistor and the resistor to the GND, and connect de LDR between the LDR and the resistor to a pin on the MCP3008.

VERY IMPORTANT: Make sure all wires going to the pi are connected with the right GPIO pin, otherwise your program won't work.

RFID

  • Most left pin (Voltage pin) to the 3v3 pin of the RPI
  • The second (RST) to the GPIO25
  • The ground to the ground
  • IRQ not
  • The MISO to the MISO of the RPI
  • The MOSI to the MOSI of the RPI
  • The SCK to the SCLK of the RPI
  • The SDA to the CEO of the RPI

The fridge button:

  • One pin to the 3v3 pin of the RPI
  • The other to the pin 13 of the RPI

The three LED's:

  • One pin to an 220 Ohm resistor and to the GROUND of the RPI
  • The other pin to the 23 pin, 24 pin and 26 pin

The LED lights in the fridge:

  • Connect the one pin (+) to the 5V
  • The other pin to the GROUND

The LOCK:

  • One pin of the lock (GROUND) you connect to the ground of the external adapter
  • The other pin of the lock (+) you connect to the Relais
  • The positive side of the external adapter you also connect to the Relais

So now you have only to connect the Relais itself.

  • The negative pin of the Relais you connect to the GROUND of the RPI
  • The pin in the middle (+pin) you connect to the 5V pin of the RPI
  • The Other pin (KY-1 pin) you connect to the 21pin of the RPI

Step 5: Building the Fridge

In this step we are building the fridge.

  1. First of all you'll need:

- The plywood

- Jigsaw

- Marker

Mark all the different parts on the plywood before you start sawing.

2. After you checked if all the parts are market you can start sawing. (Keep in mind that the blade has also some width)

3. After sawing all the parts you can start drilling the holes for your sensors.

- The bottom of the fridge need 6 big holes so the bottles can stay still.

- The floor of the fridge need 6 smaller holes for the LDR sensors.

- The roof needs 3 small holes for the 3 leds (blue, red and green).

- Make sure that the rfid can read trough the wood, otherwise you need to make the wood thinner.

- Make also an little hole in the inside front for the button.

For the door you need to make also 2 holes to connect the door to the inside of the fridge.
To open and close de door I installed a handle.

After you finished all the woordwork you can put the electrical parts in the write place.

Step 6: Connect Sensors to the Fridge

In this step we setup our fridge with all the components we bought.

You can start by sticking the breadboard and the Raspberry pi to the back of the fridge, that is the place where all the wires are end up.

Place the RFID, LED's, LDR's and the button right and make sure that you can connect to the breadboard.

Make sure that all the wires are connected correctly, you can look at the pictures or the other steps to do it write.

After you put all the components in the right place you can start screwing the different parts together as you can see in the pictures. All the wires can be hidden in the double bottom or the double top.

Step 7: Coding Hardware

I used the program Pycharm so I could test everything while I was coding. All the code that I wrote, can you find on my github

Step 8: Mysql

The database drop helps you to start using this project.

Simple acknowledgment of MySql code is helpful to change the project if you want.

I used 4 tables, Users, Drinks, Actions and Logging. These tables are the most simple and correct way to make sure the project works.

Step 9: Coding Website

You can see all the code in the following folder on Github.

I used the program Pycharm to write all of it. It is a easy way to code and see everything you do while you are working.

Step 10: Autostart Project

In this step I show you how to autostart your project on the raspberry pi.

Now we're gonna let our code autostart when our pi boots so it can run on its own. There are multiple ways to do this but I'm choosing for the rc.local method.

Open /etc/rc.local with your favorite text editor and put this code above the "exit 0" line

"sleep 15
python3 /home/pi/files/app/RUN.py &
python3 /home/pi/files/website/website.py & Finally "

when we want to see our website, you can browse to the IP address that was specified at the bottom of the website.py file (default is 169.254.10.1:5000). This is the end of my first instructable, if something's not clear, you can comment or message me.

Step 11: End

In this step we are going to put our smartfridge ready for use.


Connect the power supply from the Rasberry Pi in the socket.Wait until the Raspberry Pi is fully booted.

Connect the other power supply to the socket (for the lock).

You can take a drink by scanning your badge, close the door so the token drinks will go on your account.

To see your website: search for your IP address followed by :5000

Now your Smartfridge is ready to use. Enjoy your cold drinks without stressing out and keep an eye on the consumptions.

Woodworking Contest

Participated in the
Woodworking Contest