Arduino Intermediate Projects

Similar documents
Arduino Advanced Projects

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

Lesson 3: Arduino. Goals

Objectives: Learn what an Arduino is and what it can do Learn what an LED is and how to use it Be able to wire and program an LED to blink

FABO ACADEMY X ELECTRONIC DESIGN

Lab 2.4 Arduinos, Resistors, and Circuits

.:Twisting:..:Potentiometers:.

INA169 Breakout Board Hookup Guide

Lab 2: Blinkie Lab. Objectives. Materials. Theory

Community College of Allegheny County Unit 7 Page #1. Analog to Digital

Project #6 Introductory Circuit Analysis

Coding with Arduino to operate the prosthetic arm

Lab 06: Ohm s Law and Servo Motor Control

Arduino Sensor Beginners Guide

Lecture 4: Basic Electronics. Lecture 4 Brief Introduction to Electronics and the Arduino

Attribution Thank you to Arduino and SparkFun for open source access to reference materials.

Arduino An Introduction

Arduino Lesson 1. Blink. Created by Simon Monk

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs Introduction to Arduino

Congratulations on your purchase of the SparkFun Arduino ProtoShield Kit!

MAKEVMA502 BASIC DIY KIT WITH ATMEGA2560 FOR ARDUINO USER MANUAL

Rodni What will yours be?

Pulse Width Modulation and

Arduino: Sensors for Fun and Non Profit

TWEAK THE ARDUINO LOGO

Basic Electronics Course Part 2

CPSC 226 Lab Four Spring 2018

100UF CAPACITOR POTENTIOMETER SERVO MOTOR MOTOR ARM. MALE HEADER PIN (3 pins) INGREDIENTS

Arduino Workshop 01. AD32600 Physical Computing Prof. Fabian Winkler Fall 2014

LEDs and Sensors Part 2: Analog to Digital

Arduino Programming Part 3

DuoDrive Nixie Bargraph Kit

Digital Electronics & Chip Design

AS726X NIR/VIS Spectral Sensor Hookup Guide

Introduction to. An Open-Source Prototyping Platform. Hans-Petter Halvorsen

CURIE Academy, Summer 2014 Lab 2: Computer Engineering Software Perspective Sign-Off Sheet

Breadboard Primer. Experience. Objective. No previous electronics experience is required.

HAW-Arduino. Sensors and Arduino F. Schubert HAW - Arduino 1

LAB 1 AN EXAMPLE MECHATRONIC SYSTEM: THE FURBY

APDS-9960 RGB and Gesture Sensor Hookup Guide

Pi-Cars Factory Tool Kit

Nano v3 pinout 19 AUG ver 3 rev 1.

Lab 5: Arduino Uno Microcontroller Innovation Fellows Program Bootcamp Prof. Steven S. Saliterman

// Parts of a Multimeter

Internet of Things Student STEM Project Jackson High School. Lesson 2: Arduino and LED

Bill of Materials: PWM Stepper Motor Driver PART NO

Module: Arduino as Signal Generator

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

LA502 Assembly guide Main PCB Resistors - (2)

introduction to Digital Electronics Install the Arduino IDE on your laptop if you haven t already!

Intro to Electronics. Week 1

Arduino STEAM Academy Arduino STEM Academy Art without Engineering is dreaming. Engineering without Art is calculating. - Steven K.

ZX Distance and Gesture Sensor Hookup Guide

Objective of the lesson

Smart Circuits: Lights On!

Breadboard Arduino Compatible Assembly Guide

MP573 Assembly guide. Soldering. MP573 Assembly guide PCB split PCB split. Document revision 2.2 Last modification : 22/08/17

CMSC838. Tangible Interactive Assistant Professor Computer Science

Workshop 9: First steps in electronics

Parts List. Robotic Arm segments ¼ inch screws Cable XBEE module or Wifi module

Sten-Bot Robot Kit Stensat Group LLC, Copyright 2013

Introduction 1. Download socket (the cable plugs in here so that the GENIE microcontroller can talk to the computer)

Lighthouse Beginner s soldering kit

Project Kit Project Guide

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

CONSTRUCTION GUIDE Light Robot. Robobox. Level VI

GrovePi Temp-Humidity Sensor Lesson Video Script. Slide 1

