Show Posts
Pages: 1 ... 71 72 [73] 74 75 ... 197
1081  Using Arduino / Project Guidance / Re: Keypad and Stepper on: September 05, 2013, 03:57:27 pm
First things first, you need an encoder. It will keep track of the stepper's position and allow you to step accordingly with new keypad values. Second does one keypad value equal one step? Say you press 3 on the keypad, does that mean the stepper moves 3 steps, or does it move to a certain degree (30 degrees)?

Also, keep everything to one post, no need to make another just for the code.

Edit/Add:
If exact position is not needed, then neither is an encoder. Now using my keypad sketch and the stepper sketch, "MotorKnob" I was able to get the stepper to step depending on the key pressed. For example, when I pressed "1", the stepper moved 1 step every time, "2" = 2 steps, "3" and so on to "9". Now I only made it so that the keypad would get single digits, but I made a sketch in the past that can get up to 9 digits long (a bit excessive for this project). So it should be easy to get say a 3 digit number like "100" and have the stepper move 100 steps.

Here is the sketch I made.
** Please note, the keypad characters were recycled from another sketch, and I am using an I2C LCD, but you can send the data to the serial monitor too.
Code:
/*
 || @version 1.0
 || @author Andrew Mascolo
 ||
 || @description
 || Simple use of keypad, stepper and LCD
 */
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Stepper.h>
Stepper stepper(100, 10, 11, 12, 13);
LiquidCrystal_I2C lcd(0x20,20,4);

char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
  {
    '1','2','3','+'}
  ,
  {
    '4','5','6','-'}
  ,
  {
    '7','8','9','*'}
  ,
  {
    'C','0','=','/'}
};
byte rowPins[ROWS] = {
  2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  9,8,7,6}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup(){
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  stepper.setSpeed(10);
}

void loop(){
  lcd.setCursor(0,0);
  customKey = customKeypad.getKey();
  
  if(customKey) {
    lcd.print(customKey);
    stepper.step(customKey - '0');// this converts the char from the keypad, to an int for the stepper
  }
}
1082  Using Arduino / Programming Questions / Re: Unusual readings trying to use multiple buttons on one analog pin. on: September 04, 2013, 02:53:06 pm
Change that red wire going to the buttons, a resistor. This way you will have a voltage divider and not just a current divider.
1083  Using Arduino / Project Guidance / Re: Need Some Advice On Simple Robotics Project on: September 04, 2013, 12:11:55 am
Well, wide Popsicle sticks are great to build with, especially for small model bridges. Do you need to pick the bridge back up, once you cross it? Anyways, servos and either grippers or electromagnets will do nicely to drop and release the bridge.
1084  Using Arduino / Project Guidance / Re: Need help on 12V DC motor on: September 03, 2013, 11:43:33 pm
Yes a H-bridge / motor shield will be needed and you may want to look up simple state machines. I can tell you a simple latch will do for button A, and an IF statement for button B.

1085  Using Arduino / Project Guidance / Re: Need Some Advice On Simple Robotics Project on: September 03, 2013, 11:37:49 pm
If you have pictures of your robot and the bridge, we can suggest ways to combine the two.
Details are a must. How heavy is the bridge, the lenght/width is the gap you will be crossing, and more importantly, can the bridge support the robot?

Your most likely going to bring the bridge over the robot to then drop it across the gap. For that, you may need grippers, however, if the bridge has metal on it, you could use electromagnets. Of course you will need at least two servos on both sides, to lower the bridge first before dropping it in place.

So if you have any designs in mind, make a list of possible parts, and decide which one to make.
1086  Using Arduino / Programming Questions / Re: Unusual readings trying to use multiple buttons on one analog pin. on: September 03, 2013, 09:08:41 pm
Post your code too
1087  Using Arduino / Project Guidance / Re: Brightness Controll with LDR on: September 03, 2013, 02:35:02 am
Those values I used were just an example, I don't know his actual readings. It could be 0 - 1023. He could also add a default case to blink if need be.
Quote
map () is a very useful little function, it is linear, but the human eye isn't!
True, but if everything is scaled properly, (using the map function) you will notice a difference in light levels, with just 3 LEDs.
Now if he added more LEDs, then yes, it would be rather difficult to notice any changes.

