Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 14
61  Using Arduino / Sensors / Re: slight change in sketch means sensor won't let servo run with the +5v connected on: January 27, 2013, 09:54:33 pm
If you look at the data sheet or the quick start guide on the Maxbotix website, I think you'll see that the minimum distance is six inches for the EZ although there are other Maxbotix sensors with different ranges.

It's almost always best to change one variable at a time. You'll save tons of debugging time that way.
62  Using Arduino / Motors, Mechanics, and Power / Re: H bridge using 4 PNP transistors. on: January 27, 2013, 08:58:22 pm
also I don't think IRF 520 is even logic level
63  Using Arduino / Sensors / Re: Extreme data variation with MaxBotix Ultrasonic Rangefinder on: January 05, 2013, 04:58:00 pm
Did you read the links that you provided?
The first line of the second link says, "Continuous free run operation will generally not work when using more than one sensor in the same system."
64  Using Arduino / Programming Questions / Re: Amarino accelerometer on: December 24, 2012, 01:34:21 pm
Same results with comparison operators modified.

Code:
#include <MeetAndroid.h>

#define Forwardled 3  
#define Reverseled 11  
#define Rightled 5  
#define Leftled 6

float data[3] = {
  0};
int intdata[3] = {
  0};
int i = 1;


MeetAndroid meetAndroid(error);

void error(uint8_t flag, uint8_t values)
{
  Serial.print("ERROR: ");
  Serial.print(flag);
}


void setup() {
  Serial.begin(9600);      
  pinMode(Forwardled, OUTPUT);
  pinMode(Reverseled, OUTPUT);
  pinMode(Leftled, OUTPUT);
  pinMode (Rightled, OUTPUT);
  delay(1000);

  meetAndroid.registerFunction(floatValues, 'A');

}

void loop()
{
  meetAndroid.receive();
}

void floatValues(byte flag, byte numOfValues)
{

  meetAndroid.getFloatValues(data);

  for (int i=0; i<3;i++)
  {
    meetAndroid.send(data[i]);
  }


  //This is for Forward/Reverse
  if ((data[0] >= -10) && (data[0] <=10))    
  {
    intdata[0] = int(data[0]);
    intdata[0] = intdata[0] * 24;

    if (data[0] <= -2)
    {
      intdata[0] = abs(intdata[0]);
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Forwardled, intdata[0]);
    }

    else if (data[0] >= 2)
    {
      digitalWrite(Forwardled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Reverseled, intdata[0]);
    }

    else if ((data[0] >= -1) || (data[0] <= 1))  
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      digitalWrite(Forwardled,LOW);
    }
  }

  //This is for Turn Left/Turn Right
  if ((data[1] >= -10) && (data[1] <= 10))
  {
    if (data[1] <= -2)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Forwardled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Rightled, intdata[0]);
    }

    else if (data[1] >= 2)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Forwardled,LOW);
      digitalWrite(Rightled,LOW);
      analogWrite(Leftled, intdata[0]);
    }

    else if ((data[1] >= -1) || (data[1] <= 1))  
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      digitalWrite(Forwardled,LOW);
    }    
  }
}

65  Using Arduino / Programming Questions / Amarino accelerometer on: December 24, 2012, 12:41:16 pm
I'm trying to use Amarino to send data from my android phone's accelerometer to arduino in order to turn on or off four led lights that simulate the direction of a robot consisting of two motors. The motors can go forward or reverse. The code is copied and modified from this: http://www.instructables.com/id/Hercules-The-Motion-Controlled-Android-Robot/step8/Step-8-Programming-the-Arduino/

I would expect from my modified code that when I tilted the phone forward on the x axis, the forward light would turn on. When I tilt the phone backward on the axis, the backward led turns on. When the phone is tilted right on the y axis, the right led is turned on, and when the phone is tilted left, the left led is turned on. If the phone is tilted purely on the axis, only one led should be on at a time, but if the phone is tilted simultaneously on the x and y axis, two leds should be on at one time and by using pwm, should be lit with a brightness corresponding to the angle of the tilt. ex. forward-right, back-left, etc.

