Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: multiple ping Sensors on: March 17, 2013, 08:27:53 pm
wow, THANK YOU SOOO MUCH!!
Much appreciated
2  Using Arduino / Project Guidance / Re: multiple ping Sensors on: March 13, 2013, 09:22:04 pm
Code:

#include <Servo.h>
Servo LFTleg;
Servo RGTleg;
Servo Tail;
Servo Frontpaw;

const int buttonPin = 2;
int pingPin = 7;
int pingPin2 = 12;
int pingPin3 = 4;
const int ledPin = 13;
int speakerPin = 3;
int buttonState = 0;
int length = 15;
char notes[] = "ccggaagffeeddc";
int beats [] = {1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2);
digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);

}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1519, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
 
   for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}
 
  // play the tone corresponding to the note name



void setup()
{
  Serial.begin(115200);
  pinMode (ledPin, OUTPUT);
  LFTleg.attach(9);
  RGTleg.attach(10);
  Tail.attach(11);
  Frontpaw.attach(6);
  pinMode(speakerPin, OUTPUT);
pinMode(buttonPin, INPUT);
}


void loop()
{
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // We give a short LOW pulse beforehand to ensure a clean HIGH pulse.
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
 
  pinMode(pingPin2, OUTPUT);
  digitalWrite(pingPin2, LOW);
  delayMicroseconds(2);
 
  pinMode(pingPin3, OUTPUT);
  digitalWrite(pingPin3, LOW);
  delayMicroseconds(2);
 
 
 
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  digitalWrite(pingPin2, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin2, LOW);
 
  digitalWrite(pingPin3, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin3, LOW);
  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  pinMode(pingPin2, INPUT);
  pinMode(pingPin3, INPUT);
 
  duration = pulseIn(pingPin, HIGH);
  duration = pulseIn)pingPin2, HIGH);
  duration = pulseIn)pingPin3, HIGH);
 
 
  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
 
 
  if (inches <= 60) {
    digitalWrite (speakerPin, LOW);
    digitalWrite (ledPin, HIGH);
    LFTleg.write(50);
    RGTleg.write(50);
    Tail.write(50);
    Frontpaw.write(90);
  }
   {
   buttonState = digitalRead(buttonPin);
   if (buttonState == HIGH) {         
    LFTleg.write(110);
    RGTleg.write(110);
    Frontpaw.write(80);
    delay(3000);

   }
  else {
    digitalWrite (speakerPin, HIGH);
    for (int i = 0; i < length; i++)
      playNote(notes[i], beats[i] * tempo);
    delay(tempo / 2);
    digitalWrite (ledPin, LOW);
    LFTleg.write(90);
    RGTleg.write(90);
    Tail.write(90);
    Frontpaw.write(70);
  }

}}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 73.746 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}



I did what you said but I'm still stuck on the
void loop


if i wanted to set 3 ping sensors to work seperately like

if pingsensor 2  === read object
digital.write XXX

and if pinsensor 3 === read object
digital.write yyy

Sorry for my bad explanation smiley-cry
3  Using Arduino / Project Guidance / multiple ping Sensors on: March 13, 2013, 08:48:05 pm
Hi, I'm a beginner programmer with little knowledge regarding computer programming smiley-lol
I wanted to make 3 ping sensors read the values in inches
and through the guidebook, I could make one ping sensor work
I wanted to implement this to a servo so if the ping sensor reads someone, the servo will respond
because this was basic, it worked smiley-wink
now i want to make 3 ping sensors to work and read the values separately
However, I couldn't think of any way to code this project and i'm in lost
I would appreciate any help to how I can code this from any experienced programmer
thanx in advance 8 smiley-sweat
4  Using Arduino / Project Guidance / Re: Piezo music element to ping on: March 11, 2013, 08:46:43 pm
I tested the piezo element and it played the star wars theme just fine  smiley-fat
I think there's a problem with my code but I can't specifically point out what's wrong cuz i am a novice smiley-eek-blue
any more suggestions?
5  Using Arduino / Project Guidance / Piezo music element to ping on: March 03, 2013, 09:16:37 pm
Hi, I am a beginner programmer with abysmal knowledge on the correct terminologies of arduino so excuse me for my cheap terms. smiley-sweat
I am currently working on a piezo music element which plays a melody when the ping sensor detects 'nothing' within its vicinity(If an object is within 60 inches, it turns off). I just pasted the piezo music code in to the ping sensor code and fortunately it works smiley-yell. But the piezo only makes a 'beep, beep beep' sound continously without making any noticeable melody notes which wasn't a surprise. This is the code(I think you can ignore the servo and led pins, they are extravaganza stuff)
Code:
#include <Servo.h>
Servo LFTleg;
Servo RGTleg;
Servo Tail;
Servo Frontpaw;

int pingPin = 7;
const int ledPin = 13;
int speakerPin = 3;

int length = 15;
char notes[] = "ccggaagffeeddc";
int beats [] = {1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2);
digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);

}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1519, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  
   for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}
  
  // play the tone corresponding to the note name



void setup()
{
  Serial.begin(115200);
  pinMode (ledPin, OUTPUT);
  LFTleg.attach(9);
  RGTleg.attach(10);
  Tail.attach(11);
  Frontpaw.attach(6);
  pinMode(speakerPin, OUTPUT);
}


