LCD+LEDs+Sensor interface

What's happening people? First off, awesome forum...I am new to Arduino and new to programming period and there are some really great stuff in here that have helped me along the way with this project. But down to business...

Ultimatey, I'm trying to interface the MQ-3 gas sensor to a row of 10 LEDs and have the HIGH/LOW outputs corresponds with readings the readings from said sensor. In addition, I want those readings to be displayed on a 16 x 2 LCD. So far, this code/sketch (http://arduino.cc/en/Tutorial/BarGraph) has helped me regarding the LEDs, but I'm unsure as to how I could go about connecting the LCD to the analog inputs since the 10 LEDs would utilizing the Digital pins.

the analog pins A0 .. A5 can be addressed as digital pins 14..19. just set pinMode(14, OUTPUT); and use digitalWrite(14, HIGH) etc.

For the LCD, you should configure it with 4 datalines iso 8. Most libs support that .

robtillaart:
the analog pins A0 .. A5 can be addressed as digital pins 14..19. just set pinMode(14, OUTPUT); and use digitalWrite(14, HIGH) etc.

For the LCD, you should configure it with 4 datalines iso 8. Most libs support that .

Gotcha...I'm reading some more information on exactly how to do that, step-by-step anyway. Thanks for the help.

ok, got the pins redefined/reassigned...will update here as I go along

small sample of code

#include <Wire.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

int ledPin1 = 10;                 // LEDS connected to digital pins 10-2 and A5
int ledPin2 = 9;
int ledPin3 = 8;
int ledPin4 = 7;
int ledPin5 = 6;
int ledPin6 = 5;
int ledPin7 = 4;
int ledPin8 = 3;
int ledPin9 = 2;
int ledPin10 = A5;

void setup()
{
  pinMode(ledPin1, OUTPUT);  // sets the digital pins as outputs
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(ledPin10, OUTPUT);
}

void loop()
{
  digitalWrite(ledPin1, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin1, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
  
  //Repeat below for subsequent pins        
  
  digitalWrite(ledPin2, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin2, LOW);    
  delay(1000);                  

  digitalWrite(ledPin3, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin3, LOW);    
  delay(1000);

  digitalWrite(ledPin4, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin4, LOW);    
  delay(1000);
  
  digitalWrite(ledPin5, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin5, LOW);    
  delay(1000);
  
  digitalWrite(ledPin6, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin6, LOW);    
  delay(1000);
  
  digitalWrite(ledPin7, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin7, LOW);    
  delay(1000);
  
  digitalWrite(ledPin8, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin8, LOW);    
  delay(1000);
  
  digitalWrite(ledPin9, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin9, LOW);    
  delay(1000);
  
  digitalWrite(ledPin10, HIGH);   
  delay(1000);                  
  digitalWrite(ledPin10, LOW);    
  delay(1000);
}

Ok, the above code worked out well for me. I got all LEDs to respond. However, now that I am driving some of the analog pins (A1-A4) to the LCD, I am having issues

#include <Wire.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

// these constants won't change:
const int analogPin = A0;   // the pin that the potentiometer is attached to
const int ledCount = 10;    // the number of LEDs in the bar graph


int ledPin10 = A5;//Denote analog pin A5 as LED output
int ledPins[] = { 
  10, 9, 8, 7, 6, 5, 4, 3, 2, A5 };   // an array of pin numbers to which LEDs are attached

// delete point
int lcdPina = 18;                 // LCD connected to digital pin 18-15
int lcdPinb = 17;
int lcdPinc = 16;
int lcdPind = 15;
// delete point

LiquidCrystal lcd(12, 11, 18, 17, 16, 15);

void setup() 
{
  //delete point
  {
  pinMode(lcdPina, OUTPUT);  // sets the digital pins as outputs
  pinMode(lcdPinb, OUTPUT);
  pinMode(lcdPinc, OUTPUT);
  pinMode(lcdPind, OUTPUT);
  }  
  //delete point
  
  {
  lcd.begin(16, 2); // set up the LCD's number of columns and rows:
  lcd.print("Ethan's BAC"); // Print a message to the LCD.
  }
  for (int thisLed = 0; thisLed < ledCount; thisLed++) // loop over the pin array and set them all to output:
  {
    pinMode(ledPins[thisLed], OUTPUT); 
  }
}

void loop() 
{
  //delete point
  {
  digitalWrite(lcdPina, HIGH);  // sets the LED on
  digitalWrite(lcdPinb, HIGH); 
  digitalWrite(lcdPinc, HIGH); 
  digitalWrite(lcdPind, HIGH); 
  }
  //delete point
  
  
  int sensorReading = analogRead(analogPin);      // read the potentiometer:
  int ledLevel = map(sensorReading, 0, 1023, 0, ledCount); // map the result to a range from 0 to the number of LEDs:

  for (int thisLed = 0; thisLed < ledCount; thisLed++) // loop over the LED array
  {
    if (thisLed < ledLevel) //if the array element's index is less than ledLevel, turn the pin for this element on
     {
      digitalWrite(ledPins[thisLed], HIGH);
     } 
    
    else //turn off all pins higher than the ledLevel
     {
      digitalWrite(ledPins[thisLed], LOW); 
     }
  }
}

hi,

No idea what your issues are, but using 10 pins just to turn on/off LEDs seems like a waste of precious pins to me. Have a look at 'shift registers' for a way to drive more LEDs with less pins.

Duane B

rcarduino.blogspot.com

Hey, yeah looked at that topics earlier last night and i ordered the chip necessary.

My problem was getting the information I typed to print out on the LCD. I got the pins themselves to print in another piece of code but I cannot get those same exact pins to print out in the code posted above.