Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Sensor Values on: March 20, 2013, 04:33:39 pm
Hello All

Im working with a stretch sensor here and im trying to attach a percentage value to the analog value. I have done this (only part of the code). the problem im having is it will print all of the values 10%-100% rather than only printing the current value. I know that i need to create a range or some type only i forget what that is called in computer language... basically i need to create 

if(sensorValue >800 but below 804) than print out 0%, and so forth for the rest 10%-100%. i need to put this into all of my if statements so they are no longer true.

any thoughts on the best way to do this?


Code:
{
    if(sensorValue>800){ //You can change the number here to adjust the threshold.
      Serial.print("Straight - 0%");
    }

    //10

    if(sensorValue>805){ //You can change the number here to adjust the threshold.
      Serial.print("Straight - 10%");
    }

    //20

    if(sensorValue>810){ //You can change the number here to adjust the threshold.
      Serial.print("20%");
    }   

    //30 

    if(sensorValue>815){ //You can change the number here to adjust the threshold.
      Serial.print("30%");
    }

    //40

    if(sensorValue>820){ //You can change the number here to adjust the threshold.
      Serial.print("40%");
    }

    //50

    if(sensorValue>825){ //You can change the number here to adjust the threshold.
      Serial.print("50%");
    }   

    //60

    if(sensorValue>830){ //You can change the number here to adjust the threshold.
      Serial.print("60%");
    }
    //70 

    if(sensorValue>835){ //You can change the number here to adjust the threshold.
      Serial.print("70%");

    }   

    //80 

    if(sensorValue>840){ //You can change the number here to adjust the threshold.
      Serial.print("80%");
    }

    //90

    if(sensorValue>845){ //You can change the number here to adjust the threshold.
      Serial.print("90%");
    }

    //100 

    if(sensorValue>850){ //You can change the number here to adjust the threshold.
      Serial.print("100%");
    }


Thank you for your time.
2  Using Arduino / Project Guidance / Knee Recording Joint movement (Knee) on: January 07, 2013, 11:27:19 pm
Hello Everybody

I currently working on a project related to measuring the movement of the human knee. I am hoping to measure range of motion and orientation but I want to take things slow and work on it piece by piece to ensure I dont get to far ahead of myself. First off i would just like to ask a few technical hardware questions before i start soldering writing code.

So I have looked at accelerometers and gyroscopes as well as stretch sensors in combination with a tilt sensor for the actual record of movement of the joint.

I would like to work with an arduino pro mini because of the size and portability if possible

1. can you attach the accelerometer signal pins to digital pins? or do they only work with analog pins?
2. is there a better way to record this type of data
   
3  Using Arduino / Project Guidance / Re: Basic Stretch Sensor on: November 14, 2012, 06:59:46 pm
Does this Help? I Added colour to the wires. the resistor is between ground and the sensor.


4  Using Arduino / Project Guidance / Basic Stretch Sensor on: November 14, 2012, 05:36:19 pm
Hi Im trying to use a 2" stretch sensor and have an serial printout of the distance stretched.

The problem is the value is coming in at around 10 and when i stretch the sensor it goes down to about 4.

im looking to have a larger range here and for the output data to go up when im stretching. Iv played around with the direction of the current and moving the resistor around as well as the location of the analog wire but nothing seems to work.   


Here is my circuit.


And here is my code
Code:
/*

BODY Language:
Wearable Technology 2 (GDES 3B44)


Code taken and modified from:
Sensor Project
 Wearable Technology 1 (GDES 3B16)
 Kate Hartman - Fall 2010
 
 Example: Using a Stretch sensor to sense whether you are resting or stretching you shoulder.
 Attach the sensor to the back of a shirt
 Attach an LED or a buzzer to pin 8.
 */

int ledPin = 13;         // LED is connected to digital pin 8
int sensorPin = 0; // Stretch sensor is connected to analog pin 0
int sensorValue; // variable to store the value coming from the sensor

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

void loop() // run over and over again
{
  sensorValue = analogRead(sensorPin); // read the value from the sensor

  if(sensorValue>850){ //You can change the number here to adjust the threshold.
    Serial.print("Stretch");
    digitalWrite(ledPin, HIGH); //Turn LED on

  }
  else{
    Serial.println("Rest");
    digitalWrite(ledPin, LOW); //Turn LED off
  }

  Serial.print("                     Sensor Value: ");
  Serial.println(sensorValue);

  delay(100); // delay for 1/10 of a second
}


5  Using Arduino / Programming Questions / Re: Electret Microphone controls LED on: September 21, 2011, 11:21:56 pm
any thoughts on this code?

i feel like it should work but the led doesn't come on.


Code:
int ledPin = 13;    // LED connected to digital pin 13
int sensorPin = 0; //analog pin 0
int sensorValue;
int ledState = LOW;             // ledState used to set the LED
int val = 0;




void setup()  {
 // declare pin 13 to be an output:
 pinMode(13, OUTPUT);
 pinMode(0, INPUT);
 Serial.begin(9600);

}

void loop()  {
 sensorValue = analogRead(sensorPin);   
 Serial.print("Sensor Value: ");
 Serial.println(sensorValue);
delay(50);



if (sensorValue<600) {
  digitalWrite(ledPin, LOW);
}
 }
 
 
void fadeValue1() {


for(int fadeValue1 = 255 ; fadeValue1 >= 0; fadeValue1 -=5) {
// sets the value (range from 255 to 0):}   

if (sensorValue>600) {
  analogWrite(ledPin, fadeValue1);         
  // wait for 30 milliseconds to see the dimming effect   
  delay(1000);                           
}

}
6  Using Arduino / Programming Questions / Re: Electret Microphone controls LED on: September 21, 2011, 09:18:14 pm
i still can't make sense of these posts...

i have this code that does what i need it to, except the fade.

do i need millis? i dont want it to start counting when the loops starts, i would want it to start when the threshold is crossed.

how do i write this?
7  Using Arduino / Programming Questions / Re: Electret Microphone controls LED on: September 21, 2011, 08:32:23 pm
here is my code.

I believe what i need to do is create some kind of delay after every time fadeValue=+5. is that correct? how do i do that?

Code:

int ledPin = 13;    // LED connected to digital pin 13
int sensorPin = 0; //analog pin 0
int sensorValue;
int ledState = LOW;             // ledState used to set the LED
       // will store last time LED was updated
int val = 0;


void setup()  {
 // declare pin 13 to be an output:
 pinMode(13, OUTPUT);
 pinMode(0, INPUT);
 Serial.begin(9600);


}

void loop()  {
 sensorValue = analogRead(sensorPin);   
 Serial.print("Sensor Value: ");
 Serial.println(sensorValue);
 


 
if (sensorValue>900) {

  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(5000);   
  }

}
 
  else {
  digitalWrite(ledPin, LOW);
  }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);

 }