However, this is not the case. When the phone is tilted forward, no lights. When the phone is tilted backward, no lights.
When the phone is tilted right,the right led comes on, and when it is tilted left the left led comes on. it seems to work the right and left lights seem to work best when it is tilted diagonally in any of the four diagonal directions. But the most I can ever see on the forward and reverse is a barely detectable flicker when the phone is tilted in one of the diagonal directions.

Originally I tried to modify the origional code to drive two motors using an h bridge but got the same results as the leds. I wired up the leds as a simple simulation to try to find a problem. I've tried to change the baud rates, but my program works the same at 9600, 57600, or 115200.

Here is my code:
Code:
#include <MeetAndroid.h>

#define Forwardled 3  
#define Reverseled 11  
#define Rightled 5  
#define Leftled 6

float data[3] = {
  0};
int intdata[3] = {
  0};
int i = 1;


MeetAndroid meetAndroid(error);

void error(uint8_t flag, uint8_t values)
{
  Serial.print("ERROR: ");
  Serial.print(flag);
}


void setup() {
  Serial.begin(57600);      
  pinMode(Forwardled, OUTPUT);
  pinMode(Reverseled, OUTPUT);
  pinMode(Leftled, OUTPUT);
  pinMode (Rightled, OUTPUT);
  delay(1000);

  meetAndroid.registerFunction(floatValues, 'A');

}

void loop()
{
  meetAndroid.receive();
}

void floatValues(byte flag, byte numOfValues)
{

  meetAndroid.getFloatValues(data);

  for (int i=0; i<3;i++)
  {
    meetAndroid.send(data[i]);
  }


  //This is for Forward/Reverse
  if (-10<=data[0]<=10)            
  {
    intdata[0] = int(data[0]);
    intdata[0] = intdata[0] * 24;

    if (data[0] <= -2)
    {
      intdata[0] = abs(intdata[0]);
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Forwardled, intdata[0]);
    }

    else if (data[0] >= 2)
    {
      digitalWrite(Forwardled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Reverseled, intdata[0]);
    }

    else if (-1<=data[0]<=1)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      digitalWrite(Forwardled,LOW);
    }
  }

  //This is for Turn Left/Turn Right
  if (-10<=data[1]<=10)  
  {
    if (data[1] <= -2)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Forwardled,LOW);
      digitalWrite(Leftled,LOW);
      analogWrite(Rightled, intdata[0]);
    }

    else if (data[1] >= 2)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Forwardled,LOW);
      digitalWrite(Rightled,LOW);
      analogWrite(Leftled, intdata[0]);
    }

    else if (-1<=data[1]<=1)
    {
      digitalWrite(Reverseled,LOW);  
      digitalWrite(Rightled,LOW);
      digitalWrite(Leftled,LOW);
      digitalWrite(Forwardled,LOW);
    }    
  }
}

Any suggestions?
66  Using Arduino / Project Guidance / Re: How do you make pretty arduino schematics? on: November 30, 2012, 07:15:23 pm
Wizdum,
What did you use for the PCB views on your website? Looks good.
67  Using Arduino / Project Guidance / Re: How do you make pretty arduino schematics? on: November 30, 2012, 01:26:06 pm
So what is a fairly easy and free program for proper schematics editing? Is there one? I have looked at a few programs like PCB Express, TINA TI, Eagle CAD, PCB 123, MultiSim,  etc. It seems that either it's very difficult to find different components, or it's overly time consuming to learn, or it has very few components. I liked National Instruments MultiSim, but it isn't free.
68  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 09:59:07 pm
Thanks Nick,
Good work. You explained that well. I know I can use this down the road when I get my robot going again. It will be useful for ramping up the motors among other things. The sensors won't be interrupted by the "delay()."

