Show Posts
Pages: 1 ... 7 8 [9] 10
121  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 07, 2013, 07:44:29 pm
I bought a 1.5 amp/5v wall wart that seems to resolve power, uploading, and serial monitor problems. This sketch is working minimally, but is a little jerky and subject to quivering but it is close to the goal. The map/constrain values are the result of guesswork.
Code:
#include <Servo.h>

#define PIN_SERVO1 9
#define PIN_SERVO2 10
#define MIN_DELAY1 230
#define MAX_DELAY1 550
#define MIN_DELAY2 230
#define MAX_DELAY2 550

int sonarPin = A0;
int sonarVal =0;

Servo xservo;
Servo yservo;


void setup() {
  xservo.attach(9);
  yservo.attach(10);
  Serial.begin (9600);
  delay(50);//50
}

void loop () {
 
    sonarVal = analogRead(sonarPin);
    sonarVal = sonarVal *5;
    sonarVal = constrain(sonarVal, 200, 500);   
    sonarVal = map(sonarVal, 200, 800, 200, 1500);//  1500
   Serial.println(sonarVal);
   delay(50);
   
  if ((sonarVal < 800) && (sonarVal > 300))
  {
    long msec1 = random(MIN_DELAY1,MAX_DELAY1);
    int pos1 = random(0,181);
    xservo.write(pos1);
    delay(sonarVal);
   
    long msec2 = random(MIN_DELAY2,MAX_DELAY2);
    int pos2 = random(0,181);
    yservo.write(pos2);
    delay(sonarVal);
  }
 
}

122  Using Arduino / Motors, Mechanics, and Power / Tower pro SG 5010 servo current on: February 07, 2013, 04:12:25 pm
I have been powering a hobby servo from an Arduino but want to use an external source - a wall wart, 8v/500mA regulated with a 7806. This fails to run the servo. Nor does a 9v battery. I've read that these typically need as much as one amp each.  The project needs three. Any ideas?
123  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 07, 2013, 03:12:08 pm
I have tried to power the servos several times from external supplies but without success, with both a wall wart and 9v battery, Arduino ground connected.
124  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 07, 2013, 02:50:02 pm
I used a 7806 to regulate the voltage. Looks better?http://www.flickr.com/photos/50454200@N06/8454294456/
125  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 07, 2013, 02:15:24 pm
Yes. Do I need a regulated 5 or 6v to power the servos? I have a wall wart with min 7v.
126  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 07, 2013, 11:50:00 am
The sketch runs fine for a second or two, then stops. The serial monitor is not printing sensor values.  Here is a not so clean photo http://www.flickr.com/photos/50454200@N06/8453876230/ of the armature, none of which will be visible when the piece is complete. Thanks again.
127  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 10:27:22 pm
How about something real simple like "if" statements that would cover the entire range of values from the sensor. Probably no more than ten would suffice. Starting with the max reading, the value is 400. The delay will be "x"? 350 next.....with increments of 50 down to 100, the min distance from the sculpture.
128  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 10:09:33 pm
Too fast will cause the piece to convulse. Let's say two seconds max.The sketch above is about right in terms of speed. There is also a question of noise with faster movement.
129  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 09:34:58 pm
Found this sketch. Runs a smooth random direction, a little different than I had envisioned but is quiet. I don't know how to link the delay intervals to the sensor values.
Quote

#include <Servo.h>
 
Servo myservo; 
unsigned int duration = 0;             
int lasttime1 = 0;
int lasttime2 = 0;
int randstart = 0;
int randend = 0;
int pos = 0;   
void setup()
{
  myservo.attach(10); 
  Serial.begin(9600);
 

}
 
 
void loop()
{

lasttime1 = millis();

  randstart =  random(554, 1054);
  randend =  random(500, 2400);

  while(pos <= randend) 
  {                               
    pos += 1;
    myservo.writeMicroseconds(pos);           
    delay(2);                   
  }
 
duration = millis() - lasttime1;
Serial.println(duration);
lasttime2 = millis();
 
  while(pos >= randstart)   
  {                               
    pos-=1;
    myservo.write(pos);           
    delay(2);                     
  }

duration = millis() - lasttime2;
Serial.println(duration);
 
duration = millis() - lasttime1;
Serial.println(duration);

Serial.println();



}
130  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 08:24:56 pm
Quote
or do you intend that it will move to the new position at some higher speed, and then stop and wait before the next movement starts?
This option would seem to involve more start and stop which is the better choice but either would work so long as their is a transition as the viewer walks closer. Light and sound will also fade in and out.

This has become an interesting study of "verbal polarity" - the language of technology and sculpture.
131  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 06:58:47 pm
Quote
Do you mean you want to control the interval between movements?
Yes, as the viewer approaches the sculpture, the interval between movements will be less and the motors will move faster determined by the value of the sensor. I appreciate your help. I am honestly not trying to be evasive. An art education doesn't help much here!
132  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 05:14:49 pm
When I cut and paste these numbers in a new sketch for testing, the serial monitor prints expected values, but the serial monitor either prints nothing or garbage within the original sketch.
Code:
 
sonarVal = analogRead(sonarPin);
    sonarVal = sonarVal *4;
    sonarVal = constrain(sonarVal, 100, 300);   
    sonarVal = map(sonarVal, 300, 100, 255, 0);
133  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 04:59:57 pm
Quote
Do you mean you want to control the speed of rotation of the servo as it moves from one position to the next?

Yes

Quote
Do you mean you want to control the interval between movements?

No

Quote
Do you mean you want to control the interval between movements?

Yes

The xservo/yservo.write creates the movement I want. For some reason, the serial monitor isn't printing correctly (lots of garbage) and I can't upload without removing all the wire from pins.
134  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 04:07:54 pm
Oops! Spoke to soon. While the sketch does deliver the correct behavior, it somehow corrupts the IDE so further adjustments can't be uploaded without clearing all pins. Worse still, the serial monitor is printing illegible garbage so further tweaking of the numbers is impossible.  What could be causing this? Is it choking on random numbers?
135  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 01:30:03 pm
If only I were capable of articulate explanation, I am sure you could have easily solved the problem.  This seems to do the trick. Thanks.
Code:
#include <Servo.h>

#define PIN_SERVO1 9
#define PIN_SERVO2 10
#define MIN_DELAY1 130
#define MAX_DELAY1 350
#define MIN_DELAY2 130
#define MAX_DELAY2 350

int sonarPin = A1;
int sonarVal =0;

Servo xservo;
Servo yservo;


void setup() {
  xservo.attach(9);
  yservo.attach(10);
  Serial.begin (9600);
}

void loop () {
 
    sonarVal = analogRead(sonarPin);
    sonarVal = sonarVal *4;
    sonarVal = constrain(sonarVal, 100, 300);   
    sonarVal = map(sonarVal, 300, 100, 255, 0);
   
 
    long msec1 = random(MIN_DELAY1,MAX_DELAY1);
    int pos1 = random(0,181);
    xservo.write((pos1, sonarVal));
    delay(msec1);
   
    long msec2 = random(MIN_DELAY2,MAX_DELAY2);
    int pos2 = random(0,181);
    yservo.write((pos2,sonarVal));
    delay(msec1);
   
    Serial.println(sonarVal);
}

Pages: 1 ... 7 8 [9] 10