MaxHeadRoom
- Joined Jul 18, 2013
- 28,688
You should be able to use a 5V supply without going to a battery.
Max.
Max.
A better choice is a 9V DC supply. The Arduino power jack can accept up to 12V, but running at the maximum will heat up the onboard regulator. The DC power supplies for Arduino from several suppliers, including Arduino, are typically 9V.You should be able to use a 5V supply without going to a battery.
Max.
Thanks.You should be able to use a 5V supply without going to a battery.
Max.
Thanks.A better choice is a 9V DC supply. The Arduino power jack can accept up to 12V, but running at the maximum will heat up the onboard regulator. The DC power supplies for Arduino from several suppliers, including Arduino, are typically 9V.
You’ve paid for the voltage regulation circuitry when you’ve purchased an Arduino. No need to design and pay for your own. As far as the 5V relay, even when the Arduino is powered by 9 or 12V, it’s outputs are 5V
Thanks.Thanks.
Yes, its a good suggestion to input Arduino a 9V instead of 12V. I'll use a 7809 to step down it.
Best
Thanks.Thanks.
I just tested use a 9V battery to the Arduino without a common ground, the machine doesn't run. I used 5Vdc to the relays, and common ground. the motors just turn one turn, can not continue running, don't know why?
// [REF1] add button matrix ............................................. DOWN
#include <Keypad.h>
const byte numRows = 4; //number of rows on the keypad
const byte numCols = 4; //number of columns on the keypad
//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// byte rowPins[numRows] = {A2, A3, A4, A5}; //Rows 0 to 3
// byte colPins[numCols] = {12, 13, A0, A1}; //Columns 0 to 3
byte rowPins[numRows] = {12, 13, A0, A1}; //Rows 0 to 3
byte colPins[numCols] = {A2, A3, A4, A5}; //Columns 0 to 3
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
const int ACMUDP = 2; // '1' relay DCMotorUD positive
const int ACMUDN = 3; // 'A' relay DCMotorUD negetive
const int ACMBELTP = 4; // '4' relay DCMotorUD positive
const int ACMBELTN = 5; // 'B' relay DCMotorUD negetive
const int ACMPICKP = 8; // '7' relay DCMotorLR positive
const int ACMPICKN = 9; // 'C' relay DCMotorLR negetive
const int ACMSMEARP = 10; // '*' relay DCMotorFS positive
const int ACMSMEARN = 11; // 'D' relay DCMotorFS
const int ACMBUMP = 6; // '2' relay DCMotorFS positive
const int ACMSTH = 7; // '3' ???????????????????????????????
int ACMotors[] = {ACMUDP, ACMUDN, ACMBELTP, ACMBELTN, ACMPICKP, ACMPICKN, ACMSMEARP, ACMSMEARN, ACMBUMP, ACMSTH};
//// 10 total used Pin20 ~ Pin29
int Biaoji = 0;
boolean running = false;
void setup() {
Serial.begin(9600);
for (int i = 0; i < 10; i++) {
pinMode(ACMotors[i], OUTPUT); //// rowPins[numRows] = {A8, A9, A10, A11};
digitalWrite(ACMotors[i], HIGH);
}
for (int i = 0; i < 4; i++) {
pinMode(rowPins[i], INPUT_PULLUP); //// rowPins[numRows] = {A8, A9, A10, A11};
digitalWrite(rowPins[i], LOW);
Serial.println (rowPins[i]); // print: 61, 60, 59, 58; ('rowPins[i]') print: 26973, 26973, 26973,26973
}
for (int i = 0; i < 4; i++) {
pinMode(colPins[i], OUTPUT); //// colPins[numCols] = {A4, A5, A6, A7};
digitalWrite(colPins[i], LOW);
Serial.print (colPins[i]);
}
}
void loop() { ////
// RunningBeep(); //// beep once every 15 seconds as long as power ON
// LswitchCheck();
buttonMatrix();
DoBiaoji();
Serial.println("(boolean running");
Serial.println(running);
if (running == true) {
runMachine();
// running = !running;
Serial.println("(boolean running");
Serial.println(running);
}
}
void buttonMatrix() //// tt button
{
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
Serial.println(keypressed);
}
Serial.println("Biaoji = ");
Serial.println(Biaoji);
if (keypressed == '0') // BTSMRight;
{
running = true;
// runMachine();
delay(5);
}
if (keypressed == '#') // BTSMLeft;
{
running = false;
stopMachine();
}
if (keypressed == '1') // BTSMRight;
{
digitalWrite(ACMUDP, LOW);
delay(1000);
digitalWrite(ACMUDP, HIGH);
}
if (keypressed == 'A') // BTSMLeft;
{
digitalWrite(ACMUDN, LOW);
delay(1000);
digitalWrite(ACMUDN, HIGH);
}
if (keypressed == '4') // BTSMLeft;
{
digitalWrite(ACMBELTP, LOW);
delay(1000);
digitalWrite(ACMBELTP, HIGH);
}
if (keypressed == 'B') // BTSMDown;
{
digitalWrite(ACMBELTN, LOW);
delay(1000);
digitalWrite(ACMBELTN, HIGH);
}
if (keypressed == '7') // BTSMForward;
{
digitalWrite(ACMPICKP, LOW);
delay(1000);
digitalWrite(ACMPICKP, HIGH);
}
if (keypressed == 'C') // BTSMBackward;
{
digitalWrite(ACMPICKN, LOW);
delay(1000);
digitalWrite(ACMPICKN, HIGH);
}
if (keypressed == '*') // // BTFLC button finger long close
{
digitalWrite(ACMSMEARP, LOW);
delay(1000);
digitalWrite(ACMSMEARP, HIGH);
}
if (keypressed == 'D') // BTFLO button finger long open
{
digitalWrite(ACMSMEARN, LOW);
delay(1000);
digitalWrite(ACMSMEARN, HIGH);
}
if (keypressed == '2') // // BTFLC button finger long close
{
digitalWrite(ACMBUMP, LOW);
delay(1000);
digitalWrite(ACMBUMP, HIGH);
}
if (keypressed == '3') // BTFLO button finger long open
{
digitalWrite(ACMSTH, LOW);
delay(1000);
digitalWrite(ACMSTH, HIGH);
}
}
void runMachine() {
//if (Biaoji == 8)
digitalWrite(ACMUDP, LOW);
delay(10);
digitalWrite(ACMBELTP, LOW);
delay(100);
digitalWrite(ACMUDP, HIGH);
digitalWrite(ACMBELTP, HIGH);
digitalWrite(ACMPICKP, LOW);
delay(10);
digitalWrite(ACMSMEARP, LOW);
delay(4000);
digitalWrite(ACMSMEARP, HIGH);
digitalWrite(ACMPICKP, HIGH);
Serial.println("runMachine");
Serial.println("Biaoji'0' = ");
Serial.println(Biaoji);
Serial.println("runMachine");
Serial.println("Biaoji'0' = ");
Serial.println(Biaoji);
}
void stopMachine() {
digitalWrite(ACMUDP, HIGH);
digitalWrite(ACMBELTP, HIGH);
digitalWrite(ACMPICKP, HIGH);
digitalWrite(ACMSMEARP, HIGH);
Biaoji = 0;
}
void DoBiaoji() {
if (Biaoji == 8) {
runMachine();
}
}
Thanks.You have a 120 VAC 50/60 Hz single phase AC motor. You have a 4x4 matrix keypad using likely an Arduino Uno. How are you interfacing your Arduino to your motor? Provide a drawing or schematic? The code snippet is written around controlling a DC motor.
If you want speed control of a motor like you have I suggest you read this article paying attention to the schematic and use of an SCR. Pretty much what I believe Max suggested at the beginning. Even that may only work moderate at best.
Again, post a schematic.
Ron
Thanks.The first step is to verify that you can switch outputs on and off with the arduino board. But also you need to verify that the relay board is functioning correctly. But in the drawing I see not relay control circuit board, I see relays connected directly to the arduino outputs. Are those outputs even able to operate the relay? Are you able to measure the coil voltage of the relay while you try to operate it from your control program? The problem is probably in the software of the arduino, I can not help with that.
We need to know the specifications of the relays, particularly the relay coils. Activation voltage, hold voltage, coil resistance. Or required current for the coil, which could be calculated for the former specifications.The first step is to verify that you can switch outputs on and off with the arduino board. But also you need to verify that the relay board is functioning correctly. But in the drawing I see not relay control circuit board, I see relays connected directly to the arduino outputs. Are those outputs even able to operate the relay? Are you able to measure the coil voltage of the relay while you try to operate it from your control program? The problem is probably in the software of the arduino, I can not help with that.
Thanks.We need to know the specifications of the relays, particularly the relay coils. Activation voltage, hold voltage, coil resistance. Or required current for the coil, which could be calculated for the former specifications.
If the coil requires more than 20mA, you can’t drive it directly from the Arduino. You will need a PNP transistor or P channel logic level MOSFET with a driver.
Or, I recommend placing V+ in common to the relay coils and switching ground. This is easier. Then, use an N channel logic level MOSFET to switch ground. Like a 2N7000.
Additionally, you’ll need a diode reverse biased connected across the relay coil. That is, the cathode would be connected to V+. Without this, the Arduino or MOSFET will be destroyed.
It would be useful if you posted your sketch (between code tags) so that we can see it.
// [REF1] add button matrix ............................................. DOWN
#include <Keypad.h>
const byte numRows = 4; //number of rows on the keypad
const byte numCols = 4; //number of columns on the keypad
//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// byte rowPins[numRows] = {A2, A3, A4, A5}; //Rows 0 to 3
// byte colPins[numCols] = {12, 13, A0, A1}; //Columns 0 to 3
byte rowPins[numRows] = {12, 13, A0, A1}; //Rows 0 to 3
byte colPins[numCols] = {A2, A3, A4, A5}; //Columns 0 to 3
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
// myKeypad.setHoldTime(1000);
const int ACMUDP = 2; // '1' relay DCMotorUD positive
const int ACMUDN = 3; // 'A' relay DCMotorUD negetive
const int ACMBELTP = 4; // '4' relay DCMotorUD positive
const int ACMBELTN = 5; // 'B' relay DCMotorUD negetive
const int ACMPICKP = 8; // '7' relay DCMotorLR positive
const int ACMPICKN = 9; // 'C' relay DCMotorLR negetive
const int ACMSMEARP = 10; // '*' relay DCMotorFS positive
const int ACMSMEARN = 11; // 'D' relay DCMotorFS
const int ACMBUMP = 6; // '2' relay DCMotorFS positive
const int ACMSTH = 7; // '3' ???????????????????????????????
int ACMotors[] = {ACMUDP, ACMUDN, ACMBELTP, ACMBELTN, ACMPICKP, ACMPICKN, ACMSMEARP, ACMSMEARN, ACMBUMP, ACMSTH};
//// 10 total used Pin20 ~ Pin29
int Biaoji = 0;
boolean running = false;
void setup() {
Serial.begin(9600);
for (int i = 0; i < 10; i++) {
pinMode(ACMotors[i], OUTPUT); //// rowPins[numRows] = {A8, A9, A10, A11};
digitalWrite(ACMotors[i], HIGH);
}
for (int i = 0; i < 4; i++) {
pinMode(rowPins[i], INPUT_PULLUP); //// rowPins[numRows] = {A8, A9, A10, A11};
digitalWrite(rowPins[i], LOW);
Serial.println (rowPins[i]); // print: 61, 60, 59, 58; ('rowPins[i]') print: 26973, 26973, 26973,26973
}
for (int i = 0; i < 4; i++) {
pinMode(colPins[i], OUTPUT); //// colPins[numCols] = {A4, A5, A6, A7};
digitalWrite(colPins[i], LOW);
Serial.print (colPins[i]);
}
myKeypad.setHoldTime(3000); //// https://forum.arduino.cc/index.php?topic=407946.0
myKeypad.setDebounceTime(200);
Serial.println("setup");
}
void loop() { ////
// RunningBeep(); //// beep once every 15 seconds as long as power ON
// LswitchCheck();
buttonMatrix();
// DoBiaoji();
if (running == true) {
runMachine();
// running = !running;
Serial.println("running");
Serial.println(running);
}
if (running == false) {
stopMachine();
Serial.println("running");
Serial.println(running);
}
}
void buttonMatrix() //// tt button
{
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
Serial.println(keypressed);
}
if (keypressed == '0') // BTSMRight;
{
running = true;
// runMachine();
delay(5);
}
if (keypressed == '#') // BTSMLeft;
{
stopMachine();
running = false;
}
if (keypressed == '1') // BTSMRight;
{
digitalWrite(ACMUDP, LOW);
delay(1000);
digitalWrite(ACMUDP, HIGH);
}
if (keypressed == 'A') // BTSMLeft;
{
digitalWrite(ACMUDN, LOW);
delay(1000);
digitalWrite(ACMUDN, HIGH);
}
if (keypressed == '4') // BTSMLeft;
{
digitalWrite(ACMBELTP, LOW);
delay(1000);
digitalWrite(ACMBELTP, HIGH);
}
if (keypressed == 'B') // BTSMDown;
{
digitalWrite(ACMBELTN, LOW);
delay(1000);
digitalWrite(ACMBELTN, HIGH);
}
if (keypressed == '7') // BTSMForward;
{
digitalWrite(ACMPICKP, LOW);
delay(1000);
digitalWrite(ACMPICKP, HIGH);
}
if (keypressed == 'C') // BTSMBackward;
{
digitalWrite(ACMPICKN, LOW);
delay(1000);
digitalWrite(ACMPICKN, HIGH);
}
if (keypressed == '*') // // BTFLC button finger long close
{
digitalWrite(ACMSMEARP, LOW);
delay(1000);
digitalWrite(ACMSMEARP, HIGH);
}
if (keypressed == 'D') // BTFLO button finger long open
{
digitalWrite(ACMSMEARN, LOW);
delay(1000);
digitalWrite(ACMSMEARN, HIGH);
}
if (keypressed == '2') // // BTFLC button finger long close
{
digitalWrite(ACMBUMP, LOW);
delay(1000);
digitalWrite(ACMBUMP, HIGH);
}
if (keypressed == '3') // BTFLO button finger long open
{
digitalWrite(ACMSTH, LOW);
delay(1000);
digitalWrite(ACMSTH, HIGH);
}
}
void runMachine() {
digitalWrite(ACMUDP, LOW);
delay(10);
digitalWrite(ACMBELTP, LOW);
delay(100);
digitalWrite(ACMUDP, HIGH);
digitalWrite(ACMBELTP, HIGH);
digitalWrite(ACMPICKP, LOW);
delay(10);
digitalWrite(ACMSMEARP, LOW);
delay(5000);
digitalWrite(ACMSMEARP, HIGH);
digitalWrite(ACMPICKP, HIGH);
delay(1000);
Serial.println("runMachine");
}
void stopMachine() {
digitalWrite(ACMUDP, HIGH);
digitalWrite(ACMBELTP, HIGH);
digitalWrite(ACMPICKP, HIGH);
digitalWrite(ACMSMEARP, HIGH);
}
Oh! I didn’t understand you were using that module. Forget what I said. Everything I mentioned is likely included in the module. Your schematic likely didn’t represent the module well.Thanks.
The relay modules used here from EBAY, picture attached:
https://www.ebay.ca/itm/4-Channel-5...630353?hash=item3b2e3a1ad1:g:VIUAAOSwWk5csAb8
View attachment 214896
the sketch:
Code:// [REF1] add button matrix ............................................. DOWN #include <Keypad.h> const byte numRows = 4; //number of rows on the keypad const byte numCols = 4; //number of columns on the keypad //keymap defines the key pressed according to the row and columns just as appears on the keypad char keymap[numRows][numCols] = { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; // byte rowPins[numRows] = {A2, A3, A4, A5}; //Rows 0 to 3 // byte colPins[numCols] = {12, 13, A0, A1}; //Columns 0 to 3 byte rowPins[numRows] = {12, 13, A0, A1}; //Rows 0 to 3 byte colPins[numCols] = {A2, A3, A4, A5}; //Columns 0 to 3 Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); // myKeypad.setHoldTime(1000); const int ACMUDP = 2; // '1' relay DCMotorUD positive const int ACMUDN = 3; // 'A' relay DCMotorUD negetive const int ACMBELTP = 4; // '4' relay DCMotorUD positive const int ACMBELTN = 5; // 'B' relay DCMotorUD negetive const int ACMPICKP = 8; // '7' relay DCMotorLR positive const int ACMPICKN = 9; // 'C' relay DCMotorLR negetive const int ACMSMEARP = 10; // '*' relay DCMotorFS positive const int ACMSMEARN = 11; // 'D' relay DCMotorFS const int ACMBUMP = 6; // '2' relay DCMotorFS positive const int ACMSTH = 7; // '3' ??????????????????????????????? int ACMotors[] = {ACMUDP, ACMUDN, ACMBELTP, ACMBELTN, ACMPICKP, ACMPICKN, ACMSMEARP, ACMSMEARN, ACMBUMP, ACMSTH}; //// 10 total used Pin20 ~ Pin29 int Biaoji = 0; boolean running = false; void setup() { Serial.begin(9600); for (int i = 0; i < 10; i++) { pinMode(ACMotors[i], OUTPUT); //// rowPins[numRows] = {A8, A9, A10, A11}; digitalWrite(ACMotors[i], HIGH); } for (int i = 0; i < 4; i++) { pinMode(rowPins[i], INPUT_PULLUP); //// rowPins[numRows] = {A8, A9, A10, A11}; digitalWrite(rowPins[i], LOW); Serial.println (rowPins[i]); // print: 61, 60, 59, 58; ('rowPins[i]') print: 26973, 26973, 26973,26973 } for (int i = 0; i < 4; i++) { pinMode(colPins[i], OUTPUT); //// colPins[numCols] = {A4, A5, A6, A7}; digitalWrite(colPins[i], LOW); Serial.print (colPins[i]); } myKeypad.setHoldTime(3000); //// https://forum.arduino.cc/index.php?topic=407946.0 myKeypad.setDebounceTime(200); Serial.println("setup"); } void loop() { //// // RunningBeep(); //// beep once every 15 seconds as long as power ON // LswitchCheck(); buttonMatrix(); // DoBiaoji(); if (running == true) { runMachine(); // running = !running; Serial.println("running"); Serial.println(running); } if (running == false) { stopMachine(); Serial.println("running"); Serial.println(running); } } void buttonMatrix() //// tt button { char keypressed = myKeypad.getKey(); if (keypressed != NO_KEY) { Serial.println(keypressed); } if (keypressed == '0') // BTSMRight; { running = true; // runMachine(); delay(5); } if (keypressed == '#') // BTSMLeft; { stopMachine(); running = false; } if (keypressed == '1') // BTSMRight; { digitalWrite(ACMUDP, LOW); delay(1000); digitalWrite(ACMUDP, HIGH); } if (keypressed == 'A') // BTSMLeft; { digitalWrite(ACMUDN, LOW); delay(1000); digitalWrite(ACMUDN, HIGH); } if (keypressed == '4') // BTSMLeft; { digitalWrite(ACMBELTP, LOW); delay(1000); digitalWrite(ACMBELTP, HIGH); } if (keypressed == 'B') // BTSMDown; { digitalWrite(ACMBELTN, LOW); delay(1000); digitalWrite(ACMBELTN, HIGH); } if (keypressed == '7') // BTSMForward; { digitalWrite(ACMPICKP, LOW); delay(1000); digitalWrite(ACMPICKP, HIGH); } if (keypressed == 'C') // BTSMBackward; { digitalWrite(ACMPICKN, LOW); delay(1000); digitalWrite(ACMPICKN, HIGH); } if (keypressed == '*') // // BTFLC button finger long close { digitalWrite(ACMSMEARP, LOW); delay(1000); digitalWrite(ACMSMEARP, HIGH); } if (keypressed == 'D') // BTFLO button finger long open { digitalWrite(ACMSMEARN, LOW); delay(1000); digitalWrite(ACMSMEARN, HIGH); } if (keypressed == '2') // // BTFLC button finger long close { digitalWrite(ACMBUMP, LOW); delay(1000); digitalWrite(ACMBUMP, HIGH); } if (keypressed == '3') // BTFLO button finger long open { digitalWrite(ACMSTH, LOW); delay(1000); digitalWrite(ACMSTH, HIGH); } } void runMachine() { digitalWrite(ACMUDP, LOW); delay(10); digitalWrite(ACMBELTP, LOW); delay(100); digitalWrite(ACMUDP, HIGH); digitalWrite(ACMBELTP, HIGH); digitalWrite(ACMPICKP, LOW); delay(10); digitalWrite(ACMSMEARP, LOW); delay(5000); digitalWrite(ACMSMEARP, HIGH); digitalWrite(ACMPICKP, HIGH); delay(1000); Serial.println("runMachine"); } void stopMachine() { digitalWrite(ACMUDP, HIGH); digitalWrite(ACMBELTP, HIGH); digitalWrite(ACMPICKP, HIGH); digitalWrite(ACMSMEARP, HIGH); }
by Robert Keim
by Jake Hertz
by Jake Hertz
by Duane Benson