# Making a dancing light device

#### kourosh daryaee

May 12, 2016
38
Hello again
I want to make light device but a bit more complicated than the first one :

I decided to use a microcontroller so can play with different patterns of lights.
now I have some questions to ask if you do not mind:
First of all what kind of hardware do I need to start programming a microcontroller . like debugger or programmer etc..
Second what kind of microcontroller should I use AVR or PIC since I just started to use microcontrollers.
Third ,I have simulated ATMEGA 16 on Proteus and programmed it on Codevision before.but now I am making something on the electronics board not on the simulation software. so what kind of software I need ? I mean for designing the board , programming ,debugging (i prefer C language over assembly if its possible)
and last question what model of microcontroller should i use i want to play with 10 SMD's I need 10 output and some input for signals (if i am right?)

Thanks

Last edited:

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
12,518
what kind of hardware do I need to start programming a microcontroller
You'll need a programmer. Which one will depend on your choice of controller. A debuggerr is nice to have, but probably prohibitively expensive.

what kind of microcontroller should I use AVR or PIC
Since you already are at least a bit familiar with the ATMEGA 16, an AVR is an obvious choice.

what model of microcontroller should i use i want to play with 10 SMD's I need 10 output and some input for signals
The number of inputs and outputs is only one factor in the equation. The number of inputs and outputs can easily be increased by using I/O-expanders or multiplexing. Another, very important factor is the size of the integrated memory which needs to be large enough to hold your code. As long as you stay within a family of compatible controllers, it is usually straight forward to start with a small model and switch to the next bigger one should memory not be enough. You can often do this step within a simulator before actually buying the hardware.

If you want an easy start, use an off-the-shelf microcontroller board like e.g. the arduino (AVR based) or similar. These boards often come with a built-in boot loader so you simply connect them via USB or serial port to your computer and download the program using the programming environment (IDE).

#### kourosh daryaee

May 12, 2016
38
You'll need a programmer. Which one will depend on your choice of controller. A debuggerr is nice to have, but probably prohibitively expensive.

Since you already are at least a bit familiar with the ATMEGA 16, an AVR is an obvious choice.

The number of inputs and outputs is only one factor in the equation. The number of inputs and outputs can easily be increased by using I/O-expanders or multiplexing. Another, very important factor is the size of the integrated memory which needs to be large enough to hold your code. As long as you stay within a family of compatible controllers, it is usually straight forward to start with a small model and switch to the next bigger one should memory not be enough. You can often do this step within a simulator before actually buying the hardware.

If you want an easy start, use an off-the-shelf microcontroller board like e.g. the arduino (AVR based) or similar. These boards often come with a built-in boot loader so you simply connect them via USB or serial port to your computer and download the program using the programming environment (IDE).

Thank you, MR.Kapp
I ordered an Arduino UNO, module(am i right ? it called module?) and right now I am reading about it.
but one new problem i found is that the seller of SMD light doesn't know what type of SMD they are he just sell it, now how can I measure the voltage and amps the SMD needs to be turned on? are they same as LED's?can i drive them as I did on the leds?

Last edited:

May 12, 2016
38

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
12,518
now how can I measure the voltage and amps the SMD needs to be turned on?
You can use a series resistor and a variable voltage source to drive the LEDs and see at which current the light is good and the temperature of the LEDs is not too hot. But that can be only an approximation and can not replace a datasheet. No two LEDs are the same, so you cannot simply use another LED's datasheet.

