Arduino UNO is enough for my project? PWM and Digital outputs

Hi to all,

I'm going to begin a project where I need to read from RC receiver, outputs PWM signals and control few digital outputs. In particular, I need:

2 x PWM outputs to control two solenoids (I use a Mosfet since the solenoids need high power)
8 x digital outputs since I need to switch on/off some devices
5 inputs to read from the RC Futaba receiver

My question is: do I need PWM inputs if I want to read from the RC Futaba receiver?

I've read that Arduino UNO can only provide 6 PWM outputs but this won't be enough if I will need them also the the RC receiver.

Moreover, I'm going to use Arduino standalone version with the ATMEGA328p on breadboard and so I can't switch to Arduino MEGA.

Is there a way to add more PWM to Arduino?
What are your suggestions?
Can I read from RC Futaba receiver without using the PWM inputs?

Thank you!

There isn’t actually such a thing as a PWM input. Only digital inputs or analogue inputs.
As I understand it, the RC receiver will actually output standard servo signals, with pulses varying between 1mS and 2mS in width, at 50Hz. You’ll need to use digital inputs, and measure the pulse widths.

You’ll find that info and more here:- Futaba - Receiver Technical Information

Edit: And by the way, even the analogue inputs, A0 to A5 on an UNO, can be used as digital inputs. They default to digital inputs on power-up. Just configure them as you would any other pin, using ‘pinMode(pin, INPUT)’ or ‘pinMode(pin, INPUT_PULLUP)’.

Thank you, OldSteve, for your support!

On the Arduino datasheet, it says there are 14 Digital Out/In pins and 6 of them provide PWM outputs.
Now, I need:

2 of them for the PWM output for the solenoids.
8 for the ON/OFF controlling
5 for the futaba receiver

In total I will need 15 pins, but Arduino only have 14 pins.

I was thinking to use 2 x Atmega328p in order to divide the operations and gain more pins.

About the RC pules, in this article, the author use pins 4, 5, 6 in order to receive the RC pules from the receiver. I noticed that pins 5 and 6 are labeled as PWMs. It is just a coincidence? I mean, can I do the same even if I use pins 4, 2, 8 which are not labeled as PWM?

Thank you for your assistance!

[quote author=marcus barnet date=1472118962 link=msg=2895516]
Thank you, OldSteve, for your support!
On the Arduino datasheet, it says there are 14 Digital Out/In pins[/quote]
You’re misunderstanding this, because the pins used for analogue input can also be used for digital I/O, as I said. All in all, there are a total of 19 potential digital I/O pins on an UNO, digital pins 0 to 13, then A0 to A5.

and 6 of them provide PWM outputs.

So assuming you really need PWM output for the solenoids, you only need two of these 6 PWM pins.

Now, I need:
2 of them for the PWM output for the solenoids.
8 for the ON/OFF controlling

No problem so far.

5 for the futaba receiver

Aren’t you taking the outputs from the RC receiver, and reading them? If so, you need inputs for this, not outputs, and they need to be digital inputs, (definitely not PWM outputs).

In total I will need 15 pins, but Arduino only have 14 pins.

No, 19 pins. See above.

I was thinking to use 2 x Atmega328p in order to divide the operations and gain more pins.

Not necessary. One UNO will do the job nicely.

About the RC pules, in this article, the author use pins 4, 5, 6 in order to receive the RC pules from the receiver. I noticed that pins 5 and 6 are labeled as PWMs. It is just a coincidence? I mean, can I do the same even if I use pins 4, 2, 8 which are not labeled as PWM?

Since you’re reading the signal from the RC receiver, not writing PWM, you don’t need to use PWM output pins for that. PWM pins, when used for that purpose, (PWM), are outputs, not inputs.

Am I making things clearer, or confusing you more?

Edit: For reading the signals from the Futaba RC receiver, you need to use digital inputs, (any of the UNO’s 19 pins), then you could either read them using ‘pulseIn()’, (which is blocking), or by more exotic methods, maybe using interrupts.

Hi,
Why do you need PWM on the solenoids?

Tom... :slight_smile:

TomGeorge:
Hi,
Why do you need PWM on the solenoids?
Tom... :slight_smile:

I was wondering that too, but just assumed they must have been 'proportional' solenoids.
I planned to ask once the other points are cleared up.

Thank you a lot, OldSteve! Now, everything is more clearer for me!
I will definitely go with just one Arduino UNO!

I need PWM outputs since I need to control proportional valves, sorry for this, I didn't specified it in my first topic!

If I post here my drawings for the ATMEGA328p, can you tell me if it is correct before to proceed with the PCB printing, please?
I'm going to design it in few minutes.

I think that you're putting the cart before the horse. First get everything running using a standard UNO, then when it's all perfect and doing exactly what you want, start thinking about a standalone chip and a custom PCB.
I always do it that way, and never start by designing the final PCB.
That's the beauty of the ready-made Arduino boards - they're perfect for prototyping.

Edit: Either myself or someone else will look over your schematic to see if any mistakes are obvious, but if I were you I'd then build a UNO-based prototype as I suggest, before going further.

I already used a UNO-based board to test the schematics for the proportional valves and it works very well.
I also have tested the ON/OFF switches.

