Show Posts
Pages: [1] 2 3 ... 79
1  Using Arduino / Project Guidance / Re: Blinking an LED but need delay too on: Today at 02:22:20 pm
Quote
I need to blink an LED while there is a delay going on.
The delay needs to be there for a timing aspect of the sketch.
I know there is blink whithout delay but, I am using a delay.
delay() tells the processor to sit in a loop doing nothing until the delay-time is up.    In most real-world programs you want to avoid that.

Quote
I can get the sketch to work how i want by turning the LED on, waiting a second, then turning it off.
This works, I just wondered if there was a neater way that I could do the same thing.
Whenever you find your program doing the same thing over-and-over, it's time for a loop.  Besides the loop() function, the  for-loop is probably the most common.  There are also while() loops and do-while loops.

You can change variables inside the loop - The simplest example is incrementing a variable to count how many times you go through the loop, or you can "sequence" LEDs by switching-on a different LED each time through the loop, etc.    In your case, you can "toggle" the state of the LED each time through the loop if the time is up), so that if it's on it turns-off, and if it's off it turns-on.  And, you can "break out" of the loop depending on the conditions you set-up.

Loops, conditional branching (if-statements, etc.), and math are the 3 basic concepts that make programming worthwhile!


2  Using Arduino / Project Guidance / Re: Slotted Optical Switch on: April 22, 2014, 07:41:33 pm
Quote
A) Measure the difference in Voltage between 2 different coins that are slotted through it (both have different diameters)
B) Have my Arduino recognise which coin has been inserted/slotted...
The optical switch is an on-off switch, so it's not going to help you with that. smiley-sad     The infrared light from the built-in LED is either blocked or not-blocked, and obviously zero  light is passing-through either coin. smiley-wink    

Sometimes your coin mechanism has separate paths for different coins (and in that case you might need two or more optical switches).

Quote
... and count the number of times that type of coin has been inserted.
I think I'd start with simple pushbutton and the Button Example.  Then you can wire-up the optical switch and try it out.  

Then, look at some of the other examples and the Language Reference to figure-out how to make it count.

If you are new to programming here's a hint:  The command X++; will increment the variable X by one.   Or you can use X= X+1; which doesn't make any sense in algebra, but in C++ it means "Make X equal to the old value of X plus 1".

You'll also have to figure-out what you are going to do with the count once it's in the Arduino's memory. smiley-wink  During development and debugging, you can use the Serial Monitor to send the "count" (or any other variables/information) to your computer screen.

You'll have to "debounce" the switch (both the mechanical & optical switches).     That can be done in hardware or software, but it should be easier to do in software.  Basically, that involves "slowing-down" the count so if there is electrical "noise" as the switch turns on-and-off, you don't count the coin more than once in a few microseconds or milliseconds.

