Visualisering av dörröppningar - En trådlös prototyp Anna Nordström Sofia Svensson Examensarbete inom medicinsk teknik Stockholm 2015
Detta examensarbete har utförts i samarbete med Karolinska Universitetssjukhuset Solna Handledare på Karolinska Universitetssjukhuset Solna: Carola Kunze och Veronica Ramirez Johansson Anna Nordström Sofia Svensson Visualisering av dörröppningar - En trådlös prototyp Visualization of door openings - A wireless prototype Examensarbete inom medicinsk teknik Grundnivå, 15 hp Handledare på KTH: Anna Bjällmark Examinator: Lars-Gösta Hellström Skolan för teknik och hälsa TRITA-STH 2015:049 Kungliga Tekniska Högskolan KTH STH SE-141 86 Flemingsberg, Sweden http://www.kth.se/sth
Förord Under vårterminen 2015 har detta kandidatexamensarbete utförts som en del av Civilingenjörsprogrammet medicinsk teknik vid Kungliga Tekniska Högskolan. Vi vill tacka Carola Kunze, Veronica Ramirez Johansson och Britt Persson Askling på Karolinska Universitetssjukhuset för deras handledning och engagemang under projektets gång. Vi vill även tacka vår handledare på KTH, Anna Bjällmark, för din tillgänglighet och hjälp. Vi vill också rikta ett stort tack till Jonas Wåhslén för din inspiration och för att du alltid tagit dig tid att svara på frågor. Din hjälp har varit ovärderlig för oss. Anna Nordström Sofia Svensson KTH STH 2015
Sammanfattning Dörröppningar till en operationssal under en pågående operation ökar infektionsrisken. På Centraloperation, Karolinska Universitetssjukhuset Solna, öppnas dörrarna till operationssalen fler gånger än nödvändigt. Muntlig information till personalen har inte minskat antalet dörröppningar på lång sikt. En trådlös tekniklösning som räknar och visualiserar antalet dörröppningar tros ha en mer långvarig effekt, därför skulle en prototyp tas fram. En litteraturstudie gjordes för att hitta komponenter och för att med dessa skapa prototypen. Prototypen kan räkna och visualisera antalet dörröppningar från en dörr. Då en operationssal oftast har tre dörrar är visualiseringen förberedd för att kunna visa antalet för dessa. Prototypen behöver vidareutvecklas för att kunna användas på under en operation. Nyckelord Arduino, ESP8266, mätsystem, Wi-Fi, dörröppningar, operationssal, infektionsrisk, luftkvalitet.
Abstract Door openings to an operating theatre, during an ongoing operation, increases the risk of infection. At the Central operation department, Karolinska University Hospital Solna, the doors open more frequently than necessary. Oral information to the staff has not reduced the number of door openings for a longer time. A wireless solution that counts and visualizes is believed to have a more longlasting effect, therefore a prototype would be created. A literature study was performed in order to find components and with those build the prototype. The prototype is able to count and visualize the number of door openings from one door. However, since many operating theatres have three doors, the visualization is prepared for this. To be able to use this system during an operation the prototype needs to be further developed. Keywords Arduino, ESP8266, measurement system, Wi-Fi, door openings, operation theatre, risk of infection, air quality.
Innehållsförteckning 1. Inledning 1 1.1 Syfte och mål 1 2. Bakgrund 2 3. Metod 3 3.1 Material 3 3.2 Prototypframtagning 3 4. Resultat 6 5. Diskussion 7 6. Slutsats och framtida arbete 9 6.1 Slutsats 9 6.2 Framtida arbete 9 7. Referenser 10 Appendix 1 Appendix 2 Appendix 3 i vii xi
1. Inledning Patientförsäkringens projekt PRISS (ProtesRelaterade Infektioner Ska Stoppas), har tagit fram rekommendationer för att minska antalet infektioner i samband med ledprotesoperationer. I rekommendationerna föreslås åtgärder för att uppnå mikrobiologisk renhet i luften i operationssalen. En av åtgärderna är att minska antalet dörröppningar (PRISS expertgrupp 4, 2014). Luften kontamineras genom bakteriebärande partiklar från personer som vistas i operationssalen, ju fler personer desto mer bakteriebärande partiklar. Rörelser och dörröppningar i operationssalar påverkar luftens renhetsgrad negativt. Studien Något om skyddsventilation i operationsrum (Nordenadler, 2011) visar att det finns ett samband mellan antalet dörröppningar, antal personer och förekomsten av bakteriebärande partiklar i närheten av operationssår. Avhandlingen Patient Safety in operating room - focus on infection control and prevention baseras bland annat på en studie av dörröppningar. I den noterades ett stort antal dörröppningar som inte var nödvändiga för operationerna. Det registrerades totalt 928 stycken dörröppningar, varav ingen orsak kunde identifieras till 142 stycken av dem. Sociala besök stod för ytterligare 57 stycken dörröppningar. (Erichsen Andersson, 2013) Tillsammans stod dessa två grupper för drygt 20 % av det totala antalet och ansågs inte vara nödvändiga för operationerna. Carola Kunze, Expertsjuksköterska hygien på Karolinska Universitetssjukhuset, har med en arbetsgrupp inom hygienområdet genomfört ett antal mätningar på dörröppningar under pågående operationer. De har då sett att beteendet kring dörröppningar och personal i operationssalarna inte är i enlighet med vad som främjar luftkvaliteten. Endast nödvändiga dörröppningar och minsta möjliga antal personal inne på salen är faktorer som minskar nivån av bakteriebärande partiklar och därmed främjar luftkvaliteten. Artikeln Frekvens av dörröppningar till operationssal under pågående aktivitet (Lindberg, 2006) visar också på att det höga antalet dörröppningar är ett utbrett problem. Arbetsgruppen inom hygien har märkt att muntlig information till personalen inte gett en långvarig förändring. De har därför uttryckt en önskan om en teknisk lösning som räknar och visualiserar informationen. Detta skulle även spara tid för hygiengruppen, då mätningarna inte skulle ske manuellt. 1.1 Syfte och mål Syftet var att med en teknisk lösning ändra personalens beteende så att antalet dörröppningar under pågående operationer minskas. Målet var att ta fram en prototyp på ett trådlöst mätsystem som räknar och visualiserar antalet dörröppningar från en dörr till operationssalen. 1
2. Bakgrund Några metoder som mätsystem kan baseras på är ultraljud, infraröd strålning och mekaniskt tryck. För dessa metoder kan ett mikrokontrollerkort användas, vilket fungerar likt en begränsad dator. Arduino är en typ av mikrokontrollerkort (Arduino (1), 2015) och kan kopplas ihop med andra enheter, produktbeskrivning återfinns i Appendix 1. Exempel på en sådan enhet är ESP8266 som tillsammans med Arduinon kan kopplas upp på ett nätverk. För att skapa en mekanisk räknare kan en Arduino tillsammans med en mikrogapsströmställare användas. En mikrogapsströmställare är en mekanisk sensor som detekterar tryck. Sensorn kan därmed känna av tryck från en stängd dörr och avsaknad av tryck från en öppen dörr. Arduinos utvecklingsmiljö heter Arduino IDE, Integrated Development Environment. Ett program i utvecklingsmiljön kallas för en sketch. Den består alltid av två funktioner, setup() och loop(). I den förstnämnda kan begynnelsevillkor placeras medan i den andra placeras händelser som ska upprepas (Arduino (2), 2015). I en operationssal kan utrustningen vara känslig för störningar från trådlös elektronisk utrustning. Enligt artikeln Modern Wireless Telecommunication Technologies and Their Electromagnetic compability with Life Supporting Equipment är detta inget problem så länge avståndet är mer än en meter mellan operationsutrustningen och den trådlösa enheten (Wallin, Marve, & Håkansson, 2005). 2
3. Metod En litteraturstudie gjordes för att undersöka möjliga lösningar för trådlösa mätsystem och dess komponenter. De databaser som användes var Google Scholar och PubMed. Litteraturstudien resulterade i att en mikrogapsströmställare, Arduino Uno och Wi-Fi modulen ESP8266 valdes. Arduino Uno går hädanefter under namnet Arduinon. Kunskap om komponenterna inhämtades bland annat via produktbeskrivningar och tidigare arbeten med dem. 3.1 Material Materialet som användes finns nedan i tabell 1. Objekt Produktinformation Antal Arduino Uno Arduino, Italien 1 Arduino Software (IDE) 1.6.3 Arduino, Italien 1 MacBook Air 13 Apple, Kina 1 Kopplingsdäck 270 anslutningar E-call enterprise company limited, Taiwan 1 Mikrogapströmställare, VX-56-1A3 Omron, Japan 1 Platta för arduino och kopplingsdäck Sparkfun Electronics, USA 1 ESP8266 (Wi-Fi-modul) Seedstudio, Kina 1 Hylslist 2,54mm 1*8p TE connectivity, Tyskland 1 Flatkabel IDC (IDE-kontakt) Olimex, Bulgarien 1 Batteri 9V GP Ultra GP Batteries, Malaysia 2 Batterihållare 9V med DC-plugg Daier electron company, Kina 2 Router, TEW-711BR Trendnet, Kina 1 Tabell 1. Material 3.2 Prototypframtagning 1. För att installera Arduinon och Arduino IDE följdes 9 steg via Arduinos hemsida, dessa återfinns i Appendix 2 (Arduino (3), 2015). 2. Mikrogapsströmställaren kopplades till Arduinon via kopplingsplattan. Mikrogapsströmställaren har tre sladdar, en ingång och två utgångar. Ingången kopplades till 5V medan utgångarna kopplades till digital pin 4 respektive 7. 3. En adapter mellan ESP8266 och kopplingsplattan skapades genom att löda ihop hylslisten med IDE-kontakten. 4. ESP8266 med tillhörande adapter kopplades till kopplingsplattan enligt instruktioner i tabell 2, se figur 1 och figur 2. 3
Anslutning på ESP8266 Digital pin på Arduino 1 3,3V 2 3,3V 3 3,3V 4 2 5 8 6 7 8 GND Tabell 2. Kopplingar mellan ESP8266 och Arduino 5. Routern kopplades in och genom installationsguiden valdes ett lösenord. Datorn ihopkopplad med Arduinon anslöts till routerns nätverk. 6. Ett nytt program i Arduino IDE skapades genom att klicka Fil Ny i menyraden. 7. Ursprungskoden (Wang, 2014) för att sätta upp Wi-Fi på ESP8266 modifierades. Några viktiga delar i koden är att koppla upp ESP8266 till routern, tilldela ESP8266 en IP-adress samt att sätta den som en server. 8. Ursprungskoden (Wang, 2014) utökades med variabler som antingen var HIGH eller LOW beroende på läget hos mikrogapsströmställaren. Ytterligare lades variabeln counter till som fungerade som en räknare. Se koden i Appendix 3. 9. Programmet laddades upp genom att klicka på ikonen Ladda upp medan USB-kabeln satt i mellan Arduinon och datorn. 10. Två batterier parallellkopplades genom lödning på batterihållarnas sladdar. 11. USB-kabeln togs bort och de parallellkopplade batterierna sattes in. Arduinons reset-knapp trycktes in. 12. Visualiseringsenheten, i detta fall en läsplatta, kopplades upp på routerns nätverk. 13. Visualiseringen påbörjades då IP-adressen skrevs in i webbläsarens adressfält på läsplattan. 4
Anslutningar: 5 1 6 2 7 3 8 4 Figur 1. Anslutningar på ESP8266 Figur 2. Kopplingsschema 5
4. Resultat Prototypen bestod huvudsakligen av ett mikrokontrollerkort, en Wi-Fi modul, en mekanisk sensor, en router och en läsplatta. Uppställningen ses nedan i figur 3. Den mekaniska sensorn placerades så att den var intryckt då dörren var stängd och utsläppt då dörren var öppen. Vid intryckt läge registrerades digital pin 4 som HIGH och digital pin 7 som LOW. Vid varje dörröppning ökade värdet på variabeln counter. Tiden för systemet att registrera och visualisera en dörröppning varierar. Mätningar visade att det kan variera mellan cirka fem sekunder och en minut. Figur 3. Uppställning av prototypen Antalet dörröppningar visualiserades i ett webbläsarfönster på en läsplatta som var uppkopplad till routerns nätverk. Prototypen räknade endast öppningarna från en dörr men visualiseringen var förberedd för tre dörrar. Se figur 4. Figur 4. Exempel på visualisering 6
5. Diskussion Inför komponentval gjordes en litteraturstudie och Arduino Uno valdes framför andra liknande komponenter. Detta för att den var välanvänd och kompatibel med det befintliga operativsystemet som fanns till befogande. Troligtvis hade systemet blivit enklare att utforma om en mer avancerad typ av Arduino valts då mindre omfattande programmering behövts. Exempelvis har typen Arduino Mega flera portar för att kunna skicka och ta emot data medan Arduino Uno bara har en. Därav söktes mer information för att kunna skapa ytterligare en port genom programmeringen, vilka båda var tidsomfattande processer. Mikrogapsströmställaren valdes för att den enkelt kan simulera en dörröppning. Ultraljud och infrarödstrålning baseras på reflektion och ställer därför krav på placering och avstånd mellan system och dörr vilket den mekaniska sensorn inte gör. En annan fördel med den mekaniska sensorn är att den utgörs av en del medan både ultraljud och infrarödstrålning ofta består av två delar, sändare och mottagare. För att göra systemet trådlöst krävdes en enhet som har den funktionen, enheten ESP8266 valdes för dess låga kostnad. Ett alternativ hade varit en så kallad Wi-Fi-sköld som litteraturstudien visade vara det vanligaste alternativet men då den var betydligt dyrare valdes den bort. Anledningen till att systemet inte alltid reagerar i en önskad hastighet misstänks vara informationsöverföringen. Med multimeter visades det att mikrogapsströmställaren reagerar direkt och därför misstänks felet ligga i överföringen. En felkälla till detta tros vara ESP8266 då det är den enhet som sköter den trådlösa överföringen. Den utbredda användningen av Wi-Fi-sköldar kan tyda på att det skulle kunna vara ett snabbare alternativ. En annan felkälla rörande hastigheten kan vara programmeringen. Då ingen av projektmedlemmarna tidigare arbetat i Arduinos utvecklingsmiljö finns risk att koden inte är optimalt utformad. Även de långa kopplingstrådarna samt lödningarna kan vara felkällor som kan påverka systemet negativt, detta i form av ett långsammare system samt eventuella glapp. Resultatet kan användas för att vidareutveckla prototypen till en produkt som är anpassad till operationssalens antal dörrar samt har en snabbare reaktionshastighet. Vissa dörrar i en operationssal kan öppnas automatiskt och en sådan dörröppning varar i cirka tio sekunder. Därför skulle en rimlig tid för systemet att svara på en dörröppning och sedan visualisera den vara kring tio sekunder. Som beskrivet i inledningen är infektionsrisken i samband med operationer relaterad till antalet dörröppningar. Förhoppningen med produkten är att den indirekt ska minska antalet dörröppningar, vilket i sin tur kan leda till minskat antal vårdrelaterade infektioner. Det skulle innebära att färre patienter behöver göra återbesök. Ur ett samhällsekonomiskt perspektiv ger det minskade kostnader då patienten kan återgå 7
snabbare till arbetet. En annan positiv effekt av minskat antal vårdrelaterade infektioner är kortare vårdköer. Det gör att människor får vård snabbare och därmed slipper onödigt lidande, vilket även är positivt ur ett etiskt perspektiv för både individen och samhället. 8
6. Slutsats och framtida arbete 6.1 Slutsats Prototypen gör det möjligt att visualisera antalet dörröppningar. Systemets stabilitet i avseende på reaktionstid behöver vidareutveckling för att uppnå önskvärd hastighet. 6.2 Framtida arbete För att systemet ska kunna användas under operationer behöver det vidareutvecklas. Det viktigaste att arbeta vidare med är systemets hastighet. Nästa steg är rimligtvis att anpassa systemet till tre dörrar. Vidare kan visualiseringen utvecklas genom att använda kunskap om människans kognitiva förmåga, exempelvis kan olika färger användas vid ett visst antal dörröppningar. En annan användbar funktion kan vara att systemet ska kunna spara mätningar samt lägga dessa i ett arkiv för att kunna ta fram statistik, utföra uppföljningar samt utvärdera systemets effekt. Andra aspekter att arbeta vidare med kan också vara att systemet registrerar antalet personal i operationssalen samt luftkvaliteten. Det ultimata hade varit om systemet hade visat sambandet mellan luftkvaliteten, antalet dörröppningar samt personal i salen. 9
7. Referenser Arduino (1). (2015). Arduino. Hämtat från Products-Arduino-Arduino Uno: http://arduino.cc/en/main/arduinoboarduno den 16 04 2015 Arduino (2). (2015). Arduino. Hämtat från Learning -Getting started-foundations-sketch: http://www.arduino.cc/en/tutorial/sketch den 03 05 2015 Arduino (3). (2015). Arduino. Hämtat från Learning-Getting Started-Mac OS X: http://arduino.cc/en/guide/macosx den 16 04 2015 Erichsen Andersson, A. (2013). Patient Safety in the Operating Room - Focus on Infection Control and Prevention. Göteborg: University of Gothenburg. Sahlgrenska Academy. Lindberg, M. (2006). Frekvens av dörröppningar till operationssal under pågående aktivitet. Uppdukat, ss. 24-29. Nordenadler, J. (2011). Något om skyddsventilation i operationsrum. Stockholm: KTH. PRISS expertgrupp 4. (den 13 10 2014). Patientförsäkringen LÖF. Hämtat från PRISS-rekommendationer: http://www.patientforsakring.se/resurser/dokument/priss/priss-expertgrupp-4-optimal-oper ationsmiljoe.pdf den 16 04 2015 Wallin, M. K., Marve, T., & Håkansson, P. K. (11 2005). Modern Wireless Telecommunication Technologies and Their Electromagnetic Compatibility with Life-Supporting Equipment. Anesthesia & Analgesia, ss. 1393-1400. Wang, R. (den 14 12 2014). Rayshobby. Hämtat från Archive - October 2014 - First Impression on the ESP8266 Serial-to-WiFi Module: http://raysfiles.com/arduino/esp8266a_arduino.ino den 14 05 2015 Muntlig Kunze, C. (den 13 02 2014). Expertsjuksköterska hygien Karolinska universitetssjukhuset. (A. Nordström, & S. Svensson, Intervjuare Appendix Appendix 1: Arduino. (2015). Arduino. Hämtat från Products-Arduino-Arduino Uno: http://arduino.cc/en/main/arduinoboarduno den 16 04 2015 Appendix 2: Arduino. (2015). Arduino. Hämtat från Learning-Getting Started-Mac OS X: http://arduino.cc/en/guide/macosx den 16 04 2015 10
Appendix 1 Produktbeskrivning Arduino Uno Arduino Uno R3 Front Overview The Arduino Uno is a microcontroller board based on the ATmega328 (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started. The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USB-to-serial converter. Revision 2 of the Uno board has a resistor pulling the 8U2 HWB line to ground, making it easier to put into DFU mode. Revision 3 of the board has the following new features: 1.0 pinout: added SDA and SCL pins that are near to the AREF pin and two other new pins placed near to the RESET pin, the IOREF that allow the shields to adapt to the voltage provided from the board. In future, shields will be compatible with both the board that uses the AVR, which operates with 5V and with the Arduino Due that operates with 3.3V. The second one is a not connected pin, that is reserved for future purposes. Stronger RESET circuit. Atmega 16U2 replace the 8U2. i
"Uno" means one in Italian and is named to mark the upcoming release of Arduino 1.0. The Uno and version 1.0 will be the reference versions of Arduino, moving forward. The Uno is the latest in a series of USB Arduino boards, and the reference model for the Arduino platform; for a comparison with previous versions, see the index of Arduino boards. Summary Microcontroller ATmega328 Operating Voltage 5V Input Voltage (recommended) 7-12V Input Voltage (limits) 6-20V Digital I/O Pins 14 (of which 6 provide PWM output) Analog Input Pins 6 DC Current per I/O Pin 40 ma DC Current for 3.3V Pin 50 ma Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader SRAM 2 KB (ATmega328) EEPROM 1 KB (ATmega328) Clock Speed 16 MHz Length 68.6 mm Width 53.4 mm Weight 25 g Schematic & Reference Design EAGLE files: arduino-uno-rev3-reference-design.zip (NOTE: works with Eagle 6.0 and newer) Schematic: arduino-uno-rev3-schematic.pdf (http://www.arduino.cc/en/uploads/main/arduino_uno_rev3-schematic.pdf) Note: The Arduino reference design can use an Atmega8, 168, or 328. Current models use an ATmega328, but an Atmega8 is shown in the schematic for reference. The pin configuration is identical on all three processors. Power The Arduino Uno can be powered via the USB connection or with an external power supply. The power source is selected automatically. External (non-usb) power can come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging a 2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER connector. The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts. The power pins are as follows: ii
VIN. The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin. 5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7-12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it. 3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 ma. GND. Ground pins. IOREF. This pin on the Arduino board provides the voltage reference with which the microcontroller operates. A properly configured shield can read the IOREF pin voltage and select the appropriate power source or enable voltage translators on the outputs for working with the 5V or 3.3V. Memory The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM library). Input and Output Each of the 14 digital pins on the Uno can be used as an input or output, using pinmode(), digitalwrite(), and digitalread() functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 ma and has an internal pull-up resistor (disconnected by default) of 20-50 kohms. In addition, some pins have specialized functions: Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip. External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachinterrupt() function for details. PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogwrite() function. SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using the SPI library. LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off. The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogreference() function. Additionally, some pins have specialized functionality: TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the iii
Wire library. There are a couple of other pins on the board: AREF. Reference voltage for the analog inputs. Used with analogreference(). Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board. See also the mapping between Arduino pins and ATmega328 ports. The mapping for the Atmega8, 168, and 328 is identical. Communication The Arduino Uno has a number of facilities for communicating with a computer, another Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial communication, which is available on digital pins 0 (RX) and 1 (TX). An ATmega16U2 on the board channels this serial communication over USB and appears as a virtual com port to software on the computer. The '16U2 firmware uses the standard USB COM drivers, and no external driver is needed. However, on Windows, a.inf file is required. The Arduino software includes a serial monitor which allows simple textual data to be sent to and from the Arduino board. The RX and TX LEDs on the board will flash when data is being transmitted via the USB-to-serial chip and USB connection to the computer (but not for serial communication on pins 0 and 1). A SoftwareSerial library allows for serial communication on any of the Uno's digital pins. The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino software includes a Wire library to simplify use of the I2C bus; see the documentation for details. For SPI communication, use the SPI library. Programming The Arduino Uno can be programmed with the Arduino software (download). Select "Arduino Uno from the Tools > Board menu (according to the microcontroller on your board). For details, see the reference and tutorials. The ATmega328 on the Arduino Uno comes preburned with a bootloader that allows you to upload new code to it without the use of an external hardware programmer. It communicates using the original STK500 protocol (reference, C header files). You can also bypass the bootloader and program the microcontroller through the ICSP (In-Circuit Serial Programming) header using Arduino ISP or similar; see these instructions for details. The ATmega16U2 (or 8U2 in the rev1 and rev2 boards) firmware source code is available. The ATmega16U2/8U2 is loaded with a DFU bootloader, which can be activated by: iv
On Rev1 boards: connecting the solder jumper on the back of the board (near the map of Italy) and then resetting the 8U2. On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB line to ground, making it easier to put into DFU mode. You can then use Atmel's FLIP software (Windows) or the DFU programmer (Mac OS X and Linux) to load a new firmware. Or you can use the ISP header with an external programmer (overwriting the DFU bootloader). See this user-contributed tutorial for more information. Automatic (Software) Reset Rather than requiring a physical press of the reset button before an upload, the Arduino Uno is designed in a way that allows it to be reset by software running on a connected computer. One of the hardware flow control lines (DTR) of the ATmega8U2/16U2 is connected to the reset line of the ATmega328 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset line drops long enough to reset the chip. The Arduino software uses this capability to allow you to upload code by simply pressing the upload button in the Arduino environment. This means that the bootloader can have a shorter timeout, as the lowering of DTR can be well-coordinated with the start of the upload. This setup has other implications. When the Uno is connected to either a computer running Mac OS X or Linux, it resets each time a connection is made to it from software (via USB). For the following half-second or so, the bootloader is running on the Uno. While it is programmed to ignore malformed data (i.e. anything besides an upload of new code), it will intercept the first few bytes of data sent to the board after a connection is opened. If a sketch running on the board receives one-time configuration or other data when it first starts, make sure that the software with which it communicates waits a second after opening the connection and before sending this data. The Uno contains a trace that can be cut to disable the auto-reset. The pads on either side of the trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may also be able to disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset line; see this forum thread for details. USB Overcurrent Protection The Arduino Uno has a resettable polyfuse that protects your computer's USB ports from shorts and overcurrent. Although most computers provide their own internal protection, the fuse provides an extra layer of protection. If more than 500 ma is applied to the USB port, the fuse will automatically break the connection until the short or overload is removed. Physical Characteristics The maximum length and width of the Uno PCB are 2.7 and 2.1 inches respectively, with the USB connector and power jack extending beyond the former dimension. Four v
screw holes allow the board to be attached to a surface or case. Note that the distance between digital pins 7 and 8 is 160 mil (0.16"), not an even multiple of the 100 mil spacing of the other pins. vi
Appendix 2 Getting Started w/ Arduino on Mac OS X This document explains how to connect your Arduino board to the computer and upload your first sketch. 1 Get an Arduino board and USB cable 2 Download the Arduino environment 3 Install the Software 4 Connect the board 5 Launch the Arduino application 6 Open the blink example 7 Select your board 8 Select your serial port 9 Upload the program 1 Get an Arduino board and USB cable In this tutorial, we assume you're using an Arduino Uno, Arduino Duemilanove, Nano, Arduino Mega 2560, or Diecimila. If you have another board, read the corresponding page in this getting started guide. You also need a standard USB cable (A plug to B plug): the kind you would connect to a USB printer, for example. (For the Arduino Nano, you'll need an A to Mini-B cable instead.) 2 Download the Arduino environment Get the latest version from the download page. When the download is finished, double click the.zip fle. This will expand the Arduino application. 3 Install the Software Copy the Arduino application into the Applications folder (or elsewhere on your computer). If you're using an Arduino Uno or Mega 2560, you don't have any drivers to install. Skip ahead to the next step. If you're using an older board (Duemilanove, Diecimila, or any board with an FTDI driver chip. You will need to install the drivers for the FTDI chip on the board. You need to download the latest version of the drivers from the FTDI website. One downloaded, vii
double click the package, and follow the instructions in the installer. You'll need to restart your computer after installing the drivers. 4 Connect the board The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power from either the USB connection to the computer or an external power supply. If you're using an Arduino Diecimila, you'll need to make sure that the board is configured to draw power from the USB connection. The power source is selected with a jumper, a small piece of plastic that fits onto two of the three pins between the USB and power jacks. Check that it's on the two pins closest to the USB port. Connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on. If you're using the Arduino Uno or Arduino Mega 2560, a dialog box will appear telling you that a new network interface has been detected. Click "Network Preferences...", and when it opens, simply click "Apply". The Uno or Mega 2560 will show up as "Not Configured", but it's working properly. Quit System Preferences. 5 Launch the Arduino application Double-click the Arduino application. (Note: if the Arduino software loads in the wrong language, you can change it in the preferences dialog. See the environment page for details.) 6 Open the blink example Open the LED blink example sketch: File > Examples > 1.Basics > Blink. 7 Select your board You'll need to select the entry in the Tools > Board menu that corresponds to your Arduino. viii
Selecting an Arduino Uno For Duemilanove Arduino boards with an ATmega328 (check the text on the chip on the board), select Arduino Duemilanove or Nano w/ ATmega328. Previously, Arduino boards came with an ATmega168; for those, select Arduino Diecimila, Duemilanove, or Nano w/ ATmega168. (Details of the board menu entries are available on the environment page.) 8 Select your serial port Select the serial device of the Arduino board from the Tools > Serial Port menu. On the Mac, this should be something with /dev/tty.usbmodem (for the Uno or Mega 2560) or /dev/tty.usbserial (for older boards) in it. Selecting an Uno, Mega2560, or newer board. ix
Selecting an older FTDI-based board 9 Upload the program Now, simply click the "Upload" button in the environment. Wait a few seconds - you should see the RX and TX leds on the board flashing. If the upload is successful, the message "Done uploading." will appear in the status bar. (Note: If you have an Arduino Mini, NG, or other board, you'll need to physically present the reset button on the board immediately before pressing the upload button.) A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start to blink (in orange). If it does, congratulations! You've gotten Arduino up-and-running. If you have problems, please see the troubleshooting suggestions. You might also want to look at: the examples for using various sensors and actuators the reference for the Arduino language The text of the Arduino getting started guide is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. AddThis Button Style BEGIN AddThis Button Style END AddThis Button BEGIN x
Appendix 3 Kod i Arduino IDE //Visualization of door openings //Anna Nordstrom and Sofia Svensson /* ====== ESP8266 Demo ====== * Print out analog values * (Updated Dec 14, 2014) * ========================== * * Change SSID and PASS to match your WiFi settings. * The IP address is displayed to soft serial upon successful connection. * * Ray Wang @ Rayshobby LLC * http://rayshobby.net/?p=9734 */ #define BUFFER_SIZE 512 #include <SoftwareSerial.h> SoftwareSerial esp(2,8); // use pins 2, 8 for software serial #define kul Serial #define SSID "TRENDnet711" // WiFi SSID #define PASS "qwertyqwerty" // WiFi password #define PORT "8080" //Define variables const int SENSORPIN = 4; int sensorstate = 0; int laststate = 1; int counter = 0; char buffer[buffer_size]; // Function to wait for ESP8266 to respond char OKrn[] = "OK\r\n"; byte wait_for_esp_response(int timeout, char* term=okrn) { unsigned long t=millis(); bool found=false; int i=0; int len=strlen(term); while(millis()<t+timeout) { if(esp.available()) { buffer[i++]=esp.read(); if(i>=len) { if(strncmp(buffer+i-len, term, len)==0) { found=true; xi
break; buffer[i]=0; kul.println(buffer); return found; void setup() { //baud rate set to 9600 for both esp.begin(9600); kul.begin(9600); esp.println("at"); wait_for_esp_response(2000); esp.println("at+rst");//restart ESP8266 wait_for_esp_response(2000); esp.println("at+cwlap"); wait_for_esp_response(2000); esp.println("at+cwmode?"); wait_for_esp_response(2000); esp.print("at+cwjap=\"");//join the accesspoint esp.print(ssid); esp.print("\",\""); esp.print(pass); esp.println("\""); wait_for_esp_response(5000); esp.println("at+cipsto=30"); wait_for_esp_response(1000); esp.println("at+cipmux=1"); //Set multiple connections wait_for_esp_response(2000); esp.println("at+cipserver=1,8080"); //Set server wait_for_esp_response(2000); esp.println("at+cifsr"); //Get IP-adress for ESP8266 wait_for_esp_response(10000); xii
bool read_till_eol() { static int i=0; if(esp.available()) { buffer[i++]=esp.read(); if(i==buffer_size) i=0; if(i>1 && buffer[i-2]==13 && buffer[i-1]==10) { buffer[i]=0; i=0; kul.print(buffer); return true; return false; void loop() { //Get web page info int ch_id, packet_len; char *pb; if(read_till_eol()) { if(strncmp(buffer, "+IPD,", 5)==0) { sscanf(buffer+5, "%d,%d", &ch_id, &packet_len); if (packet_len > 0) { pb = buffer+5; while(*pb!=':') pb++; pb++; if (strncmp(pb, "GET /", 5) == 0) { wait_for_esp_response(1000); serve_homepage(ch_id); kul.print(ch_id); void serve_homepage(int ch_id) { String header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nconnection: close\r\nrefresh: 5\r\n"; sensorstate = digitalread(sensorpin); if (!sensorstate && laststate) { counter++; delay(10000); // To display number of door openings String content=""; for (int analogchannel = 1; analogchannel < 2; analogchannel++) { xiii
int sensorreading = analogread(analogchannel); content += "Number of door openings"; content += "<br />\n"; content += "<br />\n"; content += "Door "; content += analogchannel; content += ": "; content += counter; content += "<br />\n"; content += "Door 2: 0"; content += "<br />\n"; content += "Door 3: 0"; content += "<br />\n"; header += "Content-Length:"; header += (int)(content.length()); header += "\r\n\r\n"; esp.print("at+cipsend="); esp.print(ch_id); esp.print(","); esp.println(header.length()+content.length()); if(wait_for_esp_response(1000, "> ")) { esp.print(header); esp.print(content); else { esp.print("at+cipclose="); esp.println(ch_id); xiv