Electronics Proficiency Lvl 2

Introduction: Electronics Proficiency Lvl 2

This will be a quick tutorial to help you complete the level 2 electronics proficiency. You do not have to do this exactly as is! You can substitute parts/components as you like but will be responsible for changing the code to make it work. I will add comments to the code to explain what each part does.

The last thing is the microcomputer. We are using the Arduino Nano. This can be swapped out for an Arduino Uno or any other microcontroller. Operations may be different and you would be responsible to get the other computer to work.

The led strip is in the silver bag in the top of the MHD staff drawer. The microphone is also inside the bag with the LEDs. Once you have finished please return them here!

Supplies

  1. Microcomputer
    1. Arduino Nano
  2. Wires
    1. 7x F2F cables
      1. 2x Black
      2. 2x Red
      3. 3x various colors
  3. LED Strip
    1. Again we only have one. It will be with the Microphone.
  4. Microphone
    1. We only have one so attach it at the end! It will be in the staff drawer.

Step 1: Microcomputer

To start we need to be comfortable with the parts of the Arduino Nano. As seen in the picture, there are two main sides to the controller. The only parts we are worried about are as follows:

  • +5V
  • GND
  • GND
  • 3V3 (this can also appear as 3.3V but mean the same thing)
  • D2
  • D3
  • D4
  • Mini USB (the silver plug at the end)

Step 2: LED Strip

Start by getting the end of the led strip. This should have a black plug (with 4 wires going into it) and then two stray wires (1x yellow, 1x red). We will only care about the black plug. Orient it so that are in this order from left to right: red, blue, green, yellow. These colors correspond with VCC, D0, C0, GND. Using the female side of the wires push the black wire onto the GND, the red onto the VCC and the different colors onto the middle two.

**When attaching the wires, make sure that the silver tab is facing up! This will help them slide on to the pins. (Seen in the first picture)

We then will take the other female side and attach it to the Nano. Attach the GND wire from the LED strip to the GND next to D2. Then take the VCC wire and attach it to the +5V pin. Attach the C0 and D0 pin from the LED to the D2 and D3 pin on the Nano. Plug locations can be seen in the third and fourth pictures.

Step 3: Attach the Microphone

** NOTE **

Wires were scarce while taking pictures. I will update this picture when possible to reflect the instructions better. Here are the wire colors in the directions versus the colors in the pictures:

  • red -> brown
  • black -> black
  • colored -> grey

The microphone will be attached the same as the LED Strip but with only 1 data pin instead of two.

This time we need to attach the VCC pin from the mic to the 3V3 pin on the nano using a red wire. Then the GND pin on the mic to the GND on the nano using the black wire and finally the OUT pin on the mic to the D4 pin on the nano with the colored wire.

Step 4: Arduino IDE

Using the computers closest to the 3D printers, open Arduino IDE. These computers have special software installed to control our LED strip. Then using a micro USB attach the nano to the computer.

  1. Click Tools in the top bar
  2. Then under Board, click Arduino Nano
  3. Under Processor click ATmega328P (Old Bootloader)
    1. If this does not work then select ATmega328P
  4. Finally, under Port, click the only option shown.

Once that is all selected, copy and paste this code into the sketch window (where it says void setup() and void loop()). Then click the arrow pointing to the right (it can be found right below the edit menu item). This will upload the code to your nano.

#include <APA102.h>
// Define which D pins used. const uint8_t clockPin = 2; const uint8_t dataPin = 3; const uint8_t micPin = 4;// Create an object for writing to the LED strip. APA102<dataPin, clockPin> ledStrip;// Set the number of LEDs to control. const uint16_t ledCount = 60; uint8_t leds; // Audio const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz) unsigned int sample;// Create a buffer for holding the colors (3 bytes per color). rgb_color colors[ledCount];// Set the brightness of leds (the maximum is 31 but can be blindingly bright). const int brightness = 12; void setup() { Serial.begin(9600); } void loop() { equilizer(); ledStrip.write(colors, ledCount, brightness); } void equilizer() { unsigned long startMillis= millis(); // Start of sample window unsigned int peakToPeak = 0; // peak-to-peak level unsigned int signalMax = 0; unsigned int signalMin = 1024; uint8_t time = millis() >> 4; // collect data for 50 mS while (millis() - startMillis < sampleWindow) { sample = analogRead(micPin); // toss out spurious readings if (sample < 1024) { if (sample > signalMax) { signalMax = sample; // save just the max levels } else if (sample < signalMin) { signalMin = sample; // save just the min levels } } } peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude memset(colors, 0, sizeof(colors)); // clears the colors from LED strip leds = ranges(peakToPeak); // call ranges to see how many LEDS to light up uint32_t stripColor = peakToPeak/1000 + peakToPeak%1000; for(uint16_t i = 0; i <= leds; i++) { colors[i] = hsvToRgb((uint32_t)stripColor * 359 / 256, 255, 255); // adds the colors back to the strip while only lighting up the needed leds. } } rgb_color hsvToRgb(uint16_t h, uint8_t s, uint8_t v) { uint8_t f = (h % 60) * 255 / 60; uint8_t p = (255 - s) * (uint16_t)v / 255; uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255; uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255; uint8_t r = 0, g = 0, b = 0; switch((h / 60) % 6){ case 0: r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; case 2: r = p; g = v; b = t; break; case 3: r = p; g = q; b = v; break; case 4: r = t; g = p; b = v; break; case 5: r = v; g = p; b = q; break; } return rgb_color(r, g, b); } uint8_t ranges(uint8_t vol) { if(vol > 800) { return 60; } else if(vol > 700) { return 56; } else if(vol > 600) { return 52; } else if(vol > 500) { return 48; } else if(vol > 400) { return 44; } else if(vol > 358) { return 40; } else if(vol > 317) { return 36; } else if(vol > 276) { return 32; } else if(vol > 235) { return 28; } else if(vol > 194) { return 24; } else if(vol > 153) { return 20; } else if(vol > 112) { return 16; } else if(vol > 71) { return 12; } else if(vol > 30) { return 8; } else { return 4; } }

Step 5: Once Finished

Good job! Take a picture of it all working. If the led strip doesn't completely light up then the screw on the back of the microphone was adjusted. You can change the code to fix this (ask for help if you want) but is not needed. If you want to keep the project, the links for the microphone and led strip are shown below. We need those to stay at the Hub for other staff to finish it as well.

Now before disassembling everything reattach the nano to the computer and follow these steps in the Arduino IDE:

  • Click File
  • Examples
  • Basic
  • Blink
  • Once finished click the upload button

This is to ensure everyone is doing the entire process and not just attaching the wires. Now disassemble everything and put it back where you found it!

Links:

Microphone

LEDs will be added once I have the link

Be the First to Share

    Recommendations

    • Micro:bit Contest

      Micro:bit Contest
    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge
    • Rocks, Gems, and Stones Speed Challenge

      Rocks, Gems, and Stones Speed Challenge

    Comments