I Need Help with my Project, I'm a Newbie!

Here is a schematic of my project. I am trying to control the speed of a drive motor. I have 2 hall sensors Hall1 will read 1 pulse per shaft rotation, and Hall2 will read 4 pulses per shaft rotation. I have a grove push button I am using to start and stop the motor. I have 1 LED Green that will light up when the system is ready and running at the required RPM either 1800 or 3600 which will be different than the motor. I have another LED Red that I want to light up when the current I am reading from the Pololu 2994 motor driver CS terminal gets above a certain amperage, the direction of the motor does not matter as long as it operates at the required RPM of the shaft the motor is attached too which means the motor will operate at a higher speed than the shaft which will be lower because of 3 to 1 60 teeth on the shaft to 20 teeth on the motor. I have managed to do some of the code but I cannot figure out how to code the PWM with an easy and adjustable setting. for the target rpm which is either 1800 rpm or 3600 rpm for the shaft Any help would be highly appreciated.

Here is what I have for code, I was able to find a simple PWM code along with a button and sensor coding which I can understand and follow. I have to say this code stuff is FUN even though it drives me crazy, every little mistake causes problems but I can usually find them. The sensor code may or may not be working correctly to hard to tell the serial monitor changes too fast, any way to slow it down or have just 1 line that will show the fluctuations? The button code was working fine until I added the code for the driver now it doesn't want to shut off and I don't know why. The other problem I have and the reason I want the Arduino to adjust the RPM is the voltage to the motor will take a jump from 12-13 volts to 14-15 volts. I wouldn't be doing this but If I cannot get the code and Arduino to do what I want and need I do not want to buy the Lathe and Mill I have on order, I have time to cancel it they are back ordered right now. I also want to let everyone know I do plan on using the 16x2 LCD screen that came with the starter kit but do I have enough pins left over I just want to show volts amps and RPMs. if possible any help with that would also be highly appreciated. Thank You in advance!! Steve

#define LED_OVR 11                // Over current LED
#define DIR 10                    // direction input from Pololu 2994 motor driver
#define PMCU_ON 13               // Output to on input for PMCU arduino board
#define CRNT A0                  // CS Analog input from pololu 2994 motor driver
const int PSH_ON = 8;            //Push Button input 1st push start 2nd stop
const int LED_ON = 12;            // Led output showing everything is operating ok
int ledflag=0;                   // LED status
int PWM = 9;  
int HALL1 = 2; // assigning halleffect sensor 1 to pin 2
int HALL2 = 3; // assigning halleffect snesor 2 to pin 3
byte backlight = 0, rs = 1, rw = 2, enable = 3,
d4 = 4, d5 = 5, d6 = 6, d7 = 7;
// using the byte fucntion, the microprocessor is acknowledging the pin connections from the arduino board to the lcd connections
// note: only 10 out of 16 pins on board are used for display
//see diagram of lcd for pin locations
LiquidCrystal lcd(rs, rw, enable, d4, d5, d6, d7);
volatile byte half_revolutions; // measurement of how many revolutions are counted
unsigned int rpm; //this will be the units
unsigned long timeold; // lenght of time


// you can change which pins your halleffect sensor is connected to just reassign the pin numbers

