Show Posts
Pages: 1 ... 104 105 [106] 107 108 ... 197
1576  Using Arduino / Project Guidance / Re: Help please! I need to make a butterfly! on: April 22, 2013, 09:18:54 am
10x7x0.8 inches
That is kinda big. You might need to use a bigger motor than the ones found in hex bugs. However the toothbrush motor should still work fine.
1577  Using Arduino / Programming Questions / Re: How To Process a String of Several USART Commands on: April 22, 2013, 09:14:24 am
For something like "+1.00+0.25+0.25+0.10", I would use maybe strtok() to filter out the numbers. Keep the same IF statement to check if it is a '+' or '-', and then just use that function to get the numbers, to either add or subtract them from the total.
1578  Using Arduino / Programming Questions / Re: int from 0 to 8, to binary ("progress bar") on: April 22, 2013, 08:15:01 am
You can use bit shifting.

int a = 0;               // binary: 00000000
int b = a | 128;      // binary: 10000000
b >> 1;                 // binary: 01000000  // I split this
int c =  b | 128      // binary: 11000000 // and this, to show what is happening

This is probably not the best way to do it, but I dont know for sure. I can't test it on my end.
1579  Using Arduino / Displays / Re: LCD 1602 Keypad Shield - How to input single characters using up-down buttons on: April 22, 2013, 07:54:06 am
Are you only looking to use 0-9, or 0-9 and a-z / A-Z? They are all ascii characters so, you will use either HEX or decimal to cycle throught the characters.

0-9 => 48-57 DEC, 30-39 HEX
A-Z => 65-90 DEC, 41-5A HEX
a-z => 97-122 DEC, 61-7A HEX

Ascii table

Here is a sample of how to use two buttons to cycle through numbers. This code uses an I2C lcd, some tweaking may be required for your lcd.
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20,16,2);

const byte buttonPin1 = 2; // Up button
const byte buttonPin2 = 3; // Down Button
//const int ledPin =  11;

int buttonState1 = 0;
int lastReading1 = 0;
int buttonState2 = 0;
int lastReading2 = 0;
int lastcount =0;
long onTime1=0;
long onTime2=0;
int count = 0;

void setup() {
  //pinMode(ledPin, OUTPUT);     
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);

  lcd.init();                      // initialize the lcd
  lcd.backlight();
  Serial.begin(9600); 
}

void loop(){
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  if (buttonState1 == HIGH && lastReading1 == LOW) {
    onTime1 = millis();
    count++;
  }
  if (buttonState2 == HIGH && lastReading2 == LOW) {
    onTime2 = millis();
    count--;
  }

  //held
  if (buttonState1 == HIGH && lastReading1 == HIGH) {
    if ((millis() - onTime1) > 500 ) {
      delay(200);
      count++;
      lastReading1 = LOW;
    }
  }
  if (buttonState2 == HIGH && lastReading2 == HIGH) {
    if ((millis() - onTime2) > 500 ) {
      delay(200);
      count--;
      lastReading2 = LOW;
    }
  }
  Serial.println(count);
  lcd.setCursor(0,0);
  //lcd.clear();
  if(lastcount < 0 && count >= 0) lcd.clear();
  if(lastcount >=10 && count < 10) lcd.clear();
  if(lastcount >=100 && count < 100) lcd.clear();
  if(lastcount >=1000 && count < 1000) lcd.clear();
  lcd.print(count);
  //lcd.clear();
  lastcount = count;
  lastReading1 = buttonState1;
  lastReading2 = buttonState2;
}


1580  Using Arduino / Project Guidance / Re: Help please! I need to make a butterfly! on: April 22, 2013, 07:13:07 am
What about a tiny motor with an offset shaft. You can use one of the motors found in those HEX bug things, or better yet, the ones found in electric toothbrushes. All you need to do is find a way to oscillate the shaft when it turns.

Something like this.
1581  Using Arduino / Project Guidance / Re: 4WD Differential Steering? on: April 21, 2013, 07:32:17 pm
This is how I did it.
Code:
/*
Andrew Mascolo
Seminar project with Bluetooth control
 */
#include<string.h>
int DRV1,DRV2,STRR,STRL;
int x = 0;
int y = 0;
int z = 0;
int s = 0;
void move(int z = 0,int y = 0,int s = 0);
String val,X,Y,Z,state = "";
int currentCommand = 0;

byte ledpin = 13;
byte Mopen = 4;
byte Mclosed = 2;
byte M1L = 3;// PWM
byte M2L = 5;// PWM
byte M1R = 9;// PWM
byte M2R = 6;// PWM


void setup()
{
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  pinMode(Mopen, OUTPUT);                               
  pinMode(Mclosed, OUTPUT);
  pinMode(M1L, OUTPUT);                               
  pinMode(M1R, OUTPUT);
  pinMode(M2L, OUTPUT);                               
  pinMode(M2R, OUTPUT);
  Serial.begin(9600);       // start serial communication at 115200bps
}

