Untitled Post

posted Dec 7, 2009, 8:53 AM by Unknown user
okay. Ian kelley and i are making a electromagnetic field detector. we have already accomplish the base of this project. we have successfully detected these fields and have used a blink LED to measure the field's strength. we are trying to build the device to that it can be measured and seen on a bar graph of LEDs. currently we are having a lot off trouble with the programing, bug i think we got all of the minor bugs worked out.this includs the language of the arduino, and properly formating the commands. friday, we converted the program from the single LED to accomodate five LEDs, and depending on the strength of the ectromagnetic field more or less LEDs will light up. the problem is only one LED will light up. We thing that this is because of how the readings are coming in. We extended the antena we use for measuring the fields and are doing a serial print the measure these. We eliminated the map command because it wasnt neccarly because we are doing a digital wirte and have no need to ajust value. now we are going to read the value that the antena is measuring and do a serial print. fom those values we plan to adjust the constraits of the readings. we are telling each LED to light up when the reading reach a certain range. for instance, 0 will light no leds up, 1 to 20 will light the first up, 21 - 41 the first and second, and 42- 62 the 1st 2nd and 3rd and so on until we get to what the max value currentlyh is, 100, and all 5 leds light up. we are using the "if" and "if else" and "else" commands to accomplish this.
 
Here is our current code which is adjusted and manipulated from a base code from online, Led codes we worked with in the poast, codes from past exercises and the green book, and just me and Ian messing around trying to fix problems...


int inPin = 1;             // analog 5
int val = 0;                 // where to store info from analog 5
int pin9= 9;
int pin10 = 10;
int pin11 = 11;         // output of red led
int pin12 = 12;
int pin13 = 13;

void setup() {
 
  Serial.begin(9600);
 
}

void loop() {
 
  val = analogRead(inPin);                    // reads in the values from analog 5 and
                                                                   //assigns them to val
  if(val >= 1){
      
    val = constrain(val, 0, 100);    // mess with these values                                     
      
   
  if(val > 0 && val <= 20)
  {
    digitalWrite(pin13,HIGH);
  }
  else if(val >= 21 && val <= 40)
  {
    digitalWrite(pin13,HIGH);
    digitalWrite(pin12,HIGH);
  }
  else if(val >= 41 && val <= 60)
 {
    digitalWrite(pin13,HIGH);
    digitalWrite(pin12,HIGH);  
    digitalWrite(pin11,HIGH);
 }
  else if(val >= 61 && val <= 80)
  {
    digitalWrite(pin13,HIGH);
    digitalWrite(pin12,HIGH);  
    digitalWrite(pin11,HIGH);
    digitalWrite(pin10,HIGH);
  } 
   else if(val >= 81 && val <=100)
  {
    digitalWrite(pin13,HIGH);
    digitalWrite(pin12,HIGH);  
    digitalWrite(pin11,HIGH);
    digitalWrite(pin10,HIGH);
    digitalWrite(pin9,HIGH);
  }
                                               
   }else{           


 
  for(int pin = 9; pin < 13; pin++)
{
digitalWrite(pin,LOW); 
}
    
    
   }
 
 
 Serial.println(val);                               
 

  
  
  
}



HOLLA AT YA CATZ LATER!

Comments