Show Posts
Pages: 1 2 [3] 4 5 ... 10
31  Using Arduino / Programming Questions / PIR - Relay problem on: June 01, 2013, 03:40:46 pm
This sketch will turn the LED on and off with motion detected, but when the relay is included, the sketch is repetitive; flashing the LED and tripping the relay regardless of PIR input. Any idea what I am doing wrong?
Code:
int calibrationTime = 30;       

[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 = 1500; //5000

boolean lockLow = true;
boolean takeLowTime; 

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


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

}

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

  if(digitalRead(pirPin) == HIGH){
    digitalWrite(ledPin,LOW);
    digitalWrite(relayPin,LOW);
    //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()/50);//1000
      Serial.println(" sec");
      delay(50);
    }         
    takeLowTime = true;
  }

  if(digitalRead(pirPin) == LOW){       
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin,HIGH);
    delay(5000);
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin,LOW);
    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;                       

      delay(50);
    }
  }
}
[/code]
32  Using Arduino / Installation & Troubleshooting / Re: FTDI basic breakout upload problem on: May 28, 2013, 10:53:21 am
I am uploading with a Mac. Would that be a problem? 
33  Using Arduino / Installation & Troubleshooting / Re: FTDI basic breakout upload problem on: May 28, 2013, 10:47:44 am
When RX and TX are joined, the IDE says "download complete" but the simple "blink" sketch doesn't blink.
34  Using Arduino / Installation & Troubleshooting / Re: FTDI basic breakout upload problem on: May 28, 2013, 07:02:53 am
Still wrestling with this breakout board. If I understand this tutorial,  https://www.sparkfun.com/tutorials/224 TX from the board should connect to Arduino RX, TX to Arduino RX?  The sketch doesn't upload, even if this is part of the problem. Whew! Getting a little frustrated. Also, I have read something about connecting both RX and TX for testing but don't understand the details. 
35  Using Arduino / Installation & Troubleshooting / Re: FTDI basic breakout upload problem on: May 27, 2013, 11:41:13 am
Thanks for the advise, Baligena. I sent you a message from your web store about this question. Appears that I have set it up correctly. This is the FTDI board.  http://www.tinyosshop.com/index.php?route=product/product&product_id=186   I assumed the chip is Uno but have also chosen other 328 options with the same result. I am uploading to a Mac.  Any other possible mistakes?  Are you selling the programmer in the video?

Keith
36  Using Arduino / Installation & Troubleshooting / Re: FTDI basic breakout upload problem on: May 26, 2013, 07:40:04 pm
Sorry, here is a dumb question; when you say, "grounds not connected," I assume this is from the breakout pin to the Arduino? Can DTR be omitted altogether, at least for testing?
37  Using Arduino / Installation & Troubleshooting / Re: FTDI basic breakout upload problem on: May 26, 2013, 06:03:30 pm
Oops forgot the link.   http://baligena.com/shop/barebones-arduino-board/
38  Using Arduino / Installation & Troubleshooting / FTDI basic breakout upload problem on: May 26, 2013, 06:02:25 pm
I want to upload with an FTDI breakout board to this cheap board. The driver is installed on my Mac book but the sketch won't upload. The appropriate pins are connected. Any idea what I am doing wrong?

39  Using Arduino / Audio / Re: Amplify toy speaker output with LM386 on: May 18, 2013, 06:00:21 pm
Thanks for the advise. To be sure I understand correctly, should a cap be placed across pos to neg of these two wires from the toy board speaker to the 386 amp circuit.  Also, should the grounds of the two (toy and amp) be joined, or is this already happening with the ground speaker wire when connected to the amp circuit? 
40  Using Arduino / Audio / Amplify toy speaker output with LM386 on: May 18, 2013, 04:35:46 pm
My project involves sounds from boards salvaged from children's toys running at 3v~5v. These need to be much louder. I have built a circuit with LM386 (http://www.learningaboutelectronics.com/Articles/How-to-connect-a-LM386-audio-amplifier-chip) without success. I assumed that audio input was from the +/- speaker wires of the toy to the 386. Is this correct?
41  Using Arduino / Project Guidance / Re: I2C on: May 14, 2013, 10:42:18 pm
Thanks for the advise. I have written another sketch with an attempt at the "no delay" but without success because I simply lack the programming skill to write the code. I really needed to know if the multiple Arduino idea is practical, even if it isn't the most efficient solution. Gold is the more sought after, but silver will buy as much if you don't mind the extra weight.
42  Using Arduino / Project Guidance / Re: I2C on: May 14, 2013, 08:46:35 pm
Yes, I think my expectations have not been realistic, i.e. everything happening at once in response to sensor input using a single Arduino. That's why the multiple Arduino boards.

