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.
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);
}
}
}
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.
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.