EGG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

Saturday Academy Program

Experiment #5 Series and Parallel Resistor Circuits

EARTH PEOPLE TECHNOLOGY. EPT-200TMP-TS-U2 Temperature Sensor Docking Board User Manual

Touch Potentiometer Hookup Guide

The Motor sketch. One Direction ON-OFF DC Motor

Community College of Allegheny County Unit 4 Page #1. Timers and PWM Motor Control

Getting Started with the micro:bit

PLAN DE FORMACIÓN EN LENGUAS EXTRANJERAS IN-57 Technology for ESO: Contents and Strategies

PIR Motion Detector Experiment. In today s crime infested society, security systems have become a much more

Inspiring Creative Fun Ysbrydoledig Creadigol Hwyl. S4A - Scratch for Arduino Workbook

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

TS500 Assembly guide. Soldering. TS500 Assembly guide Main PCB 1. Diodes. Document revision 1.2 Last modification : 17/12/16

Build a Mintronics: MintDuino

Trinket Powered Analog Meter Clock

Voltage Dividers a learn.sparkfun.com tutorial

An important note about your Charged Up Exploration Kit.

Physics 323. Experiment # 1 - Oscilloscope and Breadboard

Demon Pumpkin APPROXIMATE TIME (EXCLUDING PREPARATION WORK): 1 HOUR PREREQUISITES: PART LIST:

Sidekick Basic Kit for Arduino V2 Introduction

Programmable Timer Teaching Notes Issue 1.2

555 Morse Code Practice Oscillator Kit (draft 1.1)

Product overview. Features. Product specifications. Order codes. 1kΩ Resistance Output Module

Microcontrollers and Interfacing

Bill of Materials: Metronome Kit PART NO

Prelab: Introduction and Greenhouse Construction

Computational Crafting with Arduino. Christopher Michaud Marist School ECEP Programs, Georgia Tech

CONSTRUCTION GUIDE IR Alarm. Robobox. Level I

Circuit Board Assembly Instructions for Babuinobot 1.0

Rotary Switch Potentiometer Hookup Guide

Experiment #3: Micro-controlled Movement

Resistive Circuits. Lab 2: Resistive Circuits ELECTRICAL ENGINEERING 42/43/100 INTRODUCTION TO MICROELECTRONIC CIRCUITS

Transcription:

Arduino Intermediate Projects Created as a companion manual to the Toronto Public Library Arduino Kits. Arduino Intermediate Projects Copyright 2018 Toronto Public Library. All rights reserved. Published by the Toronto Public Library. 1

Table of Contents TABLE OF CONTENTS... 2 PREFACE... 3 INTRODUCTION... 4 SAFETY TIPS... 12 ARDUINO UNO TOUR... 14 GETTING TO KNOW YOUR BREADBOARD... 15 USING SERIAL DEBUG AND A POTENTIOMETER... 17 USING AN RGB LED... 21 CONTROL COLOURS WITH A POTENTIOMETER... 24 HOTTER OR COLDER THAN AVERAGE... 29 RECOMMENDED RESOURCES... 34 2

Preface Thank you for borrowing Toronto Public Library s Arduino Kit. Please return this kit to the Digital Innovation Hub from which it was borrowed. 3

Borrowing Arduino Kits Arduino Kits are available to Toronto Public Library customers with a valid Teen (13-17), Adult Under 25 (18 24), or Adult (25+) library card. Holds cannot be placed on the Arduino Kits. You can only borrow one Arduino Kit at a time. Each kit can be borrowed for 21 days and cannot be renewed. Fines Per Day and Maximum Fines for Arduino Kits CARD TYPE FINE AMOUNT PER DAY Adult $0.35 $14.00 Adult Under 25 (18-24) $0.15 $6.00 Teen (13-17) $0.15 $6.00 MAXIMUM YOU WILL BE CHARGED FOR EACH LOAN PERIOD If you lose an Arduino Kit, you will be charged the purchase price of the Arduino ($50). The library does not accept a replacement Arduino or an item of equal value. If the Arduino Kit is overdue by more than 40 days, the library considers it lost. If you find the kit within 6 months of paying the replacement cost you can get a refund, minus any overdue fines so please keep your receipt. Please report damaged equipment or missing parts to the Digital Innovation Hub staff from which it was borrowed. Damaged Arduino boards and kits are subject to replacement purchase fees. 4

