Monster Moto H-bridge Motor Driver affects the Serial communication


hi! i'm facing problem our project.
we developing motion simulator platform , game controlled real bike.

here code.(a speedometer code got web uses reed switch )

code: [select]

//---variables reed---//
#define reed a0            //pin connected read switch
#define led 14

//storage variables
float radius = 13.5;       // tire radius (in inches)- change own bike
//int reed = 44;
int reedval;
long timer = 0;            // time between 1 full rotation (in ms)
int mph = 0;
int kph = 0;
int rpm = 0;               //variable rpm
float circumference;
int maxreedcounter = 100;  //min time (in ms) of 1 rotation (for debouncing)
int reedcounter;


void setup(){
 
  reedcounter = maxreedcounter;
  circumference = 2*3.14*radius;
  pinmode(reed, input);
 
  serial.write(12);//clear
 
  // timer setup- timer interrupt allows preceise timed measurements of reed switch
 
  cli();                    //stop interrupts

  //set timer1 interrupt @ 1khz
  tccr1a = 0;               // set entire tccr1a register 0
  tccr1b = 0;               // same tccr1b
  tcnt1  = 0;
 
  // set timer count 1khz increments
  ocr1a = 1999;             // = (1/1000) / ((1/(16*10^6))*8) - 1
 
  // turn on ctc mode
  tccr1b |= (1 << wgm12);
 
  // set cs11 bit 8 prescaler
  tccr1b |= (1 << cs11);   
 
  // enable timer compare interrupt
  timsk1 |= (1 << ocie1a);
 
  sei();//allow interrupts
  //end timer setup
 
  serial.begin(9600);

}

isr(timer1_compa_vect)

  //get val of a0
  reedval = digitalread(reed);
 
  //if reed switch closed
  if (reedval)
  {
    //min time between pulses has passed
    if (reedcounter == 0)
    {
      //mph = (56.8*float(circumference))/float(timer);  //calculate miles per hour
      kph = (36*float(circumference))/float(timer);  //calculate kilometer per hour
      rpm = float(6000)/float(timer);                  //calculate rotations per minute
      timer = 0;                                       //reset timer
      reedcounter = maxreedcounter;                    //reset reedcounter
      digitalwrite(led, high);
    }
   
    else
    {
      digitalwrite(led, low);
      //don't let reedcounter go negative
      if (reedcounter > 0)     
      {
        reedcounter -= 1;                              //decrement reedcounter
      }
    }
  }
  else  //if reed switch open
  {
    if (reedcounter > 0)           //don't let reedcounter go negative
    {
      reedcounter -= 1;            //decrement reedcounter
    }
  }
 
  if (timer > 2000)
  {
    kph = 0;                       //if no new pulses reed switch- tire still, set mph 0
    rpm = 0;
  }
  else{
    timer += 1;                    //increment timer
  }
}

void loop()
{
    serial.print(kph);
    serial.print(",");
    serial.print(rpm);
    serial.println();
}




the problem is, every time connect arduino's +5v & gnd pin monster moto, values in serial monitor changing.

please help. thanks

quote
the problem is, every time connect arduino's +5v & gnd pin monster moto,
what!!

is bike 5v system? if surely not regulated 5v it?

what voltage of bike?


Arduino Forum > Using Arduino > Project Guidance > Monster Moto H-bridge Motor Driver affects the Serial communication


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code