How is Melbs? I was there at this time last year. I wish I was there now haha.
69  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 09:26:21 pm
Thanks, Nick. That's what I'm trying to do. In my previous post I said that the first bit example of code that I modified from arrch was working correctly. It isn't. I doesn't increment every 10ms; It increments as fast as it can. The "delay" functions aren't working.  I'll play with it a bit and see if I can get it to work. I know I shouldn't worry about it as the second posted code in my previous post works, but I just like to try to understand things. Maybe there will be a situation where I could modify the code into something useful.
70  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 09:11:19 pm
Code:
int led = 3;
int i = 0;
long interval = 10;
long previousMillis = 0;
int lastcheck = 0;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  unsigned long currentMillis = millis();
 for (int i=0;i<=255;i++)
{
  if (millis() - lastcheck > interval)
  {
    lastcheck = millis();
    analogWrite (led, i);
  }
  Serial.println (i);
}
}

The above code works as intended. It resets the led to 0 every time through the loop. The following code works in a different way. Once the led reaches 255, it stays there constantly lit. As I said a few times, I'm trying to learn different ways of implementing a delay without "delay()." That's why it "wasn't sticking."
Code:
int led = 3;
int i = 0;
long interval = 10;
long previousMillis = 0;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    analogWrite (led, i++);
    i = constrain (i,0,255);
    Serial.println (i);
  }
 // analogWrite (led, 0);
  //Serial.println (i);
}







71  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 08:30:32 pm
Thanks Billroy. That works. I had to add a line to constrain i to a maximum of 255.
 
Code:
int led = 3;
int i = 0;
long interval = 10;
long previousMillis = 0;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    i = min (i, 254);            sets pwm to 255 maximum
    analogWrite (led, i++);
    Serial.println (i);
  }
}


Although this works to turn the light on, I am still curious how to fix my origional code. Fading the light is just something I picked to try to get to understand the "blink without delay." That really was the origional question. I suppose the question is: how do I use the "blink without delay" with a for loop? Any ideas would be greatly appreciated
72  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 08:09:36 pm
I am trying to slow the loop down by trying to use the "blink without delay." Are you saying that there is no way to slow the for loop down without using delay()?
It does work without any delay() like this:
Code:
for (int i = 0; i <=255; i++){
    analogWrite (led, i);
    Serial.println (i);
73  Using Arduino / Programming Questions / Re: pwm with delay on: November 25, 2012, 07:53:16 pm
It doesn't take long at all to "rip" through the loop. The point isn't fading the led. The point is trying to understand "blink without delay" in a concept other than blinking a light.
74  Using Arduino / Programming Questions / pwm with delay on: November 25, 2012, 07:12:08 pm
Hello,

In order to try to get my head around the "blink without delay" concept, I have run into a wall. I am trying to use pwm to turn on the led and modify the blink without delay example to replace the "delay (50);" I think you can see what I'm trying to do through the code. Unfortunately the light never comes on and I always get 0 in the serial monitor. Can anybody shed some light for me? Thanks in advance.
I'm trying to replace this:
Code:
int led = 3;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  for (int i = 0; i <=255; i++){
    analogWrite (led, i);
    delay (50);  
    Serial.println (i);
  }
}

with this:
Code:
int led = 3;

long interval = 50;
long previousMillis = 0;

void setup()
{
  Serial.begin (9600);
  pinMode (led, OUTPUT);
}
void loop()
{
  unsigned long currentMillis = millis();

  for (int i = 0; i <=255; i++){
    if (currentMillis - previousMillis > interval) {
      previousMillis = currentMillis;
      analogWrite (led, i);

      Serial.println (i);
    }
  }
}
75  Using Arduino / Sensors / Re: Distance Sensor on: November 18, 2012, 09:01:43 pm
for people detection, you probably want the ez-0 or ez-1. But they aren't reliable for people detection. You would be better off buying a cheap ultrasonic sensor and try teckel's newping library.

http://code.google.com/p/arduino-new-ping/
Pages: 1 ... 3 4 [5] 6 7 ... 14