ATtiny85 Unstable when using delay()


I am trying to design a simple battery voltage monitor using the ATtiny85, programming with Arduino Uno as ISP in Arduino IDE. I have done all of the hard work, I have measured the voltages and know their corresponding 10-bit number, and got the LEDs responding appropriately - as long as I don’t have any delay functions in the sketch.

What I would like is to flash all three LEDs to show they are working before it measures the voltage, so I have simplified my sketch down to show the problem as it is happening.

int Rpin = 0;       // Pin5 Red
int Ypin = 1;       // Pin6 Yellow
int Gpin = 2;       // Pin7 Green
int Probepin = 3;   // Pin2 Probe Pin
int voltage = 0;

void setup() {
  //Pin Setup
  pinMode(Rpin, OUTPUT);
  pinMode(Ypin, OUTPUT);
  pinMode(Gpin, OUTPUT);

  //Flash All
  digitalWrite(Rpin, HIGH);
  digitalWrite(Ypin, HIGH);
  digitalWrite(Gpin, HIGH);
  digitalWrite(Rpin, LOW);
  digitalWrite(Ypin, LOW);
  digitalWrite(Gpin, LOW);
  digitalWrite(Rpin, HIGH);
  digitalWrite(Ypin, HIGH);
  digitalWrite(Gpin, HIGH);

void loop() {

Below is a link to the video of what it is doing, usually very inconsistent, very unpredictable results. I can turn all LEDs on, or off, or some on and off, but if I throw a delay in there it craps itself :/… Any ideas?

LEDs example

I can draw the circuit and add later if it helps but I don’t think this is an issue, it is very simple.

testing.ino (574 Bytes)

I just removed the L7805C regulator and ran it directly off the arduinos 5V supply and it works fine. So this is a power supply problem...? Any way to smooth out the L7800s to be reliable..?

A .1uF capacitor across the L7805s output fixes the problem…

Mod’s feel free to remove this post entirely :astonished:

Thank you for the follow-up.

You will need a second such capacitor across VCC and GND as close to the processor as possible.

The datasheet calls for a capacitor on the LM7805 input as well.

I did see it mentioned that, though it says "if the regulator is an appreciable distance from the supply". Very open to interpretation I guess. I will put one in for safe measure anyway, thanks for comment!