loading

How do i key in a 4x4 matrix keypad input into arduino and control the brushless motor?

I need to use a 4x4 matrix keypad to key in the value ( or angle 0-180) using a servo library to spin a brushless motor.  i was thinking of typing each character and then put them in an array. After that, change it to interger using atoi. how do i do that?? taking the pressed numbers from the keypad, put it in array and then change it to integer to run the bldc motor.?? help pleeeasseee.... an explanation and coding sample would be a great help..

sort by: active | newest | oldest
steveastrouk4 months ago

Why don't you try it and report back. You have the process worked out.

AndrahyzertekosterA (author)  steveastrouk3 months ago

here's my code... but i have a new problem... the code only can read the any value between 103 till 180. Knowing that servo library have a value of 0-180... i tried to input any value from 0-102... the code does not read it and no spinning of the motor... i was wondering you can guide me on that..Here's my code

#include "Keypad.h"

#include <LiquidCrystal.h>

#include <Servo.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);

Servo myservo;

const byte ROWS = 4; //four rows

const byte COLS = 3; //four columns

char keys[ROWS][COLS] =

{{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'*','0','#'}

};

byte rowPins[ROWS] = {9,8,7,6}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {5,4,3}; //connect to the column pinouts of the keypad

int count=0;

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()

{

Serial.begin(9600);

lcd.setCursor(0,0);

lcd.print("Servo");

lcd.begin(16,2);

myservo.attach(11);

}

void loop()

{

static char buffer[4];

static byte i = 0;

char key = keypad.getKey();

// i < 3: prevent buffer overflow

if ('0' <= key && key <= '9' && i < 3)

{

buffer[i] = key;

++i;

lcd.print(key);

}

else if (key == '#' && i > 0)

{

buffer[i] =0; // null-terminate buffer

Serial.print(buffer);

int value = atoi(buffer);

myservo.write(value);

i = 0;

}

}

The terminating condition for your buffer collection is wrong. It will ONLY accept three numbers, not one or two.

1+

iceng3 months ago

You only need a full-wave bridge...

If the BLDC needs less then 300ma a dual 555 = 556 can turn it for you....

Click a pic to see entire image..

12V-Motor complimentry 556.pngACmotor.GIF