6
CONSTRUCTION ELECTRONICS FOR YOU • OCTOBER 2006 77 WWW.EFYMAG.COM CMYK B everage vending machines are commonplace at railway sta- tions, airports, fast-food restau- VINAY CHADDHA SANI THEO rants and even in companies. Press a switch and the machine delivers a hot cup of your favourite drink. This looks quite a simple operation but has a very complex logic behind it: It involves use of twelve precision timers and four counters apart from physical devices like display, solenoid and mo- tor to deliver water and premixed tea/coffee/soup powder in exact quantity for better taste and in ex- act sequence. This has become pos- sible because of the use of microcontrollers, which allow compact size, higher reliability, lower cost and multiple functionalities. This tea/coffee/soup vending ma- chine controller uses Freescale’s latest MC908JL16 microcontroller chip. The controller is programmable and user- friendly. You can set the quantity of the beverages through a button switch provided on the front panel of the con- troller as per your requirements. Thus, cups of any size can be filled at any time. The hardware Fig. 1 shows the block diagram of the vending machine controller. It com- prises the following sections: power supply, microcontroller, relays, relay driver, alphanumeric display, keyboard and memory. The power supply circuit is shown in Fig. 2. The control unit uses low-cost, readily available components. The temperature con- trol section has not been included in the design as the parts re- quired are expensive and not easily avail- able. However, a low- cost thermostat used in water heaters can be used in the unit. Power supply. The relays need 12V DC and the microcontroller and memory need 5V DC for operation. Bridge rectifier, capaci- tive filter and regulator ICs 7812 and 7805 are the standard parts used in the power supply. Microcontroller. We need individually BEVERAGE VENDING MACHINE CONTROLLER Fig. 1: Block diagram of the beverage vending machine controller Fig. 2: Power supply circuit The prototype of beverage vending machine controller developed by the author

Oct 2006 - Beverage Vending Machine

Embed Size (px)

Citation preview

Page 1: Oct 2006 - Beverage Vending Machine

CONSTRUCTION

E L E C T R O N I C S F O R Y O U • O C T O B E R 2 0 0 6 • 7 7W W W . E F Y M A G . C O M

CMYK

Beverage vending machines arecommonplace at railway sta-tions, airports, fast-food restau-

� VINAY CHADDHA

SANI THEO

rants and even in companies. Press aswitch and the machine delivers a hotcup of your favourite drink.

This looks quite a simple operationbut has a very complex logic behind

it: It involves use oftwelve precision timersand four counters apartfrom physical devices likedisplay, solenoid and mo-tor to deliver water andpremixed tea/coffee/souppowder in exact quantityfor better taste and in ex-act sequence.

This has become pos-sible because of the use ofmicrocontrollers, which

allow compact size, higher reliability,lower cost and multiple functionalities.

This tea/coffee/soup vending ma-chine controller uses Freescale’s latestMC908JL16 microcontroller chip. Thecontroller is programmable and user-friendly. You can set the quantity ofthe beverages through a button switchprovided on the front panel of the con-troller as per your requirements. Thus,cups of any size can be filled at anytime.

The hardware

Fig. 1 shows the block diagram of thevending machine controller. It com-prises the following sections: powersupply, microcontroller, relays, relay

driver, alphanumericdisplay, keyboard andmemory. The powersupply circuit is shownin Fig. 2.

The control unituses low-cost, readilyavailable components.The temperature con-trol section has notbeen included in thedesign as the parts re-quired are expensiveand not easily avail-able. However, a low-cost thermostat used inwater heaters can beused in the unit.

Power supply. Therelays need 12V DCand the microcontrollerand memory need 5VDC for operation.Bridge rectifier, capaci-tive filter and regulatorICs 7812 and 7805 arethe standard parts usedin the power supply.

Microcontroller.We need individually

BEVERAGE VENDING

MACHINE CONTROLLER

Fig. 1: Block diagram of the beverage vending machine controller

Fig. 2: Power supply circuit

The prototype of beverage vending machine controllerdeveloped by the author

Page 2: Oct 2006 - Beverage Vending Machine

CONSTRUCTION

7 8 • O C T O B E R 2 0 0 6 • E L E C T R O N I C S F O R Y O U W W W . E F Y M A G . C O M

CMYK

settable tim-ings for theseven relaysand multipletime delays be-tween the op-eration of theserelays, i.e., thewater inlet re-lay should op-erate onlywhen waterhas to be dis-pensed. Allthese functions,though pos-sible using dis-crete compo-nents, are besthandled byF r e e s c a l e ’ sM C 9 0 8 J L 1 6microcontroller.

