Show Posts
Pages: [1] 2 3 ... 231
1  Using Arduino / Programming Questions / Re: gsm SimpleWriteln not working... HELP! on: Today at 04:51:39 am
When you say it does not work what do you mean exactly ?
2  Using Arduino / Programming Questions / Re: Servo project help! on: April 17, 2014, 12:56:41 am
Or you might like to use the more obvious
Code:
pinMode(pushbutton, INPUT_PULLUP);
This ensures that the input pin is held at a known state (HIGH) at all times until pressing the button takes it LOW.  Obviously the wiring and the program logic need to match the HIGH/LOW off/on state of the button.
3  Using Arduino / Programming Questions / Re: Servo project help! on: April 16, 2014, 03:01:05 pm
Yes, it will need to be time based using delay() or the BWD technique.

Despite BWB being better to use in the long run (see below) I suggest that you use delay() at first and get the program working.  As to reaction to the button becoming pressed rather than being pressed, have a look at the StateChangeDetection example in the IDE.

BWD is better for most purposes because it uses the technique of noting a start time and then looking every now and again to see if the timing period has ended.  If it has then do the next action.  If not, then do something else such as reading another input, which you cannot do using delay() because the program stalls until the delay is over.
4  Using Arduino / Programming Questions / Re: Servo project help! on: April 16, 2014, 01:21:08 pm
The servo connection problem is nothing to do with the pins used. The servos take more current from the Arduino than is advisable so it is preferable to use an external power supply for them with a common GND to the Arduino.

This sounds like the outline of what you want to do
Code:
start of loop
  read the button pin
  if the button becomes pressed
    issue the command for move servo 1 to 45 degress
    wait for required period
    issue the command for move servo 2 to 45 degrees
  end if
  wait for 2 seconds
  issue the command for move servo 1 to the original position
  issue the command for move servo 2 to the original position
end of loop 
There are many details to sort out such as how to detect that the button has become depressed rather than being currently depressed, and how to know that the servos have reached 45 degrees.  (Actually that is not possible with normal servos so what can you do ?) 
How should you implement the waits ?  Using the delay() function, or is there a better way ?  (There is)
5  Using Arduino / Programming Questions / Re: error: expected initializer before 'void' need a second set of eyes!!! on: April 16, 2014, 11:14:43 am
It would be better to see your whole program, but in the meantime try Auto Formatting it and see what happens.

Code:
        }
    return GearCommand;
}
Which one of these braces ends the function ?
6  Using Arduino / Programming Questions / Re: Servo project help! on: April 16, 2014, 06:42:14 am
You need to sort out the power as Paul suggests and can you explain what you want to do in more detail ?
Quote
I'm attempting to write a code where when I use a push button the micro servo rotates and then after a delay the standard servo does the same, plus a basic LED for indication.
What should happen if you hold the button down ?
What should happen if you just tap the button ?
What triggers the servos to return to their starting position ?  Time passing, releasing the button or something else ?
7  Using Arduino / Programming Questions / Re: Servo project help! on: April 16, 2014, 01:12:06 am
Some comments about your code.

Code:
  if (digitalRead(pushbutton) == LOW)
    for(ppos = 0; ppos < 25; ppos += 25)  // degrees from 0 to 45
      for (mpos = 0; mpos < 90; mpos += 90)
      {                                 
        pinservo.write(ppos);    //servo to position in variable "pos"
        mtrservo.write(mpos);                     
      }
It is not immediately obvious to me what statement(s) will be executed if
Code:
  if (digitalRead(pushbutton) == LOW)
 
is true.  The statements to be executed would be better in a block with braces round them.

What is the object of
Code:
    for(ppos = 0; ppos < 25; ppos += 25)  // degrees from 0 to 45
anyway ?  What values will ppos have ?  Does the servo really move from 0 to 45 degrees ?

Similarly
Code:
      for (mpos = 0; mpos < 90; mpos += 90)
and
Code:
      for(mpos =90 ; mpos>=90; mpos-=90)

How is the pushbutton wired ?
How are the servos powered ?  Directly from the Arduino or externally ?

That will do for now I think.
8  Using Arduino / Programming Questions / Re: Need Help how to control 4 dc motors with 2 potentiometers atAdafruitMotorShield on: April 15, 2014, 04:37:04 pm
Quote
AF_DCMotor left1stMotor(1);
I was assigned " left1stMotor " as my left bottom motor at my tank project. There will be 4 motors at body.
That does not explain what the 1 refers to.

Quote
Will the result ever be greater than 127 ?
I have 1K potentiomter ( but I will get 10K one soon ) ;so with this "potentiometerValue = potentiometerValue/4; " I wanted to make smaller the value for less pot rotation with my fingers.
If it is wired correctly it will not matter if the potentiometer is 1K or 10K, the value returned by analogRead() will still be between 0 and 1023.  How is the potentiometer wired ?

