ME 120: Photoresistors and Arduino Programming Arduino Programming Case Study: Photoresistor Measurements ME 120 Mechanical and Materials Engineering Portland.

Slides:



Advertisements
Similar presentations
Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Advertisements

EMS1EP Lecture 6 Digital Inputs
ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
Lab7: Introduction to Arduino
Intermediate Electronics and Lilypad Where Electronics Meet Textiles Workshop with Lynne Bruning and Troy Robert Nachtigall Sponsored by Spark Fun and.
Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the.
Working with Arduino: Lesson #2: Variable, Photo, and Force Sensitive Resistors EGN1007.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Arduino Part 2 Topics: Serial Communication Programming Constructs: functions, loops and conditionals Digital Input.
Basic Circuits – Lab 2 Arduino and Sensors
Image of Arduino. Arduino discussion Address issues with circuit walk-through – Electricity, Programming, Arduino Concepts Work on BeatTable (next week)
Objectives: Lead Switching Circuitry/Control Analog to Digital Converter Write to Computer.
Motors Make the world go ‘round By Jackson Greer, Room 305.
Intro to Arduino Programming. Draw your circuits before you build them From Arduino 330 Ohm From Arduino 330 Ohm From Arduino 330 Ohm.
Automatic Target System Welcome The Automatic Target System (ATS) is a senior project for ME 102 at the University of California Berkeley. This project.
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 1 Getting Started to Arduino.
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS.
Basic Circuits – Lab 4 Serial and OSC (maybe some theory too) Xmedia Spring 2011.
Servo Demonstration In MPIDE, select File > Examples > Servo > Sweep.
Line following tips photoresistors positioned near floor photoresistor circuits © 2011 LWTL faculty team living with the lab.
Photoresistor resistance changes dramatically with light level living with the lab Using Photoresistors with an Arduino © 2011 LWTL faculty team.
ELECTRONICS – Input Transducers Engineering Science – National 5.
ECE 102 Engineering Computation Chapter 11 LabJack Photo Resistor & Mechanical Switch Interface Dr. Herbert G. Mayer, PSU Status 9/2/2015 For use at CCUT.
ME 120: Arduino PWM For Loops in Arduino ME 120 Mechanical and Materials Engineering Portland State University
ME 120: User-defined functions: average analog input reading Arduino Programming – Part 5: User-defined functions ME 120 Mechanical and Materials Engineering.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
LAB1 TYWU. Devices Dip Switch (4 Switches) Triple Output LED (RGB) –Common Cathode.
Introduction to Programming the Arduino Dr Gaw 3/21/14.
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Electronic instrumentation Digitization of Analog Signal in TD
Pulse-Width Modulation: Simulating variable DC output
ME 120: Arduino Programming Arduino Programming Part 1 ME 120 Mechanical and Materials Engineering Portland State University
ME 120: Arduino PWM Breathing LED Code: Implementation on Arduino ME 120 Mechanical and Materials Engineering Portland State University
Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw.
Arduino Application: Speed control of small DC Motors
Arduino Programming. THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER.
Hacking on Arduino George Patterson
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
Michael Rahaim, PhD Candidate Multimedia Communications Lab
Arduino Setup & Flexing the ExBow
Arduino & its hardware interfacing
Arduino Programming Part II
European Robotic LABoratory
Sensors with Arduino A Microcontroller.
Line Following Tips photoresistor circuits
INC 161 , CPE 100 Computer Programming
Control the color and brightness of an RGB LED with a Potentiometer
Arduino Uno and sensors
Control a motors angular position with a flex sensor
Analog Input through POT
What is an Arduino ? Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Arduino Application: Speed control of small DC Motors
IoT Programming the Particle Photon.
Digital Acquisition of Analog Signals – A Practical Guide
Using Photoresistors with an Arduino
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Line Following Tips photoresistor circuit
Topics: Programming Constructs: loops & conditionals Digital Input
Arduino : Introduction & Programming
Programming 2: The Arduino IDE & First Sketches
Arduino Practice: Photoresistors, PWM, Potentiometers, Motors
Sensors and actuators Sensors Resistive sensors
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Arduino 7 Segment Display Lab
Introduction to Arduinos
Pulse-Width Modulation: Simulating variable DC output
Arduino Programming: “if” statements
CTY SAR FCPS Alexander Velikanov
Presentation transcript:

