Wednesday 25 November 2015

Arduino Lab 6: Light Sensor

Purpose:
This lab will teach you how to change one LED's brightness according the level of light that is hitting the light sensor.

Equipment:
-1 light sensor
-1 10k ohm resistor
-1 LED (any colour)
-330 ohm resistor
-1 wire (red)
-1 wire (black)
-4 wires (any colour) 
-1 Arduino UNO 
-1 breadboard 
-1 USB cable

Program Details:
-Download Arduino here

Time to Program and Complete:
-Approximately 25 min

Results:
-There were no issues and it worked completely fine

Photo/Video:




Program:
int lightPin = 0;
int ledPin = 9;
void setup()
{
  pinMode (ledPin, OUTPUT);
}
void loop()
{
  int lightLevel = analogRead(lightPin);
  lightLevel = map(lightLevel, 0, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  analogWrite(ledPin, lightLevel);
}

Program Modifications:
-There were none

Helpful Tips:
-Check spelling/spacing

References:
-Arduino website: arduino.cc 
-New Innovators: Lab 6

No comments:

Post a Comment