Paxlo_05
Published © GPL3+

Show the luminosity with coloured LEDs

It's a little and easy project using the photoresistor and LEDs

IntermediateShowcase (no instructions)7
Show the luminosity with coloured LEDs

Things used in this project

Hardware components

Arduino Mega 2560 & Genuino Mega 2560
Arduino Mega 2560 & Genuino Mega 2560
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
5 mm LED: Red
5 mm LED: Red
×8
Resistor 220 ohm
Resistor 220 ohm
×8
Through Hole Resistor, 1 kohm
Through Hole Resistor, 1 kohm
×1
Elegoo 74hc595 IC
×1
Photo resistor
Photo resistor
×1
Male/Male Jumper Wires
×16

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

photocell_1

photocell_2_xdRu1yPzZc.png

Code

Photocell.ino

Arduino
//www.elegoo.com
//2016.12.9

int lightPin = 0;
int latchPin = 11;
int clockPin = 9;
int dataPin = 12;

int leds = 0;

void setup() 
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
}
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}
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();
}

Credits

Paxlo_05

Paxlo_05

0 projects • 0 followers

Comments