Introduction An Arduino is a microcontroller; a small, simple computer. It is designed specifically for beginners who are new to coding and electronics. You can learn more about the Arduino at https://www.arduino.cc/en/guide/introduction. There are thousands of projects you can build with an Arduino. Parts in This Kit You assembled kit includes all the parts you ll need for the Arduino projects outlined in this manual. When you re done with your projects, please return the parts to their proper slots, as indicated in this diagram, for the next person to enjoy. There are different types of Arduinos. This kit uses a blue Arduino Uno board. The different parts on the Arduino are labelled in white. 5

The USB cable is used to connect the Arduino to your computer. The breadboard lets you build circuits. It has a series of holes where you can insert wires to create circuits. The magic of a breadboard is that it s reusable, and you don t need to solder (permanently joining components together to form a circuit by melting metals). 6

Jumper wires are used to create electric circuits and can be inserted into the breadboard. RGB LED (red, green and blue light-emitting diodes) are electronic devices that emit light when an electrical current passes through them. This includes three LED s in one to create colours. Using the 4 pins from the RGB LED you can make it output red, green and blue light and also mix them together. Resistors help control the flow of electricity in your circuit by limiting the current. They come in different values measured 7

in ohms (Ω). Using the correct value resistor is important because they protect the LEDs and other parts from being damaged by too much current. They have different colour bands on them to tell you what kind of resistance it is. Potentiometers are a manually adjustable variable resistor with 3 terminals. Two terminals are connected to both ends of a resistive element, and the third middle terminal connects to a sliding contact, called a wiper, moving over the resistive element. The position of the wiper determines the output voltage of the potentiometer. 8

Temperature Sensors work very similar to a potentiometer. The middle pin can be connected to our analog input pin on the Arduino to read the resistance value. That value can be converted to a temperature. The outer pins are used to connect 5 volts and GND. 9

Part Inventory for the Intermediate Kit 1x Arduino The Arduino is the microcontroller and brains of our project. It stores programs and processes inputs and outputs. 1x Breadboard The breadboard is used to temporarily connect multiple components and wires together during prototyping. 16x Jumper Wires Jumper wires connect the components completing a circuit. Note: The colour of the wires do not matter when building the projects. 3x 220ohm Resistors (red, red, brown, gold) Resistors are used to reduce the flow of electric current in a circuit. This prevents damage to LEDs that require a lower voltage. 1x Temperature Sensor 3x Potentiometers 1x RGB LED Used to detect the ambient temperature of the room when connected correctly to the Arduino analog input pins. Can be used to detect the position of a knob when connected to the Arduino analog input pins. LED stands for Light Emitting Diode & is used to create light. These LEDs typically require around 1 volt. 10

Before you can use the Arduino, you will need to set up the Arduino IDE software on your computer. You ll be using the IDE (Integrated Development Environment) to write code and upload it to your Arduino. The code for the Arduino is called a Sketch. 11

Safety Tips Toronto Public Library s Arduino Kits use low voltage electricity and are not inherently dangerous. However, safety is always important when working with electrical circuits. Please follow the safety tips and instructions in this manual at all times. Expert Tip: Always treat electronic projects as if they could have potentially dangerous voltages. Each project has been planned and mapped out for you. Please take the time to read and thoroughly review the project instructions from beginning to end before you begin. Ensure that wires are connected accurately and in accordance with the diagrams provided. Not following the instructions as specified may result in personal injury or damage to the equipment. Expert Tip: Turn off all power sources before modifying the circuit. Keep your Arduino unplugged while you are connecting wires and parts. Only connect it to the computer after your setup matches the diagram provided. Keep your work surface clear when using this kit and maintain an orderly and safe work environment. Keep food and drinks away from the work area while working with your Arduino kit. Always unplug the Arduino when not in use. After using the kit, return all the parts to their proper storage place. Expert Tip: Place the Arduino on a non-metal surface and refrain from working on metallic surfaces. 12

