Monster Moto H-bridge Motor Driver affects the Serial communication

Hi! I’m facing some problem about our project.
We are developing a motion simulator platform and a game controlled with a real bike.

Here is the code.(a speedometer code that i got from the web that uses a reed switch )

//---variables for reed---//
#define reed A0            //pin connected to read switch
#define led 14

//storage variables
float radius = 13.5;       // tire radius (in inches)- CHANGE THIS FOR YOUR OWN BIKE
//int reed = 44;
int reedVal;
long timer = 0;            // time between one 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 one rotation (for debouncing)
int reedCounter;


void setup(){
  
  reedCounter = maxReedCounter;
  circumference = 2*3.14*radius;
  pinMode(reed, INPUT);
  
  Serial.write(12);//clear
  
  // TIMER SETUP- the timer interrupt allows preceise timed measurements of the reed switch
  
  cli();                    //stop interrupts

  //set timer1 interrupt at 1kHz
  TCCR1A = 0;               // set entire TCCR1A register to 0
  TCCR1B = 0;               // same for TCCR1B
  TCNT1  = 0;
  
  // set timer count for 1khz increments
  OCR1A = 1999;             // = (1/1000) / ((1/(16*10^6))*8) - 1
  
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  
  // Set CS11 bit for 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 is 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 is open
  {
    if (reedCounter > 0)           //don't let reedCounter go negative
    {
      reedCounter -= 1;            //decrement reedCounter
    }
  }
  
  if (timer > 2000)
  {
    kph = 0;                       //if no new pulses from reed switch- tire is still, set mph to 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 I connect the arduino’s +5V & GND pin to monster moto, the values in the serial monitor are changing.

Please Help. Thanks

The problem is, every time I connect the arduino's +5V & GND pin to monster moto,

What!!

Is the bike a 5V system? If so it is surely not a regulated 5V is it?

What is the voltage of your bike?

the reed switch attached to the bike is supplied from the +5V/GND of the arduino.
The value from serial monitor is okay but when I connect the monster moto's source to arduino, that is the point where there is something wrong. I get random numbers. I think, monster moto is affecting the output

Still not answered any of my questions.

If it is only a reed switch then why do you have to connect up the arduino's supply to the bike?

reed switch acts like a button, where it can be triggered by a magnet, and it need +5V and GND.
here is the link where I got that idea. Please check this.

Arduino Bike Speedometer

reed switch acts like a button, where it can be triggered by a magnet,

Yes

and it need +5V and GND.

No.
You only need to connect the reed switch between the input pin and ground on your arduino and then enable the Arduino's internal pull up resistors. This is perfectly isolated there is no need for any electrical connection to the bike.
Here is how to use inputs.

http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

here is the link where I got that idea. Please check this.

It is instructables and therefore by definition crap, I will comment no more.

Hi, please..

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

Tom..... :slight_smile:
The Monster moto thingy, is it this?

If not please post link to specs of the device.

Hi Mike, I understand, I’m not familiar with the built-in pull up resistor of Arduino. I’ll check this issue.

@Tom, Here is the schematic diagram of my reed switch. And yes, it is the monster moto shield that I’m saying.

reed_schem.JPG

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?
We need to see how the power supply and motor and arduino are connected, please.

Tom.... :slight_smile:

Hi, here is the diagram showing the connection of monster moto, arduino mega and the reed switch.

Is the motor shield wired up using jumpers? or have you fitted it on top of the Arduino?

I've not looked at the shields datasheet but I suspect A0 is used by the shield. It gives the ammount of current drawn by the motor.

Mark

Hi, the resolution is not the best, can't read the pin numbers, also Frizzing is not the best way to do a circuit. It allows you to assume connections are made.
Hand drawing it will make sure you know the connections are made.
Drawing circuit diagrams can be very therapeutic and can help you solve wiring problems quite quickly.
Especially drawing the first draft by hand, pencil and paper.

Have you got the GND of the boards connected together ,I can't see it in your diagram.

Tom........ :slight_smile:

holmes4:
I suspect A0 is used by the shield. It gives the ammount of current drawn by the motor.

Yes, it is a pin conflict. A0 is one of the enable line outputs. So once you initialize the library, you're no longer reading the reed switch state, you're reading the current enable line state. Worse, when the reed switch closes, you're shorting the line to 5V, which means a huge slug of current into the pin if the output is currently low.

Look at the schematic: MonsterMoto-Shield-v12.pdf

The connections to the Arduino are in the lower left. It uses pins A0 through A3, and D4 through D9. You want to leave D0 and D1 open for the serial port and D13 for the on-board LED. So use D2, D10, D11, D12, or A4 or higher for the reed switch. Since it's a Mega, you have digital pins higher than D13 as well, you can also use any of those.

Hi! The problem is already solved. Thanks for helping me :slight_smile:

Please share the solution. It will help the next person who is trying to do this.

Hello, I encountered same problem again, I thought it was okay. But when I tried and test it again, the problem came back. Please help.

ShapeShifter:
Please share the solution. It will help the next person who is trying to do this.

So you didn't you selfish **** so how do you expect help now?
We don't know what you did to fix it so we don't know what you did wrong.

Sorry. I forgot to tell what I've done before.

What I've done is check the wirings and connection. Also I changed the analog pin of reed switch(A0) to A4. Based on what Shapeshifter say.

But now, the problem is still happening. :frowning:

What I've done is check the wirings and connection. Also I changed the analog pin of reed switch(A0) to A4. Based on what Shapeshifter say.

So you have not actually done anything to fix it, you just fiddled around with it and it happened to appear to function.
How about all that advice you were given?
Specifically:-

Worse, when the reed switch closes, you're shorting the line to 5V, which means a huge slug of current into the pin if the output is currently low.