Show Posts
Pages: 1 [2] 3 4 ... 10
16  Using Arduino / Programming Questions / Re: analog values stop at threshold on: July 08, 2013, 12:02:44 pm
Here is the sketch for a mini pro board driving a unipolar motor with what would seem to be the exact same method.  The analog values are displayed without a problem.

Code:
#include <Stepper.h>

//stepper
#define STEPS1 200
#define STOP 0

const int stepsPerRevolution = 200;

Stepper stepper1(STEPS1, 9,8,7,6);

int sonarPin = A0;
int sonarVal =0;

void setup()
{
  stepper1.setSpeed(30);
  Serial.begin(9600);
  pinMode(sonarPin,INPUT);
}
void loop()
{
  sonarVal = analogRead (sonarPin);
  Serial.println(sonarVal);
  delay(500);
  {   
    if (sonarVal > 800)
    {
      stepper1.step(stepsPerRevolution); 
    }
    else
    { 
      stepper1.step(STOP);
      delay(50);
      // stepper1.step(-300);
    }
  }
}






17  Using Arduino / Programming Questions / Re: analog values stop at threshold on: July 08, 2013, 11:08:58 am
Now the serial monitor displays nothing until the threshold has been surpassed, then just a single digit and locks up as before. If the marked out Serial.println is included, the lesser values are listed up to the threshold but stop. Whew! This would seem a simple analog problem, no different that the previous five boards with what seems to be the exact same setup.




Code:

#include <Stepper.h>

#define STEPS1 200
#define STOP 0

int rightSwitchPin =7;
int leftSwitchPin =8;
int sonarPin = A0;
int sonarValue = 0;

Stepper stepper1(STEPS1, 3,5,4,6);//bipolar

void setup()
{
  stepper1.setSpeed(30);
  Serial.begin(9600);
 
}
void loop()
{
  sonarValue = analogRead (sonarPin);
  //Serial.println (sonarValue);
  delay(500);

  if (sonarValue >900)
  {
    Serial.print("sonarValue ");
    Serial.println(sonarValue);
    while (digitalRead(rightSwitchPin) == LOW) //keep going until limit switch reached
    {
      stepper1.step(-1);  //move right
    }
    while (digitalRead(leftSwitchPin) == LOW) //keep going until limit switch reached
    {
      stepper1.step(1);  //move left
    }
  }
}


18  Using Arduino / Programming Questions / Re: analog values stop at threshold on: July 07, 2013, 08:34:13 pm
The switches are wired on each end of the carriage with 10K pulldown resistors. Again, these were working fine without the "if". I'll try the Serial.print() tomorrow. Thanks for the help.
19  Using Arduino / Programming Questions / Re: analog values stop at threshold on: July 07, 2013, 06:26:26 pm
At this point, nothing happens. The serial monitor reads the values right up until it arrives at the threshold, then stops, gets stuck at 900, and ceases to continue reading. Only after exceeding the threshold is the stepper supposed to begin which, of course, is impossible without current data. I have noticed similar behavior with the other boards but the intended action occurs, even though the data stops at the threshold. When the photocells are covered, the serial monitor once again lists the values.
20  Using Arduino / Programming Questions / Re: analog values stop at threshold on: July 07, 2013, 05:46:06 pm
Sorry, should have named them appropriately for the forum.  I have a bunch of pro mini boards, each with a photocell installed within a short length of pipe on one end and an LED on the other. The LED responds to a Maxsonar sensor. I need everything; servos, dc motors, LED's, sound, and steppers, to all fire at the same time. I am sure this can be accomplished programmatically but after months of advise and experiment, I opted for this not so elegant method. The moment the LED lights, the whole shebang cranks up.

The sketch worked fine before writing the "if statement", the stepper responding perfectly to the switches as it passes back and forth (a printer salvage). 
21  Using Arduino / Programming Questions / analog values stop at threshold on: July 07, 2013, 04:49:50 pm
My pro mini is writing values from a photocell to the serial monitor, reading correctly until exceeding the threshold, then stops and will not restart, even when the cell is returned to darkness. Assuming this is a software error. Would appreciate advise. Thanks.

Code:

#include <Stepper.h>

#define STEPS1 200
#define STOP 0

int rightSwitchPin =7;
int leftSwitchPin =8;
int sonarPin = A0;
int sonarValue = 0;

Stepper stepper1(STEPS1, 3,5,4,6);//bipolar

void setup()
{
  stepper1.setSpeed(30);
  Serial.begin(9600);
 
}
void loop()
{
  sonarValue = analogRead (sonarPin);
  Serial.println (sonarValue);
  delay(500);

  if (sonarValue >900)
  {
    while (digitalRead(rightSwitchPin) == LOW) //keep going until limit switch reached
    {
      stepper1.step(-1);  //move right
    }
    while (digitalRead(leftSwitchPin) == LOW) //keep going until limit switch reached
    {
      stepper1.step(1);  //move left
     
    }
  }
  else
  {
    stepper1.step (STOP);
  }
}