8  Using Arduino / Programming Questions / Re: Electret Microphone controls LED on: September 21, 2011, 08:04:52 pm
i've been looking at this tutorial the fading tutorial and i think it is what i need. it actually doens't matter if there is a delay because once the threshold is crossed it needs to run the fade in, pause, fade out every time so a delay would work and it doesn't matter if it misses some data.

so what i need to know is how do i increase the fade time?
9  Using Arduino / Programming Questions / Re: Electret Microphone controls LED on: September 21, 2011, 07:53:10 pm
I can't seem to figure out how to make this work. Unfortunately i don't seem to have enough experience with arduino or programing in general to add the slow fade in and out using the "blink without delay" tutorial. could anyone maybe help me or explain how i adapt the two codes together?

What the goal is, is; the mic registers the sound, when the threshold is crossed the led fades in over 2 seconds then pauses for 2 seconds then fades out over 2 seconds.

I truly appreciate any help.

 
10  Using Arduino / Programming Questions / Re: Electret Microphone controls LED on: September 20, 2011, 02:38:44 pm
I've combined the codes that you mentioned as best i could.

what is happening is this; the led is off, when it reaches the threshold it led starts blinking. and doesn't stop. same thing when i do it without the delay only every 50millis. also my serial data has jumped from hovering around 450-500 to 650 area.

