Help Needed with LED Outputs

I want to use the Adafruit 24 LED ring to combine these two projects, however, my coding is not good and could use some help.

How would I code the nano pixel to do what it does in this project:https://create.arduino.cc/projecthub/yvesmorele/particles-detector-for-air-quality-44142c?offset=37&ref=search&ref_id=nanopixel+ring

But for this set up:https://create.arduino.cc/projecthub/plouc68000/portable-fine-dust-pm10-analyzer-with-large-oled-digits-1c20c2?ref=search&ref_id=PM2.5&offset=2?

Any help is much appreciated!

Charlie

Hi Charlie, I'll post your links correctly for you this time. Please use the "link" icon. This forum's software does not automatically parse links.

https://create.arduino.cc/projecthub/yvesmorele/particles-detector-for-air-quality-44142c?offset=37&ref=search&ref_id=nanopixel+ring

https://create.arduino.cc/projecthub/plouc68000/portable-fine-dust-pm10-analyzer-with-large-oled-digits-1c20c2?ref=search&ref_id=PM2.5&offset=2?

So let's see your best attempt to create the code you need. If you don't feel confident enough to attempt to put the code together, then you are not ready for this project and you should spend more some time working through tutorials. But if you are ready to attempt it, do your best, even if the code will not compile/verify, or does not work as expected, post it and we can help you. Please read the forum guide to find out how to post code and error messages and read the advice about not saying "it doesn't work".

Thanks for the help with the links, I wasn’t aware. This is the code I have at the moment. When uploaded it spins the fan of the sensor and the first two LEDs on the ring light up white, I’m not sure what the issues are…

// Target: Arduino UNO

// SDS011 on Serial
#include "SoftwareSerial.h"
SoftwareSerial mySerial(2, 3); // RX, TX for SDS011 sensor ( to keep Serial monitor available )

// 24 LED ring
#include <Adafruit_NeoPixel.h>
#define PIN        6 // On Trinket or Gemma, suggest changing this to 1
#define NUMPIXELS 24 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

// colors for 3 bands; green, yellow, red, and each band increases in brightness
const uint32_t color_table[NUMPIXELS] =
{ pixels.Color( 0, 2, 0 ), pixels.Color( 0, 4, 0 ), pixels.Color( 0, 6, 0 ), pixels.Color( 0, 8, 0 ), pixels.Color( 0, 10, 0 ), pixels.Color( 0, 12, 0 ), pixels.Color( 0, 14, 0 ), pixels.Color( 0, 16, 0 ), // green band
  pixels.Color( 2, 2, 0 ), pixels.Color( 4, 4, 0 ), pixels.Color( 6, 6, 0 ), pixels.Color( 8, 8, 0 ), pixels.Color( 10, 10, 0 ), pixels.Color( 12, 12, 0 ), pixels.Color( 14, 14, 0 ), pixels.Color( 16, 16, 0 ), // yellow band
  pixels.Color( 2, 0, 0 ), pixels.Color( 4, 0, 0 ), pixels.Color( 6, 0, 0 ), pixels.Color( 8, 0, 0 ), pixels.Color( 10, 0, 0 ), pixels.Color( 12, 0, 0 ), pixels.Color( 14, 0, 0 ), pixels.Color( 16, 0, 0 ), // red band
};

void setup()
{
  mySerial.begin(9600);     // SDS011
  mySerial.setTimeout(200);
}

void loop()
{
  // Read SDS011
  unsigned char buffSDS[25];
  mySerial.readBytesUntil(0xAB, buffSDS, 20);
  unsigned int PM2_5 = ((buffSDS[3] * 256) + buffSDS[2]) / 10; // extract PM2.5 value
  unsigned int PM10 = ((buffSDS[5] * 256) + buffSDS[4]) / 10; // extract PM10 value

  // map sensor to display
  int num_pixels_on;
  num_pixels_on = map( PM2_5, 0, 999, 0, 24 );
  num_pixels_on = constrain( num_pixels_on, 0, 24 );

  // render on display
  pixels.clear(); // Set all pixel colors to 'off'
  for (int i = 0; i < num_pixels_on; i++)
    pixels.setPixelColor(i, color_table[ i ]);
  pixels.show();
}

PaulRB: Hi Charlie, I'll post your links correctly for you this time. Please use the "link" icon. This forum's software does not automatically parse links.

Actually, the corrected ("sanitised") versions of the links are, FWIW:

https://create.arduino.cc/projecthub/yvesmorele/particles-detector-for-air-quality-44142c

https://create.arduino.cc/projecthub/plouc68000/portable-fine-dust-pm10-analyzer-with-large-oled-digits-1c20c2

Have you tested that the led ring works correctly? Use one of the example sketches such as "strandtest" from the examples menu.

Next, can you find a test sketch for the sensor? One which simply reads the sensor values, echoes them to serial monitor, and does not rely on any other components.

The above is important to ensure your components are connected and working correctly.

You need

pixels.begin();

in setup().

I can confirm the LED ring works correctly from previous tests and that the sensor can output values by its self. Both components work.

I have added this to the code [pixels.begin();] however it does the same thing still, unfortunately.

Yes but we are not asking that. We are saying wired up the way it is have you just tried running software that exercises just one component.

Then when each one works on its own then just run the sensor and the LEDs.

The circuit has some shortcomings, you should have a large capacitor across the power supply of the LED ring and something like a 330 ohm series resistor in the data line to the ring. Also you seem to be powering it all from the Arduino’s 5V pin, I doubt if you can get enough current from this to drive it all. What is the ultimate source of power, USB?

Do you know how much current your sensor uses? If it has a fan it might be a lot and the fan might also be generating interference that is upsetting the Arduino.

For the LED ring allow 60mA per LED.