Pumpkin Night Light

by wxie00986 in Circuits > Arduino

168 Views, 0 Favorites, 0 Comments

Pumpkin Night Light

10470.jpg

reference by https://www.instructables.com/id/LED-Pumpkin-Light-controlled-by-Arduino/

What You Need

10473.jpg

a pumpkin

1 x Arduino

1 x LED

1 x LDR

1 x 1000 ohm resistor

1 x 220 ohm resistor

Build a Circuit

10629.jpg

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

10647.jpg

Light Up the Pumpkin

10470.jpg

put the circuit back in the pumpkin and shut the light off and light it up

Video View

arduino pumpkin night light