
This project is based around three normal LEDs that I control so that they look like a flickering flame:
The LEDs are connected in series with a resistor to the PWM pins on the Arduino so that I can control the brightness.
And in the code, I change the brightness of each LED to a random value every 50 milliseconds.
I 3D-printed my pumpkin, but you can place your LEDs in whatever you have at hand. For example a carved pumpkin or an old lantern.
The code is pretty straightforward
In the setup() function, I set up the LED pins as outputs. And in the loop() function, I use the analogWrite() function to set a random brightness value to each LED, with a 50-millisecond delay between each change of value.
int ledPin1 = 9; int ledPin2 = 10; int ledPin3 = 11; void setup() { // Set LED pins as outputs pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); } void loop() { analogWrite(ledPin1, random(10, 255)); delay(50); analogWrite(ledPin2, random(10, 255)); delay(50); analogWrite(ledPin3, random(10, 255)); delay(50); }
Do you think that the Arduino UNO takes up too much space for this project? Well, then how about shrinking it down onto an ATtiny85 chip?
If you're able to build projects with Arduino, there's not a lot you need to learn to build with the ATTiny85.
But that's for another email.
Keep On Soldering!
Oyvind @ build-electronic-circuits.com
PS! Whenever you're ready, here are two ways I can help you learn electronics:
- Join Ohmify: Ohmify is for people interested in electronics who want to learn skills like Arduino, soldering, microcontrollers, and more - while also getting a proper understanding of the basics.
- Get the eBook Fun Circuit Experiments with Sound and Light where you'll learn basic electronics through experiments. If you're new to electronics, this is the perfect place to start. The book comes bundled with a component kit for an easy beginning of your journey.
- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Comments
Post a Comment