Go Down

Topic: Spurious analog input, nothing connected (Read 2396 times) previous topic - next topic

hesynergy

http://www.youtube.com/watch?v=YwFi3cAXYBk


Code below
/*
April 1, 2011 it WORKS ON THE TINY85!!!
 
 programmed with the Tiny shield, using the .0023 ide.
 Thanks to all the folks that contributed my understanding!
 
 
 this experiment takes an initial reading reading from the voltage
 devider circuit hooked to the CDS photocell, maps it to a value
 of 0-255, then outputs the result a flash to
 an array of 21 leds, indicating  a change un lux levels. 
 
 
 AtTiny85 pins below
 
 * digital pin zero is physical pin five (also PWM)
 * digital pin one is physical pin six (also PWM)
 * analogue input two is physical pin seven
 * analogue input three is physical pin two
 * analogue input four is physical pin three
 
 // ATMEL ATTINY85
 //AI=Analog Input
 / /
   // ATMEL ATTINY85
//
//                        o-\/-
.  .        .@ NC   PB5  1|    |8  VCC ?@
/   @ NC (AI 3)v         2|    |7  PB2 (AI 1)-@PIR
//      @LDR (AI 2) PB4  3|    |6  PB1 PWM@ buzzer
//    n    @        GND  4|    |5  PB0 PWM @ PWM to LEDs
//               n  nn    +----+
 
 //below are the AtTiny85 pins--------------*/
//int ledArray = PB0;
//int PIRpin=PB2; // digital input -HIGH or LOW
//int LDRpin=PB4;
// int buzzPin=PB1;
////arduino pins below<------------------------- !!!
int ledArray = 9;
int PIRpin=A1; // HIGH or LOW
int LDRpin=A0;
 int buzzPin=10;
/////pins above-----------------------------
boolean LightsOn = false;
int Sound=0;
int LuxRead=0;
int PIRread=0;
int PrevLux=0;
int Pause=25;

void setup()
{     
 
  pinMode(ledArray, OUTPUT);   // sets the pins as output
  pinMode(buzzPin, OUTPUT);
//  digitalWrite(LDRpin, HIGH);
 // digitalWrite(PIRpin, HIGH);


  Serial.begin(9600);  // ...set up the serial ouput

  digitalWrite(ledArray,LOW);
  //FlashWhite();

 Raygun(); // Raygun - like sounds - once, run indicator

}

void loop()
{

    //Raygun();
    ////
    //FlashWhite();
     LuxRead = analogRead(LDRpin);
     delay(Pause);
      PIRread=analogRead(PIRpin);
       delay(Pause);
      PrintNum(LuxRead,PIRread,LightsOn);
    dayORnite(LuxRead) ;//monitor light level
}// End of Main Loop


//
void PrintNum(int newLight,int PIRread,boolean On)
{Serial.println("Printnum Activated");
  //
  //      
  Serial.print("Lux: ");
  Serial.print(newLight);
  Serial.print(" , PIR Val= ");
  Serial.print(PIRread);
  Serial.print(" , LightsOn = ");
  Serial.println(On);
  //       
}
//


void dayORnite(int LightLevel) //monitor light levels
{// now lights are bumping up LightLevel to ~high 40s
  Sound=0;
  if(LightLevel<100 )

  {
   
    LightsOn=true;
    Serial.println("DayOrNite Lights on Activated");
   
  LuxRead = analogRead(LDRpin);
  PIRread=analogRead(PIRpin);
  PrintNum(LuxRead,PIRread,LightsOn);

    digitalWrite(ledArray,HIGH);

    while(analogRead(PIRpin)<500)
    { delay(Pause);
      digitalWrite(ledArray,LOW);
      delay(100);
      digitalWrite(ledArray,HIGH);
      delay(random(5000,15000));
    }
 ChkMovement( LightsOn);
   
  }   
  else

  {  
       Serial.println("DayOrNite Lights OFF Activated");
    digitalWrite(ledArray,LOW);

   while(analogRead(PIRpin)<100)
    {  delay(Pause);
     LightsOn=false;
//     LuxRead = analogRead(LDRpin);
//  PIRread=analogRead(PIRpin);
//  PrintNum(LuxRead,PIRread,LightsOn);
      digitalWrite(ledArray,HIGH);
      delay(100);
      digitalWrite(ledArray,LOW);
      delay(random(5000,15000));
    }
  
    ChkMovement( LightsOn);
    //  delay(random(5000,30000));
  }   

  // PrintNum(LuxRead,digitalRead(PIRpin),LightsOn);
}

