3
\$\begingroup\$

I have an Arduino UNO R3 Plus with 14 digital pins, but they don't function well. Or maybe they do, but the point is, I think I am overusing them. I have an LCD connected to ports 13-7, 4 LED lights connected to 5-2 and 2 buttons connected to 0-1. But I'm only using one button, so it is technically 1 button connected to port 1. The LED + button is an LED game, and I'm trying to make the LCD screen a counter for it. The LCD and and the LED "power cords" share the same breadboard segments, the LED is the one going up to the 5V power pin. The problem is that I can only make one work at a time, so I don't know if its the programming or the hardware. So please tell me how I can reprogram/rewire this (or else explain why it is impossible). Circuit

My code:

int currentLED = 2;
int delayValue = 200;
int numberShown = 0;

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 12, 10, 9, 8, 7);

void setup() {
    pinMode(1, INPUT); //Button
    pinMode(2, OUTPUT); //White LED
    pinMode(3, OUTPUT); //Yellow LED
    pinMode(4, OUTPUT); //Green LED
    pinMode(5, OUTPUT); //RED LED
    // set up the LCD's number of columns and rows: 
    lcd.begin(16, 2);
    // Print a message to the LCD.
    lcd.print("hello, world!");
}

int checkInput() {
  if(digitalRead(1)==0) {
    return 1;
  } else {
    return 0;
  }
}

}
void loop(){

// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);

  if(digitalRead(1) == 0){
    if(currentLED == 4) {
      digitalWrite(4, HIGH);
      delay(200);
      digitalWrite(4, LOW);
      delay(200);
      digitalWrite(4, HIGH);
      delay(200);
      digitalWrite(4, LOW);
      delay(200);
      delayValue = delayValue - 10;
    } else {
      digitalWrite(currentLED, HIGH);
      delay(200);
      digitalWrite(currentLED, LOW);
      delay(200);
      digitalWrite(currentLED, HIGH);
      delay(200);
      digitalWrite(currentLED, LOW);
      delay(200);
    }
  }
  digitalWrite(currentLED, HIGH);
  delay(delayValue);
  digitalWrite(currentLED, LOW);
  delay(delayValue);
  currentLED = currentLED + 1;
  if(currentLED > 5) {
    currentLED = 2;
  }
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Resistor value for the leds? And what are the forward voltages of the led? \$\endgroup\$ – Passerby Dec 10 '13 at 23:53
  • \$\begingroup\$ Sorry if I am terrible at electrical engineering, it just fascinates me. But the voltage is 5v for both and the resistor is 330 ohm \$\endgroup\$ – The Knights Who Say Ni Dec 10 '13 at 23:57
  • \$\begingroup\$ Several pins on the LCD are miswired. \$\endgroup\$ – Ignacio Vazquez-Abrams Dec 11 '13 at 0:58
  • \$\begingroup\$ The ends of your pot should be connected to supply and ground, and the wiper should be connected to V0. \$\endgroup\$ – Ignacio Vazquez-Abrams Dec 11 '13 at 1:19
  • 1
    \$\begingroup\$ Use a multimeter. \$\endgroup\$ – Passerby Dec 13 '13 at 5:10
1
\$\begingroup\$

NB: I realise this is an old question by now, and should probably be migrated to Arduino SE, but questions without answers are just noise, so I'll plum for an answer..

Arduino UNO R3 Plus Digital Pins Overused?

Or to rephrase: Can an Arduino UNO drive both an LCD and series of LEDs together?

The answer is of course a definite yes.. here's an example of it working.

If the Fritzing diagram in the question can be believed, the primary reason why the circuit was not working as expected is because the LCD is not wired correctly (as pointed out by Ignacio in the comments). In particular, the pot is not doing it's job to adjust contrast, but is pulling RS high.

Fritzing is a good tool, but it is worth getting used to the schematic view. It can make problems like this self-evident, when they are so easy to miss in the breadboard view.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.