Also he did add a Serial.println to his code, to see the values change.
1088  Using Arduino / Project Guidance / Re: Brightness Controll with LDR on: September 03, 2013, 02:18:38 am
Ok, bad on my part, I just read the title then skimmed the post and went from there.

Ok, I would use a case statements and the map function. This way everything is scaled and neat.
But IF statements are ok too, if you want to control at what brightness to set the LEDs to.

Code:
#define Lowest 0
#define Highest 600

LDRValue = map(analogRead(LDR), Lowest, Highest, 0, 3); // This will automatically scale your values

switch(LDRValue)
{
 case 0: // lowest LDR value = All LEDs on
     digitalWrite(13, HIGH);
     digitalWrite(12, HIGH);
     digitalWrite(11, HIGH);
     break;

 case 1:// LDR gets some light = 2 LEDS on
     digitalWrite(13, LOW);
     digitalWrite(12, HIGH);
     digitalWrite(11, HIGH);
     break;
 
 case 2: // More light = 1 LED on
     digitalWrite(13, LOW);
     digitalWrite(12, LOW);
     digitalWrite(11, HIGH);
     break;

 case 3: // Full brightness = All LEDs off
     digitalWrite(13, LOW);
     digitalWrite(12, LOW);
     digitalWrite(11, LOW);
     break;
}
1089  Using Arduino / Displays / Re: Arduino tft variables flickering on: September 01, 2013, 12:37:12 pm
Code:
int current_value, old_value; //set globally

current_value = analogRead(A0); // Read a value from analogpin 0

if(current_value != old_value) // Check to see if anything changed, if it did change show it, otherwise don't.
{
  //print("     ", X, Y); // clear that section of the lcd
  //print(current_value, X, Y); // show the new value
}
old_value = current_value; // Update old_value
1090  Using Arduino / Displays / Re: Arduino tft variables flickering on: August 31, 2013, 05:59:19 pm
Why not see if the variable changes first, then if it does change, clear that segment of the screen and display the new number. This way you will get rid of the flicker and make it look much smoother and professional.
1091  Using Arduino / Programming Questions / Re: how can i do split string function? on: August 29, 2013, 03:18:20 pm
Post your full code.
1092  Using Arduino / Programming Questions / Re: Make a Stepper motor Hold/Lock on: August 26, 2013, 10:45:12 pm
Well, you could just keep those particular poles energized, but that would either drain your battery or burn out your stepper motor (if the voltage is too high to begin with).
Another thing you could do is make some kind of disk break, similar to the ones used on hobby RC cars/trucks.
1093  Using Arduino / Programming Questions / Re: Stepper Motor Sun Tracker Script Help Needed on: August 26, 2013, 10:39:45 pm
Well how do you get a percentage from anything? Simple, you find its max value and divide the current value by the max. In this case, I just going to guess that the max value you get is 1023.
So you simply take the new value and divide it by 1023, and you should get a certain percentage, base on the amount of light your photodiode is receiving.

So in programming terms:

New_Value = analogRead(sensor_one);
Percent_S1 = New_Value / 1023;

or just simply,

Percent_S1 = analogRead(sensor_one) / 1023;
1094  Using Arduino / Project Guidance / Re: Mini Car , Xbee , PS2 controller , Camera on: August 25, 2013, 03:22:42 pm
You cant do that, the Arduino cannot handle video, it does not have the memory. The best thing you could do would be still frames, but even then you wouldn't be able to send them. Your only practical option for video is just to get a wifi webcam.

Well there is also a raspberry Pi + camera, but that's another story.
1095  Using Arduino / Project Guidance / Re: 4 serial connections on arduino uno on: August 25, 2013, 03:16:15 pm
Software serial may work, but I'm not sure how many serial connections you are limited to.
Pages: 1 ... 71 72 [73] 74 75 ... 197