Arduino Vending Machine

 Arduino Vending Machine

For this practice we have to create an arduino program and use some sensors and actuators in order to simulate a real coffee vending machine.

HARDWARE COMPONENTS:

  • Joystick
  • DHT11 (humidity and temperature sensor)
  • Ultrasonic sensor
  • Boton
  • 2 Leds
  • LCD
  • Arduino Uno

What is its behavior ?

We are going to have 3 different behavior stages 

1) Loading mode:

The led 1 is going to blink 3 times at 1 seconds intervals. At the same time that we are executing the blinks of the led, we are going to write a loading message ("CARGANDO...") in the LCD; after that, it is going to entry to the service mode.

2) Service Mode:

We are going to print a waiting for client message ("ESPERANDO CLIENTE") at the LCD until the distance sensors get a 1 meter or less detection, simulating the client detection.

When the client has been detected, we are going to show the products at the LCD and letting the client search for the product that he wants using the joystick (up / down) and  the switch of the button to confirm the selection.

Finally, we are going to show a "preparing coffee message" at the LCD and a "get the drink message" when the preparation time have finished.  

* If the client wants to restart this mode, he just have to press the button during 3 seconds.

3) Admin mode:
Whenever the user want, he can push the button during 5 seconds or more and the 2 leds will light up and the machine will enter at the admin mode.

In this mode a menu will be displayed at the LCD and he will navigate through it using the joystick.
This menu have 4 options, one for display the humidity and temperature detected by the DHT11 sensor, other for display the distance to an object detected by the distance sensor, another one for showing how much time has been pass(in seconds) since the machine started working; and the last one is going to allow the user to change the prices of the products confirming with the switch of the joystick what item price want to change and what price does he want, and  moving the joystick up and down changing the item selected and its price. 

How does it really work?

1) How are we going to do the led blink?

For this, we are going to use the Arduinothread library, creating a thread that will execute the blink function in the correct moment and which, when it has make the led blink 3 times, is going to be disabled. 

2) Get distance form the distance sensor.

The ultrasonic sensor uses sonar to determine the distance to an object




The time between the transmission and reception of the signal allows us to calculate the distance to an object. This is possible because we know the sound's velocity in the air.


3) Show text at the LCD:

For this we are going to use the LiquidCrystal library.   

The most important functions of this library are: 
  • LiquidCrysta lcd(correct arudino pins)  -> create an LCD object
  • ldc.clear() -> clean the screen
  • ldc.setCursor(row, col) -> select where do you want to start writing at the LCD
  • ldc.print(text) -> show the text at the LCD
4) Calculate the time since the machine started to work.

We use the library TimerOne to execute a software interruption every second which will increment a counter of seconds.

5) Button Control:

We have already seen that our machine is going to be having a planned behavior but it has to change his state as sons as the button is pressed. To achieve this, we are going to use the attachinterrupt() function to get a hardware interruption that is going to control the behavior of the vending machine when the button is pressed. Also we are going to wait some time before execute the code of the button callback, in order to avoid the button bounces.

6) Humidity and temperature lectures:

We use the library DHT-sensor-library created by adafruit to get this measures.

The most important functions of this library are: 
  • dht DHT  -> create a dht object
  • DHT.read11(dhtpin) -> read the input of the sensor and actualize the attributes of the DHT object 
  • DHT.temperature -> get the temperature (which is an attribute of the DHT object)
  • DHT.humidity -> get the humidity (which is an attribute of the DHT object)

7) Joystick lectures:

We just have to connect the joystick to the analog pines of our arduino and read it values in order to determine if the joystick has been moved, and for the switch, it just work as a normal button.

8) Coffee preparation simulation:

We are just going to use the random function to generate a random number which is going to represent the time during which we are preparing the coffee.

See a demo:


See the schematic circuit:



 * The DHT11 sensor and joystick of the image are not the same as the ones that I used, but the components connection is the same. 








Comentarios

Entradas populares de este blog

Localized Vacuum Cleaner

Autonomous drone for search and rescue mission

OMPL Amazon warehouse