Arduino Lighting Project

Discusses Hulls, Mast & Deck Furnishings
Post Reply
User avatar
GemmaJF
Petty Officer First Class
Petty Officer First Class
Posts: 457
Joined: Mon Feb 20, 2017 1:31 pm
Location: Essex, UK

Arduino Lighting Project

Post by GemmaJF » Sat Apr 15, 2017 10:01 am

A lot of you will have heard of Arduino controller boards and how they are being utilized in hobbies.

This is a simple lighting project that gives control over the 'brightness' of LED's, I am also developing flicker effects and 'sequencing' of LEDs. Firstly I will present Project 1, which gives the brightness control.

Before using LEDs with Arduino there is some maths, so here is the start of the project:


Choosing Resistors for LEDs


As you may decide to use different LEDs for your project a quick bit of maths is needed to select an appropriate resistor.

There is an online calculator here with an explanation of the maths:

http://www.ohmslawcalculator.com/led-re ... calculator

The reason a resistor is required is that the maximum PWM output voltage of Arduino UNO is 5v. You will find your LED is likely to be rated at a lower voltage. The resistor lowers the current that can run in the circuit and by Ohm’s law, it therefore lowers the voltage.

When using the calculator

Vs (source voltage) is the maximum PWM output of 5v

VLED is the voltage drop for the LED (the stated voltage when you buy the LED)

ILED is the current through the LED (the stated current rating when you buy the LED)

An example of using the calculator

The orange 3 mm LEDs I purchased are 2v, 20mA

Start with entering 5v as the voltage source

2v as the Voltage drop

20mA as the current through the LED

The calculator yields the following result:
Untitled-1 copy.jpg
Untitled-1 copy.jpg (67.1 KiB) Viewed 614 times
So I needed to purchase 150 ohm resistors


Controlling Individual Light Levels of LEDs

Part of the project brief I gave myself is that it should be possible to alter the brightness of individual LEDs. One perhaps would not want the cabin lighting as bright as the Lanterns at the rear of the ship.

There are several approaches I have thought of to achieve this part of the brief. But there are pros and cons to each.
The easiest approach I can think of is to lower the PWM output in the software sketch to dim an LED. This though creates a problem with the flicker routines as less ‘steps’ become available to them and the results can get a bit unpredictable at lower brightness levels.

The next approach is to control the brightness by installing a higher value resistor. The higher the value of the resistor the more dim the LED would appear, without reducing the PWM steps available to flicker routines.

One last approach might be to use trim pots, looking into this though there is not a lot of mileage in it. It would create a high component count and results or using a pot in a direct way to alter voltage might at best be mediocre.

So assuming there are two approaches to the dimming, one is simple and the other is a little more complicated but suitable for flicker routines, at this point it seems wise to split the project in two!

Project 1

Six LEDs with a global dimmer control and individual software scaling of the relative brightness of the LEDs (STPT switch not required) Ideal if you want to light a ship model but are not concerned about adding flicker effects.

Project 2

Six LEDs, with global dimmer control, individual relative brightness of LEDs controlled by selecting different resistors, flicker effects available.

One of the upshots of this approach is that Project 1 could be used as a tool in the development of Project 2 with a little bit of modification.
Last edited by GemmaJF on Sun Apr 16, 2017 3:49 am, edited 1 time in total.
Current Build: ZHL Black Pearl 1:50

Next Up: Billing Boats Bounty 1:50

Researching for POB scratch build : HMS Ferret 1:48 (1711)

Projects: Arduino Lighting Project

User avatar
GemmaJF
Petty Officer First Class
Petty Officer First Class
Posts: 457
Joined: Mon Feb 20, 2017 1:31 pm
Location: Essex, UK

Re: Arduino Lighting Project

Post by GemmaJF » Sat Apr 15, 2017 10:15 am

Project 1

Bread Board layout of the circuit:

Project 1.jpg
Project 1.jpg (151.42 KiB) Viewed 603 times

LEDs of your choice, resistors as calculated, and a 100K linear potentiometer to give a 'global' dimming control. The brightness of the LEDs can be controlled by turning the potentiometer.

Each LED is connected to a PWM (Pulse Width Modulation) output of the Arduino. I use UNO for all development work, but the 'sketch' to follow can be altered to work with Nano or Mega or many other Arduino based boards.
Last edited by GemmaJF on Sat Apr 15, 2017 1:25 pm, edited 1 time in total.
Current Build: ZHL Black Pearl 1:50

Next Up: Billing Boats Bounty 1:50

Researching for POB scratch build : HMS Ferret 1:48 (1711)

