Help please on a PWM project for a newbie?!

Hi guys

I'm a newbie to both Arduino and circuits in general but I have a project that's probably simple to you folk however after a fair amount of reserach I'm a bit stuck! I need to create a circuit (and subsequent Arduino programme) that can do the following:-

Send a 9v electrical pulse to 7 individual outputs in a particular sequence.

I need to be able to:

• Adjust the speed of the entire sequence in it’s totality.
• Adjust the duration/length of the pulse. (digital or analogy rotary switch with character display)
• Adjust the duration of the interval between each individual output. (digital or analogy rotary switch with character display)
• Loop indefinitely
• Switch on/off with button

Example Sequence might be:

9v pulse to output #1 on for 10ms then off.
15ms delay
9v pulse to output #2 on for 10ms then off.
15ms delay
9v pulse to output #3 on for 10ms then off.
15ms delay
9v pulse to output #4 on for 10ms then off.
15ms delay
9v pulse to output #5 on for 10ms then off.
15ms delay
9v pulse to output #6 on for 10ms then off.
15ms delay
9v pulse to output #7 on for 10ms then off.
15ms delay

Notes: Whilst I want to adjust the pulse duration/duty cycle and interval length between output pulses it would only need to be done globally i.e if I changed the pulse duration to 15ms then all pulses in the sequence will be the same value. The same principle applies for the duration of delay between pulses.

Do I need to use an N555 timer(s) or a IR2104 driver chip + IRFP150 MOSFET as a switch? Can the Arduino use the PMW to do this? Or perhaps a 74HC595?

Help please!

Let's start at the beginning. What exactly do you mean by "9v electrical pulse" and what will be using this pulse?

...R

Ok, well starting at the beginning sounds good!

So I need to send power i.e 9v to a load (such as a lamp for instance) for a amount of time. Imagine if you will, a set of lamps, that need to be programmed to turn on and off in a particular sequence and then loop indefinitely. They don't need to have their brightness controlled (dimmed up or down) - just a simple on and off. I need to be able to control the overall speed of the sequence and additionally have long the lamp is on for and how long they are off for.

Does that help?

Woz22:
They don't need to have their brightness controlled (dimmed up or down) - just a simple on and off.

Then there is no need for PWM - PWM is used for dimming the lights.

I presume you have a suitable 9v power supply (and a small PP3 style smoke alarm battery is not suitable).

An Arduino cannot control 9v or the amount of current needed by your light. You have not told us what current (amps) each light requires.

The simplest solution may be to use the Arduino to operate a relay for each light. Another approach would be to create a transitor circuit for each light so that the Arduino can signal the transistor to turn the current for the light on or off.

As far as programming the timing is concerned the demo Several Things at a Time illustrates the use of millis() to manage timing.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R

Using the Arduino is a good start for the project. You are missing a lot of information such as how much current the load requires, is it inductive, etc. Not knowing I will assume it is inductive such as a motor winding. The current has a big impact on the driver selection. There are lots of way of accomplishing this, there is no one right way of doing this. First lets rule out relays, most are not fast enough, you are operating in the 40 Hz range. The IR2104(S) are high voltage, high speed power. MOSFET and IGBT drivers with dependent high and low side referenced output channels. They are not intended to drive a load directly. consider the IRL540 The L shows that is a logic level mosfet, not all are marked this way. A logic level mosfet means that it is designed to turn on fully typically from the logic level of a microprocessor. If the load is inductive you do not need a clamp diode, the mosfet is Repetitive Avalanche Rated, the information is on the data sheet: https://www.vishay.com/docs/91300/sihl540.pdf. Unless you use an opto isolator be sure the grounds (- assuming single ended supplies) from the power supply(s) are connected together. Each of could be cycled in a simple loop assuming they sequently cycle. IE. Turn on 1, delay, turn off 1, delay, turn on 2, delay, turn off 2, delay ... etc. You can define the delays with two statements. int ondelay = 10, offdelay = 15. then the statement delay(ondelay); or delay(offdelay); should work. This should get you a good start.
Good Luck & Have Fun!
Gil

gilshultz:
Not knowing I will assume it is inductive such as a motor winding

Reply #2 clearly says it is a lamp.

...R

Forget about the load, that can be taken care off later.
Forget about PWM, you just need to turn digital pins on/off in sequence and with varying time intervals.

Need to learn how to manage time with millis(), so your loop doesn't stop, and you have the un-interrupted ability to change duration and interval with e.g. two pots.
Leo..

Edit: Project sounds like a "Knight Rider" scanner.

Thanks everyone for your comments - they are very much appreciated!

So just to clarify a little further (as I did mention lamps above), I basically want to send a 9v current through a series of individual coils for a very brief amount of time, in a particular sequence. It's a 'fully on' then off situation. I just need to be able to control the duration of the 'on' and the duration of the 'off'. I was just doing a little more research and would an N-Channel Enhancement type MOSFET do the switching controlled by the Arduino or would I need a driver chip also?