void loop()
{
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // We give a short LOW pulse beforehand to ensure a clean HIGH pulse.
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  if (inches <= 60) {
    digitalWrite (speakerPin, LOW);
    digitalWrite (ledPin, HIGH);
    LFTleg.write(50);
    RGTleg.write(50);
    Tail.write(50);
    Frontpaw.write(90);
  }
  else {
    digitalWrite (speakerPin, HIGH);
    for (int i = 0; i < length; i++)
      playNote(notes[i], beats[i] * tempo);
    delay(tempo / 2);
    
    
    digitalWrite (ledPin, LOW);
    LFTleg.write(90);
    RGTleg.write(90);
    Tail.write(90);
    Frontpaw.write(70);
  }

}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 73.746 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
Any suggestions from an experienced programmer? And can you tell me how and why the code is malfunctioning?
I want to know for further projects, thanks! smiley
6  Using Arduino / Sensors / ping sensor to 6 led on: October 04, 2012, 09:22:37 pm
i'm a starter in Arduino programs and I wanted to make the pingsensor convert distance to brightness for 6 led lights all at once
I've finished the code with the help of my teacher but the only led that works is pin 5
Is anyone experienced in understanding malfunctions within the code?
Thanks in advance

Code:
const int PingPin = 7;     //sets signal pin for the PING
 
int ledPins[] = {3,5,6,9,10,11};
 
int brightness = 0;

 
 
void setup()

{
 
 for(int i = 0; i <= 6; i++)
pinMode(ledPins[i],OUTPUT);
  Serial.begin(115200); //Sets up serial should you need it

 
 
 
}
void loop()
{
   int i = 0; i <= 6; i++;
  digitalWrite(ledPins[i], LOW);

int cm = findDistance();  //calls down to the code block at the bottom of the sketch to run the Ping and find CM
 
if (cm >50 || cm ==0)
 
  {
 
    digitalWrite(ledPins[i], LOW);
 
    Serial.println("OFF");
 
    delay(100);
 
   int cm = findDistance();

  }
 
else
 
{
 
 
 
   brightness = map(cm, 50, 0, 0,255);

 
 
  Serial.print(cm);
 
  Serial.println("cm, ");

  Serial.print("brightness = ");
 
  Serial.println(brightness);
 
 
 
  analogWrite(ledPins[i], brightness);
 
  delay(100);
 
  int cm = findDistance();
 
}
 
}
 
 
 
// When this block of code is called, it runs the PING sensor and returns CM
 
int findDistance()

{
 
  long duration, inches, cm;
 
  pinMode(PingPin, OUTPUT);
 
  digitalWrite(PingPin, LOW);
 
  delayMicroseconds(2);
 
  digitalWrite(PingPin, HIGH);
 
  delayMicroseconds(5);          // The same pin is used to read the signal from the PING))): a HIGH
 
  digitalWrite(PingPin, LOW);   // pulse whose duration is the time (in microseconds) from the sending
 
  pinMode(PingPin, INPUT);   // of the ping to the reception of its echo off of an object.
 
 
 
  duration = pulseIn(PingPin, HIGH);

 
 
  cm = duration / 29 / 2; // convert the time into a distance
 
 
 
 
 
 
 
  return cm; // sends CM back to the block that called it
 
}
 
 
7  Using Arduino / Sensors / Re: Ping sensor to light dim/brighten on: September 30, 2012, 08:26:06 pm
wow thanks a lot really i appreciate it
8  Using Arduino / Sensors / Ping sensor to light dim/brighten on: September 26, 2012, 08:16:33 pm
Hi i'm a beginner in using Arduino programs. I've successfully merged the codes for Ping Sensor and 8 Leds
My codes allows my 8 leds to fade when far away and brighten up when closed up
However my leds stay bright even when noone is there
I've programmed it to say dim as long as 300cm but there was no change
Code:
const int pingPin = 7;
int ledPins[] = {3,5,6,9,10,11};
int brightness;
void setup() {
  brightness = 0;
  // initialize serial communication:
  Serial.begin(9600);
  for(int i = 0; i < 6; i++){         //this is a loop and will repeat eight times
  pinMode(ledPins[i],OUTPUT);
 }
}

void loop()
{
  for(int i = 0; i < 6; i++) {
  digitalWrite(ledPins[i], LOW);}

  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
 
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
 
  delay(5);
 
  brightness = map(cm, 300, 0, 0, 255);
    for(int i = 0; i < 6; i++) {
  analogWrite(ledPins[i], brightness);
   
}
  {
  while (cm>300)
  brightness = 0;}
  for(int i = 0; i < 6; i++) {
  analogWrite(ledPins[i], brightness);
}
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

I'll be extremely grateful if someone can assist me to change the codes so the led lights will stay dim/off
when no one is there(By that, I mean when the Ping Sensor does not read anyone near it)
9  Using Arduino / Sensors / Re: Ping sensor light on: September 16, 2012, 09:17:07 pm
well teckel for a grumpy little kid like you, i don't need ur help smiley
so don't think anyone would appreciate ur help smiley-lol
10  Using Arduino / Sensors / Re: Ping sensor light on: September 15, 2012, 08:02:10 am
thanks but i have a ping sensor and i want to combine the ping sensor code with the led light code smiley
11  Using Arduino / Sensors / Ping sensor light on: September 12, 2012, 09:19:58 pm
Hi i'm a new user of the Arduino program
I want to make a led light which reacts to the ping sensor as I get closer
For instance, If i get closer the light will get brighter and fader when I'm far
I have little knowledge in codes or wires so internet research was of little use
can anyone be helpful enough to show me the codes and the breadboard layout of the ping sensor to light
for Arduino Uno??   smiley-confuse
Pages: [1]