As seen in the previous blog postings, the LED (Light Emitting Diode) was used to DISPLAY the result of various sensors. It was also used to create a variety of Light patterns or sequences.
The LED is commonly used as an OUTPUT device, however, I have since found out: there is another option.
You can use the LED as an INPUT device !!
I have only tried this with a Yellow LED and a Red LED, however, this should work with any colour. Some sites recommend using a clear/transparent/colourless LED for best effect, but it depends on what you are trying to achieve.
The LED responds better to light of the same wavelength that it emits. So a yellow LED responds better to yellow light, and a red LED responds better to Red light.
The following experiment attempts to prove this theory. A Red and Yellow LED alternate and fade in to maximum brightness using PWM (Analog Output). Meanwhile, a separate LED is used as an INPUT device to receive the light. The value obtained is plotted using a processing sketch.
The chart above used a Yellow LED to measure the light emitted from a Red and then a Yellow LED.
As the Yellow LED gets brighter, the INPUT LED takes less time to discharge, and thus produces a lower result. On the other hand, the Red LED has little effect on the INPUT LED, despite it's brightness.
Ambient light will produce different graph patterns.
Parts Required:
Arduino UNO
2 x Yellow LEDs
1 x Red LED
3 x 330 ohm Resistors (choose resistors suitable for your LEDs)
//Alternate the flashing of the Yellow and Red LED if(switcher==0){ lightLevelR+=4; if(lightLevelR>255){ lightLevelR=0; switcher=1; } } else { lightLevelY+=3; if(lightLevelY>255){ lightLevelY=0; switcher=0; } } analogWrite(Red_LED,lightLevelR); analogWrite(Yellow_LED,lightLevelY);
// Charge the LED by applying voltage in the opposite direction pinMode(LED_Sensor_NEG,OUTPUT); digitalWrite(LED_Sensor_NEG,HIGH);
// Set pin 8 to read the input and Turn off the internal pull up resistor. // The greater the amount of light in the room, the smaller the number represented by variable "darkness". long darkness=0; int outputVal=0; pinMode(LED_Sensor_NEG,INPUT); digitalWrite(LED_Sensor_NEG,LOW); while((digitalRead(LED_Sensor_NEG)!=0) && darkness<80000){ darkness++; }
outputVal=darkness/80; //Print the darkness level in the room. Serial.println(outputVal); }
// This program takes ASCII-encoded strings // from the serial port at 9600 baud and graphs them. It expects values in the // range 0 to 1023, followed by a newline, or newline and carriage return // Created 20 Apr 2005 // Updated 18 Jan 2008 // by Tom Igoe // This example code is in the public domain.
import processing.serial.*;
Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph
void setup () { // set the window size: size(400, 300);
// List all the available serial ports println(Serial.list()); // I know that the second port in the serial list on my PC // is always my Arduino, so I open Serial.list()[1]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[1], 9600); // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); // set inital background: background(0); } void draw () { // everything happens in the serialEvent() }
void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n');
if (inString != null) { // trim off any whitespace: inString = trim(inString); // convert to a float and map to the screen height: float inByte = float(inString); inByte = map(inByte, 0, 1023, 0, height);
// at the edge of the screen, go back to the beginning: if (xPos >= width) { xPos = 0; background(0); } else { // increment the horizontal position: xPos++; } } }
Have you ever wondered if there was a way to store and retrieve data from a USB stick with an Arduino UNO? Most people choose SD cards to store their project data, but you may be surprised there IS a way! IC Station have a nice little module which allows you store and retrieve your Arduino (or other MCU) project data to a USB stick. I am not too sure why USB storage is not widely used in Arduino projects? These modules are not expensive, they have been around for quite a while, and are relatively simple to use. You do not need any libraries to get them to work, however, I must say that documentation for this module is not that easy to find. This site and this document proved to be very useful in my endevour to get this module working, and I hope my tutorial below will help you get started and bridge some of the information gaps. The...
Introduction Nextion is a programmable human machine interface (HMI) that can be customized and designed to simplify the interaction between you and your project. This Nextion Enhanced module (NX4827K043) with a resistive touch screen display, has some additional features not seen in previous traditional versions of the Nextion series. A built in real time clock (RTC) Accessible flash memory (32MB) GPIO functionality Faster clock speed Before you connect the Nextion Enhanced module to your project, you need to design your interface with the free Nextion Editor. The editor can be downloaded here. In this project, I will be designing a simple dynamic interface, which will allow me to interact with a stepper motor in two different ways. The first interface will let me control the direction and speed of the stepper motor through the use of a simple GUI. I will have left and right arrows for the direction, and up and down arrows for the speed. I will also map the Expansion board...
PART THREE If you happened to land on this page and missed PART ONE , and PART TWO , I would advise you go back and read those sections first. This is what you'll find in partone : Downloading and setting up the Android SDK Downloading the Processing IDE Setting up and preparing the Android device Running through a couple of Processing/Android sketches on an Andoid phone. This is what you will find in part two : Introducing Toasts (display messages) Looking out for BluetoothDevices using BroadcastReceivers Getting useful information from a discovered Bluetooth device Connecting to a Bluetooth Device An Arduino Bluetooth Sketch that can be used in this tutorial InputStream and OutputStream We will now borrow some code from the Android developers site to help us to establish communication between the Android phone and the Bluetooth shield on the Arduino. By this stage we have already scanned and discovered the bluetooth device and made a successful connection. We now need to create ...
Comments
Post a Comment