Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
int irReader = 1; // the analog input pin for the ir readerint ledPin = 13;int irVal = 0; // stores value from Ir readerint 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}
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};
int irvalarr = 512; //or some single number representing the alarm point
int irReader = 1; // the analog input pin for the ir readerint ledPin = 12;int irVal = 0; // stores value from Ir readerint 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);}
int irReader = 1; // the analog input pin for the ir readerint ledPin = 12;int irVal = 0; // stores value from Ir readerint 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);}
int irReader = 1; // the analog input pin for the ir readerint ledPin = 12;int irVal = 0; // stores value from Ir readerint 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);}
Try this:Code: [Select]int irReader = 1; // the analog input pin for the ir readerint ledPin = 12;int irVal = 0; // stores value from Ir readerint 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.
if (irVal >= irvalarr)
I'm sorry--LAST question. I'm having a new problem. The alarm is periodically going off--with nothing tripping it. Any ideas?
Hi,Quote from: schiz0id on June 06, 2010, 06:39:58 PMI'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.
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.
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.
Hi,Quote from: schiz0id on June 07, 2010, 01:01:16 PMYou 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 Quote from: schiz0id on June 07, 2010, 01:01:16 PM1) How would I program averaging over time? andIt 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).Quote from: schiz0id on June 07, 2010, 01:01:16 PM2) Define "capacitave sensor"?A sensor that senses changes in capacity 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 itQuote from: schiz0id on June 07, 2010, 01:01:16 PMAlso, 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.