Pages: 1 2 [3] 4   Go Down
Author Topic: Blinking LEDS with motion sensor  (Read 3174 times)
0 Members and 1 Guest are viewing this topic.
London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is what I was told by the tech guy from the shop

"You can still use this sensor without using the serial interface with your Arduino. There is an analog output (10mV/inch) which you can easily read with an analog input pin on your Arduino"

Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 34488
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok I missed that bit on the spec sheet. That makes it a lot simpler.
Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

he has written back and said

"On closer inspection of the data sheet it looks as though the serial output is at the TTL level"

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26465
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My reading of it is that there's an analogue output, a PWM TTL output (pulse width proportional to range) and an RS232 interface, I guess for setup.

Edit: scratch that, the RS232 is output only, with range messages.
I'd go with the PWM output and use pulseIn to time it.
That is a confusing data sheet!
« Last Edit: September 29, 2011, 11:36:29 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, so i am really confused now, has anyone got an example of how it would be connected to the arduino
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26465
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just connect a digital input pin on the Arduino to "PW" on the sensor, connect power and ground and use "pulseIn".
Or, connect an analogue input on the Arduino to "AN" on the sensor, connect power and ground and use "analogRead"
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so i dont need to purchase an RS232 Shifter?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26465
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Big thankyou :-) smiley smiley smiley smiley
Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all, so I got my maxsonar EZ0, and i am getting readings from it using Analogue, I found this example which lights up the LED as u get closer and gave it a try

/*
From the datasheet of the The LV-MaxSonar-EZ0 the output analog
voltage with a scaling factor of (Vcc/512) per inch.
A supply of 5V yields ~9.8mV/in. and 3.3V yields ~6.4mV/in.
The output is buffered and corresponds to the most recent range data.
http://www.maxbotix.com/uploads/LV-MaxSonar-EZ0-Datasheet.pdf
*/

// pin connected to analog output on maxsonar sensor
int sonarPin = 0;
// pin connected to digital output on red led
int ledPin = 7;

void setup() {
  Serial.begin(9600);  // sets the serial port to 9600
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // The Arduino’s analog-to-digital converter (ADC) has a range of 1024,
  // which means each bit is ~4.9mV.
  // Therefore, to convert the number returned by the ADC to inches, wet
  // have to divide by 2.
  // To convert to cm is necessary to divide by 0.3937.
  // 1 centimeter = 0.3937 inch
  int distance = analogRead(sonarPin)/(2*0.3937);

  Serial.print(distance, DEC); // prints the value read
  Serial.println("cm");
  // If something is at a distance less than 20 cm than LED lights up.
  if(distance > 300) {
    digitalWrite(ledPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(ledPin, LOW);
    delayMicroseconds(500);
  }
}

it seems to work well, but when I look at the numbers in the serial monitor, the numbers get higher as I get closer, also the readings can be a little erratic, can someone help me modify this to a PW, when I tried i just got no readings at all
Logged

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, so I have made some progress and managed to merge some code which works for detecting movement, Grumpy Mike wrte some code for me which was for the Sharp sensor, I am struggling to get the code implemented into my sketch, here is what I have sketched to detect movement and turn the LED on, please help me to change it so that the LEDs are blinking and then the blinking speeds up as the movement is detected


/*
From the datasheet of the The LV-MaxSonar-EZ0 the output analog
voltage with a scaling factor of (Vcc/512) per inch.
A supply of 5V yields ~9.8mV/in. and 3.3V yields ~6.4mV/in.
The output is buffered and corresponds to the most recent range data.
http://www.maxbotix.com/uploads/LV-MaxSonar-EZ0-Datasheet.pdf
*/

// pin connected to analog output on maxsonar sensor
int sonarPin = 7;
// pin connected to digital output on red led
int ledPin = 9;

void setup() {
  Serial.begin(9600);  // sets the serial port to 9600
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // The Arduino’s analog-to-digital converter (ADC) has a range of 1024,
  // which means each bit is ~4.9mV.
  // Therefore, to convert the number returned by the ADC to inches, wet
  // have to divide by 2.
  // To convert to cm is necessary to divide by 0.3937.
  // 1 centimeter = 0.3937 inch
  int distance = pulseIn(sonarPin, HIGH)/(2*0.3937);

  Serial.print(distance, DEC); // prints the value read
  Serial.println("cm");
  // If something is at a distance less than 20 cm than LED lights up.
  if(distance < 10000) {
    digitalWrite(ledPin, HIGH);
    delayMicroseconds(5000);
    digitalWrite(ledPin, LOW);
    delayMicroseconds(5000);
  }
}
attached is the breadboard image


* pwm_turnLEDon_bb.jpg (59.61 KB, 1035x718 - viewed 3 times.)
« Last Edit: October 18, 2011, 02:00:09 pm by TheVerse » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26465
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It would be useful if you could re post that properly, without the italics.
Use the # icon on the editor's toolbar.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, so I have made some progress and managed to merge some code which works for detecting movement, Grumpy Mike wrote some code for me which was for the Sharp sensor, I am struggling to get the code implemented into my sketch, here is what I have sketched to detect movement and turn the LED on, please help me to change it so that the LEDs are blinking and then the blinking speeds up as the movement is detected
Code:
/*
From the datasheet of the The LV-MaxSonar-EZ0 the output analog
voltage with a scaling factor of (Vcc/512) per inch.
A supply of 5V yields ~9.8mV/in. and 3.3V yields ~6.4mV/in.
The output is buffered and corresponds to the most recent range data.
http://www.maxbotix.com/uploads/LV-MaxSonar-EZ0-Datasheet.pdf
*/

// pin connected to PW output on maxsonar sensor
int sonarPin = 7;
// pin connected to digital output on red led
int ledPin = 9;

void setup() {
  Serial.begin(9600);  // sets the serial port to 9600
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // The Arduino’s analog-to-digital converter (ADC) has a range of 1024,
  // which means each bit is ~4.9mV.
  // Therefore, to convert the number returned by the ADC to inches, wet
  // have to divide by 2.
  // To convert to cm is necessary to divide by 0.3937.
  // 1 centimeter = 0.3937 inch
  int distance = pulseIn(sonarPin, HIGH)/(2*0.3937);

  Serial.print(distance, DEC); // prints the value read
  Serial.println("cm");
  // If something is at a distance less than 20 cm than LED lights up.
  if(distance < 10000) {
    digitalWrite(ledPin, HIGH);
    delayMicroseconds(5000);
    digitalWrite(ledPin, LOW);
    delayMicroseconds(5000);
  }
}




attached is the breadboard image
« Last Edit: October 18, 2011, 02:35:36 pm by TheVerse » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26465
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're not using the A/D converter, so the comments about it are a waste of space.
It is a useful side effect that pins default to inputs, because otherwise you'd have to write another pinMode.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry, I will re-edit the comments. I am a contemporary artist, and I have no background in electronics at all, rather than just pay someone to do it for me I am doing my best to learn. I know some of the things I have asked are really obvious, but I am really new to this and doing my best  smiley-confuse but appreciate the help I have gotten of this forum.
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: