Go Down

Topic: ARDUINO + MATLAB Real time graph *help asap please (Read 2037 times) previous topic - next topic


Mar 05, 2013, 06:39 am Last Edit: Mar 05, 2013, 06:49 am by Coding Badly Reason: 1
I am working on a controls project. mech engr dont know much about ece
i have an IR emitter and detector that detects how fast the radiometer is spinning using the arduino uno
the code is here

Code: [Select]
int ledPin = 13;
int statusPin = 12;

volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
volatile int stat;

void fan_interrupt() {
 time = (micros()-time_last);
 time_last = micros();
 if(stat == LOW) {
   stat = HIGH;
   else {
     stat = LOW;
 digitalWrite(statusPin, stat);

void setup() {
 attachInterrupt(0, fan_interrupt, FALLING);
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, HIGH);
 pinMode(statusPin, OUTPUT);

void loop() {
 int rpm = 0;
 while(1) {
   if(time>0) {
     rpm_array[0] = rpm_array[1];
     rpm_array[1] = rpm_array[2];
     rpm_array[2] = rpm_array[3];
     rpm_array[3] = rpm_array[4];
     rpm_array[4] = 60*(1000000/(time*4));
     rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4])/5;

i need help in creating the real time plot on matlab
the graph should show rpm vs time

Attempting connection .............
Basic I/O Script detected !
Arduino successfully connected !

i got the uno to connect to matlab
just need help on the code
can anyone help me please asap

Moderator edit: [code] [/code] tags added.

Coding Badly


just need help on the code

Did you get help writing that Arduino code on the MatLab forum?


1000000  ==> 1000000L  to explicitely make it long, for the rest it should work (you do some average rounds per minute ?)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131