Relays. Se-lection of eachbeverage re-quires two so-lenoid valves,one for premixpowder andanother for wa-ter outlet. Thesolenoid valvesare operatedthrough relays.That is, forthree bever-ages, we needsix solenoidsand six relaysto operatethem. The wa-ter heater tankis not con-nected to thesource of wateras this may in-crease thepower con-sumption. Thewater inlet isopened forsome time afterone cup isfilled to allowsmall quantityof water to be

Fig

. 3:

Cir

cuit

of t

he b

ever

age

vend

ing

mac

hine

con

trol

ler

Page 3: Oct 2006 - Beverage Vending Machine

CONSTRUCTION

E L E C T R O N I C S F O R Y O U • O C T O B E R 2 0 0 6 • 7 9W W W . E F Y M A G . C O M

CMYK

filled again in the tank. This requiresone more solenoid. So a total of sevensolenoids are required.

To activate these high-current so-lenoids, sugar-cube type relays areused. These are cheap and used in low-cost UPS for PCs. The relays needaround 100mA, 12V supply to oper-ate.

Relay driver ULN2003. Themicrocontroller cannot drive 12V,100mA relays directly and needs abuffer. This can be easily achieved us-ing BC547 transistors and a few resis-tors. However IC ULN2003 has beenused to drive the relays.

Alphanumeric display. The opera-tor needs a visual interface for settingthe various parameters and the statusof the input switches pressed. LED dis-plays will not be visible in brightly-litplaces, so LCDs are the best choice.Character size is not a constraint asthe machine is to be operated from aclose distance. A standard-size, 16-character, single-line alphanumericLCD has been used here. It is readilyavailable and commonly used in in-dustrial applications and PCO moni-tors.

Keyboard. We need at least fourkeys: two for beverages (one each fortea and coffee), one for half or full cup,and one for hot water. Tactile keyswitches have been used here. Theseare low-cost and readily available.

Memory. The control unit doesn’thave a battery backup system and willlose the set data when power fails. So

a provision has to be made to ensurethat the unit recalls the set parameterswhen power resumes. This is achievedby using a small-size 24C02 memory,which is commonly used in electronicgoods like TV sets.

Circuit description

Fig. 3 shows the circuit of the vendingmachine controller.

Power supply. The power supplycircuit comprises a 15V, 1A step-downtransformer, filters, 12V DC regulator7812 (IC1) for relays and 5V DC regu-lator 7805 (IC2) for microcontrollers(see Fig. 2). Fuse F1 protects againstsurge current in the event of shortcircuit.

Microcontroller. The MC908JL16microcontroller (also called theMC68HC908JL16) from FreescaleSemiconductor, Inc. (formerlyMotorola) has 28 pins with 23 general-purpose I/O lines, 16 kB of flashmemory to store program and 512bytes of RAM. It utilises an HC08 CPUcore and provides a cost-effectivereprogrammable flash memory. It alsohas two 16-bit timers and other stan-dard functionalities, making it an all-in-one control IC.

The device is a part of the growingJL Family that includes multiple clockoptions, keyboard interrupts, low-volt-age inhibit and a watchdog timer. Inparticular, the MC908JL16 has a built-in serial communications interfacemodule, master inter-integrated circuit(I2C) interface and 10-bit analogue-to-

digital converter (not used in this pro-gram).

The MC908JL16 is a low-cost, high-performance, 8-bit microcontrollerunit. It uses the enhanced M68HC08central processing unit (CPU08) andis available with a variety of modules,memory sizes, package types, etc. Itsdatasheet is available on Freescale’swebsite ‘www.freescale.com.’

Relays. The 12V, 1/CO relays arecapable of switching up to 7A, 220VAC loads. Across each relay contact,metal-oxide varistor (MOV) and resis-tor-capacitor (RC) snubber circuit havebeen added to reduce noise generatedby sparking at relay contacts at thetime of switching. Fuse F2 used forprotection against surge current can bereplaced with another higher-currentfuse as per the requirement of the so-lenoid used.

Relay driver. The relay driverULN2003 with seven outputs is ca-pable of sinking 500mA on each out-put. Inputs are TTL CMOS-compatibleand outputs are fed to relay coils di-rectly. With this driver, no free-wheel-ing diode is required across the relaycoils. Datasheets are included in thismonth’s EFY-CD.

Display. The display GDM1601Aused here is a 16x1 alphanumeric LCDbased on Hitachi HD44780 LCD con-troller. It is interfaced to themicrocontroller using four data lines(D7 through D4) and two control sig-nals (RS and E). Complete details ofHD44780 are available on the Internet.