Code:
#include <Servo.h>
#include <Stepper.h>

//stepper
#define STEPS1 200
#define STEPS2 200

#define STOP 0
int toSlave = 15;


//stepper

Stepper stepper1(STEPS1, 2,3,4,5);//bipolar
Stepper stepper2(STEPS2,53,51,49,47);//unipolar


//LED's
int ledLeft = 35;
int ledMiddle = 36;
int ledRight = 37;
int ledFrontRow [10] = {
  20,21,22,23,24,25,26,27,28,29};

//Motors
int motorLeft = 29; //dc motors
int motorMiddle = 31;
int motorRight = 33;

//Servo
Servo myservo1;
Servo myservo2;
Servo myservo3;

unsigned int duration = 0;             

int lasttime1 = 0;
int lasttime2 = 0;
int randstart = 0;
int randend = 0;

int pos1 = 0;
int pos2 = 0;
int pos3 = 0;

int sonarPin = A1;
int sonarVal =0;

void setup()
{

  stepper1.setSpeed(30);
  stepper2.setSpeed(30);

  pinMode(toSlave,OUTPUT);
  pinMode(motorLeft, OUTPUT);  //dc motors
  pinMode(motorMiddle, OUTPUT);
  pinMode(motorRight, OUTPUT);

  //pinMode(sonarVal,INPUT);

  myservo1.attach(9);
  myservo2.attach(10);
  myservo3.attach(11);

  Serial.begin(9600);
  pinMode(sonarPin,INPUT);
}

void loop()
{

  sonarVal = analogRead (sonarPin);
  {

    //ALL STOP   
    if (sonarVal > 15)
    {
      stepper1.step(STOP);  ////not responding to analog input
      stepper2.step(STOP);

      digitalWrite (motorLeft,LOW);
      digitalWrite (motorMiddle,LOW);
      digitalWrite (motorRight,LOW);

      myservo1.write (0);
      myservo2.write (0);
      myservo3.write (0);

      digitalWrite(toSlave, LOW);

    }


    if (sonarVal < 15)
    { 
      stepper1.step(300);
      stepper1.step(-300);
      stepper2.step(200);   
    }

    //MOTORS

    if (sonarVal < 15)
    {
      digitalWrite (motorLeft, HIGH);
      digitalWrite (motorMiddle,HIGH);
      digitalWrite (motorRight, HIGH);

      digitalWrite(toSlave,HIGH);
    }     

    //SERVO
    if (sonarVal < 15)
    {
      lasttime1 = millis();
      randstart =  random(554, 1054);
      randend =  random(500, 2400);

      while(pos1 <= randend) 
      {     
        pos1 += 1;
        myservo1.writeMicroseconds(pos1);   
        delay(2);   //2                 
      }
      while(pos2 <= randend) 
      {     
        pos2 += 1;
        myservo2.writeMicroseconds(pos2);
        delay(2);   //2                 
      }
      while(pos3 <= randend) 
      {
        pos3 += 1;
        myservo3.writeMicroseconds(pos3);   
        delay(2);   //2                 
      }
      duration = millis() - lasttime1;
      lasttime2 = millis();

      while(pos1 >= randstart)   
      {                               
        pos1-=1;
        myservo1.write(pos1);   
        delay(2);                     
      }
      while(pos2 >= randstart)   
      {                               
        pos2-=1;
        myservo2.write(pos2);   
        delay(2);                     
      }
      while(pos3 >= randstart)   
      {                               
        pos3-=1;
        myservo3.write(pos3);   
        delay(2);                     
      }
      duration = millis() - lasttime2;
      duration = millis() - lasttime1;
    }
  }
}



43  Using Arduino / Project Guidance / I2C on: May 14, 2013, 05:18:35 pm
I have been working on a sculpture that includes steppers, DC motors, servos, LEDs, and sounds. All need to fire simultaneously when sensor input is less than a threshold. Currently, a Mega is programmed with "if" statements that are too slow to respond as planned. I have ordered cheap Arduino Pro and plan to have one read sensor values and communicate via a single digital output to the other 5 boards. What is the best method to accomplish this? Is I2C practical? A relay? Something primitive such as an LED surrounded by 5 cps?
44  Using Arduino / Programming Questions / Re: FSM stepper/servo problem on: April 27, 2013, 03:47:50 pm
I found use of the comma in several texts and web sites, but these have to do with parsing a string.
45  Using Arduino / Programming Questions / Re: FSM stepper/servo problem on: April 27, 2013, 03:33:56 pm
If the sensor returns more than 15, the FSM is supposed to run the motors, servos, and steppers. Case 4,3,and two.  I had the serial monitor checking sensor values but removed those lines. Is there another parameter to check?
Pages: 1 2 [3] 4 5 ... 10