For Iload use the real current (30 mA9, not the max. current in the datasheet.
For hfe use 100 for a bit of safety margin.
For Vbesat use 800mV. This value is in between the two datasheet values for IC=10 mA and Ic=100 mA

Ibase= Iload/hfe = 30 mA / 100 = 300 µA
R = (5 V - 0.8 V) /Ibase = 4.2 V / 300 µA = 14 kΩ
The value for Rbase is not critical. Using 12 kΩ or easily available 10 kΩ will work fine and keep the transistor in saturation (fully on).

#### Jouellet

Feb 2, 2015
86
Why don't you consider the Arduino Nano ? They come with their own USB/Serial converter.

You can get some "chinese" version, for 3US$on Ebay ! Also, do some research on the "MSGEQ7" ; you might want to use that as well ! #### kourosh daryaee May 12, 2016 38 Why don't you consider the Arduino Nano ? They come with their own USB/Serial converter. You can get some "chinese" version, for 3US$ on Ebay !

Also, do some research on the "MSGEQ7" ; you might want to use that as well !

but it's a little late now since I wanted something to be little smaller nano would be a better choice.
but having both of them make it a heaven I can programme on UNO and when I want to assemble using nano.
and MSGEQ7 sound like a heaven for me !!!! but all I know about multiplexing is some symbols if you can
show me a link about how to do them on out of the paper I will be thankful.

Moderator
Nov 17, 2011
12,518

#### kourosh daryaee

May 12, 2016
38
I want to use Arduino Nano as a decoder for MSGEQ7 and controller of light
does the whole idea make sense?

Last edited:

#### kourosh daryaee

May 12, 2016
38
what kind of potentiometer i should use? the input is 5v and DC Current per I/O Pin is 20 mA ,I want to use it as the controller for light's
I searched the web but every project I found they just said use a potentiometer not what value it must have?
does a 50 kohm will work as an input for Arduino Uno?

#### Jouellet

Feb 2, 2015
86

You will get everything you need ! That how I got started with that chip !

You will even find sample sketches for the Arduino.

Keep in mind that people will help you up to the point where it seems like you are not making you own research !!!

#### kourosh daryaee

May 12, 2016
38
I have a problem with driving Smd led ,I found that they are 3 volt ,1-watt LEDs, which i think it means their currents consume is 350 ma.
now according to
Ibase= Iload/hfe = 30 mA / 100 = 300 µA
R = (5 V - 0.8 V) /Ibase = 4.2 V / 300 µA = 14 kΩ
The value for Rbase is not critical. Using 12 kΩ or easily available 10 kΩ will work fine and keep the transistor in saturation (fully on).
so I used 2n2222 transistor so for 350ma current
hfe =40
Vbe = 2
Ibase = Iload/hfe= 350 / 40 =8750 μa
since i need 350 ma ,I set Vbe as 2 according to datasheet
so R=(5-2)/Ibase = 3 /8750μa =342Ohm

but according to
R = ((V - VBE) × hFE) / (Iload × n)
so
R = ((5-2)*40)/(350ma*3) =114 Ω
I used 1kΩ and 10kΩ and 80Ω and 380Ω as R for the circuit but on all of them led keeps on, with Ibase signal Low or High.
First why there is 2 equation with different results for the same circuit?
i checked the circuit multiple times so i can be sure there's no fault in wire's ,etc
Can you tell me where is my fault?

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
12,518
R = ((V - VBE) × hFE) / (Iload × n)
Do you understand the meaning of "n" an d why you use n=3?

It's not all to clearly stated in the reference you use but n=2...10 is an arbitrary value to ensure the transistor is really completely turned on (saturated). 3*114 Ω = 243 Ω, this is where the difference between your two calculations comes from. By using hfe=40 you use the minimum specified hfe for the 2N2222. The real hfe will be higher, which already gives you a safety margin. The max. specified hfe is 300, so the real value will be somewhere in between.
Assume hfe=100 and you get Rbase = 855 Ω. That's why you see the LED on with Rbase=1 kΩ or 380 Ω in your tests.
Also Vbe=2 V is the max. value (worst case). The real value is likely to be much less, around 0.6 V ... 0.8 V. You can simply measure this value with a multimeter. Less Vbe means the voltage drop across Rbase is higher, therefore Ibase is higher and the transistor is easier saturated.
Rbase = 80 Ω completely drives the transistor into saturation, meaning there will not be more collector current due to increased base current (lower Rbase) as the transistor is already fully on.
With RBase = 10 kΩ the LED will still be on. I'd expect a slight difference in intensity when you compare directly one LED where Rbase = 10 kΩ with another where Rbase = 1 kΩ.

Using worst case parameters (e.g. hfe=40, Vbe=2 V) of a datasheet is good design practise to produce a circuit that works under "all" circumstances. However, as you noticed, it involves design decisions that lead to possibly unreasonable results (e.g. component values, power dissipation). You'll have to take a close look at the parameters and the conditions under which these are valid (or defined).
If you look at e.g. this datasheet from OnSemi, you will find a graph of hfe vs. Ic which shows that hfe declines rather sharply for Ic > 100 mA, but for IC = 350 mA, hf >=70 is much more than the worst case hfe=40 for Ic=500mA.
Reading and understanding a datasheet is an art by itself

#### kourosh daryaee

May 12, 2016
38
Hi, I have got a weird problem and that is when I plug the arduino to power my speaker starts a noise.
since both of them are connected to the car battery i think they make a circuit . but how the arduino can
affect the sound that comes out of the speaker? that is my question.and if you have any idea how can i solve this problem I will be thankful.
last time i used a Ground Loop Isolator but that was for to isolate sound input , this time, the noise comes from power plug will the ground loop isolator work?

Replies
26
Views
885
Replies
3
Views
784
Replies
1
Views
254
Replies
22
Views
1K