void ChkMovement(boolean lights)
{  
 
  Serial.println("ChkMovement Activated");
   delay(Pause);
  if (analogRead(PIRpin)>0)//takes~ 30 seconds for PIR to settle
  {
    FlashWhite(lights);
  }
}




void Raygun()
{
  Sound++;
 
     Serial.print("Raygun Activated ");
      Serial.println(Sound);
    
  for( int i = 0; i<500 ; i++)
 //  for( int i = random(500,2900); i >0; i=i-random(10))
 
  {  
    digitalWrite(buzzPin, HIGH);
    delayMicroseconds(i);
    digitalWrite(buzzPin, LOW);
    delayMicroseconds(i);
  }
}




void   FlashWhite(int Lights)
{   Serial.println("FlashWhite Activated");
  while(analogRead(PIRpin)>650)
    {// delay(Pause);
    //LuxRead = analogRead(LDRpin);
    //delay(Pause);
   // PIRread=analogRead(PIRpin);
    //PrintNum(LuxRead,PIRread,Lights);
      if(analogRead(PIRpin)<100)
          {
            Sound=0;
            break;
          }

    digitalWrite(ledArray,LOW);
    //delay(Pause);
    Raygun();
    digitalWrite(ledArray,HIGH);
    //delay(Pause);
//    Raygun();
//    digitalWrite(ledArray,LOW);
  }//  while(digitalRead(PIRpin==HIGH)


}// Alternate FlashWhite();




Krodal

What is your question?

Is it that the input value is all over the place, if nothing is connected. That is normal.
The inputs of the Arduino are high impedance, and  they can be anything if they are not connected.

Graynomad

Ummm, just connect the pin. It will show crap if left floating.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Grumpy_Mike


hesynergy

Drat.... I thought this might be tied to getting spurious input values when the project board with PIR and LDR ARE CONNECTED... Could the disconnected readings be used as some stable value of "Arduino noise"?

Thus if I used something like

While AnalogRead(PIRpin>"ArduinoBackGroundNoise")
{
          If(AnalogRead(PIRpin<"ArduinoBackGroundNoise")
              {
                 Exit;//While AnalogRead(PIRpin>"ArduinoBackGroundNoise")
               }
Do stuff;


}// go back to calling Fn
??

Thanks,

chas

pylon

To be short: No.

If you wired your sensor correctly, you get values that represent the sensors state. If you just get crap, check the wiring or show us your wiring, maybe the forum members will find an error.

PaulS

Quote
Thus if I used something like

While AnalogRead(PIRpin>"ArduinoBackGroundNoise")

Typically, a PIR is a digital device (Hey, I saw something warm move"; "Nothing moving here..."). Why are you using analogRead to read that kind of data? Why even connect a digital device to an analog pin?

hesynergy

1. Because I ran out of digital I/O on the tiny 85 around which the entire project is designed
2. Because I can, since , as I understand it, any analog input can evaluate a digital input as a value between 0-1024.

See http://youtu.be/DFMk1MOYv1Y

Thanks for the input!

chas

hesynergy


To be short: No.

If you wired your sensor correctly, you get values that represent the sensors state. If you just get crap, check the wiring or show us your wiring, maybe the forum members will find an error.


Believe me, my wiring on my project looks sucky, but checks out, on a vom, no shorts, nothing open, all values check out, including voltages on the PIR and LDR.

BUT HERE YA GO... http://youtu.be/DFMk1MOYv1Y

hesynergy


Ummm, just connect the pin. It will show crap if left floating.

______
Rob


Thanks Pylon and Grumpy!

chas

Grumpy_Mike

Quote
Because I ran out of digital I/O on the tiny 85 around which the entire project is designed

You can use any analogue input as a digital input, just do a digital read of the corresponding correct pin number. For example on a Uno is is pin 14 for the digital read of analogue 0. Off hand I don't know what it is on a tiny 85.

pylon

You just can use A0, A1 and so on for digitalRead():

Code: [Select]
byte value = digitalRead(A0);

and it will work (the Ax values are translated to integer values with some defines anyway). You might have to specify the pin as an input with:

Code: [Select]
pinMode(A0, INPUT);

before using it to read values.

This is much faster than reading analog values and interpreting them.

PaulS

Quote
You just can use A0, A1 and so on for digitalRead():

Do you know, for sure, that A0, A1, etc. are defined for the ATTiny85?

pylon

He uses them in his code and that code seems to work (watched the video). On a standard Arduino it works that way and the macro desert in the hardware directory is taking care of the translation. Do you have other information?

PaulS

Quote
Do you have other information?

No, but the ATTiny85 is not a standard Arduino. That's why I asked.

Go Up