Using Arduino with Matlab and Simulink to build a controller?

Hi

I would like to build a controller for a system. My measures are volts (ie a signal raging from 0-5 volts) and my output is also a voltage (measuring from 0 to 5).

Is it possible to use Arduino to have my measures as an input, connct to Simulink, generate the required output, and use Arduino to send it back to voltage form which will be connected to my system?

Thanks,
Eedo

I have no experiance with Matiab or Simulink, however assuming that they can communicate via USB serial then it should be possible. The tricky part is that an Arduino does not have a true analog output function. The analogWrite() command generates a PWM TTL voltage level square wave signal the varies it's duty cycle from 0-100%. You have to wire the pwm output pin to a low pass filter (a simple series resistor followed with a capacitor to ground. The junction of the resistor and cap will then show a true analog voltage of 0-5vdc. This could then be wired back to a analog input pin and it's value sent back out via USB serial link to your PC.

However this would seem redundant unless you were actually using the true analog output voltage to control something physical. Otherwise just send the PWM value signal used inside the program, with proper scaling and send it back to your PC ?

That make sense?

Lefty

Thanks for the reply.

I indeed intend to do something physical with this signal. My attempt is at creating a controller with simulink for a physical device.

I understand it outputs only PWM that I can turn to a pure analogue by an LPF, does it also accept only PWM? because creating that out of an analogue voltage would be more difficult...

I understand it outputs only PWM that I can turn to a pure analogue by an LPF, does it also accept only PWM? because creating that out of an analogue voltage would be more difficult...

The Arduino analog input pins accept true analog input voltages. They can measure 0 to +5vdc and the internal 10 bit A/D converts that to a integer value of 0-1024 range. Caution no negative voltages allowed and no voltages over +5vdc allowed without possible electrical damage to the chip.

Lefty

Is the analogue input a normal one or a differential one? My device outputs a simple voltage, I wouldn't like to convert it myself to a differential input.

eedo:
Is the analogue input a normal one or a differential one? My device outputs a simple voltage, I wouldn't like to convert it myself to a differential input.

No, the Arduino analog input pins are single ended, which means there must also be a common ground connection from the voltage source being measured to the Arduino board.

Lefty

I get it.

Thanks for all your help :slight_smile:

Analog input is unipolar so you can't feed it negative voltages. The actual ADC is possibly differential (but not implemented in Arduino), which means you can have two channels work in differential mode, but that doesn't mean either input can go below 0V or above AREF. That could damage it.

Some details of what you want to do is helpful, without mentioning names like matlab or simulink. Say, what problem you are attacking, what input are you getting, range, frequency, and how do you want to process it and what output do you want to do. You're assuming everyone know what you're all along, like opening a physics book to chapter 5 section 4 and point at formula 6 and say help. If you instead say you need help with understanding forces, and then lead us to some details, we could possibly follow and help.