Problem with glowing LEDs after adding code for display.

Hi!

Im new to Arduino and trying my first own Project running on a Arduino Uno.

It´s a temperature monitor with a display that prints current temperature to display, and a RGB-LED that shows current status by lighting up in different colors or blinking in different colors, depending on thresholds.

it also includes a button that prints the current status and temperature to serial monitor, my plan was to replace it with a GSM module that sends a text message if pressed.

It all worked fine untill i added the display.

The diodes works fine while blinking but as soon as they´re about to shine constantly, they´re only glowing very weak.

As soon as i Comment the code for the display in IDE the LEDs work fine again.

The display is connected to its own power supply.

What have i made wrong?

//Include buttons library
  #include <Button.h>

//Include Oled Library
  #include <U8glib.h>

//New display
  U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);

//Define time of blink
  byte blinkTime = 500;

//Define temperature tresholds
  const int tempHigh = 25;
  const int tempDangerHigh =28;
  const int tempDangerLow = 0;
  const int tempLow = 5;
  const int tempNormal = tempHigh / 2 + tempLow / 2; 
  const int tempRangeNormal = tempHigh / 2 - tempLow / 2;

const String statusCheck[] = {
  "Temperature is dangerously low, current temperature is: ",
  "Temperature is low, current temperature is: ", 
  "Temperature is low but OK, current temperature is; ", 
  "Temperature is OK, Current temperature is: ", 
  "Temperature is high but OK, current temperature is: ", 
  "Temperature is high, Current temperature is: ", 
  "Temperature is dangerously high, current temperature is: ",
  "Couldnt get status, Current temperature is: "
  };
 
//Setting Status
  byte setStatus;

//Define sensor
  int tempSensor = A0;

//Storage of sensor value
  int actualTemp;

//Define button
  Button btnTestMessage(2);

//Define LEDS
  int redLed = 7;
  int greenLed = 4;
  int blueLed = 8;

void setup() {
  
  // Set LEDs as output

  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(blueLed, OUTPUT);

  // Set Button as input
  btnTestMessage.begin();
  // Start serial monitor

  Serial.begin(9600);
  

}

void loop() {


  //Read temperature from sensor
  actualTemp = analogRead(tempSensor);
  actualTemp = map(actualTemp, 0, 1023, -40.0, 40.0);
  
  
  //Print to Oled.

  oled.firstPage();

  do {
    oled.setFont(u8g_font_helvB08);
    char currentTxt[] = "Current Temperature: ";
    int xCurrentTxt = (oled.getWidth() - oled.getStrWidth(currentTxt)) / 2;
    oled.drawStr(xCurrentTxt, 10, currentTxt);
  
    oled.setFont(u8g_font_helvB14);
    char buf[9];
    sprintf (buf, "%d", actualTemp);
    int xBuf = (oled.getWidth() - oled.getStrWidth(buf)) /2;
    oled.drawStr(xBuf, 40, buf);
  
    oled.setFont(u8g_font_helvB08);
    char degreesTxt[] = "Degrees Celsius";
    int xDegreesTxt = (oled.getWidth() - oled.getStrWidth(degreesTxt)) / 2;
    oled.drawStr(xDegreesTxt, 60, degreesTxt);
  } 
   while(oled.nextPage());


  //If testbutton is pressed
  
  if (btnTestMessage.pressed()){
  Serial.print(statusCheck[setStatus]);
  Serial.print(actualTemp);
  Serial.println("°C");

  }
 
  
  //If Danger Cold
  if (actualTemp <= tempDangerLow){
    digitalWrite(blueLed, HIGH);
    setStatus = 0;
  }
  
  //If cold
  else if (actualTemp > tempDangerLow && actualTemp <= tempLow) {
    digitalWrite(blueLed, HIGH);
    delay(blinkTime);
    digitalWrite(blueLed, LOW);
    delay(blinkTime);
    setStatus = 1;
  }
  
  // if temp OK

  else if (actualTemp <= tempNormal + tempRangeNormal  && actualTemp >= tempNormal - tempRangeNormal ){
      digitalWrite(greenLed, HIGH);
      setStatus = 3;
  }
  
  // temp OK but Low
  else if (actualTemp > tempLow && actualTemp <= tempLow + tempRangeNormal / 2){
      digitalWrite(greenLed, HIGH);
      delay(blinkTime);
      digitalWrite(greenLed, LOW);
      delay(blinkTime);
      setStatus = 2;
  }
  
  // temp OK but High
    else if (actualTemp < tempHigh && actualTemp >= tempHigh - tempRangeNormal / 2){
      digitalWrite(greenLed, HIGH);
      delay(blinkTime);
      digitalWrite(greenLed, LOW);
      delay(blinkTime);
      setStatus = 4;
    }

  //If Hot
  else if (actualTemp >= tempHigh && actualTemp < tempDangerHigh) {
    digitalWrite(redLed, HIGH);
    delay(blinkTime);
    digitalWrite(redLed, LOW);
    delay(blinkTime);
    setStatus = 5;
  }
  
  //If Danger Hot
  else if (actualTemp >= tempDangerHigh) {
    digitalWrite(redLed, HIGH);
    setStatus = 6;
  }
  
  
  //If Error
  else { 
    digitalWrite(blueLed, HIGH);
      delay(blinkTime);
      digitalWrite(blueLed, LOW);
      delay(blinkTime);
      digitalWrite(greenLed, HIGH);
      delay(blinkTime);
      digitalWrite(greenLed, LOW);
      delay(blinkTime);
      digitalWrite(redLed, HIGH);
      delay(blinkTime);
      digitalWrite(redLed, LOW);
      delay(blinkTime);
      setStatus = 7;
  }

  //Set all LEDs Low
  digitalWrite(greenLed, LOW);
  digitalWrite(blueLed, LOW);
  digitalWrite(redLed, LOW);
  }