Here is my code without the delays:

Code:

int ledPin = 13;    // LED connected to digital pin 13
int sensorPin = 0; //analog pin 0
int sensorValue;
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
int val = 0;

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)



void setup()  {
 // declare pin 13 to be an output:
 pinMode(13, OUTPUT);
 pinMode(0, INPUT);
 Serial.begin(9600);

}

void loop()  {
 sensorValue = analogRead(sensorPin);   
 Serial.print("Sensor Value: ");
 Serial.println(sensorValue);
 

 val = analogRead(ledPin);   // read the input pin
  analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
// here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   
  }

if (sensorValue>600) {
  digitalWrite(ledPin, HIGH);

}
 
  else {
  digitalWrite(ledPin, LOW);
  }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);

 }





11  Using Arduino / Programming Questions / Re: Electret Microphone controls LED on: September 20, 2011, 02:17:04 pm
Thanks awol

This seems to be working. Now how do i make the LED fade in then out over a period of 3 seconds?


Code:

int ledPin = 13;    // LED connected to digital pin 13
int sensorPin = 0; //analog pin 0
int sensorValue;



void setup()  {
 // declare pin 13 to be an output:
 pinMode(13, OUTPUT);
 pinMode(0, INPUT);
 Serial.begin(9600);

}

void loop()  {
 sensorValue = analogRead(sensorPin);   
 Serial.print("Sensor Value: ");
 Serial.println(sensorValue);
 delay(50); 

           

if (sensorValue>600) {
  digitalWrite(ledPin, HIGH);
  delay(1000);
}
 
  else {
  digitalWrite(ledPin, LOW);
  }


 }


12  Using Arduino / Programming Questions / Electret Microphone controls LED on: September 20, 2011, 01:53:36 pm
Hey everyone,

Im using the spark fun electret mic as an analog sensor and a lilypad arduino to control leds.

what i want is to have a threshhold of 600. if the sensorValue is over 600 the led turns on if it is below 600 it turns off.

here is my code, it doesn't seem to work right not.

Code:
int ledPin = 13;    // LED connected to digital pin 13
int sensorPin = 0; //analog pin 0
int sensorValue;



void setup()  {
 // declare pin 13 to be an output:
 pinMode(13, OUTPUT);
 pinMode(0, INPUT);
 Serial.begin(9600);

}

void loop()  {
 sensorValue = analogRead(sensorPin);   
 Serial.print("Sensor Value: ");
 Serial.println(sensorValue);
 delay(50); 



if (sensorValue>600) {
  (ledPin, LOW);
}
 if (sensorValue<600) {
  (ledPin, HIGH);

 }
}
13  Using Arduino / Sensors / Measuring height. on: May 24, 2011, 02:35:45 pm
Hi everybody

Im trying to use an accelerometer to measure how high something jumped.

imagine a skateboard equipped with an accelerometer, how how did the rider ollie.

what would i need as far as code? z-axis + time? Velocity?


cheers.

14  Using Arduino / Programming Questions / Re: Accelerometer data to processing (skateboarding project) on: April 04, 2011, 09:42:54 pm
Hi Again.


I need to figure out what to replace mousePressed() with. so instead of mousePressed() it would be accelerometer data >550.
15  Using Arduino / Programming Questions / Re: Accelerometer data to processing (skateboarding project) on: April 04, 2011, 09:10:58 pm
Hi

here is what i have narrowed it down to.

I have arduino sketch that registers vertical lift and prints "Ollie" into the serial monitor.

I have a processing sketch that posts "Ollie" on twitter when i press the mouse.

I have a processing sketch that posts "Ollie" on twitter when it registers data from the arduino, which is every 100millis, therefore every 100 millis it posts Ollie on twitter.

what i need to figure out is; how to have any data lower that 550 be classified as null to processing. i need the accelerometer to act as a button in processing.
Pages: [1] 2 3 ... 5