void loop() {
  if( Serial.available())       // if data is available to read
  {
    digitalWrite(ledpin, HIGH);
    char c= Serial.read();
    if (c == ','){
      currentCommand++;
    }
    else {
      val += c;
      //Serial.println(val);
      switch (currentCommand) {
      case 0:
        X += val;
        val = "";
        break;
      case 1:
        Y += val;
        val = "";
        break;
      case 2:
        Z += val;
        val = "";
        break;
      case 3:   
        state = val;
        currentCommand = 0;
        val = "";
        x=X.toInt(); //Convert string to a usable integer
        y=Y.toInt(); //Convert string to a usable integer
        z=Z.toInt(); //Convert string to a usable integer
        s=state.toInt(); //Convert string to a usable integer
        X=""; Y=""; Z=""; state=""; //Clear string
        move(z, y, s); // send to motors
        break;
      }
    }
  }
}
   
  void move(int z, int y, int s)
  { 
  //Movement varibles
  int DRV2 = map(z, -15, 0, 255, 0);
  int DRV1 = map(z, 0, 15, 0, 255);
  int STRL = map(y, -10, 0, 255, 0);
  int STRR = map(y, 0, 10, 0, 255);
  //constrain((DRV1,DRV2,STRL,STRR),0,255);

  if(z > 0)//forwards with left/ right skew turning           
  {
    //Serial.println("Driving");
    analogWrite(M1L, constrain(abs(DRV1 - STRL),0,255)); analogWrite(M1R, constrain(abs(DRV1 - STRR),0,255));   
    digitalWrite(M2L, LOW);                              digitalWrite(M2R, LOW);   
  }
  else if(z < 0)//backwards with left/ right skew turning                 
  {
    //Serial.println("Driving");
    digitalWrite(M1L, LOW);                              digitalWrite(M1R, LOW);   
    analogWrite(M2L, constrain(abs(DRV2 - STRL),0,255)); analogWrite(M2R, constrain(abs(DRV2 - STRR),0,255));   
  }
   else if(z < 4 && z > -4 && y > 0)//zero point turn Right  +-4 is the dead zone, it makes it drive more smoothly             
  {
    //Serial.println("Driving");
    digitalWrite(M2L, LOW); analogWrite(M2R, STRR);   
    analogWrite(M1L, STRR); digitalWrite(M1R, LOW);
  }
  else if(z < 4 && z > -4 && y < 0)//zero point turn Left   +-4 is the dead zone, it makes it drive more smoothly               
  {
     //Serial.println("Driving");
    analogWrite(M2L, STRL); digitalWrite(M2R, LOW);   
    digitalWrite(M1L, LOW); analogWrite(M1R, STRL);   
  }

  else //full stop
  {
    digitalWrite(M1L, LOW); digitalWrite(M1R, LOW);       
    digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);   
  }

// Claw controls
   if(s == 1)
    {
      Serial.println("Claw Opening");
      digitalWrite(Mopen, HIGH); digitalWrite(Mclosed, LOW);
    }
    if(s == 2)
    {
      Serial.println("Claw Closing");
      digitalWrite(Mopen, LOW); digitalWrite(Mclosed, HIGH);
    }
    if(s == 0)
    {
      digitalWrite(Mopen, LOW);  digitalWrite(Mclosed, LOW);
    }
   else
   {
    digitalWrite(ledpin, LOW);
    x=0; y=0; z=0; s=0;
   }
 val,X,Y,Z,state = "";  //Clear string
}