Sorry this id a bit vague - I did say I was a newbie!

First circuit on this page can be used to switch coils.

This (untested) sketch can be a base for your experiments.
Leo..

unsigned long currentMillis, previousMillis;
unsigned int duration = 10, interval = 15;
const byte ledPin[] {4, 5, 6, 7, 8, 9, 10};
const byte ledCount = 7;
boolean ledOn;
byte index;

void setup() {
}

void loop() {
  // duration = analogRead(A0); // optional pot for duration
  // interval = analogRead(A1); // optional pot for interval
  currentMillis = millis(); // update time with each loop
  if (ledOn = false && currentMillis >= interval) {
    digitalWrite(ledPin[index], HIGH);
    ledOn = true;
    previousMillis = currentMillis;
  }
  if (ledOn = true && currentMillis >= duration) {
    digitalWrite(ledPin[index], LOW);
    ledOn = false;
    previousMillis = currentMillis;
    index++; // next LED
    if (index >= ledCount) index = 0;
  }
}

Woz22:
So just to clarify a little further (as I did mention lamps above), I basically want to send a 9v current through a series of individual coils for a very brief amount of time,

I feel I am just wasting my time here. First you say lamps. Now you say coils.

Stop being secretive and just tell us exactly what you are trying to create and then it will be easier to give useful advice.

...R

Hi Robin - Sorry that you feel that you are wasting your time! I do really appreciate the help and it's all been really useful indeed.

It's not so much about being 'secretive' as much as just trying to figure out if the top-level principle is even possible/viable with a load that runs at a higher voltage (and current) than the Arduino board itself, however I do see how it might have appeared. I was (and still am) thinking about lamps but also I'm thinking about coils (home made motor windings) hopefully using the same principle of setup.

I am an visual artist and it's for a potential art installation (physical art sculpture) in an exhibition. The creative look is still somewhat in my head however if the Arduino can control programmed coils/motors, lights/lamps and maybe more that can be adjusted on a PC and loop indefinitely in a particular sequence then I can use that to help create something visually awesome, fingers crossed!

Thanks once again.

Woz22:
just trying to figure out if the top-level principle is even possible/viable with a load that runs at a higher voltage (and current) than the Arduino board itself,

Yes that is very possible. It is a very common use of Arduinos (and microprocessors in general). I guess it is so common that it had not occurred to me that you did not know.

However there needs to be some controller device between the Arduino and the load. The Arduino sends a control signal (5v and very low current) to the controller and the controller switches the high voltage and high current.

The choice of controller device depends on the type of load, the required voltage and current and the way in which the load is to be controlled - for example, simple ON/OFF or variable speed or brightness control.

…R

Motors, unlike lamps, are usually directional. You might have a motor to open and close your blinds at home. So a motor driver usually has quite fine control and is reversible.

A motor driver like the Adafruit Motor Shield is very flexible* and can drive lamps and coils too. Expensive for that purpose but it is quick to build, which might be valuable to you if you need to do something fast.

Art installations often need some kind of motor that can rotate to a specific angle. Think of the eyes in a statue following the visitors, or moving some other small object. That's best done with a "hobby" or "radio control" servo. (Industrial servos are quite a different thing.)

For things that need accurate positioning but move more than half a turn, like maybe a 3D printer, use stepper motors. They require specialized drivers, which are easily available for small 1-amp or 2-amp motors.

Lights are easier to drive than motors, particularly if you only need on and off. But if you have more than 3, look into specialized drivers for those. The very best are addressable LEDs which allow an unlimited number of RGB-programmable lights run of a single Arduino pin. 7-segment displays (like the time machine in Back to the Future) have specialist drivers too.

  • Don't believe their claims of running stepper motors with that shield.

Wawa:
Forget about the load, that can be taken care off later.
Forget about PWM, you just need to turn digital pins on/off in sequence and with varying time intervals.

Need to learn how to manage time with millis(), so your loop doesn't stop, and you have the un-interrupted ability to change duration and interval with e.g. two pots.
Leo..

Edit: Project sounds like a "Knight Rider" scanner.

Hi Leo

Yes that's essentially what I need! Thank you very much for the sketch too. Quick question, can the timing (once set) be controlled via a Potentiometer + LCD display? It would save me an awful lot of time if I could fine tune the time of the pulse and time of the interval without having to jump back on a PC again?!

Finetuning with two pots is already build into the sketch.
Just un-comment the two analogRead lines, and connect 10k lin pots to A0 and A1.

Adding an LCD is easy. You should do that yourself though.
Wise to play with the examples of the LCD before you think of adding that to the sketch.
Leo..

Wawa:
Finetuning with two pots is already build into the sketch.
Just un-comment the two analogRead lines, and connect 10k lin pots to A0 and A1.

Adding an LCD is easy. You should do that yourself though.
Wise to play with the examples of the LCD before you think of adding that to the sketch.
Leo..

Leo - thank you so very much!