Projects: Arduino Lighting Project

User avatar
GemmaJF
Petty Officer First Class
Petty Officer First Class
Posts: 457
Joined: Mon Feb 20, 2017 1:31 pm
Location: Essex, UK

Re: Arduino Lighting Project

Post by GemmaJF » Sat Apr 15, 2017 10:27 am

Project 1

UNO Sketch:

Code: Select all

/*
Project 1 - Model Ship Lighting

Provides global dimming and individual dimming control to 6 LEDs

 Created 04 Feb 2016
 By Gemma Fairchild

 This code is in the public domain.

*/

float ledPin1Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off)
float ledPin2Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off) 
float ledPin3Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off) 
float ledPin4Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off)
float ledPin5Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off)
float ledPin6Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off)

int potPin = A0;
int readValue;
int globalDim;
int ledPin1 = 3;   // LED connected to digital pin 3
int ledPin2 = 5;   // LED connected to digital pin 5
int ledPin3 = 6;   // LED connected to digital pin 6
int ledPin4 = 9;   // LED connected to digital pin 9
int ledPin5 = 10;  // LED connected to digital pin 10
int ledPin6 = 11;  // LED connected to digital pin 11

void setup() {
  
  pinMode(potPin, INPUT);  // Set potPin (pin A0) to input
  Serial.begin(9600); // turn on serial port
}

void loop() {
  
  // read potentiometer value for globalDim
  readValue = analogRead(potPin); //Read the voltage on the potentiometer
  globalDim = (255./1023.) * readValue; //Calculate the value for global dim
  Serial.print("Dimmer PWM value is ");
  Serial.println(globalDim);  //Send current PWM value to Serial Monitor
  
    analogWrite(ledPin1, globalDim * (ledPin1Bright / 255));
    analogWrite(ledPin2, globalDim * (ledPin2Bright / 255));
    analogWrite(ledPin3, globalDim * (ledPin3Bright / 255));
    analogWrite(ledPin4, globalDim * (ledPin4Bright / 255));
    analogWrite(ledPin5, globalDim * (ledPin5Bright / 255));
    analogWrite(ledPin6, globalDim * (ledPin6Bright / 255));

The statement "This code is in the public domain" means you are free to use this code in any way you like, copy it, distribute it, there is no copyright restriction on its use.
Current Build: ZHL Black Pearl 1:50

Next Up: Billing Boats Bounty 1:50

Researching for POB scratch build : HMS Ferret 1:48 (1711)

Projects: Arduino Lighting Project

User avatar
GemmaJF
Petty Officer First Class
Petty Officer First Class
Posts: 457
Joined: Mon Feb 20, 2017 1:31 pm
Location: Essex, UK

Re: Arduino Lighting Project

Post by GemmaJF » Sat Apr 15, 2017 11:04 am

Using Project 1

I have purposely not put up much material regarding using Arduino, sketches etc. It is all published elsewhere. If anyone tries the project and gets stuck, just ask. I can probably answer any questions or point people in the right direction.

So, having set-up a breadboard, upload the Project 1 sketch to your board from your PC.

If you have installed the code as written and built the circuit correctly, you should see 6 LEDs uniformly lit at 'full' brightness.
Bright LEDs.jpg
Bright LEDs.jpg (204.61 KiB) Viewed 599 times
Turning the potentiometer will dim all the LEDs together, from fully bright to 'off'

I have added more though, I want to be able to dim individual LEDs so I can control the brightness of each LED to suit the scene of my model.

This is how to achieve it:

Open the serial monitor in Arduino, the button that opens it is is circled in the image below:
Serial Monitor.jpg
Serial Monitor.jpg (122.2 KiB) Viewed 599 times
Turn the potentiometer so the LEDs are fully bright and one will see the PWM value is 255 or 'fully bright'. Twiddle the potentiometer and one can see the PWM value changing from 255 for fully bright to 0 for 'off'.
dimmervalue_01.jpg
dimmervalue_01.jpg (84.89 KiB) Viewed 599 times
To set an individual LED to a new brightness level, use the potentiometer to turn all the lights to the desired brightness. Here I have chosen Dimmer PWM value 27
Serial Monitor_02.jpg
Serial Monitor_02.jpg (87.67 KiB) Viewed 599 times
Make a note of the value.

Edit the initial value in the sketch to reflect maximum brightness for a particular LED that needs to be 'dimmed' compare to the others, so I will use the value 27 on pin 3

Code: Select all

float ledPin1Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off)
float ledPin2Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off) 
float ledPin3Bright = 27;   //LED individual brightness control (enter 255 for fully bright to 0 off) 
float ledPin4Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off)
float ledPin5Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off)
float ledPin6Bright = 255;   //LED individual brightness control (enter 255 for fully bright to 0 off)
Upload the edited sketch. Now the LED connected to Pin 3 is less bright than the others. All the LEDs will still dim in proportion to each other using the potentiometer, but the LED on Pin 3 will always be less bright than the others.
LEDs.jpg
LEDs.jpg (146.88 KiB) Viewed 599 times

