Highscore on Breathalyzer

Hi guys,

i’m currently working on a breathalyzer as a party gadget.
I’m using a MQ-3 Gas sensor, Arduino Uno and a 1m NeoPixel strip (30Leds).

My wish is to show the current “highscore” (a peak hold) on the strip, so it becomes more of a game.

Does anyone has an idea for me how to achieve that?

I couldn’t find a suitable solution on other projects (for example VU Meters). As I’m quite new to Arduino maybe the codes were a bit to complicated for me to adapt onto my project.

Here is my sketch so far:

#include <Adafruit_NeoPixel.h>
#define NEOPIXELPIN 6
#define PIXNUM 30

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXNUM, NEOPIXELPIN, NEO_GRB + NEO_KHZ800);

int analogPin = A0;

int Value = 0;

void setup()
{
  Serial.begin(9600);
  
  strip.begin();
  strip.show();
  
  pinMode(analogPin, INPUT);
}

void loop()
{
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);

  alcohol();
  
  strip.setBrightness(255);

}

void alcohol(){  

  //get the value of the MQ-3
   Value = analogRead(analogPin);

  //lower the shown Value
  for(int y = 0; y <= 30; y++){
    strip.setPixelColor(y, strip.Color(0, 0, 0));
  }

  //show the Value on the NeoPixel
  for(int i = 0; i < map(Value, 100, 400, 0, 30); i++){
    strip.setPixelColor(i, strip.Color(i*3, 30 - i, 0));
  }
  strip.show();
}

Nice easter

What actual values are you getting from the sensor?

Did you see the comments Google found searching for “MQ-3 Gas sensor”. They relate to sensor value vs. temperature.

Paul

Hi Paul,

I guess you don't mean the values that are printet by the serial monitor?!

I don't need to know the exact concentration as it is just a fun gadget.

Isn't it possible to just hold the highest shown pixel of the strip?

Tim

timbo91:
Hi Paul,

I guess you don't mean the values that are printet by the serial monitor?!

I don't need to know the exact concentration as it is just a fun gadget.

Isn't it possible to just hold the highest shown pixel of the strip?

Tim

Just wondered. You get the value once and print it on the monitor and then get a different value and use that for the LED display. And then get another value and print it and then get another value and use it. Is there something wrong with the first value?

Not familiar with the LED display functions.

Paul

Paul_KD7HB:
Just wondered. You get the value once and print it on the monitor and then get a different value and use that for the LED display. And then get another value and print it and then get another value and use it. Is there something wrong with the first value?

Not familiar with the LED display functions.

Paul

There is nothing wrong with the first value. I just want to show the highest measured value of the sensor on the Neopixels.

Just in case of understanding: higher value of the Sensor means more Leds are light up at the strip

There is nothing wrong with the first value. I just want to show the highest measured value of the sensor on the Neopixels.

You get a reading. It is higher than the highest value, or it isn't. Determining that isn't rocket science. It's a simple if statement.

If the current reading is higher than the highest reading, you have a new highest reading, so replace the highest reading with the current reading. A dirt simple assignment.

Well, it would be IF you had a place to store the highest reading so far.

How will you reset the highest reading? Reboot the Arduino?

Do you know the range of expected values ?

Let's say they go from 0 to 100. You can use the map() function to convert 0 to 100 to 0 to 30 which will give you the number of the LED to write to.

How to determine the highest value ?
Easy. Initially set the highest value to 0, then each time you take a reading compare it with the current highest value. If it is larger then set the highest reading to the current reading and display it.

I tried a few different things but nothing worked, i don’t know why…

this is my latest try based on a Peak hold from a VU Meter I found:

  if(Value > 0 && Value <= 30){
    map(Value,100, 400, 0, 30); 
    strip.setPixelColor(Value, (255, 255, 255));
  }
  strip.show();

Apart from anything else that may be wrong in the code that you have not posted

map(Value,100, 400, 0, 30);

throws the result of the map() away. It needs to be assigned to a variable as it does not change the value of your Value variable.

Also, why are you checking that Value is between 1 and 30 ? Is that is what is returned by the sensor ? If so why then try to map() values between 100 to 400 ?