Arduino Lesson 9. Sensing Light



Similar documents
Arduino Lesson 4. Eight LEDs and a Shift Register

Arduino Lesson 13. DC Motors. Created by Simon Monk

Arduino Lesson 5. The Serial Monitor

Arduino Lesson 14. Servo Motors

Arduino Lesson 0. Getting Started

Arduino Lesson 1. Blink

Arduino Lesson 16. Stepper Motors

Arduino Lesson 17. Sending Movement Detector

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

Adafruit's Raspberry Pi Lesson 11. DS18B20 Temperature Sensing

Character LCDs. Created by Ladyada. Last updated on :45:29 PM EDT

SSH to BeagleBone Black over USB

Playing sounds and using buttons with Raspberry Pi

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Adafruit's Raspberry Pi Lesson 9. Controlling a DC Motor

2.2" TFT Display. Created by Ladyada. Last updated on :15:09 PM EDT

V out. Figure 1: A voltage divider on the left, and potentiometer on the right.

Capacitive Touch Sensor Project:

RGB LED Strips. Created by lady ada. Last updated on :00:18 PM EST

Set up and Blink - Simulink with Arduino

Sending an SMS with Temboo

Thermistor. Created by Ladyada. Last updated on :30:46 PM EDT

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

TEECES DOME LIGHTING SYSTEMS

Basic Pulse Width Modulation

Kirchhoff s Laws Physics Lab IX

Basic DC Motor Circuits. Living with the Lab Gerald Recktenwald Portland State University

Basic DC Motor Circuits

Tiny Arduino Music Visualizer

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

DEPARTMENT OF ELECTRONICS ENGINEERING

Objectives: Part 1: Build a simple power supply. CS99S Laboratory 1

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

Adafruit BME280 Humidity + Barometric Pressure + Temperature Sensor Breakout

Lab 6 Introduction to Serial and Wireless Communication

MCP4725 Digital to Analog Converter Hookup Guide

Battery Power for LED Pixels and Strips. Created by Phillip Burgess

Experiment 4 ~ Resistors in Series & Parallel

How to Move Canon EF Lenses. Yosuke Bando

Building the AMP Amplifier

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable. Created by Simon Monk

Cornerstone Electronics Technology and Robotics I Week 15 Voltage Comparators Tutorial

ADC-20/ADC-24 Terminal Board. User Guide DO117-5

Arduino DUE + DAC MCP4922 (SPI)

1.8" TFT Display Breakout and Shield

Adafruit Proto Shield for Arduino

LM 358 Op Amp. If you have small signals and need a more useful reading we could amplify it using the op amp, this is commonly used in sensors.

Arduino Motor Shield (L298) Manual

TRANSISTOR/DIODE TESTER

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

IR Communication a learn.sparkfun.com tutorial

Electronic Brick of Current Sensor

OHM S LAW AND RESISTANCE

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

BUILDING INSTRUCTIONS

A REST API for Arduino & the CC3000 WiFi Chip

Parallel DC circuits

DS1307 Real Time Clock Breakout Board Kit

Tutorial 12 Solutions

Input, Process and Output

AirCasting Particle Monitor Bill of Materials

TSL2561 Luminosity Sensor

Introduction to Arduino

Lab 3 Rectifier Circuits

How to Make a Pogo Pin Test Jig. Created by Tyler Cooper

THE BREADBOARD; DC POWER SUPPLY; RESISTANCE OF METERS; NODE VOLTAGES AND EQUIVALENT RESISTANCE; THÉVENIN EQUIVALENT CIRCUIT

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

Kit Watt Audio Amplifier

Using an IR Remote with a Raspberry Pi Media Center

Adding a Real Time Clock to Raspberry Pi

Basic voltmeter use. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

DET Practical Electronics (Intermediate 1)

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

C4DI Arduino tutorial 4 Things beginning with the letter i

Electrical Resonance

Measuring Resistance Using Digital I/O

How to program a Zumo Robot with Simulink

1 Coffee cooling : Part B : automated data acquisition

Experiment 8 Series-Parallel Circuits

ECEN 1400, Introduction to Analog and Digital Electronics

Green House Monitoring and Controlling Using Android Mobile Application

Series and Parallel Circuits

Maximum value. resistance. 1. Connect the Current Probe to Channel 1 and the Differential Voltage Probe to Channel 2 of the interface.

Operating instructions Diffuse reflection sensor. OJ50xx / / 2004

AXE114S BINARY CLOCK. revolution Revolution Education Ltd. Web: Version /09/08 AXE114.PMD.

Voltage Measurement with A PIC Microcontroller

Tristan s Guide to: Solving Parallel Circuits. Version: 1.0 Written in Written By: Tristan Miller Tristan@CatherineNorth.com

0.9V Boost Driver PR4403 for White LEDs in Solar Lamps

Resistors in Series and Parallel Circuits

Designing Gain and Offset in Thirty Seconds

MAS.836 HOW TO BIAS AN OP-AMP

WICE-SPI Hardware Operation Manual

Series and Parallel Resistive Circuits

