Show Posts
Pages: 1 ... 1068 1069 [1070] 1071 1072 ... 1859
16036  Using Arduino / Programming Questions / Re: Sonar sensor to arduino to servo on: March 15, 2012, 04:50:20 am
Think of arrays as a row of houses.

You can refer to any house simply by specifying the house number (the number in the square brackets).

Quote
got stuck up here
I'm sorry, but from here, I can't see what you're stuck on, so you'll have to show me.
16037  Using Arduino / Programming Questions / Re: Sonar sensor to arduino to servo on: March 15, 2012, 04:16:54 am
Quote
now my problem is comparing the ranges, and after that the servo will face the nearest range
That is much, much simpler, now that you have an array.
16038  Using Arduino / Programming Questions / Re: Sonar sensor to arduino to servo on: March 15, 2012, 03:26:00 am
Simplified, but uncompiled and untested.
Code:
#include <Servo.h>
const int trigger=3;
const int echo=2;
const int nAngles = 5;

Servo xServo;
const int angles [nAngles] = {0, 45, 90, 135, 180};
float ranges [nAngles];

void setup()
{
  Serial.begin(9600);
  pinMode(trigger,OUTPUT);
  pinMode(echo,INPUT);
  xServo.attach(10);
}

void loop()
{
  for (int i = 0; i < nAngles; ++i) {
    xservo.Write (angles [i]);
    delay (500);
    ranges [i] = getRange ();  
    delay(50);
  }

  for (int i = 0; i < nAngles; ++i) {
    Serial.println(ranges [i]);
  }
}

float getRange ()
{
  digitalWrite(trigger,LOW);
  delayMicroseconds(5);
  digitalWrite(trigger,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger,LOW);
 
  return pulseIn(echo,HIGH) * 0.0001657;
}
16039  Using Arduino / Programming Questions / Re: Sonar sensor to arduino to servo on: March 15, 2012, 03:16:06 am
Quote
but it does not stores the data from the sensor.
See my last comment.

Stop calling me "sir".
16040  Using Arduino / Programming Questions / Re: Sonar sensor to arduino to servo on: March 15, 2012, 03:06:29 am
Quote
but its not working.
That's really, really not helpful.
Describe to us what "working" means to you, and how you code's behaviour differs from that definition.

Code:
distance = a;
Did you mean:
Code:
a = distance;
?
16041  Using Arduino / Programming Questions / Re: Sonar sensor to arduino to servo on: March 15, 2012, 02:56:50 am
Quote
d storing the ranges sensed by the sensor into variables.
an array would be much simpler.
Post your code and we'll see what we can do.
16042  Using Arduino / Programming Questions / Re: DC MOTOR on: March 14, 2012, 04:34:33 pm
Can you tell us what you want to do?
16043  Using Arduino / Programming Questions / Re: DC MOTOR on: March 14, 2012, 02:04:24 pm
But you know what speed the motor is going, because you wrote it to the PWM
16044  Using Arduino / General Electronics / Re: Potentiometer to change speed of DC motor on: March 14, 2012, 12:14:30 pm
Can you simply turn the motor on and off using a digitalWrite to the transistor pin?
16045  Using Arduino / General Electronics / Re: Potentiometer to change speed of DC motor on: March 14, 2012, 10:56:10 am
Oops, sorry, posting on a mobile with no proper scroll - I only saw zeroes.
Apologies.
16046  Community / Bar Sport / Re: So many members... on: March 14, 2012, 10:20:29 am
Quote
, Given AWOL's scrutinizing and eliminating POST COUNT BUMPING
Ni$hant: If you have an issue with the guidlines, I suggest you reacquaint yourself with them here

(BTW, your post the other day about my age? Like most things I post here, I made it up smiley-wink
16047  Using Arduino / General Electronics / Re: Potentiometer to change speed of DC motor on: March 14, 2012, 10:16:36 am
That's not good.
Looks like a direct short to ground - what happens if you completely disconnect your pot?
16048  Using Arduino / General Electronics / Re: Potentiometer to change speed of DC motor on: March 14, 2012, 09:46:31 am
Try this and see what the serial monitor prints:
Code:
const int potPin = 0;           // Analog in 0 connected to the potentiometer
const int transistorPin = 9;     // PWM Pin 9 connected to the base of the transistor

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

void loop()
{
  int potValue = analogRead(potPin) / 4;
  Serial.println (potValue);
  analogWrite(transistorPin, potValue);
  delay (200);
}
16049  Using Arduino / Networking, Protocols, and Devices / Re: Wireless audio streaming to arduino+WiFly on: March 14, 2012, 07:59:22 am
DO NOT CROSS-POST
16050  Using Arduino / Programming Questions / Re: int to char question on: March 14, 2012, 07:43:23 am
Quote
It does work...but only partially
That's...partially helpful
Pages: 1 ... 1068 1069 [1070] 1071 1072 ... 1859