The only thing I didn't tested is the RC receiver reading, but I think it should be Ok since I only have to report the connection on the PCB and then add the code in my software.

Anyway, you have reason, it is better to test also the RC parts, so I can be sure that everything works.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What is your electronics, programming, arduino, hardware experience?

As Oldsteve has said, leave the PCB till last, you need to breadboard your project to get everything working.

Check your proportional valves, they will have a spec relating to the PWM frequency, look up the Arduino UNO specs and check the PWM frequencies, if they don't match the valve, you will have to use a library which produces a custom PWM frequency.

Thanks.. Tom.. :slight_smile:

Yep. It's surprising how often little unexpected surprises will pop up if you don't test everything at the prototype stage, before moving on and committing yourself to a final design.

Edit: So as Tom says - show us that schematic diagram. :slight_smile:

Hi again, guys!

This is my schematics: Schematics.
And this is a picture of it: Picture.

I tried to improved it after having tested the whole circuit on Arduino UNO yesterday night.

Do you have any suggestions or do you see any errors?

If I run the ERC on Eagle, it gives me some warnings, but I'm not able to solve them.
I tried to use NET instead of WIRE, but nothing changed.

Can you help me, please?

Why two 1K resistors in parallel for the green power LED?

And that circuit can't possibly be working with the components shown. An IRF9540 is a P-channel MOSFET, yet you have them connected as if they were N-channel. That can't work.

Furthermore, when you do change to N-channel MOSFETs, they need to be "logic-level", not standard MOSFETs. Only "logic-level" MOSFETs can switch fully on with only 5V applied to the gate.
Also, you should place resistors between the '328P outputs and the MOSFET gates, to limit the current at switch-on.
N.B. "Logic-level" MOSFETs don't typically start with "IRF". "IRL" is more usual.

Can we see your code as well? I'll be interested to see how you're handling the RC signals.

Edit: Sorry, I can't help with Eagle. I use an old version of Protel Advanced PCB for my PCB layouts, and it's totally different.

Hi,
Put 470R resistors in series with your gate leads to limit gate current with PWM drive.(I know this circuit has 220R)
Output_Bypass1.jpg

Tom… :slight_smile:

TomGeorge:
Hi,
Put 470R resistors in series with your gate leads to limit gate current with PWM drive.(I know this circuit has 220R)
.....

Tom... :slight_smile:

220 ohms is fine. That's only a little over 20mA. Well within safe limits. (That's what I usually use.)
(Right now, it's more important for him to switch from P-channel to N-channel MOSFETs. :wink: )

Edit: Oh, and it's technically better if the 10K resistor connects the Arduino pin to ground, rather than the MOSFET gate. That way, it doesn't act as a voltage divider. (Not that it makes a lot of difference.)

I replaced the P-Mosfet with the N-Mosfet type: IRF540N.

Do you think it can be OK with this solution?

If yes, I will replace all the other FETs and i’ll post again the schematics.

N-Mosfet.png

Hi,
Okay but;

IRF540 is not a logic level MOSFET.

Tom... :slight_smile:

Thank you, Tom, for your support!

I replaced it with the FQP30N06L which surely is a logic level MOSFET :slight_smile:

If it is OK, I will change also all the other FETs.
The package is TO-220 so I won’t have problems with the mounting holes.

N-Mosfet-Logic.png

That’s more like it. Logic-level, and low Rds(on).

But you still need to add a series gate resistor.

Aren’t you going to show us your code as well?

I updated the schematics by replacing all the FETs and by fixing all the errors, now Eagle says there are no errors on the schematics.

I added a 220R resistor in series with the gate, is it correct? If yes, I will add it to each FET.
(It is better to use the right click to open the image to see it better)

About the code, I have to post it this night since I don’t have it on this PC.
Anyway, for the Futaba receiver, I used the code explained in this article:

/*
 RC PulseIn Joystick
 By: Nick Poole
 SparkFun Electronics
 Date: 5
 License: CC-BY SA 3.0 - Creative commons share-alike 3.0
 use this code however you'd like, just keep this license and
 attribute. Let me know if you make hugely, awesome, great changes.
 */

int ch1; // Here's where we'll keep our channel values
int ch2;
int ch3;

void setup() {

pinMode(5, INPUT); // Set our input pins as such
pinMode(6, INPUT);
pinMode(7, INPUT);

Serial.begin(9600); // Pour a bowl of Serial

}

void loop() {
  
  ch1 = pulseIn(5, HIGH, 25000); // Read the pulse width of 
  ch2 = pulseIn(6, HIGH, 25000); // each channel
  ch3 = pulseIn(7, HIGH, 25000);
  
  if(ch1>1000){Serial.println("Left Switch: Engaged");} 
  if(ch1<1000){Serial.println("Left Switch: Disengaged");}
  /* I found that Ch1 was my left switch and that it 
  floats around 900 in the off position and jumps to 
  around 1100 in the on position */

Serial.print("Right Stick X:"); // Ch3 was x-axis 
Serial.println(map(ch3, 1000,2000,-500,500)); // center at 0

Serial.print("Right Stick Y:"); // Ch2 was y-axis
Serial.println(map(ch2, 1000,2000,-500,500)); // center at 0

Serial.println(); //make some room

delay(100);// I put this here just to make the terminal 
           // window happier
}