void setup() {
Serial.begin(115200);
pinMode(HALL1, INPUT);
pinMode(HALL2, INPUT);
pinMode(LED_ON, OUTPUT);
pinMode(LED_OVR, OUTPUT);
pinMode(PWM, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(PSH_ON, INPUT);
pinMode(PMCU_ON, OUTPUT);
pinMode(CRNT, INPUT);
//pinMode(6, OUTPUT);
//pinMode(backlight, OUTPUT);
//digitalWrite(backlight, HIGH);
//lcd.begin (20,4); // telling processor how many rows and columns the LCD has
//lcd.setCursor (0,0); //telling the processor where to begin
//lcd.print (“Carrier RPM”);
//lcd.setCursor (0,1);
//lcd.print(DEC);
//lcd.setCursor(0,2);
//lcd.print (“Output RPM”);
//lcd.setCursor (0,3);
//lcd.print(DEC);


attachInterrupt(0, HALL1, RISING); // connects interrupt to pin 2
// interrup allows you to “multitask” – will switch off one function to show another funtion
// this processor cannot run more than one function at once
attachInterrupt(3, HALL2, RISING); // attaches intterupt to pin 3
half_revolutions=0; // These are all your starting points
rpm=30;
timeold=0;
}

void loop() {
if (digitalRead(PSH_ON)==HIGH){ // if button is pressed
    if (ledflag==0) {             // and the status flag is LOW
      ledflag=1;                  // make status flag HIGH
      digitalWrite(LED_ON, HIGH);
      digitalWrite(PWM, HIGH);     // and turn on the LED
      }                           // 
    else {                        // otherwise...
      ledflag=0;                  // make status flag LOW
      digitalWrite(LED_ON, LOW);
      digitalWrite(PWM, LOW);      // and turn off the LED
    }
  delay(1000);                    // wait a sec for the hardware to stabilize begin again
  }
int sensorValue = analogRead(A0);
    float current = sensorValue * (5 / 1023.0);
    Serial.println(current);
    if ((sensorValue)==sensorValue+2){
    digitalWrite(PWM, LOW);
    digitalWrite(LED_OVR, HIGH);
    }
attachInterrupt(2, HALL1, RISING); // connects interrupt to pin 2
// interrupt allows you to “multitask” – will switch off one function to show another funtion
// this processor cannot run more than one function at once
attachInterrupt(3, HALL2, RISING); // attaches intterupt to pin 3
half_revolutions=0; // These are all your starting points
rpm=0;
timeold=0;
if (half_revolutions>=20) {
rpm = 30*1000/(millis()-timeold)*half_revolutions;
timeold=millis();
half_revolutions=0;// this section is telling the processor how to convert tO rpm
  }
}  ~~~

First off, the LEDs in the schematic are reversed.

Note: If you had an I2C display, you would only need 2 (two) pins to talk to the LCD.

Analog pins can be used as digital pins so you should have enough pins for the LCD.

Do not use delay( ) in your sketches as it freezes normal code execution for that amount of time.

Look at when a switch changes state, not the state of the switch.

Look at the docs for attachInterrupt too - you're supposed to specify a function to be called when the interrupt fires.

The external interrupt on pin 3 is interrupt 1. You would be better off using the digitalPinToInterrupt() function to specify the interrupt number in the attachInterrupt() function.

Your schematic is confusing. You have the Hall effect sensors on pins 1 and 2, but in the code they are on pins 2 and 3. Also, I see no part numbers for the Hall sensors. Are they digital? Do they need pullup resistors?

Yeah, I do sorry I was rushing with the schematic. I also put the hall sensors on the wrong pin they should be on 2 and 3 since 0 is missing altogether and 1 are tx and rx and can not be used. Sorry! but thanks for the reply. Steve

ps, any ideas on the sketch should I start over and look for a different one on the web. and any clue as to why I can't turn it off?

Hi! yeah sorry I was rushing also reversed the LEDs but on the prototype, the HALL sensors are on pins 2 and 3 and the LEDs work. The Hall sensors I'm using are generic sensors from Amazon. The sensor themselves for the prototype is 3144. The ones I'm actually gonna use are most likely from a 2000-something Subaru 4-cylinder engine since they have a magnet in the Camshaft and will mount better. Do you think I'm asking too much of the controller will she be able to withstand the frequency since the shaft is going to spin at either 1800 RPMs? Thank You for the response Steve

sorry, Here is the sensor data from Amazon

Brand Name MXRS
Ean 0748043034162
Model Number MXRS-MKGW-02
Part Number MXRS-MKGW-02
Specification Met
UNSPSC Code 41110000
UPC 748043034162
Voltage 5 volts

I just read the link, and I can understand why to use them just not sure how to I'm just a newbie but this PWM code is past me. Can you write or show me a code and explain to me why just so I can learn what I can and can not do? I would really appreciate it! I just want to figure out if I should cancel my mill and lathe order, LOL. Thank You Again! Steve

Here is the actual motor I am gonna use.
surplus center part number
ITEM NUMBER: 10-2893
SPECIFICATIONS

  • Power 1/4 HP
  • Voltage 12 DC
  • Speed/Amps
    2600 RPM, 2.2 amps no load
    2300 RPM, 25 amps, 7 in.lbs. torque
  • Rotation Reversible
  • Bearings Ball
  • Enclosure TENV
  • Duty Continuous
  • Frame Rigid welded base
  • Mount 4-1/8" x 2-1/2"
  • Shaft 5/16" dia. x 11/16" w/flat
  • Size 4-1/4" dia. x 4-1/2"
  • Shpg. 8 lbs.
    right now i am using a tiny little motor from Amazon, it was cheaper and smaller.

It helps if you read the question.

Are they digital or analog hall sensors... both can be generic.... best to post the link from where you purchased them.

If you want it to work properly you need to address the interface for the particular sensor...

Good luck

:smiley_cat:

A motor at 1800 RPM is spinning at 30 revolutions per second. That is a revolution every 0.033 seconds. A mega328 processor (Uno Nano) running at 16MHz can execute over 500,000 machine instructions in 0.033 seconds.

Using the digitalPinToInterrupt() function:

   attachInterrupt(digitalPinToInterrupt(2), HALL1, FALLING); // connects interrupt to pin 2
   attachInterrupt(digitalPinToInterrupt(3), HALL2, FALLING);

Those are digital and open drain so they reqjuire pullup resistors to work. If the wires between the sensor and the processor are short (6") you should get by with the internal pullups that are enabled with pinMode(pin, INPUT_PULLUP); Otherwise external resistor will be needed. Start with 10K and go lower until the input is not responding to noise. The sensor will read LOW in the presence of a magnet (proper pole) and HIGH when not. The high to low transition means something happened, hence the FALLING interrupt type.

IMHO, I suggest you 'google' the data sheet for the device you are going to use and read it... You might not understand it all, but you will pick up a couple of things. When you ask here, many here can clarify the parts of the data sheet you don't understand. You don't need to know much to make most of them work...

Some of us are getting old, we need people like to help others :crazy_face:

Good luck...

:smiley_cat:

1 Like

If only !

:face_with_spiral_eyes:

Here's the link

Hi! Everyone,
I found a code that will work I'm using a PID control code it works great. I just have to figure out the LCD that came with the kit and ON/OFF input then it will be perfect, Thank You Everyone!!

Steve

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.