Warnings This kit is not a toy and is not appropriate for small children. Small parts may present a choking hazard. Not for children under 3. Avoid touching the exposed end of ground and power wires when connected to the Arduino. Use only the materials provided in the Arduino Kit. Do not make alterations or perform major repairs on the Arduino Kit. No soldering with the TPL Arduino kit. Do not use lithium ion batteries, they may explode when shorted Do not use on metallic surfaces, such as your Macbook. Place the Arduino on a nonmetal surface and refrain from working on the surface of your Macbook. The library is not responsible for damage to any equipment and hardware used with the kit, including personal computers, laptops or tablets. Unplug the Arduino when not in use. Turn off/disconnect all power sources before modifying a circuit. While you re connecting components, keep your Arduino unplugged. Only connect it to a computer or power source after the circuit is complete. 13

Arduino Uno Tour Time Required: 10 minutes Spend a few moments looking at the diagram below and compare it to the Arduino included in your kit. The Arduino has been labeled to help you learn all the different connectors and parts. 14

Getting to Know your Breadboard Time Required: 20 minutes Link to video resources about breadboards: http://goo.gl/6hphbg In order for us to connect our tiny components together, we need our breadboard. A breadboard is great for prototyping since it does not create a permanent connection between components like soldering does. Everything is held together by friction when you insert them into those tiny holes inside your breadboard. Remember: If you have any questions, or need some extra help, feel free to visit a Digital Innovation Hub at the Toronto Public Library for classes or assistance. 15

On the previous page left there is an example of how a breadboard usually looks; on the right is how a breadboard would look if we could see the wires that connect all of the holes together. Those hidden wires are used to connect all your components to each other while you prototype. Take a look at your breadboard. You may have noticed that the breadboard holes are all labeled A to J (vertically) and from 1-30 (horizontally). This is used to indicate where to place your components. Throughout this guide, we will be asking you to place your components in very specific holes within your breadboard. For example, we might ask you to put a wire into hole 3E. Now is the time to get familiar with the layout of your breadboard. 16

Using Serial Debug and a Potentiometer Time Required: 35 minutes For this project, we will go over the benefits of using our serial monitor and how to use it in our Arduino software. You are able to use serial monitor to output messages and values of variables from the Arduino that we are using in our sketch. This allows you to see how the information is being processed. Serial communication could also be used to send messages to an Arduino to trigger commands, however we will not be going over this functionality in this kit. We also will be using a potentiometer and reading it as a user input for our Arduino. A potentiometer is a knob that provides a variable resistance, which we can read using the Arduino board as an analog value. We connect the potentiometer with three wires to the Arduino board. The first wire goes to ground from one of the outer pins of the potentiometer. The second goes from 5 volts to the other outer pin of the potentiometer. The third goes from analog input 2 to the middle pin of the potentiometer. What are the pins on a typical Potentiometer? Positive Power Ground Output: This pin can be connected to an Arduino. The Arduino will read the resistance value from the potentiometer. 17

By turning the shaft of the potentiometer, we change the amount of resistance on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023 (this is not exactly what happens, but a simplified explanation). In between, analogread() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin. Required Components 1x Arduino 1x Breadboard 3x Jumper Wires 1x Potentiometer 18

Wiring Guide 19

Code Line 1. const int inputpin = A0; Line 2. Line 3. int userinputvalue = 0; Line 4. Line 5. void setup() { Line 6. Line 7. pinmode(inputpin, INPUT); Line 8. Line 9. Serial.begin(9600); Line 10. Line 11. } Line 12. Line 13. void loop() { Line 14. Line 15. userinputvalue = analogread(inputpin); Line 16. Line 17. Serial.print("User input: "); Line 18. Line 19. Serial.println(userInputValue); Line 20. Line 21. Line 22. Line 23. } delay(1000); Create a variable where it s value will never change (const) called inputpin that will store an integer (A0). Create a variable where it s value will change called userinputvalue that will store the value of the potentiometer. Initially set the value to 0. Set our inputpin (A0) as an input when the Arduino first turns on or reboots. Start Serial communication. Set the baud speed to 9600 (how fast the communication is between the computer and the Arduino). Analog read the inputpin (A0), and store the value in our variable called userinputvalue. In the serial monitor, output the text User input:. In the serial monitor, output the value in our userinputvalue variable. Since we are using Serial.println, the ln means to create a line break after the text is outputted. Pause for a second. This pause is only so Arduino won t send our messages to the serial monitor too quickly so we can read them easier. 20