22  Using Arduino / Installation & Troubleshooting / Mac serial port, now you see it, now you don't! on: June 23, 2013, 02:38:12 pm
The most exasperating problem with Arduino has been the availability of serial ports, or rather, the lack of serial ports.  In the past, the easy fixes described in the troubleshooting pages have been generally successful but the problem has been becoming chronic to the point of completely eliminating my Uno boards as well as Pro Mini which were uploading perfectly until yesterday. The Pro's worked so well in fact, I ordered ten, assuming these would finally resolve the serial port dilemma.  The sometimes on, sometimes off, behavior is maddening! Tried previous Arduino versions with the same result. Mega and older boards with Uno chips will show appropriate ports. Help! Not much hair left!
23  Using Arduino / Motors, Mechanics, and Power / unipolar motor problem on: June 22, 2013, 06:00:30 pm
My six wire unipolar motor vibrates, but does not respond, not matter which sketch is uploaded.  I have switched wires and played with the sketch pin numbers in every way imaginable.  Is this a software problem? I am using a 5v mini pro board powered by an 8 amp, 7 volt supply. 

Code:
#include <Stepper.h>

//stepper
#define STEPS1 200
#define STOP 0

Stepper stepper1(STEPS1, 6,7,8,9);//bipolar

int sonarPin = A0;
int sonarVal =0;

void setup()
{
  stepper1.setSpeed(30);
  Serial.begin(9600);
  pinMode(sonarPin,INPUT);
}
void loop()
{
  sonarVal = analogRead (sonarPin);
  Serial.println(sonarVal);
  {   
    if (sonarVal < 900)
    {
      stepper1.step(STOP);  ////not responding to analog input
    }
    if (sonarVal > 900)
    { 
      stepper1.step(300);
      stepper1.step(-300);
    }
  }
}





24  Using Arduino / Motors, Mechanics, and Power / Re: Power supply for relay on: June 10, 2013, 10:39:22 am
Sorry, I am using 6v for the Arduino Pro, and 5v for the 5v relay.
25  Using Arduino / Motors, Mechanics, and Power / Re: Power supply for relay on: June 10, 2013, 10:27:49 am
Thanks for the help. The datasheet says 40ma. Having ordered a bunch of these, guess I will try to use them. If run from a transistor, I assume two wall warts are necessary?
26  Using Arduino / Motors, Mechanics, and Power / Power supply for relay on: June 10, 2013, 08:27:14 am
I have a project involving a relay, PIR sensor, and AC fan. All finally works as intended but it is so ugly, really ugly, with two wall warts, one supplying the Arduino, another for the relay, and a wire for the fan, all coming from a power strip. A single wire from the AC outlet to a box would be much more elegant.  I assume the Arduino and relay can't be supplied by a single wart via transistor, or in this case, a tip120?  Could mains power be accessed from a single terminal inside a project box by the two warts? Ignorant question, but anything coming from the wall gives me the Willies!
27  Using Arduino / Sensors / Re: PIR and relay problem on: June 07, 2013, 03:24:34 pm
Should have added another question: How can I supply both Arduino and relay with the same wall wart? I burned a Seeeduino experimenting with the same 8v source.
28  Using Arduino / Sensors / Re: PIR and relay problem on: June 07, 2013, 03:16:17 pm
Thank you so much! I have been beating this monkey for days. The inexperienced can find great web resources most of the time but can't often distinguish good from bad. Also, the ABC link will be very helpful.
29  Using Arduino / Sensors / Re: PIR and relay problem on: June 07, 2013, 12:47:22 pm
Sorry, I don't quite understand.  Is the wire pictured from the middle pin of the tip120 joining the relay coil incorrect? 
30  Using Arduino / Sensors / PIR and relay problem on: June 07, 2013, 08:31:49 am
I have a 5v relay set up in this configuration  http://arduino.sundh.com/wp-content/uploads/2011/10/transistor_TIP120_12V_g5LE-1.png The PIR sensor is working fine until the ground is joined (AR to relay breadboard). Then, the LED remains on and does not trip the relay. Oddly enough, this isn't always the case. Infrequently, it will work fine for a few minutes, then fail, regardless of the board (Uno, Pro Mini). Here is the sketch.

Code:
int calibrationTime = 30;       

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000; 

boolean lockLow = true;
boolean takeLowTime; 

int pirPin =8;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;
int relayPin = 9;


/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin,OUTPUT);
  digitalWrite(pirPin, HIGH);
  digitalWrite(relayPin,HIGH);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
    //delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
}

////////////////////////////
//LOOP
void loop(){

  if(digitalRead(pirPin) == HIGH){
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin,LOW);
    delay(2000);
    digitalWrite(ledPin,LOW);
    digitalWrite(relayPin,HIGH);
    //the led visualizes the sensors output pin state
    if(lockLow){ 
      //makes sure we wait for a transition to LOW before any further output is made:
      lockLow = false;           
      Serial.println("---");
      Serial.print("motion detected at ");
      Serial.print(millis()/1000);
      Serial.println(" sec");
      delay(50);
    }         
    takeLowTime = true;
  }

  if(digitalRead(pirPin) == LOW){       
    digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state
    digitalWrite(relayPin,HIGH);
    if(takeLowTime){
      lowIn = millis();          //save the time of the transition from high to LOW
      takeLowTime = false;       //make sure this is only done at the start of a LOW phase
    }
    //if the sensor is low for more than the given pause,
    //we assume that no more motion is going to happen
    if(!lockLow && millis() - lowIn > pause){ 
      //makes sure this block of code is only executed again after
      //a new motion sequence has been detected
      lockLow = true;                       
      Serial.print("motion ended at ");      //output
      Serial.print((millis() - pause)/1000);
      Serial.println(" sec");
      delay(50);
    }
  }
}

Pages: 1 [2] 3 4 ... 10