Drive a 16x2 LCD with the Raspberry Pi

Experiment NO.3 Series and parallel connection

Lab 3 - DC Circuits and Ohm s Law

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

LAB2 Resistors, Simple Resistive Circuits in Series and Parallel Objective:

Contents. Document information

Transcription:

Arduino Lesson 9. Sensing Light Created by Simon Monk Last updated on 2014-04-17 09:46:11 PM EDT

Guide Contents Guide Contents Overview Parts Part Qty Breadboard Layout Photocells Arduino Code Other Things to Do 2 3 4 4 4 7 8 9 11 Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 2 of 11

Overview In this lesson, you will learn how to measure light intensity using an Analog Input. You will build on lesson 8 and use the level of light to control the number of LEDs to be lit. The photocell is at the bottom of the breadboard, where the pot was in lesson 8. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 3 of 11

Parts Part Qty 5mm red LED 8 270 Ω Resistors (red, purple, brown stripes) 8 1 kω Resistor (brown, black, red stripes) 1 74HC595 Shift Register 1 Photocell (Light Dependent 1 Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 4 of 11

Resistor) 1 Half-size Breadboard 1 Arduino Uno R3 1 Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 5 of 11

Jumper wire pack 1 Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 6 of 11

Breadboard Layout The breadboard layout for this lesson is the same as for lesson 8, except that the pot is replaced by an LDR and a 1 kω resistor. Here is the layout for lesson 8, near the pot. Simply remove the pot and replace it with the photocell and resistor as shown below: Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 7 of 11

Photocells The photocell used is of a type called a light dependent resistor, sometimes called an LDR. As the name suggests, these components act just like a resistor, except that the resistance changes in response to how much light is falling on them. This one has a resistance of about 50 kω in near darkness and 500 Ω in bright light. To convert this varying value of resistance into something we can measure on an Arduino's analog input, it need to be converted into a voltage. The simplest way to do that is to combine it with a fixed resistor. The resistor and photocell together behave rather like a pot. When the light is very bright, then the resistance of the photocell is very low compared with the fixed value resistor, and so it is as if the pot were turned to maximum. When the photocell is in dull light the resistance becomes greater than the fixed 1kΩ resistor and it is as if the pot were being turned towards GND. Load up the sketch given in the next section and try covering the photocell with your finger, and holding it near a light source. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 8 of 11

Arduino Code The sketch that you used in lesson 8, will work, but you will find that you will not be able to find a light bright enough to light all the LEDs. This is because of the fixed resistor, so we need to compensate for the fact that no matter how low the resistance of the photocell falls, there will always be the 1 kω of the fixed resistor offsetting it. The slightly modified lesson 8 sketch is listed below: /* Adafruit Arduino - Lesson 9. Light sensing */ int lightpin = 0; int latchpin = 5; int clockpin = 6; int datapin = 4; int leds = 0; void setup() { pinmode(latchpin, OUTPUT); pinmode(datapin, OUTPUT); pinmode(clockpin, OUTPUT); } void loop() { int reading = analogread(lightpin); int numledslit = reading / 57; //1023 / 9 / 2 if (numledslit > 8) numledslit = 8; leds = 0; // no LEDs lit to start for (int i = 0; i < numledslit; i++) { leds = leds + (1 << i); // sets the i'th bit } updateshiftregister(); } void updateshiftregister() { digitalwrite(latchpin, LOW); shiftout(datapin, clockpin, LSBFIRST, leds); digitalwrite(latchpin, HIGH); } Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 9 of 11

The first thing to note is that we have changed the name of the analog pin to be 'lightpin' rather than 'potpin' since we no longer have a pot connected. The only other substantial change to the sketch is the line that calculate how many of the LEDs to light: int numledslit = reading / 57; // all LEDs lit at 1k This time we divide the raw reading by 57 rather than 114 from lesson 8. In other words we divide it by half as much as we did with the pot, to split it into nine zones, from no LEDs lit, to all eight lit. This extra factor is to account for the fixed 1 kω resistor. This means that when the photocell has a resistance of 1 kω (the same as the fixed resistor) the raw reading will be 1023 / 2 = 511. This will equate to all the LEDs being lit and then a bit (numledslit will be 9). Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light Page 10 of 11

Other Things to Do To vary the sensitivity of the light meter you have just made, try changing the value of the factor (57) that you divide the analog reading by. Increasing this value will make the reading less sensitive. Another thing that you could try is to change the sketch so that while the reading is below a certain level, the LEDs are on, but they automatically turn off when a threshold is exceeded. So putting your finger near the photocell to cut out most of the light will turn on the LEDs. http://adafru.it/aus About the Author Click Here for the Next Lesson Simon Monk is author of a number of books relating to Open Source Hardware. The following books written by Simon are available from Adafruit: Programming Arduino (http://adafru.it/1019), 30 Arduino Projects for the Evil Genius (http://adafru.it/868) and Programming the Raspberry Pi (http://adafru.it/am5). Adafruit Industries Last Updated: 2014-04-17 09:46:12 PM EDT Page 11 of 11