Pumpkin Night Light
reference by https://www.instructables.com/id/LED-Pumpkin-Light-controlled-by-Arduino/
What You Need
a pumpkin
1 x Arduino
1 x LED
1 x LDR
1 x 1000 ohm resistor
1 x 220 ohm resistor
Build a Circuit
solder the 220 ohm resistor to the short leg of the LED and insert it in the ground pin.Insert the long leg into digital pin 9.Insert one wire from the LDR and one leg of the 1000 ohm resistor into analog pin 3insert the other end of the LDR in 5v, and the other end of the 1000 ohm resistor into the second ground.
Write a Program
int ledPin = 9;//
int val = 0;
int cycle = 750;
int analogInput = 3;
int value = 0;
void setup() //
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
randomSeed(analogRead(0));
pinMode(analogInput, INPUT);
}
void loop() //
{
if (cycle > 700)
{
value = analogRead(analogInput);
}
if (value > 650)
{
cycle++;
val = random(256);
analogWrite(ledPin, val);
if (val > 250)
delay (val * random(3));
else if (val < 2)
if (cycle > random(800, 3500))
{
for (val = 250; val > random(20, 40); val--)
{
analogWrite(ledPin, val);
delay(random(2, 14));
}
analogWrite(ledPin, val);
delay(random(10, 1000));
cycle = 0;
}
}
else { digitalWrite(ledPin, LOW);
delay(10000);
}
}
https://create.arduino.cc/editor/wxie00986/0c275c5a-ad0b-46c0-ab2a-4e966f597339/preview
Light Up the Circuit
Light Up the Pumpkin
put the circuit back in the pumpkin and shut the light off and light it up