Show Posts
Pages: 1 ... 8 9 [10]
136  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 06, 2013, 12:48:00 pm
The sketch is causing random movement more or less as intended.  Analog input from the Maxsonar sensor should control the speed of this random movement. The closer the viewer is to the sculpture, the faster the speed. After mapping the values, I don't understand how to write the sketch so that both the random number (pos1) and analog input (sonarVal)can be passed to the motor pins (servo/yservo).
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);
    delay(msec1);
   
    long msec2 = random(MIN_DELAY2,MAX_DELAY2);
    int pos2 = random(0,181);
    yservo.write(pos2);
    delay(msec1);
   
    Serial.println(sonarVal);
}

137  Using Arduino / Programming Questions / Re: MaxSonar EZ0 for servo speed control on: February 05, 2013, 10:25:49 pm
Yes, they move too fast but provide the kind of jerky movement necessary.  When the viewer approaches the sculpture, the servos should speed up. I want to use the analog values to control this transition.
138  Using Arduino / Programming Questions / MaxSonar EZ0 for servo speed control on: February 05, 2013, 08:20:13 pm
I am working on a sculpture that involves servos moving randomly but speed controlled by EZ0 analog input. This sketch runs the random sequence but linking speed to the sensor is a puzzle. Any suggestions?
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);
}

void loop () {
 
    sonarVal = analogRead(sonarPin);           
    sonarVal = map(sonarVal, 0, 1023, 1, 30);
   
 
    long msec1 = random(MIN_DELAY1,MAX_DELAY1);
    int pos1 = random(0,181);
    xservo.write(pos1);
    delay(msec1);
   
    long msec2 = random(MIN_DELAY2,MAX_DELAY2);
    int pos2 = random(0,181);
    yservo.write(pos2);
    delay(msec1);
}
139  Using Arduino / General Electronics / Re: LM317 regulating voltage but no current! on: February 05, 2013, 02:36:38 am
I should have avoided details about the motor because they digress from the immediate problem: Why is the circuit regulating voltage but killing the current? I'm using a 240 ohm resistor and 5k pot.
140  Using Arduino / General Electronics / Re: LM317 regulating voltage but no current! on: February 04, 2013, 10:07:38 pm
I set the multimeter to measure the resistance (through the multimeter) while under load. In any case, my circuit is adjusting voltage, but killing current. After reviewing the tutorials, there seems to be no mention of how to fix the current while regulating the voltage.
141  Using Arduino / General Electronics / Re: LM317 regulating voltage but no current! on: February 04, 2013, 09:14:59 pm
Sorry, I am not experienced. The 53 was the load taken while running it off the battery.
142  Using Arduino / General Electronics / Re: LM317 regulating voltage but no current! on: February 04, 2013, 09:00:59 pm
Should have added that I want to use this circuit as a benchtop adjustable power supply for a variety of applications. 
143  Using Arduino / General Electronics / LM317 regulating voltage but no current! on: February 04, 2013, 08:51:47 pm
I have used the typical LM317 circuithttp://www.ee.buffalo.edu/courses/elab/LM117.pdf with a salvaged, 30v printer power supply. It adjusts voltage but there is absolutely no measureable current. Can't turn a small motor that runs easily on a 9v battery at 53 mV. If I replace this circuit with the current limiting configuration, won't the amp burn components? 
144  Using Arduino / Programming Questions / Re: random direction L298 driver on: January 30, 2013, 06:06:26 pm
If I use the "two state", I assume a delay for the minimum duration is necessary?
145  Using Arduino / Programming Questions / Re: random direction L298 driver on: January 30, 2013, 01:39:38 pm
Yes, I have a sketch that runs the motor in different directions by alternating the two pins - HIGH/LOW - LOW/HIGH. The problem is random direction.  I wonder if a dumb dumb method might involve creating random numbers of say, 1000, then an "if", "else" statement that runs the motor forward >500, or backward <500? 
146  Using Arduino / Programming Questions / random direction L298 driver on: January 30, 2013, 11:40:32 am
I am using a Solarbotics L298 driver board to run a geared motor, random direction, random speed. The speed should be determined by an Max sonar sensor. The sketch stops randomly, but direction is only one way and doesn't respond to the sensor which reads 120 ~ 15. Must be doing just about everything wrong! I have scoured the web for examples have found nothing helpful.
Code:
int randNumberDir;  // variable to store the random direction value
int motorSpeed = 8; // motor speed
int motorDir = 9; // motor direction
long previousMillis =0;
long interval = 500;
int enable = 10;
int sonarPin =A0;
int value;

void setup()
{
Serial.begin(9600);

randomSeed(millis());

pinMode(motorSpeed,OUTPUT);
pinMode(motorDir,OUTPUT);
pinMode(sonarPin,INPUT);

digitalWrite(motorSpeed,HIGH);
digitalWrite(motorDir,HIGH);
digitalWrite(enable,HIGH);
}
void loop()
{
randNumberDir = random(255); // random number from 0-255
analogWrite(motorDir, randNumberDir); // outputs PWM signal
delay(500); // pauses for half a second

value = analogRead(sonarPin);
Serial.println(value);

int motor_speed = value/4;
analogWrite(motorSpeed,motor_speed);
}
void motorStop(){

if(millis() - previousMillis  > interval) {
   digitalWrite(motorDir,HIGH);
   digitalWrite(motorSpeed,LOW);
   digitalWrite(enable,LOW);
   previousMillis = millis();
}
delay(1000);

}

 

Pages: 1 ... 8 9 [10]