2

Author Topic: Need help with arduino--not exactly a robot  (Read 1564 times)

0 Members and 1 Guest are viewing this topic.

Offline schiz0idTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Need help with arduino--not exactly a robot
« on: June 03, 2010, 05:42:14 PM »
Hey all! I used to be on this forum as "geek1", then took a hiatus from robotics, and uh, here I am again! I have a question. My brother has issues sleepwalking. He has an alarm to alert him when he gets up--but it relies on a pressure sensor which isn't comfortable. I am attempting to build an alarm which uses an IR range sensor to sense when he gets up, then sounds a beeper. I am currently doing my source code experiments using an LED. I can't get it to work--the code follows.
Code: [Select]

int irReader = 1; // the analog input pin for the ir reader
int ledPin = 13;
int irVal = 0; // stores value from Ir reader
int irvalarr[23] = {286, 275, 263, 248, 222, 213, 154, 131, 150, 140, 138, 134,
                    138, 140, 150, 131, 154, 213, 222, 248, 263, 275, 286};

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);  // begins serial communication with the computer
}

void loop(int servtime) {
  irVal = analogRead(irReader);  // read the value from the ir sensor
  if (irVal <= irvalarr) {
    digitalWrite (ledPin, HIGH);
  }
  Serial.println(irVal);       // sends ir val to computer

}

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: Need help with arduino--not exactly a robot
« Reply #1 on: June 03, 2010, 08:43:02 PM »
It's because you initialize irvalarr as an array, and then compare it as if it where a number.


Change
Code: [Select]
int irvalarr[23] = {286, 275, 263, 248, 222, 213, 154, 131, 150, 140, 138, 134,
                    138, 140, 150, 131, 154, 213, 222, 248, 263, 275, 286};
to
Code: [Select]
int irvalarr = 512; //or some single number representing the alarm point

Offline schiz0idTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Need help with arduino--not exactly a robot
« Reply #2 on: June 04, 2010, 09:43:07 PM »
Thank you, however I have a new problem. Updated code:

Code: [Select]
int irReader = 1; // the analog input pin for the ir reader
int ledPin = 12;
int irVal = 0; // stores value from Ir reader
int irvalarr = 512;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);  // begins serial communication with the computer
}

void loop() {
  irVal = analogRead(irReader);  // read the value from the ir sensor
  if (irVal <= irvalarr) {
    digitalWrite (ledPin, HIGH);
  }
 
  else (irVal >= irvalarr); {
    digitalWrite (ledPin, LOW);
  }
 
  Serial.println (irVal);
}
I have also tried it as
Code: [Select]
int irReader = 1; // the analog input pin for the ir reader
int ledPin = 12;
int irVal = 0; // stores value from Ir reader
int irvalarr = 512;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);  // begins serial communication with the computer
}

void loop() {
  irVal = analogRead(irReader);  // read the value from the ir sensor
  if (irVal <= irvalarr) {
    digitalWrite (ledPin, HIGH);
  }
  Serial.println (irVal);
}
 
 

As the first one, it won't turn on. As the second, it won't turn off. Why is this? I've tried moving my hand back and forth dozens of times in front of the sensor and still no response from the LED.

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: Need help with arduino--not exactly a robot
« Reply #3 on: June 04, 2010, 10:43:39 PM »
Try this:

Code: [Select]
int irReader = 1; // the analog input pin for the ir reader
int ledPin = 12;
int irVal = 0; // stores value from Ir reader
int irvalarr = 512;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);  // begins serial communication with the computer
}

void loop() {
  irVal = analogRead(irReader);  // read the value from the ir sensor
 
if (irVal <= irvalarr)
    digitalWrite (ledPin, HIGH);
  else
    digitalWrite (ledPin, LOW);

 Serial.println (irVal);
 delay(100);
}

Remember, you might have to adjust the irvalarr number to get it to work.
« Last Edit: June 04, 2010, 10:45:06 PM by madsci1016 »