1582  Using Arduino / Programming Questions / Re: Push Button Debouncing improperly on: April 21, 2013, 12:11:15 am
Try this.
Code:
/*
 Debounce
 This example code is in the public domain.
 http://www.arduino.cc/en/Tutorial/Debounce
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin[] = {A0,A1,A2,A3}; // Number of buttons
const int ledPins[] =  {13,12,11,10};      // the number of the LEDs

int MAX_PINS = 4; // how many buttons to look for
int i = 0;
int counter=0;
int reading[4];

//byte ledState = HIGH;

int buttonState[4];             // the current reading from the input pin
int lastButtonState[] = {LOW,LOW,LOW,LOW};   // the previous reading from the input pin
long lastDebounceTime[] = {0,0,0,0};  // the last time the output pin was toggled

long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
  Serial.begin(9600);
  for(i = 0; i <= MAX_PINS; i++){
    pinMode(buttonPin[i], INPUT); //set button states
    pinMode(ledPins[i], OUTPUT); // set LED states
  }
}

void loop() {
  // read the state of the switch into a local variable:
  for(counter = 0; counter <= MAX_PINS; counter++) // cycle through and check all buttons
  {
    reading[counter] = digitalRead(buttonPin[counter]);// look at button input and record it.
    if (reading[counter] != lastButtonState[counter]) {
    lastDebounceTime[counter] = millis();
    }

    if ((millis() - lastDebounceTime[counter]) > debounceDelay) {
      buttonState[counter] = reading[counter];
    }

    digitalWrite(ledPins[counter], buttonState[counter]);
    lastButtonState[counter] = reading[counter];
    //Serial.print("counter: ");
    //Serial.print(counter);
    //Serial.println();
  }
}

1583  Using Arduino / Project Guidance / Re: Cheap Arduino RC Car? on: April 20, 2013, 09:56:01 pm
Quote
Yes sorry I meant autonomous;) The circuit board transmits the radio signal from the controller to control to servos, 1 at the top is to turn the wheels and the bottom one is to make it go forward and backwards. I don't care for the remote controller, I want to ditch it and just use it with the arduino and make a program to automatically do a preprogrammed course. I'm planning to use the arduino to just tell the motors where to go with a preprogrammed track. I plan to use the car as a robot and for the steering I can add a second motor in the code and create custom turns to do.

Are you going to measure the time (preset delay) in which the car turns or use an encoder to track the distance of how far the car goes to then decided when to turn?
1584  Using Arduino / Project Guidance / Re: Need a help with Servo and IR sensor on: April 20, 2013, 09:51:37 pm
Quote
Yes, I edit the code and I will try to explain what I want to do:
1- A person be closer to the IR sensor.
2- if the Sensor read more than 300 (val > 300).
3- the Servo will move from 0 to 180.
4- As soon as the person there in the range of ( val >300) the servo does not move.
5- Whenever the person goes back and the Sensor read is less than 300 (val < 300).
5- The Servo will move back from 180 to 0.
6- As soon as no body there, the Servo will hold in this position.

Ok, 2 and 6 will conflict with each other, if you don't set more limits. I don't know the sensitivity of your sensor, so I don't know how far out it can accurately take measurements. Now with your current needs, you want the servo to activate, lets say open (0 - 180), when someone is within a range of 300 "something". You also want the servo to close when the person is outside the range of 300, and you want the servo to hold its position when the person is completely gone. Does that sound right?

My questions to you are how far can your sensor accurately measure, and at what point is the person considered completely gone? The code for that is simple, you just need to get more information in order to put it together the way you want it.

if(less than 300) open up
else if(greater than 300, but less than say 500) close
else hold servo position
1585  Using Arduino / Project Guidance / Re: Cheap Arduino RC Car? on: April 18, 2013, 08:12:50 pm
Quote
I know to wire the car's GND to the arduino's GND but how do I hook up the other things so that I can make it go forward, backward, left and right?
You need to either make a H-bridge (motor driver) or buy one online. Look up Arduino motor driver, or Arduino H-bridge.
1586  Topics / Robotics / Re: 2 motors controlled by one joystick on: April 18, 2013, 08:07:25 pm
Why do this?

Quote
servoVal3 = map(servoVal3, 0, 1023,1000, 1750);    // scale it to use it with the servo (result  between 0 and 180)
servoVal4 = map(servoVal4, 0, 1023, 1250, 1750);     // scale it to use it with the servo (result between 70 and 180)
.....
servoVal1 = map(servoVal1, 0, 1023,1000, 1750);     // scale it to use it with the servo (result  between 0 and 180)
servoVal2 = map(servoVal2, 0, 1023, 1250, 1750);     // scale it to use it with the servo (result between 70 and 180)

Don't you want to get values between 0 - 90, and 90 - 180? You need to use IF statements like how I have done. If you don't isolate the values, and use them when you need them, you have problems controlling the robot.
1587  Using Arduino / Programming Questions / Re: Needing a little bit of guidance for connecting arduino codes... on: April 18, 2013, 02:52:00 pm
@Pauls
Yea, I overlooked that, my mistake.
same for this, "buttonCount = 1 ; buttonCount < 6"

I have a headache right now, so I'll come back later.

Last thing before I go, this needs a closing bracket.
Quote
for (int buttonCount = 1 ; buttonCount < 6 ; buttonCount++)
{
 pinMode(buttonPin[ buttonCount ], INPUT);
1588  Using Arduino / Programming Questions / Re: Needing a little bit of guidance for connecting arduino codes... on: April 18, 2013, 02:05:26 pm
They stay just like that.
1589  Using Arduino / Programming Questions / Re: Needing a little bit of guidance for connecting arduino codes... on: April 18, 2013, 01:38:38 pm
Quote
for (int ledCount = 8 ; ledCount < 13 ; ledCount++)
{
 /* Your pin modes go here*/
 }
  // initialize the pushbutton pin as an input:
for (int buttonCount = 1 ; buttonCount < 6 ; buttonCount++){
/* Your pin modes go here*/ 
 
}
1590  Using Arduino / Programming Questions / Re: Needing a little bit of guidance for connecting arduino codes... on: April 18, 2013, 01:22:08 pm
Post what you have done.
Pages: 1 ... 104 105 [106] 107 108 ... 197