I'm husnu from indonesia. I get an examp about arduino. Anyone Help me sketch Sensor MQ7 with LED indicators. I will use 10 LED from pin 2 until the last. and how to show value of range sensor to PPM? ![]()
Change the analog pin. Use IDE Blink example on how to drive leds.
Use Case to test for values to drive the leds.
Google " arduino CASE "
I use this sketch but when I try, in serial monitor arduino IDE nothing value number.
Whats Wrong?
const int analogPin = 0; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = {
10,9,8,7,6,5,4,3,2,1 // Here we have the number of LEDs to use in the BarGraph
};
void setup() {
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}}
void loop() {
//This is the code to light up LED's
int sensorReading = analogRead(analogPin);
int ledLevel = map(sensorReading, 500, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}
but this sketch it works
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int ledPin = 13; // LED connected to digital pin 13
int sensorValue = 0; // value read from the sensor
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// determine alarm status
if (sensorValue >= 750)
{
digitalWrite(ledPin, HIGH); // sets the LED on
}
else
{
digitalWrite(ledPin, LOW); // sets the LED off
}
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.println(sensorValue);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}
and I don't know to add 10 pin LED in this sketch. can you teach me ? my english is bad , sorry.
const int analogPin = 0;
0 is not an analog pin , it is RX SERIAL PIN.
The sketch that works has this declaration:
const int analogInPin = A0;
Do you see the difference ?
"0" is digital pin 0, so using this for an analogRead statement will not work. (It would work with for an ATtiny85 but explaining why to you right now would just confuse you).
sorry, when I try, it doesnt work too.