November 23, 2024, 04:56:21 AM

Using the analog read function ?

Started by rbjassoc, September 17, 2017, 04:04:32 AM

Previous topic - Next topic

rbjassoc

So I'm trying to get my Olimex-85 to react to voltage levels using the "A1" pin. It seems that the attiny is reading something but I do not know what. from what I have read 0 VDC should be 0 and 5 VDC should be represented with 1023.
the code compiles and if I put any voltage from 2-4 volts it reacts with a slow blink. If I disconnect the voltage it reacts with the faster blink ? so I know the chip is seeing something. The whole goal is to be able to set a value lets say 3 VDC (which is approx 610 ) and to make the LED blink according to the if-else statement .

I;m taking power off of the VCC running it through a poti to reduce the voltage to 3 VDC (Or whatever I want)

Any help would be greatly appreciated.

ALERT **************************
well I have answered my own post !!!  THe problem was not software but hardware !!!! My pull down resistor was too low !!! I put a 10k on it and it seems to work fine !
*************************************

below is my code:

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  //pinMode(0, OUTPUT); //LED on Model B
 
 
 
  pinMode(1, OUTPUT); //LED on Model A  or Pro
}

// the loop routine runs over and over again forever:
void loop() {
 
  int analogIn;
  int analogInPin = A1;
  pinMode(analogInPin, INPUT);
  analogIn = analogRead(analogInPin);
 
// digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
  if(analogIn > 600)
  { 
  digitalWrite(1, HIGH);
  delay(1000);               // wait for a second
  //digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(1, LOW);
  delay(1000);
  }
  else
  {
    digitalWrite(1, HIGH);
   delay(300);               // wait for a second
    //digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
    digitalWrite(1, LOW);
    delay(300);
  }
                 // wait for a second
}

LubOlimex

Thanks for sharing your experience! Glad you found the root of the problem.
Technical support and documentation manager at Olimex