Continue in this way until you have all the relative brightness for your model adjusted.

That is it for Project 1. It would be great if someone gives Project 1 of the Arduino Lighting project a go. :handgestures-thumbup:
Current Build: ZHL Black Pearl 1:50

Next Up: Billing Boats Bounty 1:50

Researching for POB scratch build : HMS Ferret 1:48 (1711)

Projects: Arduino Lighting Project

User avatar
GemmaJF
Petty Officer First Class
Petty Officer First Class
Posts: 457
Joined: Mon Feb 20, 2017 1:31 pm
Location: Essex, UK

Re: Arduino Lighting Project

Post by GemmaJF » Sat Apr 15, 2017 11:46 am

A brief note on the limits of directly using an Arduino to control LEDs, specifically the direct voltage and current it can supply.

Arduino UNO

5V from a PWM output

maximum current of 30mA at each input/output pin is usually recommended.

The sum of all the input/output pins combined for a single board should not exceed 200mA.

There are ways to control many more LEDs, or bulbs rather than LEDs etc. I'm not covering it all here, but for dozens of LEDs take a look at LED controllers and multiplexing etc.

For light bulbs working on higher voltages and currents, there are many electrical ways to use the signals from an Arduino to switch much higher voltages and currents.
Current Build: ZHL Black Pearl 1:50

Next Up: Billing Boats Bounty 1:50

Researching for POB scratch build : HMS Ferret 1:48 (1711)

Projects: Arduino Lighting Project

User avatar
aew
Petty Officer Second Class
Petty Officer Second Class
Posts: 131
Joined: Wed Mar 20, 2013 11:25 am
Location: Leeds, WY, England

Re: Arduino Lighting Project

Post by aew » Thu Apr 27, 2017 5:01 am

I have flickering LEDs fitted in my model of Vanguard. It's using the same microprocessor as the Arduino, but I programmed it a while ago using BASCOM.
I'll see if I still have the code. It'll need modifying to run on the Arduino as the timers are different but that shouldn't be a problem.
I'm still waiting for another Arduino I ordered a while ago, as my current 'spare' is running bensid's 'Charon' RC programme.
When/if I get it working I'll send you the sketch.
There are some pictures in this post: http://www.modelshipbuilder.com/e107_pl ... php?7649.0
Arthur

Current Build - HMS Vanguard

User avatar
GemmaJF
Petty Officer First Class
Petty Officer First Class
Posts: 457
Joined: Mon Feb 20, 2017 1:31 pm
Location: Essex, UK

Re: Arduino Lighting Project

Post by GemmaJF » Thu Apr 27, 2017 8:26 am

aew wrote:I have flickering LEDs fitted in my model of Vanguard. It's using the same microprocessor as the Arduino, but I programmed it a while ago using BASCOM.
I'll see if I still have the code. It'll need modifying to run on the Arduino as the timers are different but that shouldn't be a problem.
I'm still waiting for another Arduino I ordered a while ago, as my current 'spare' is running bensid's 'Charon' RC programme.
When/if I get it working I'll send you the sketch.
There are some pictures in this post: http://www.modelshipbuilder.com/e107_pl ... php?7649.0

Thanks for the link Arthur,

I have a couple of blocks of code that produce flicker effects using different methods, anything you have can be added to the pot too!

I will cover the flickering in 'Project 2'. I want to leave the write up until I have the hardware built for the Pearl so I can demonstrate it more easily.
Current Build: ZHL Black Pearl 1:50

Next Up: Billing Boats Bounty 1:50

Researching for POB scratch build : HMS Ferret 1:48 (1711)

Projects: Arduino Lighting Project

User avatar
aew
Petty Officer Second Class
Petty Officer Second Class
Posts: 131
Joined: Wed Mar 20, 2013 11:25 am
Location: Leeds, WY, England

Re: Arduino Lighting Project

Post by aew » Sat Apr 29, 2017 7:21 am

I've got a working setup.
PM me an email address and I'll send you the sketch. Feel free to use it or modify it in your next installment.
Arthur

Current Build - HMS Vanguard

Post Reply

Return to “Hulls, Mast & Deck Furnishings”