Quote
//use this line or the next line but not both  , what do you mean by " next line " ? it is the bottom line that is under the " potentiometerValue = map(potentiometerValue, 0, 1023, 0, 255); " ,right ? thanks.
The map function turns a range of values between 0 and 1023 into a range of values between 0 and 255.  This effectively divides the original value by 4.  Then your next line divides the value by 4 again so the maximum value will now be 64 and can never be greater than 127.

More generally, have you tried printing the value of any of the variables in your program to see if is doing what you expect ?  Printing potentiometerValue just before you test it to see whether it is greater/less than 127 would be interesting.
9  Using Arduino / Programming Questions / Re: Need Help how to control 4 dc motors with 2 potentiometers atAdafruitMotorShield on: April 15, 2014, 11:55:15 am
It looks like you were very close with the firs program you posted.  Here it is in code tags and without the commented lines which only serve to confuse.  I have also reformatted it to make it easier to read.
Code:
#include <AFMotor.h>

int potentiometerPin = 7; // analog pin used to connect the potentiometer
int potentiometerValue; // variable to read the value from the analog pin


AF_DCMotor left1stMotor(1); // 1. motor ( Left back motor )

int i;

void setup()
{
  Serial.begin(9600); // set up Serial library at 9600 bps
  left1stMotor.setSpeed(200);
  left1stMotor.run(RELEASE);
}

void loop()
{
  potentiometerValue = analogRead(potentiometerPin); // reads the value of the potentiometer (value between 0 and 1023)
  potentiometerValue = map(potentiometerValue, 0, 1023, 0, 255);  //use this line or the next line but not both
  potentiometerValue = potentiometerValue/4;

  Serial.print("tick");
  left1stMotor.run(FORWARD);

  for (i=0; i<255; i++)
  {
    if(potentiometerValue <= 127)
    {
      left1stMotor.setSpeed(i);
      delay(10);
    }
  }
  Serial.print("tock");
  left1stMotor.run(BACKWARD);

  for (i=0; i<255; i++)
  {
    if(potentiometerValue >= 127)
    {
      left1stMotor.setSpeed(i);
      delay(10);
    }
  }

  Serial.print("tech");
  left1stMotor.run(RELEASE);
  delay(1000);
}
Note my comment about using one line or the other but not both.  The first line maps the 0 to 1023 value to 0 to 255 then the second line divides the answer by 4.  Will the result ever be greater than 127 ?

What does the 1 in this line do ?
Code:
AF_DCMotor left1stMotor(1);
Does it mean that you are using digital pin 1 ?  If so then it will conflict with Serial.print() and vice versa.
10  Using Arduino / Programming Questions / Re: Ethernet Shield using Alarms for Garduino on: April 15, 2014, 11:32:18 am
It is a safeguard to ensure that the water() function only gets called once when the time to water matches the current time.  Probably not a problem when the timing is to the second but imagine what might happen if the timing was being done only to the minute, particularly if the water() function is non blocking, which it should be.
11  Using Arduino / Programming Questions / Re: Basic question: Pin modes and enums on: April 14, 2014, 06:43:16 am
If you really want to do things that way have you tried printing the values of INPUT and OUTPUT ?
12  Using Arduino / Programming Questions / Re: Example: SerialBlinkWithoutDelay on: April 14, 2014, 01:24:49 am
Code:
  while (Serial.available())
Won't this effectively act as blocking code, albeit for a very short time ?  Whatever you are timing with millis() will have to wait until all available serial data has been processed.  Might it not be better to read just one character from serial before returning to loop() so that the millis() timing can do its stuff between serial characters ?

Also, there is an argument for implementing the millis() timing differently.  Instead of
Code:
    previousMillis = now;   
use
Code:
    previousMillis = previousMillis + BLINK_INTERVAL;   
This ensures that reacting to the interval ending remains constant even if time consuming events have occurred in the meantime.
13  Using Arduino / Programming Questions / Re: Misbehaving servo on: April 13, 2014, 04:45:47 pm
Can you provide a link to the servo that you are using ?
14  Using Arduino / Programming Questions / Re: Misbehaving servo on: April 13, 2014, 01:33:49 pm
What happens if you use a simple program (no dependence on external input) that cycles the servo between 0, 90 and 180 with a delay between the movements ?
15  Using Arduino / Programming Questions / Re: Misbehaving servo on: April 13, 2014, 09:42:09 am
How is the servo powered ?
What data type is inByte ?
What values do you see if you print inByte when serial data is available and just before writing it to the servo ?
Pages: [1] 2 3 ... 231