Offline schiz0idTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Need help with arduino--not exactly a robot
« Reply #4 on: June 05, 2010, 02:24:03 PM »
Try this:

Code: [Select]
int irReader = 1; // the analog input pin for the ir reader
int ledPin = 12;
int irVal = 0; // stores value from Ir reader
int irvalarr = 512;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);  // begins serial communication with the computer
}

void loop() {
  irVal = analogRead(irReader);  // read the value from the ir sensor
 
if (irVal <= irvalarr)
    digitalWrite (ledPin, HIGH);
  else
    digitalWrite (ledPin, LOW);

 Serial.println (irVal);
 delay(100);
}

Remember, you might have to adjust the irvalarr number to get it to work.
That solved it--although an interesting side note is that it actually needed to be
Code: [Select]
if (irVal >= irvalarr)

Offline schiz0idTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Need help with arduino--not exactly a robot
« Reply #5 on: June 06, 2010, 02:07:05 PM »
Actually, one last question. Do you happen to know the maximum input value for a Sharp IR rangefinder? I realized it would work better if the alarm could be tripped by stepping anywhere in the beam at all--and thus wanted to set the threshold as high as possible.

Offline schiz0idTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Need help with arduino--not exactly a robot
« Reply #6 on: June 06, 2010, 06:39:58 PM »
I'm sorry--LAST question. I'm having a new problem. The alarm is periodically going off--with nothing tripping it. Any ideas?


Thanks, maybe I'll move this to another thread.

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: Need help with arduino--not exactly a robot
« Reply #7 on: June 06, 2010, 06:51:06 PM »
The Sharp IR isn't perfect, there may be the occasional spike that triggers it. You could figure out a kind of moving-average system to reduce the effect of random spikes like that.

To help you with the "maximum value" we need to know what model Sharp IR you are using, since there are several.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Need help with arduino--not exactly a robot
« Reply #8 on: June 06, 2010, 09:47:54 PM »
Hi,

I'm sorry--LAST question. I'm having a new problem. The alarm is periodically going off--with nothing tripping it. Any ideas?
Did you consider other (simpler) sensors, like whether there's weight (his) on his bed?

Whichever sensor, you'd do well in averaging over time and only sound the alarm (light the LED) when you have had an alarm condition for perhaps 1 or 2 seconds (wouldn't stop it from working, as he's sleepwalking, not sleeprunning after all).

A capacitive sensors would be another option that won't be a nuisance to your brother, it can be made for next to nothing and your brother won't feel the sensor parts at all - and it only needs a controller if you absolutely want to include it, as simple CMOS gates will do nicely with no programming to go wrong.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline schiz0idTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Need help with arduino--not exactly a robot
« Reply #9 on: June 07, 2010, 01:01:16 PM »
You seem to overestimeate me. As I said in my initial post, about a year or two ago I would have understood all of this, but I sort of didn't do anything hardware-related at all during that time, and as such am insanely rusty.

1) How would I program averaging over time? and
2) Define "capacitave sensor"?

Also, I don't know how easy it would be to attach a weight sensor to the bed.

Hi,

I'm sorry--LAST question. I'm having a new problem. The alarm is periodically going off--with nothing tripping it. Any ideas?
Did you consider other (simpler) sensors, like whether there's weight (his) on his bed?

Whichever sensor, you'd do well in averaging over time and only sound the alarm (light the LED) when you have had an alarm condition for perhaps 1 or 2 seconds (wouldn't stop it from working, as he's sleepwalking, not sleeprunning after all).

A capacitive sensors would be another option that won't be a nuisance to your brother, it can be made for next to nothing and your brother won't feel the sensor parts at all - and it only needs a controller if you absolutely want to include it, as simple CMOS gates will do nicely with no programming to go wrong.


Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Need help with arduino--not exactly a robot
« Reply #10 on: June 07, 2010, 04:19:59 PM »
Hi,