Screenshot 1: The CodeWarrior 5.2 integrated developmentenvironment

Screenshot 2: The PROG08SZ programming environment

Page 4: Oct 2006 - Beverage Vending Machine

CONSTRUCTION

8 0 • O C T O B E R 2 0 0 6 • E L E C T R O N I C S F O R Y O U W W W . E F Y M A G . C O M

CMYK

Fig. 4: An actual-size, single-side PCB layout for the beverage vending machine controller

Fig. 5: Component layout for the PCB

Page 5: Oct 2006 - Beverage Vending Machine

CONSTRUCTION

E L E C T R O N I C S F O R Y O U • O C T O B E R 2 0 0 6 • 8 1W W W . E F Y M A G . C O M

CMYK

Keyboard. It has four push-to-onswitches (S2 through S5) connected tothe microcontroller using five lines, ofwhich four are shared with LCD datalines as shown in Fig. 3.

Memory. EEPROM 24CO2permanently stores information likedifferent timings, options forswitches and count of cups filled. Itis connected to the microcontrollerusing two lines, namely, serial data(SDA) and serial clock (SCL).Technical details of I2C bus and thememory have been covered earlierin EFY. (Refer to articles ‘AccessControl’ in EFY Sept. 2002, ‘Set-Top Converter’ in EFY June ’97,‘Caller ID’ in EFY April ’99 and‘Remote-Controlled Audio ProcessorUsing Microcontroller’ in EFYSept. ’99). Datasheet and I2C protocolsare included in this month’sEFY-CD.

An actual-size, single-side PCB lay-out for the beverage vending machinecontroller is shown in Fig. 4 and itscomponent layout in Fig. 5.

The software

The software has been developedin ‘C’ language using Metrowerks’Code Warrior ‘C’ compiler. A 16kBfree version of the compiler isavailable on the website‘www.metrowerks.com’

The program in ‘C’ is written onthe MC68HC908JL8, which is equiva-lent to the MC68HC908JL16, exceptthat the MC68HC908JL8 has only 8kBflash memory and 256 bytes of RAM.A specially developed programmerboard along with PROG08SZ software(www.pemicro.com) has been used forprogramming the microcontrollerchip.

Seven program modules have beenused for this project: ‘disp.c,’ ‘iic.c,’‘main.c,’ ‘initlcd.c,’ ‘sense_kbd.c,’‘timer.c’ and ‘utils.c.’

The software is developed intwo stages: First, basic common in-put/output (I/O) routines are devel-oped to display information on theLCD, read or write data from a spe-cific memory location, scan the key-board input (check which key has beenpressed) and switch on the relays.Next, logic/program specific for thisfunction is developed. This is more orless a translation job where you con-vert the end-product requirement in‘C’ language so that it performs asexpected.

CodeWarrior. The CodeWarrior 5.2integrated development environment(IDE) includes compilers, linkers,source-code browser, debugger, editorand rapid application developmenttool set (see Screenshot 1). You can useit to edit, navigate, examine, compileand link code throughout your soft-ware development process. You canalso configure options for code gen-eration, project navigation and otheroperations.

If you have this IDE tool, justcopy the relevant files fromthe EFY-CD into your PC. Open theproject file ‘tea_coffee.mcp.’ When thesource code is compiled, a ‘.s19’ file

is generated in ‘bin’ folder of the di-rectory where the original sourcecode is located. This file is equivalentto the hex code in other programmingtools.

Programmer. The PROG08SZ ver-sion 2.12 is a programmer forEEPROM/EPROM modules internalto a Motorola HC08 processor. Itcommunicates to the processor’s moni-tor mode (MON08) via one of P&EMicrocomputer Systems’ hardware in-terfaces that is designed to workwith the monitor mode. Alternatively,the MON08 circuitry can bebuilt directly into the end user’shardware. The PROG08SZ program-ming environment is shown inScreenshot 2.

The connection dialogue appearsinitially. We have used ‘class-3 directserial-to-target W/Mon08 serial portcircuitry’ option for the programmerboard used for programming. Next,select the serial port, tick the box cor-responding to the ‘ignore security fail-ure and enter monitor mode’ and thenclick ‘contact target with this setting…’The ‘power cycle dialogue’ box ap-pears. Now switch off the program-mer board.

Switch on the programmer boardagain and press ‘ok.’ Select the deviceand open ‘.s19’ file under ‘File’ menuto program into the chip.

Operations of the unit

Each switch performs dual functionsas follows:

Switch Normal mode Setting mode

S2 Tea Reset

S3 Coffee Increment

S4 Soup or half/full Decrement

S5 Hot water Setting/next/OK

Setting mode. Normally, this modeis used only once to set various pa-rameters as per the specific require-ment, say, the size of the cup. Thiscan be done by following a simpleprocedure. Switch off the controllerunit. Press switch S5 (marked as ‘hotwater’) for the settings mode andswitch on the unit. Follow the in-structions on the LCD. Press switchS5 again for the desired option. Press-

PARTS LISTSemiconductor:IC1 - 7812, 12V regulatorIC2 - 7805, 5V regulatorIC3 - 24C02 I2C memoryIC4 - MC908JL16C

microcontrollerIC5 - ULN2003 relay driverD1-D8 - 1N4148 switching diodeLED1-LED8 - 5mm light-emitting

diodeBR1 - 1A bridge rectifierResistors (all ¼-watt, ±5% carbon):R1 - 4.7-kilo-ohmR2, R3, R5, R6,R7, R8, R11 - 10-kilo-ohmR4 - 10-mega ohmR9 - 10-ohmR10 - 1-kilo-ohmR12-R18 - 100-ohmCapacitors:C1 - 2200µF, 35V electrolyticC2, C4, C5,C7, C11, C12 - 0.1µF ceramicC3, C6, C8 - 10µF, 25V electrolyticC9, C10 - 33pF ceramicC13-C19 - 0.01µF ceramicMiscellaneous:X1 - 230V AC primary to 15V,

1A secondary transformerS1 - On/off toggle switchS2-S5 - Push-to-‘on’ switch

(4-pin)RL1-RL7 - 12V, 1/CO relayXTAL - 4.1943MHz crystal

oscillatorF1 - 0.5A fuseF2 - 1.5A fuseSOL1-SOL7 - Solenoid valveLCD - 16×1 liquid-crystal

display

Page 6: Oct 2006 - Beverage Vending Machine

CONSTRUCTION

8 2 • O C T O B E R 2 0 0 6 • E L E C T R O N I C S F O R Y O U W W W . E F Y M A G . C O M

CMYK

ing switches S3 and S4 will incre-ment or decrement the value (in sec-onds), respectively.

The program has an option for ahalf or full cup of the beverage. S4can be used for either ‘soup’ or‘half/full’ option in the setting mode.When ‘OPT3’ is selected, S4 will func-tion as a switch for dispensing thesoup. When ‘half/full’ option is se-lected, S4 will function as a switchfor filling up the cup to half or full.For dispensing tea and coffee, twotime settings are required, i.e., premix-dispensing time and water-dispens-ing time. These can be adjusted asper specific requirements, say, quan-

tity and strength (flavour) of thebeverage.

Dispensing of tea has an ex-tra function of brewing (op-tional). In this mode, water isdispensed for a second, thenstopped to allow mixing of thepowder with water, and dis-pensed again after some time.This timing can be set through

the ‘brew time’ option.Common setting for tea/coffee/

soup. The time for activation of thewater solenoid valves can be set toallow hot water to be dispensedthrough the common outlet.

After dispensing, some water re-maining in the pipes cools off. In thenext dispensing, this water is dis-pensed along with hot water from thewater heater. So a provision is madeto automatically flush the cold waterout from the pipes at regular inter-vals. The time interval to flush outthe cold water can be set by the user.For example, if you set ‘Flush To’ as‘010 m,’ i.e., 10 minutes as the time

duration for which nobody uses themachine, message “flush required”will be displayed. The user will haveto press switch S5 to flush the waterout.

Apart from this, there are time set-tings for delay, refill, etc. The delaytime is the time interval between theconsecutive dispensing of water andpremix powder. Refill time is the timefor refilling water into the waterheater. Relay RL7 energises throughpin 10 of IC5 to refill water in theheater.

After you are done with settings,switch off the power supply for about30 seconds to allow complete dischargeof the filtering capacitor used in thepower supply section. Switch on theunit again and it is now ready for use.The display will show “have a niceday.”

EFY note. 1. The source codes havebeen included in this month’s EFY-CD.

2. This article is based on commer-cial vending machines developed byGVC Systems. �

Message Displayed on PressingSwitches S2 through S5

Switch pressed Message displayed

S2 for dispensing tea Serving tea

S3 for dispensing coffee Serving coffee

S4 for dispensing soup Soup or half/full dependingon the setting

S5 for dispensing hot water Hot water