Your datasheet for the optical switch doesn't show any example circuits...  It's basically an opto-isolator with a slot in it to block the light from the LED.   I found something here for a regular opto-isolator (figure 16), but it's not very complete.    Maybe, you can find some opto-isolator application examples.   You need a current-limiting resistor in series with power to the LED (not shown on the 4n25 datasheet), and you need a pull-up resistor on the output transistor.      Assuming the thing is running off the Arduino's 5V power supply, a 150 Ohm resistor in series with the LED will give you a little more than 20mA.  The the pull-up resistor value is not critical at all (because of the Arduino's very-high input impedance) and the easiest thing to do is to configure the Arduino's Internal Pull-Up Resistor.
3  Using Arduino / Project Guidance / Re: Help! Controling light and sound with heart beat on: April 22, 2014, 04:10:13 pm
Quote
Also, most professors put strict limitations on what you're allowed to use if the objective is to demonstrate the ability to use uCs to implement some project because it would be defeating the purpose of the assignment (unless the laptop was "in addition to" the uC)
I don 't think that's the objective...  He/she is a media arts student.    The electronics and "low level" computer programming would be for the engineering student's project/thesis. (If such collaboration is allowed.).   

To minimize the electronics & engineering...  You don't need to be an engineer (or electronics or programming expert) to hook-up a computer and DMX lighting controller and "program" a light show.   DJs and people who work in  theater lighting don't usually build their own electronics.   Sometimes you might need something special in a theatrical situation, but you've also got a deadline so there isn't much time for design, building, troubleshooting & debugging...  In that case, if you don't already know how to do it, you find an expert.    There certainly isn't time to learn electronics.

If you can find a heart monitor that plugs into a computer, you wouldn't need to build any electronics.     You'd just have to "program" the lighting effects application. 

It would also require a little computer programming to "connect" the heart monitor application to the DMX application, and this could be tricky because the applications are not designed to talk to each other.  (That's something you'll probably need some help with.)  The sound could also require some programming, or maybe some MIDI "programming". depending on how fancy you want to get with the sound.    MIDI programming is something a music student could help you with if you don't know anything about it already.

P.S.
Another issue with collaboration is that the first part of the project is 90% engineering and 10% art.   The 2nd part of the project is 10% engineering and 90% art...   It might take an extra semester to complete the whole thing.
4  Using Arduino / Project Guidance / Re: Help! Controling light and sound with heart beat on: April 22, 2014, 01:01:25 pm
I don't know anything about sensing a heartbeat, but I assume that's no problem.

Quote
I know its really abstract, I'm new in electronics.
I'm an electronics guy, and to me this sounds like an electronics project  (and a programming project, which is part of many electronics projects and part of every Arduino/microcontroller project).   So, here's my suggestion:   Partner-up with an engineering student.    He/she can do the electronics & programming, and you can to the artistic part!   I assume that's allowed for a BA thesis, and I assume you can both get credit..  I think it's pretty common for PhD candidates to get help from various specialists as needed.   And if you each want to own one of these things,  building two of something is only slightly more work than building one (although it's twice the parts & material cost).

An engineering  partner could really help with all the stuff you are asking about here!

Quote
...without using a laptop in the circuit.
Why not?   A computer could add a LOT.   The Arduino is great at "sound controlled lights" (I've done 3 such projects), but it's not that great at generating/controlling sound.   You can generate simple sounds, but it requires an external digital-to-analog converter for high-quality sounds, and it doesn't have much memory for sound files.     With a computer, you could use MIDI to generate synthesized synchronized to the heartbeat...  It could be "synthesizer sounding" techno-like music or realistic-sounding orchestral or jazz music, etc.

Quote
Then for lightning, I think, dmx would be the best option, because I don't want to use a 220v dimmer
In my projects I haven't used DMX, because it's an extra transmitter & receiver and extra programming for the DMX protocol.   It's going to be more expensive than building something directly-connected* from scratch.    The advantage of DMX is that you can buy DMX-controlled lights, or DMX controlled dimmers.   And, you can even buy a DMX controller that plugs-into a computer.   That greatly reduces the amount of electronics you have to build.

Quote
...and led's are too insufficient or too expensive.
Actually, LEDs are worth considering.   One of my projects was a "giant VU meter" made out of regular 'ol "high brightness" LEDs.   It's plenty bright enough for in indoor lighting effect.   For light output, you can get "high power" LEDs (1 Watt or more).   These are the kinds of LEDs used in home lighting and DJ lighting effects.   High power LEDs require a special power supply, but you can buy it, and in some ways they are easier to dim/control than incandescent lamps and the 120-V/220V power is isolated from the low-voltage control, so that's wone less thing to deal with (engineering considerations).   With RGB LEDs, you can have color-changing LEDs that generate "any color of the rainbow",   and of course LEDs can flash on & off faster than incandescents (artistic considerations).

Quote
Maybe there is a way to control a party strobe light with arduino?
Yes. That can be done.  For example, strobes used in photography are synchronized to the shutter.   Or, I'm sure you can find one that's DMX controlled, or you you could build/hack something.    Electrically, traditional xenon strobes require fairly high voltage (maybe 400V minimum), so if you build one from scratch, that's extra circuitry to boost the supply voltage (and extra danger) but there are also LED strobes.  (That one runs off 120V/220V power, but I'm sure the LEDs are lower voltage internally.)    



* You can't "directly" connect the Arduino (or a computer) to 120 or 220VAC.   You need an opto-isolator, or a solid-state relay (which is optically isolated).    
5  Using Arduino / Audio / Re: Using modulation to send low freq signals through AC-coupled audio line inputs ? on: April 21, 2014, 06:43:27 pm
Hmmm...  Remember dial-up Internet and telephone modems?  Those converted digital to audio, and back.

In reality, it's probably easier to use USB or Ethernet, or maybe RS-232.
6  Using Arduino / General Electronics / Re: Noise filter for Uno power supply? on: April 21, 2014, 06:34:14 pm
The first thing I'd try is a capacitor across the battery.     Maybe 1000uF for starters.   If a 1000uF capacitor works but it 's physically too big, you can experiment with smaller capacitors. 

Or, a capacitor across the Arduino's power supply connectors, plus a diode in-between the battery and Arduino (with the motors connected directly to the battery).   The diode prevents the capacitor from discharging into the motors*, but a regular silicon diode will have about a 0.6V drop across it.    If the voltage drop is problem, a Schottky diode will have about 0.2V across it.

(You can't generally use an RC filter in a power supply because there is too much voltage drop across the resistor.)



* The diode makes the capacitor more effective in filtering-out negative voltage spikes when the motor suddenly draws more current.  But with positive spikes, it's no more effective than the capacitor alone.  However, the Arduino's on-board regulator should be very effective in killing positive spikes.
7  Using Arduino / General Electronics / Re: what resister values to use with a transister NOT gate? on: April 17, 2014, 04:05:12 pm
First, you shouldn't need a logic inverter on the Arduino output (or input).   You can invert the state in software... smiley-wink

And, when you need an inverter, it's more common to use an inverter chip (or other gate wired as an inverter) than to use a transistor.   The 7404 (and 74LS04, etc.) is the "original" inverter chip.



OK....
250 Ohms is OK for the base resistor (1k would probably work too).  The resistors depends on how much current you need out of the circuit.  

Quote
...one website said most gates can only handle 20mA of current,
That's probably a good rule-of-thumb for a logic chip.   The Arduino is rated for 40mA maximum.    If you look at the transistor's datasheet, I'm sure it can handle more.  (And, you should check the datasheet before you use a logic chip.)

The way a transistor works as a "switch" is that it has current gain, and you want to "saturate" the transistor so the calculated collector-emitter current is more than the current allowed by the collector-resistor.     A typical transistor has a gain (hfe) of around 100.    

 - Let's say we have a 50 Ohm "load" (or a 50 Ohm collector resistor).   At 5V, that's 100mA.

 - If the transistor has a current gain of 100, you need 1mA into the transistor's base.   That's 5k Ohms.

 - Since we want to be darn-sure to saturate the transistor, it's a good idea to cut the base resistance in half.

 - With a 2.5k base resistor, the we can be sure the transistor will remain saturated with loads of 50 Ohms or more (collector current of 100mA or less).
8  Using Arduino / General Electronics / Re: Help identifying ground lead and signal of switch. on: April 17, 2014, 03:45:40 pm
This is a single-pole, double-throw switch (SPDT).  We don't know anything about how you want to use it...

It's not unusual to use only two of the terminals with a microswitch  (common and normally open or common and normally closed).  With two terminals it works like an ordinary on-off switch.

If... the 3 connections are power, ground and "signal", signal would go to common ("C").   The power probably goes to normally open ("NO") and ground probably goes to normally closed ("NC").    If it seems to work "backwards", reverse the power & ground.   

If power AND ground go the the same switch, NEVER connect power OR ground to common.
9  Using Arduino / Audio / Re: Small Class D amplifier on: April 17, 2014, 01:19:46 pm
Quote
i am hoping I can put several in parallel to dropthe eff resistance to whatever the minimum the amp can handle
A Bad, bad, bad, idea! smiley-sad   The general rule is NEVER connect outputs together. (That's why you use an audio mixer to mix audio signals.)   Solid state amplifiers have very low internal source impedance (often less than one Ohm).   The output of one amp "shorts out" the output of the other.

The most common "trick" is to make a bridge amplifier.    That doubles your peak-to-peak output voltage (theoretically 26V P-P = 9V RMS) with a 13V power supply) and that gives you 4 times the power into the same load.  Doubling the voltage doubles the current, so an 8-Ohm speaker "looks like" a 4-Ohm speaker to each amplifier.   In theory you can get about 10W into 8 Ohms, but there is some voltage drop across the transistor/MOSFET and you can't actually get the full power supply voltage across the speaker.

High power automotive amplifiers have a voltage-boosting power supply.

10  Using Arduino / General Electronics / Re: Will this voltage doubler works with DC input? on: April 17, 2014, 12:28:42 pm
What's the voltage used for and how much current do you need? 

For a "signal" (very low current) you can double a voltage with a simple op-amp circuit, but you need to power the op-amp with slightly more than you are trying to get out of it.

There are fairly simple capacitor-oscillator based voltage doublers if you need a small amount of power and you don't need efficiency (they do require a chip or other active circuitry).   

If you need to "power" a circuit, you need an inductor-based voltage booster (again they require active circuitry).   These are very efficient, but of course  you can't get more power out than you put in...  So if you double the voltage, you cut the current (approximately) in half.   But normally if you are gong to power something, you start-out with enough voltage...  Boosting (or inverting) the power supply voltage is usually a "last resort", like if you need to run something off a car battery and it needs more than 12V, etc.

P.S.
Quote
Actually its a pretty small circuit so I'm using 2AA battery.  I need about 6v in my application
4 AA batteries. smiley-wink
11  Using Arduino / Project Guidance / Re: Driving a 150 ohm speaker on: April 16, 2014, 06:56:34 pm
First - You should NOT connect an 8-Ohm speaker directly to the Arduino!  If you are using an 8-Ohm speaker, you need a series resistor to limit the current.  (This will also reduce speaker volume.)

A 150 Ohm speaker will simply draw less current.   You don't have to change the software (sketch).

The Arduino is rated for 40mA maximum.   From Ohm's Law, 5V/8 Ohms = 0.625 Amps (625 milliamps).   You're not actually going to get 625mA... But Ohm's Law is ALWAYS true...  The voltage is going to drop, and the Arduino is going to overheat and possible get fried.   

Quote
...and the only commercially available speakers (digikey) have 150 ohm resistance.
As my old boss used to say, "Stranger than truth!" smiley-grin   Most speakers are 8 Ohms.  Most car stereo speakers are 4 Ohms.
12  Using Arduino / General Electronics / Re: Amplifying Audio signal for use with TIP31 power transistor and LED array on: April 16, 2014, 03:21:21 pm
You can turn on & off* LEDs with a transistor, but making a linear amplifier requires a few resistors & capacitors, and some careful design.   Depending on how much gain and you need, you may need multiple stages (with at least one transistor in each stage).   Here is an example. 

Sure, in the "old days" amplifiers were designed with discrete transistors but it's a LOT easier to use op-amps.   With an op-amp circuit you just need two resistors to set the gain.  (But most op-amps only about enough current capability to drive one LED.)


* With PWM (built-into the Arduino) you are turning the voltage on & off rapidly and that allows you to dim an LED (or appear dim, or off, to the human eye).    With PWM, you can use a single transistor or MOSFET in a simple circuit to "boost" the voltage/current and dim/control multiple LEDs.
13  Using Arduino / General Electronics / Re: Is it necessary to have both a digital and analog oscilloscope? on: April 15, 2014, 06:45:00 pm
I don' think you can even buy a new analog 'scope from a "serious" test & measurement company like Tektronix or Agilent.    Where I work, our last analog Tektronix 'scope died several years ago and I've never missed it.
14  Using Arduino / General Electronics / Re: Limiting current to motor? on: April 15, 2014, 06:36:16 pm
Quote
Oh, and I'm going to be controlling this motor with PWM.
PWM will do the trick!  ...Wth a transistor or MOSFET to "boost" the voltage & current...  You can't run a motor directly from the Arduino output.

A resistor will work, but it will have to dissipate power (heat) so you have to have the a big enough resistor and it's inefficient.  And, you'll probably have to try a few different resistor values to determine what value you need.

Quote
Ie, how would it affect the speed and torque?
Torque, speed, and load are related.  Often in an "unpredictable" way...  For example, if you limit the current to a fan-motor it will slow-down.   But if you remove the fan, there is less load and the motor will run faster.    If you want to precisely control the speed of a DC motor, you need some sort of RPM sensor.
15  Using Arduino / General Electronics / Re: Uno's analog pins and short circuits on: April 14, 2014, 02:51:41 pm
It's generally OK to "short" input pins because they are simply "reading" or "sensing" a voltage.   As long as you don't connect an input pin to a negative voltage, or a voltage greater than 5V, you are safe.    You can safely connect two inputs together, although you shouldn't have a need for that very often.

However, you should never short outputs.  For example if you connect (short) an output pin to ground, you'll get excessive current and possible damage when software tries to make the output pin go high.   Or, vice-versa if you connect an output pin to +5V (or any fixed voltage).   Or if you connect two outputs together,  one output may be trying to go high while the other is trying to go low, they will "fight" and again excessive current and potential damage.

The above is true for both analog and digital inputs/outputs.      The question comes-up in audio once in awhile.... It's OK to connect the inputs of two amplifiers together to run two amplifiers from one CD player, but it's NOT OK to connect the outputs of two CD players together to run two CD players into one amplifier  (for that you need an audio mixer).
Pages: [1] 2 3 ... 79