You seem to overestimeate me. As I said in my initial post, about a year or two ago I would have understood all of this, but I sort of didn't do anything hardware-related at all during that time, and as such am insanely rusty.
It's like riding a bike, a few trips to the ER and you're back  ;)


1) How would I program averaging over time? and
It can be done several ways, but here's the rough outline:
Each time you take a sample, you store it in an array.
Then you add each element of the buffer and divide with the number of elements it holds.
Finally, you compare the result with a constant that defines something around the middle value of the full on and full off values. (and then either shift all elements of the array, dropping the "oldest" value, OR use a ring buffer and just update the "put in" and "take out" pointers).


2) Define "capacitave sensor"?
A sensor that senses changes in capacity  ;D
One way to produce it would be:
An oscillator running at eg. 1..2 MHz connected to a wire or a piece of foil under the sheets around upper torso height and a wire/foil around the height of the pelvic area going to a receiver.
That way, the signal will travel through your brother when he's there and will appear at the receiver.
One possible disadvantage is if he sweats a lot, it may seem like he's still there when he isn't

'Then oscillator and receiver can be connected through two small caps and a wire from their common node going under the wire (adjusted to positively detect when your brother grounds the weak signal capacitively.
I can redo a circuit for it, if you need it


Also, I don't know how easy it would be to attach a weight sensor to the bed.
It doesn't have to be anything fancy, just he's there/he's gone, so a microswitch under a bedspring or board can be used, just mount the microswitch so it is off when there's no weight on the bed (and the mount should be able to give of course)


Both methods work. I have tried both of them as part of a sleep pattern study. Simple does it.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline schiz0idTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Need help with arduino--not exactly a robot
« Reply #11 on: July 01, 2010, 08:31:27 AM »
The Sharp IR isn't perfect, there may be the occasional spike that triggers it. You could figure out a kind of moving-average system to reduce the effect of random spikes like that.

To help you with the "maximum value" we need to know what model Sharp IR you are using, since there are several.

2Y0A02

Offline schiz0idTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Need help with arduino--not exactly a robot
« Reply #12 on: July 01, 2010, 09:11:49 AM »
Hi,

You seem to overestimeate me. As I said in my initial post, about a year or two ago I would have understood all of this, but I sort of didn't do anything hardware-related at all during that time, and as such am insanely rusty.
It's like riding a bike, a few trips to the ER and you're back  ;)


1) How would I program averaging over time? and
It can be done several ways, but here's the rough outline:
Each time you take a sample, you store it in an array.
Then you add each element of the buffer and divide with the number of elements it holds.
Finally, you compare the result with a constant that defines something around the middle value of the full on and full off values. (and then either shift all elements of the array, dropping the "oldest" value, OR use a ring buffer and just update the "put in" and "take out" pointers).


2) Define "capacitave sensor"?
A sensor that senses changes in capacity  ;D
One way to produce it would be:
An oscillator running at eg. 1..2 MHz connected to a wire or a piece of foil under the sheets around upper torso height and a wire/foil around the height of the pelvic area going to a receiver.
That way, the signal will travel through your brother when he's there and will appear at the receiver.
One possible disadvantage is if he sweats a lot, it may seem like he's still there when he isn't

'Then oscillator and receiver can be connected through two small caps and a wire from their common node going under the wire (adjusted to positively detect when your brother grounds the weak signal capacitively.
I can redo a circuit for it, if you need it


Also, I don't know how easy it would be to attach a weight sensor to the bed.
It doesn't have to be anything fancy, just he's there/he's gone, so a microswitch under a bedspring or board can be used, just mount the microswitch so it is off when there's no weight on the bed (and the mount should be able to give of course)


Both methods work. I have tried both of them as part of a sleep pattern study. Simple does it.
A circuit would help.

 


Get Your Ad Here

data_list