Go Down

Topic: Mq3 sensor -> LED stripe (Read 48 times) previous topic - next topic

sylke

Hi HALLO

we are making alcohol mask with MQ3 alcohol sensor!

we will going to use 1m digital LED stripe, adafriut Neopixels.

If the alcohol level is over than 500, 1-20 pixels will turn on as RED color.
100<alcohol level<500 - 21~40 YELLOW color.
under 100 alcohol level - 41~60  GREEN color.

(IN THE ATTACHED PICTURE ARDUINO IS NOT TURNED ON, WE KNOW :) )

This is the code that we used:
#include <Adafruit_NeoPixel.h>
int mq3_analogPin = A0; // connected to the output pin of MQ3
#define PIN 6
// remenber 100 to 1000 ohm resistor in series with each led


Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

void setup()
{

Serial.begin(9600); // open serial at 9600 bps
}

void loop()
{
// give ample warmup time for readings to stabilize

int mq3_value = analogRead(mq3_analogPin);
Serial.println(mq3_value);

if (mq3_value<100)
{
    for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, 0,255,0);
    strip.show();
    delay(50);

}
}  else if(mq3_value>500)
{
    for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, 255,0,0);
    strip.show();
    delay(50);
}
}
else
{
    for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, 255,255,0);
    strip.show();
    delay(50);
}
delay(100); //Just here to slow down the output.
}}





It is not working now, and we dont know if it is because of the code or the connection to the arduino/power supply, someone can maybe help?

Thank you in advance!

knut_ny

#1
Mar 04, 2016, 02:00 pm Last Edit: Mar 04, 2016, 02:20 pm by knut_ny
Code is OK.
Select correct card and com-port.. and it should upload.

(I dont like the way you power your circuit. Use external power or lower pwm value)

Code: [Select]
#include <Adafruit_NeoPixel.h>
int mq3_analogPin = A0 , i; // connected to the output pin of MQ3
#define PIN 6
#define  pwm  200 // Led intensity
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
  Serial.begin(9600); // open serial at 9600 bps
   strip.begin();
}

void loop()
{
  int mq3_value = analogRead(mq3_analogPin);
  Serial.println(mq3_value);
  if (mq3_value < 100)  // LEDs 40..59 green
  {
    for (i = 0; i < 40; i++) strip.setPixelColor(i, 0, 0, 0);
    for (i = 40; i < 60; i++) strip.setPixelColor(i, 0, pwm, 0);
  }
  else if (mq3_value > 500) // LEDS 0..20 red
  {
    for (i = 0; i < 20; i++)strip.setPixelColor(i, pwm, 0, 0);
    for (i = 20; i < 60; i++)strip.setPixelColor(i, 0, 0, 0);
  }
  else  // LEDS 20..39 yellow
  {
    for (i = 0; i < 20; i++) strip.setPixelColor(i, 0, 0, 0);
    for (i = 40; i < 60; i++) strip.setPixelColor(i, 0, 0, 0);
    for (i = 20; i < 40; i++) strip.setPixelColor(i, pwm, pwm, 0);
  }
  strip.show();
  delay(150);
}
Ny

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy