13
Lab 5: Arduino Uno Microcontroller Innovation Fellows Program Bootcamp Prof. Steven S. Saliterman Exercise 5-1: Familiarization with Lab Box Contents Objective: To review the items required for working with the Arduino Uno. Dupont Wire Jumpers (Peel off what you need.) Power Adapter for Arduino Arduino Uno R3 Microcontroller Potentiometer (top and bottom)

Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

  • Upload
    dokhue

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Lab 5: Arduino Uno Microcontroller Innovation Fellows Program Bootcamp

Prof. Steven S. Saliterman

Exercise 5-1: Familiarization with Lab Box Contents Objective: To review the items required for working with the Arduino Uno. Dupont Wire Jumpers

(Peel off what you need.) Power Adapter for Arduino

Arduino Uno R3 Microcontroller Potentiometer (top and bottom)

Page 2: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 2 Exercise 5-2: Installing Arduino Software Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple “sketch” or program to blink an LED. A. You will be connecting your computer to the Arduino via a USB 2.0 cable. This cable will provide power to the Arduino, and will allow you transfer programs from your computer to the Arduino. In addition, if your program is using the Arduino serial interface, then you can display the data on your computer. Our discussion of C programming was limited primarily to its application with the Arduino IDE (Integrated Development Environment). For this reason we did not discuss input/out of data (excepting the above), files or advanced C features. However, you will be able to program and allow your Arduino to operate independently of the computer, and you may power it with a separate wall-mount power supply or even a battery. B. Arduino home page is shown below (https://www.arduino.cc):

Page 3: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 3 Select the “Learn Arduino” menu item, and following display appears:

Page 4: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 4 Follow the directions for your particular board and operating system. On the right hand side is additional instruction for the Uno board. Download the appropriate software. Follow the Quick Start instructions, including opening and running the LED blink “sketch” or program.

Page 5: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 5 Exercise 5-3: Wiring Your Own LED Objective: Connecting an external LED to the Arduino, and then a push button to control it. 5-3-1: First, using an external LED A. Download the Arduino software to your computer if you have not already done so. B. Connect your Arduino with a USB cable to your computer. Confirm powered. C. Connect your Arduino to an LED and 220 ohm resistor as shown: D. Copy, paste and upload the following program:

const int LED = 10; int blinks = 5; // blink 5 times; bool done = false; void setup() { pinMode(LED, OUTPUT); //set pin 10 as an OUTPUT digitalWrite(LED, LOW); // Initialize off

Page 6: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 6

} void loop() { while (done != true) { for (int i = 1; i<= blinks; ++i) // ++i same as i = i+1 { digitalWrite(LED, HIGH); // Turn on LED delay(500); //Pause digitalWrite(LED, LOW); // Turn off LED delay(500); //Pause } done = true; } }

E. Run the program. Does the LED blink five times? ______________ (yes or no)

Page 7: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 7 Exercise 5-4: Reading a Potentiometer. Objective: Reading analog data and turning on an LED based on a resistance threshold, then flashing the LED at a rate relative to the resistance of the potentiometer. 5-4-1 This example demonstrates the use of “if()” statements. It reads the state of a potentiometer (an analog input) and turns on an LED only if the potentiometer goes above a certain threshold level. It prints the analog value regardless of the level using the serial output. A. Wire the Arduino as shown: The potentiometer is connected to analog pin 0. The center pin of the potentiometer goes to the analog pin. The side pins of the potentiometer go to +5V and ground. On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example.

Feddersen, J. Inside the Potentiometer http://fddrsn.net/pcomp/examples/potentiometers.html

Page 8: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 8 B. Copy, paste and upload the following program:

const int analogPin = A0; // pin that the potentiometer is attached to const int ledPin = 13; // pin that the LED is attached to on UNO const int threshold = 400; // an arbitrary threshold level that's in the range of // the analog input void setup() { pinMode(ledPin, OUTPUT); // initialize the LED pin as an output Serial.begin(9600); // initialize serial communications } void loop() { int analogValue = analogRead(analogPin); // read the value of the potentiometer if (analogValue > threshold) // if the analog value is high enough, turn on the LED { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } Serial.println(analogValue); // print the analog value delay(1); // delay in between reads for stability }

C. Run the program and display the Serial Monitor (under the “Tools” menu). Does the LED respond to a threshold? ______________ (yes or no) Do you have a serial output of the data? ______________ (yes or no) At what value does the LED change state? _____________

Page 9: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 9 5-4-2 (Optional) Write a new program so that the LED flashes at a rate relative to the potentiometer position (resistance). Include a serial output of the potentiometer reading and flash rate. Write your final tested code with comments here: _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________

Page 10: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 10 _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ _________________________________ _____________________________________ (Continue on the back if necessary.) TA initial if code works as intended: _____________________ Exercise 5-6: Sensors & Actuators Objective: To make you aware of available project modules in addition to those items already contained in your lab box and reviewed before. These items are in the storage cabinet for use with your projects or for just experimenting with (please return these items when you are done). You can find technical details on them by searching the internet (Adafruit, Amazon, Spark Fun etc.):

Standard Size - High Torque - Metal Gear Servo 5V Delay Relay Module Delay Switch High and Low Level Trigger

Page 11: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 11

Ultrasonic Sensor - HC-SR04

2-Channel 5 V Solid State Relay Module 2-Channel 5V Relay Module

IR Sensor 2Y0A21

Sharp Digital Distance Sensor

Adafruit 9 Degree of Freedom Absolute Orientation Sensor BN005

Adafruit (PID 3316) VL6180X Time of Flight Distance Ranging Sensor

Adafruit VL53L0X Time of Flight Distance Sensor ~30 to 1000 mm

Page 12: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 12

Thermocouple Temperature Control K Type Sensor Probe

Diymall Bme280 Pressure Temperature Sensor Module with IIC I2c

SunFounder Accelerometer ADXL335

Tilt Switch SUNKEE Photoresistor

MAX6675 Module + K Type Thermocouple Temperature Sensor

Breadboard Power Supply 3.3V/5VDC XBee Module – Series 1 – 1mW with Antenna – XB24-AWI-001

Page 13: Arduino Uno Microcontroller - University of Minnesota · Objective: To download and install the Arduino software for programming your Arduino Uno microcontroller. You will run a simple

Page 13

End of Arduino Uno Microcontroller

Mini ISD2548 Digital Voice Recorder 7-Segment Serial Display - Red

Adafruit 1.8” Color TFT LCD Display with MicroSD Card Breakout – ST77 35R

Diymall 0.96" Inch I2c IIC Serial 128x64 Oled LCD LED White Display Module

Raspberry Pi & Accessories