Please read this. See #7.

Sorry! Corrected!

Please read this. See #11

Sorry!

Monstret:
The display is connected to its own power supply.

So what is powering the UNO?

You need a regulated 5 V supply for the UNO. If you have a 5 V supply for the display, then you would use that to power the UNO via its 5 V pin.

Please post a complete schematic especially how it’s powered. Paul is on the right track sounds like a current issue.

Added a poorly made wiring diagram :wink:

anything?!? we need something to work with... otherwise we can just guess.... like your cat messed up your circuit while you were sleeping...

Not really familiar with fritzing yet. better?

ok the reason why we need the wiring diagram... it can be a hand drawn picture.. it's possible that something is not wired correctly or interfering with something else... Since you say the problem happens when you connect the display perhaps it's not wired correctly. Can you get it to work correctly using the computer/ IDE serial monitor?

Its not wired correctly. vin has to be 7-12v, If you're using that power supply board (which is not really recommended) you should put the 5v to the 5v pin on the Arduino. You're dropping voltage against the onboard voltage regulator so that's why the LED are dim...

yes he needs to move the supply to the arduino he's dropping voltage against the internal regulator.

Monstret:
If you're using that power supply board (which is not really recommended) you should put the 5v to the 5v pin on the Arduino.

What do you mean by "not really recommended"?

There's a lot of conjecture about this... You could possibly damage your arduino if you accidentlly put higher voltage through this. It bypasses the regulator there is no protection in the circuitry so use at your own risk. No shunt, no protection diode... etc.

It will work though. I would have powered this project entirely with the arduino... no outboard needed. there's not much current being used.

Oled is very efficient (about 20 mA)
3 LED's and minor current draw on the rest. (appro 60 mA)

wolframore:
There's a lot of conjecture about this...

I don't think so.

While if you have very few devices beyond the Arduino that require 5 V, and you power it with 7 V, you can possibly get away with supplying 100 mA from the built-in regulator. Power it with 12 V and you have tripled the power dissipation in the regulator for any given load, you barely have enough capacity for the Arduino itself.

wolframore:
You could possibly damage your Arduino if you accidentally put higher voltage through this. It bypasses the regulator there is no protection in the circuitry so use at your own risk. No shunt, no protection diode... etc.

This is quite a bizarre concept. :astonished: Whether you power it through the USB port where you have a "polyswitch" fuse in the UNO, or via the 5 V pin, you use a regulated, 5 V supply (5.5 V is quite acceptable). A commonly available one is a USB "phone charger". There is no reason to use a protection diode or whatever a "shunt" is because you simply connect it correctly to a regulated 5 V supply. That is how you connect anything; if you cannot get that right, you have no place dealing with electronics.

A recent thread details the result of plugging a laptop charger (19 V) into the "barrel jack". Yes, it didn't (necessarily) bypass the regulator - which in fact promptly exploded - so that was not very good "protection". :astonished:

Did you see the picture. He’s using a 9v battery. As long as he doesn’t accidentally connect it to the 5v it should be fine. I don’t like the idea of possible reverse voltage through the regulator if he connects vin possibly later and it’s not correct.

And as you pointed out shit happens. It’s good for beginners to learn about the things that could release smoke and if it happens to have a clue as to what happened.

Whats the suggested voltage on the "Barrel jack"?

In the posted picture it says 9-12V but if i consult my friend goolge it says 7-12VDC.

Anyway, tried hooking up a 8VDC 1.25A supply and wired everything up directly to the UNO,
but problem still remains.

look it up this is directly from Arduino Voltage In

where do you even find an 8vdc supply?

Strange, this is what i looked at Arduino Store under Tech specs and recomended voltage.

Problem persists with power via USB/phone charger too.

Supply is from a pair of old speakers :slight_smile: