hi , i want to make a arduino gas sensor with neopoxel strip to light up the emergency
i have the code for the gas sensor and the neopixel led code but i cannot understand how to connect the two codes toghether so when the sensor senses gas i need my neopixel to light up , and when in stand by to do nothing.
This code is for the gas sensor
// viral science
// gas sensor
int redLed = 12; //led red
int greenLed = 11; //led green
int buzzer = 10; //buzzer
int smokeA0 = A5; //mq2 sensor
int sensorThres = 620; //change the threshold value asper your need
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
if (analogSensor > sensorThres) //checks if it has reached threshold value
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}
And this code is for neopixel
// Left as-is from the example
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 5
// All of this stuff below is from the example
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);
//NOTE: I tested this code with an 8 LED module, but you should be able to daisy chain multiple modules
//NOTE: Try changing the "8" to "4" to see how it reacts.
// This warning is from the example, probably worth considering
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
// This stuff is from the example, I commented it out since I am not using a Trinket
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
//#if defined (__AVR_ATtiny85__)
// if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
//#endif
// End of trinket special code
strip.begin();
strip.show();
}
void loop() {
// This is a 2 color wigwag
WigWag2(strip.Color(255, 0, 0), strip.Color(255, 0, 0), 200); // Blue and Red
// ClearLights();
delay(10);
}
void WigWag2(uint32_t c, uint32_t c2, uint8_t wait) {
for (int j = 0; j < 20; j++) { // The j<# determines how many cycles
for (int i = 0; i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, c);
}
for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, 0);
}
strip.show();
delay(wait);
for (int i = 0; i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, 0);
}
for (int i = (strip.numPixels() / 2); i < strip.numPixels(); i = i + 1) {
strip.setPixelColor(i, c2);
}
strip.show();
delay(wait);
}
}
i need to put the neopixel code in if statement , can you help me how please ?