ME 120: Photoresistors and Arduino Programming Arduino Programming Case Study: Photoresistor Measurements ME 120 Mechanical and Materials Engineering Portland State University

ME 120: Photoresistors and Arduino Programming Overview What is a photoresistor? How do we measure a photoresistor’s output? Basic Arduino circuit for reading and reporting Using “if” statements to respond to analog input readings See on-line reference: ❖ 2

ME 120: Photoresistors and Arduino Programming What is a photoresistor? 3

ME 120: Photoresistors and Arduino Programming A photoresistor is a semiconductor A photoresistor is a two-terminal semiconductor device that has an electrical resistance that depends on the light incident on the exposed semiconductor surface. The resistance decreases with increases in incident. 4 Incident light level Electrical resistance

ME 120: Photoresistors and Arduino Programming More information is available via the datasheet 1.Visit sparkfun.com 2.Enter “photoresistor” in the search box 3.Locate product #9088 or its more recent replacement 4.Click on the datasheet link 5.Note that there are many vendors 5

ME 120: Photoresistors and Arduino Programming Voltage divider circuit for photoresistor 6 Why is the fixed resistor on the bottom of the voltage divider?

ME 120: Photoresistors and Arduino Programming Basic Arduino code to read and report photoresistor output 7

ME 120: Photoresistors and Arduino Programming Display voltage divider output on the serial monitor Connect the voltage divider output to analog pin 0 8 See void setup() { Serial.begin(9600); // Initialize serial port object } void loop() { int reading; float voltage; reading = analogRead(A0); // Read analog input channel 0 voltage = reading*(5.0/1023.0); // and convert to voltage Serial.print(reading); // Print the raw reading Serial.print(” ”); // Make a horizontal space Serial.println(voltage); // Print voltage value }

ME 120: Photoresistors and Arduino Programming Use an “if” statement to respond to analog input readings 9

ME 120: Photoresistors and Arduino Programming Logical statements to control code execution “if” construct to make a single choice “if – else” construct to choose either/or 10 if ( something is true ) { code block } if ( something is true ) { code block 1 } else { code block 2 } See

ME 120: Photoresistors and Arduino Programming Syntax of “if” construct “if” construct to make a single choice “something is true” must be a logical expression Examples ❖ if ( x<0 ) ❖ if ( y>=z ) 11 if ( something is true ) { code block } SymbolMeaning <Is less than >Is greater than ==Is equal to >=Is greater than or equal to <=Is less than or equal to !=Is not equal to

ME 120: Photoresistors and Arduino Programming Test your understanding What is the value of z? 12 x = 2; y = 5; if ( x < y ) { z = y – x; } x = 2; y = 5; if ( x > y ) { z = y – x; } x = 2; y = 5; if ( (y-x)<= 3 ) { z = y/x; } x = 2; y = 5; if ( (y-x)<= 3 ) { z = y/x; } else { z = 0.0; } a. b. c. d.

ME 120: Photoresistors and Arduino Programming Compound “if-else-if” Implement a piecewise function Notice the error-handling for x x4 13 if ( x<x1 ) { Serial.println(“Error: x<x1”); } else if ( x<x2 ) { y = ya; } else if ( x<x3 ) { y = yb; } else if ( x<x4 ) { y = yc; } else { Serial.println(“Error: x>x4”); }

ME 120: Photoresistors and Arduino Programming Output dependent on photoresistor reading 14 void setup() { Serial.begin(9600); // Initialize serial port object } void loop() { int reading; float voltage; reading = analogRead(A0); // Read analog input channel 0 voltage = reading*(5.0/1023.0); // and convert to voltage if ( voltage < 2.5 ) { Serial.println(”Getting dark”); // Print the raw reading }

ME 120: Photoresistors and Arduino Programming Output dependent on photoresistor reading Next step ❖ Add a second test at 1.75 V (or some value). Print a different message for very low analog input (low ambient light values) Study questions ❖ What are minimum and maximum voltage levels for photoresistor outputs? ❖ Will the test for darkness work without converting to voltage first? 15