Welcome, Guest

Author Topic: Using the analog read function ?  (Read 798 times)


  • Newbie
  • *
  • Posts: 1
  • Karma: +1/-0
Using the analog read function ?
« on: September 17, 2017, 04:04:32 AM »
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);
    digitalWrite(1, HIGH);
   delay(300);               // wait for a second
    //digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
    digitalWrite(1, LOW);
                 // wait for a second
« Last Edit: September 17, 2017, 04:17:43 PM by rbjassoc »


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1816
  • Karma: +46/-2
Re: Using the analog read function ?
« Reply #1 on: September 18, 2017, 02:14:50 PM »
Thanks for sharing your experience! Glad you found the root of the problem.
Technical support and documentation manager at Olimex