Greetings,
I have read plenty of books and sketches, not grasping every concept yet, but getting there.
My project:
A gravity assisted mini grain/feed elevator/provider, grain flows down by itself, sometimes stops, this just moves it along "insuring" a more constant feed. impeller the motor is connected to is spring loaded and will keep a tension on the feed until feed is depleted and IR sensor detects no feed is present.
What I have:
IRF520 module, IR sensor, Arduino Nano, 9v battery* (which is a part of the problem)
My current simple code that works:
int digitalPin = 8; //IRF520 module signal pin
int sensorPin = 7; //Infrared sensor module signal pin
int IRGate = HIGH; // < need explanation on its usage? rem'ing it out give errors in compiling.void setup() {
pinMode (digitalPin, OUTPUT);//IRF520 module signal pin
pinMode (sensorPin, INPUT);//Infrared sensor module signal pin
Serial.begin(9600);
}
void loop() {
IRGate = digitalRead(sensorPin);
if (IRGate == LOW) //if gate is blocked stop motor
{
Serial.println ("Grain is present");
digitalWrite(digitalPin, LOW); //stop motor
}
else
{
Serial.println("Feeding");//run motor
digitalWrite(digitalPin, HIGH);//send signal to IRF520 to run motor
}
delay(200);//not certain I need this at this location in the sketch... but I do need the motor to run a bit longer than instantly start/stop, like a 1/4 second to 1/2 a second or so.
}
I need to limit the speed of the motor, its too fast, I had analysed the initial non arduino board I am trying to replicate, under no motor connected the motor has ~7v at the motor leads (I dont have a scope to measure PWM at the moment), ~0.5Ah no load but running the impeller and 1Ah stall load, motor connected and under load ~3v, with a 9V it runs too fast and a simple 9V battery does not have the amount of mAh for long run times.
I can simply change the battery from a 9v to 4AA or a 4000mah 1S Lipo ... yes ... ok, but would like to know if I could write this better using smarter code.
My questions are:
- Id like to use PWN syntax/function with the IRF520 to change the % of volts feeding the motor, can this be done using digitalWrite/digitalRead? (possibly learning how to use PWM better in the process) or is it simpler to use AnalogWrite/read? (I was not successful yet in writhing this code with analogWrite).
- Could I add a Pot to the setup and have it read to modify the PWM input to the IRF520 module? I can write the % or V needed from the power source I would be using. do I need a specific motor library to run the IRF520 and be able to alter the voltage (or on time) the motor gets?
- Should I just shut up and run the lower voltage battery and keep everything as it is?
Thanks,
Matt.