Using an RGB LED Time Required: 45 minutes For this project, we will be using an RGB led to create many different colours. An RGB led is nothing more than three led s in one package. For this example we will create a project that will turn on each LED colour on for one second. The project will make the RGB LED glow green for one second, then to blue for one second, and then glow red for one second and repeat forever. 1x Arduino 1x Breadboard 4x Jumper Wires 3x 220ohm Resistors (red, red, brown, gold) 1x RGB LED 21

How to use an RGB LED? Our RGB LED is just three LED s in one device. The one included in the kit is a common cathode type. This means one of the LED legs (which is the longest wire coming from the RGB led) is the negative (cathode) and is shared for the red, green and blue led s inside. The other 3 legs are positive (anode) that we will send individual power from three of our analog output pins, letting us full control of the colours that should be displayed. Wiring Guide Connect the RGB LED with the longest leg (longest leg is the negative cathode) into the breadboard pin #G2. 22

Code Line 1. const int ledgreen = 9; Line 2. const int ledblue = 10; Line 3. const int ledred = 11; Line 4. Line 5. void setup() { Line 6. pinmode(ledgreen, OUTPUT); Line 7. pinmode(ledblue, OUTPUT); Line 8. pinmode(ledred, OUTPUT); Line 9. } Line 10. Line 11. void loop() { Line 12. digitalwrite(ledgreen, HIGH); Line 13. digitalwrite(ledblue, LOW); Line 14. digitalwrite(ledred, LOW); Line 15. delay(1000); Line 16. Line 17. digitalwrite(ledgreen, LOW); Line 18. digitalwrite(ledblue, HIGH); Line 19. digitalwrite(ledred, LOW); Line 20. delay(1000); Line 21. Line 22. digitalwrite(ledgreen, LOW); Line 23. digitalwrite(ledblue, LOW); Line 24. digitalwrite(ledred, HIGH); Line 25. delay(1000); Line 26. } Create variables where its value will never change (const) to store the value of what pins we will be using and call them ledgreen (pin 9), ledblue (pin 10) and ledred (pin 11). Set ledgreen (pin 9), ledblue (pin 10) and ledred (pin 11) as an OUTPUT. Set ledgreen (pin 9) as HIGH (turn on), set ledblue (pin 10) as LOW (turn off) and set ledred (pin 11) as LOW (turn off). Pause for one second. Set ledgreen (pin 9) as LOW (turn off), set ledblue (pin 10) as HIGH (turn on) and set ledred (pin 11) as LOW (turn off). Pause for one second. Set ledgreen (pin 9) as LOW (turn off), set ledblue (pin 10) as LOW (turn off) and set ledred (pin 11) as HIGH (turn on). Pause for one second. 23

Control Colours with a Potentiometer Time Required: 45 minutes For this project, we will be using an RGB led to create many different colours. We will be using three potentiometers so we can control how intense we want to show red, green and blue from the single RGB LED. By changing how bright and intense each colour is from the LED, we can create thousands of colours. 1x Arduino 1x Breadboard 16x Jumper Wires 3x 220ohm Resistors (red, red, brown, gold) 1x RGB LED 3x Potentiometers 24

Wiring Guide Connect the RGB LED with the longest leg (longest leg is the negative cathode) into the breadboard pin #J2. 25

Code Line 1. const int ledredpin = 11; Line 2. const int ledgreenpin = 10; Line 3. const int ledbluepin = 9; Line 4. Line 5. const int sensorredpin = A2; Line 6. const int sensorgreenpin = A1; Line 7. const int sensorbluepin = A0; Line 8. Line 9. int sensorredvalue = 0; Line 10. int sensorgreenvalue = 0; Line 11. int sensorbluevalue = 0; Line 12. Line 13. int outputred = 0; Line 14. int outputgreen = 0; Line 15. int outputblue = 0; Line 16. Line 17. void setup() { Line 18. pinmode(ledredpin, OUTPUT); Line 19. pinmode(ledgreenpin, OUTPUT); Line 20. pinmode(ledbluepin, OUTPUT); Line 21. Line 22. pinmode(sensorredpin, INPUT); Line 23. pinmode(sensorgreenpin, INPUT); Line 24. pinmode(sensorbluepin, INPUT); Line 25. Line 26. Serial.begin(9600); Line 27. } code continues next page 26 Create 3 variables where its value will never change (const) that is an integer to store the value of what pins we will be using and call them ledredpin (pin 11), ledgreenpin (pin 10) and ledbluepin (pin 9). Create 3 variables where its value will never change (const) to store the value of what pins we will be using and call them sensorredpin (pin A2), sensorgreenpin (pin A1) and sensorbluepin (pin A0). Create 3 integer variables where its values will change that will be called sensorredvalue, sensorgreenvalue, sensorbluevalue. Initially it will only store 0. These variables will be used to store the raw values from our potentiometer. Create 3 integer variables where its values will change that will be called outputred, outputgreen, outputblue. Initially it will only store 0. This variable will be used to store how bright each colour will be for our RGB LED. Set ledredpin (pin #11), ledgreenpin (pin #10), ledbluepin (pin #9) as an OUTPUT. Set sensorredpin (analog input pin A2), sensorgreenpin (analog input pin A1), sensorbluepin (analog input pin A0) as an INPUT. Start serial communication from the Arduino to the computer. Set the communication speed to 9600 baud.

Line 28. void loop () { Line 29. sensorredvalue = analogread(sensorredpin); analogread each of our sensor pins (A0, A1, A2) and store each potentiometer s raw data into our variables sensorredvalue, sesnsorgreenvalue, sensorbluevalue. Line 30. sensorgreenvalue = analogread(sensorgreenpin); Line 31. sensorbluevalue = analogread(sensorbluepin); Line 32. Line 33. outputred = map(sensorredvalue, 0, 1023, 0, 255); Line 34. Line 35. outputgreen = map(sensorgreenvalue, 0, 1023, 0, 255); Line 36. Line 37. outputblue = map(sensorbluevalue, 0, 1023, 0, 255); Line 38. Line 39. analogwrite(ledredpin, outputred); Line 40. analogwrite(ledgreenpin, outputgreen); Line 41. analogwrite(ledbluepin, outputblue); Line 42. Map the raw sensor data (our sensor gives us a value between 0-1024) to a value between (0-255) and store the converted value to outputred. Map the raw sensor data (our sensor gives us a value between 0-1024) to a value between (0-255) and store the converted value to outputgreen. Map the raw sensor data (our sensor gives us a value between 0-1024) to a value between (0-255) and store the converted value to outputblue. analogwrite the values for outputred, outputgreen, outputblue to our corresponding pins to the RGB LED (ledredpin [pin 11], ledredgreen [pin 10], ledbluepin [pin 9]). Line 43. Line 44. Line 45. Line 46. } Serial.print("Output - R:"); Serial.print(outputRed); Serial.print(" G:"); Serial.print(outputGreen); Serial.print(" B:"); Serial.println(outputBlue); This code will output the values of the variable outputred, outputgreen, and outputblue to the serial monitor. This will allow us to see exactly the values the Arduino is outputting for the brightness of each colour (red, green, blue) for our RGB LED while your computer is plugged into the Arduino. 27

What is the map() function? Re-maps a number from one range to another. This is perfect for when we have a input values from analogread() ranges from 0-1024, but our analogwrite() outputs a value from 0-255. We can map it so when our input is 1024, it will output 255 for us. When the input value is 512, it could automatically output 128 for us. 28

Hotter or Colder than Average Time Required: 60 minutes For this project, we will be using an RGB led to show to the user blue when the temperature is lower than the median, and show the user red when the temperature is higher than the median. In this project, we will not be using the green portion of our RGB LED. This will be able to show if it is colder or hotter in the room than usual. 1x Arduino 1x Breadboard 8x Jumper Wires 2x 220ohm Resistors (red, red, brown, gold) 1x RGB LED 1x Temperature Sensor 29

What are the pins on Temperature Sensor? Be careful! When using the temperature sensor, make sure you don t reverse the positive and negative pins when connecting it to the Arduino. In this diagram, the front of the temperature sensor is the flat part facing towards you. Take a note below of the the pins to watch our for. Flat part of sensor facing towards you Positive Power (5 Volts) GND (Negative) Voltage Output (This is the pin the Arduino will use to read the temperature) If the temperature sensor gets hot and does not work, unplug the power to the Arduino and double check your connections. 30

Wiring Guide Connect the RGB LED with the longest leg (longest leg is the negative cathode) into the breadboard pin #G2 31

Code Line 1. const int ledbluepin = 10; Line 2. const int ledredpin = 11; Line 3. Line 4. const int sensorpin = A0; Line 5. int rawsensorvalue = 0; Line 6. float sensorvoltage = 0.0; Line 7. Line 8. float sensortemperature = 0.0; Line 9. Line 10. int outputred = 0; Line 11. int outputblue = 0; Line 12. Line 13. float sensorminvalue = 1024.0; Line 14. float sensormaxvalue = -1024.0; Line 15. float halftemp = 0; Line 16. Line 17. void setup() { Line 18. pinmode(ledredpin, OUTPUT); Line 19. pinmode(ledbluepin, OUTPUT); Line 20. Line 21. pinmode(sensorpin, INPUT); Create 2 variables where its value will never change (const) that is an integer to store the value of what pins we will be using and call them ledblue (pin 10) and ledred (pin 11). Create a const integer variable to store the value for the analog input pin (A0) for the temperature sensor. Create an integer variable to store the raw temperature sensor values. Create a float variable to store the converted raw temperature sensor value to a voltage value. Create a float variable to store the converted voltage value to a temperature in Celsius. Create an integer variable called outputred and outputblue to store how bright the red and blue will be to the RGB led. Create a float variable called sensorminvalue and sensormaxvalue to remember the lowest and highest temperatures it knows. Create a float variable called halftemp, that will be used to store the median value of our temperatures that the Arduino remembers. Set our ledredpin (Pin #11) and ledbluepin (Pin #10) as an OUTPUT. Set our sensorpin (Pin A0) as an INPUT. code continues next page 32 What is a float variable? A float variable is used to store numbers with decimal point unlike an integer, which stores only whole numbers.

Line 22. Serial.begin(9600); Line 23. } Line 24. void loop () { Line 25. Line 26. rawsensorvalue = analogread(sensorpin); Line 27. sensorvoltage = (rawsensorvalue/1024.0) * 5.0; Line 28. Line 29. sensortemperature = (sensorvoltage - 0.5) * 100; Line 30. Line 31. Serial.print("Temperature: "); Line 32. Line 33. Serial.println(sensorTemperature); Line 34. if(sensortemperature < sensorminvalue) { Line 35. sensorminvalue = sensortemperature; } Line 36. Line 37. if(sensortemperature > sensormaxvalue) { Line 38. sensormaxvalue = sensortemperature; } Line 39. Line 40. halftemp = (sensormaxvalue - sensorminvalue) / 2; Line 41. halftemp = sensorminvalue + halftemp; Start serial communication at the baud speed of 9600. Read the temperature sensor and save its values into the variable Convert the raw sensor values to how many volts is being read from the analogread() (the value was stored previously in rawsensorvalue). Convert the voltage from the temperature sensor into a temperature in Celsius. Output debug information to the serial monitor. This will output the user Temperature: and then the temperature of the sensor in Celsius. Check if the current temperature is lower than the lowest recorded temperature. If it is, then store the current temperature into the variable sensorminvalue which holds the lowest temperature the Arduino remembers. Check if the current temperature is higher than the highest recorded temperature. If it is, then store the current temperature into the variable sensormaxvalue which holds the highest temperature the Arduino remembers. Calculate the median value of our temperature by getting the value of sensormaxvalue minus the value of sensorminvalue and then dividing the result by two. code continues next page After, use the previous value that was calculated and add it to the value of sensorminvalue, which gives us our median value between the sensormaxvalue and sensorminvalue. 33

Map how bright the blue colour should be in the LED. The blue is brightest when the current temperature is closest to the lowest temperature the Arduino remembers. The halftemp + 1 has the + 1 so the blue light will still be on dimly when the current temperature is the same as the median temperature the Arduino remembers. Map how bright the red colour should be in the LED. The blue is brightest when the current temperature is closest to the lowest temperature the Arduino remembers. The halftemp + 1 has the + 1 so the blue light will still be on dimly when the current temperature is the same as the median temperature the Arduino remembers. Line 42. outputblue = map(sensortemperature, sensorminvalue, halftemp + 1, 255, 0); Line 43. Line 44. outputred = map(sensortemperature, halftemp - 1, sensormaxvalue, 1, 255); Line 45. Line 46. outputred = constrain(outputred, 0, 255); Line 47. outputblue = constrain(outputblue, 0, 255); Line 48. Line 49. Line 50. Line 51. Line 52. Line 53. Line 54. Line 55. Line 56. Line 57. Line 58. Line 59. Line 60. analogwrite(ledredpin, outputred); analogwrite(ledbluepin, outputblue); Serial.print("Half Temp: "); Serial.println(halfTemp); Serial.print("Min Temp: "); Serial.println(sensorMinValue); Serial.print("Max Temp: "); Serial.println(sensorMaxValue); Serial.print("Blue Output: "); Serial.println(outputBlue); Serial.print("Red Output: "); Serial.println(outputRed); delay(600); Create a delay so that we can see the serial monitor text. Without the delay the Arduino will talk to the computer too fast for us to read. Make sure the integer in outputred and outputblue only have a value between 0-255. Use analogwrite() to output to the red and blue part of our RGB LED using the values from outputred and outputblue that we already calculated. Print to the serial monitor the median temperature the Arduino remembers currently for debugging. Print to the serial monitor the lowest and highest temperature the Arduino remembers. Print to the serial monitor the current brightness of our red and blue values to the RGB LED. 34

Recommended Resources Get these for free at the Toronto Public Library Want to learn more about Arduinos? Here is a list of our favourite Toronto Public Library books and resources. When using the Arduino Kit, please stick to the projects outlined in this manual. Additional projects found in the recommended resources are for educational and entertainment purposes and are only intended for use with your personal Arduino. http://www.arduino.cc The official website has great tutorials and reference resources. The website includes information on all commands you can do for the Arduino programming language and examples on how to use them. Learning Arduino with Peggy Fisher This beginner course consists of two hours of video and can be accessed for free from Lynda.com (via tpl.ca/elearning with a valid Toronto Public Library card). 35

Adventures in Arduino by Becky Stewart This book provides simple, easy-to-follow introductions to the Arduino. It is written for 11 to 15 year olds, but we ve found the concepts, content, and language engaging and applicable to adult Arduino users. Available from Safari (via tpl.ca/elearning with a valid Toronto Public Library card). Arduino for Kids (2017) by Priya Kuber, Rishi Gaurav Bhatnagar, Vijay Varada This book is intended for children (ages 9 and up) and their parents. It includes a series of fun, easy projects that don t require any knowledge of electronics. Available from Safari (via tpl.ca/elearning with a valid Toronto Public Library card). The Maker's Guide to the Zombie Apocalypse: Defend Your Base with Simple Circuits, Arduino, and Raspberry Pi (2016) by Simon Monk No one knows what the future holds, so we can t definitively say whether or not the Arduino projects in this book will come in handy. What we can guarantee is that you ll have fun learning about Arduinos in a unique and creative way. Available in regular print. 36

Make: Drones: Teach an Arduino to Fly by David McGriffy Have you ever wondered how drones work? This book reveals drone building secrets and explains how you can get your Arduino to fly. Available in regular print and as an ebook from Safari (via tpl.ca/elearning with a valid Toronto Public Library card). The Arduino Inventor's Guide (2017) by Derek Runberg and Brian Huang Ready to move on from the Arduino kits and start working on some more advanced projects? Why not build a tiny electric piano, a desktop greenhouse, or a colour-mixing night light? You ll find ten fun Arduino projects in this new ebook, available from Safari (via tpl.ca/elearning with a valid Toronto Public Library card) Arduino Playground : Geeky Projects for the Experienced Maker (2017) by Warren Andrews This is the perfect resource for more advanced Arduino projects. One of our favourites is the Garage Sentry Parking Assistant, a project that can help you pull into your garage by setting off an alarm when you ve gone far enough and need to hit the brakes. Available in regular print and as an ebook from Safari (via tpl.ca/elearning with a valid Toronto Public Library card) 37