Capacitive Sensor to Turn on Neopixel LED's (w/ Arduino)
by dgh20 in Circuits > Arduino
891 Views, 0 Favorites, 0 Comments
Capacitive Sensor to Turn on Neopixel LED's (w/ Arduino)
This project is intended to provide instructions to set up an arduino based circuit (as a starting point for use in other projects) that allows for a metal object to be used (in this case a piece of foil tape) as a touch sensor (Capacitive Input) to reach a predetermined threshold as measured by the Arduino (Processing) to activate LED's (Output) connected to the circuit (in this case a strip of neopixel 2812B RGB led's).
This project is inspired by course 3681C at UWF under the instruction of Professor Asmuth and will be developed into a larger project for this class, but for me specifically it has a long existing tie to an old circuit I pulled from an old metal based touch light which I connected to a single strand of speaker wire I attached to my head board of my bed when growing up and it worked fabulously.
The light color and intensity of the LED's in this project are randomized and cycle with each loop of the code as long as there is a change in the capacitance (a hand touching the foil tape) sensor. Once the capacitance returns to normal (no contact with the foil tape) the LED's turn off.
Supplies
Supplies start with a Super Starter Kit UNO R3 Project (through Amazon.com)
In particular from the kit; the Bread board, Uno R3, jumper wires (2 Red, 3 Black, 2 White, 1 Yellow), a (1MΩ) resistor & (10MΩ) resistor, use of the usb cable for loading code, and 9v battery with adapter for powering the board once the code is loaded.
B41827 2200 µF capacitor, for power smoothing/filtering. (through digikey.com)
Foil tape (Walmart or any hardware store like Lowes or Home Depot, even Amazon.com)
Strip of addressable 2812B Neopixel RGB LED's (with or without* connector/adapter) (through Amazon.com or Adafruit.com), for this project I used an 8 LED strip.
*Note: If the Neopixel strip is not used with the connector the user will have to solder wires to it for connection to the circuit. If this happens additional wires, soldering setup and heat shrink will likely be needed.
Step 1: Building the Circuit
In this step I will walk the viewer through a video of actually building the circuit and connecting it to an arduino, a schematic of it will also be supplied, as the foil tape is not an object in tinkercad, I substituted it with another object and labeled it accordingly.
The link to the video for this project build is at:
Step 2: Loading the Code
The code is/should be attached to this step as an Arduino IDE .ino sketch, and the libraries needed (which can be found through the Arduino IDE library manager) are: CapacitiveSensor by Paul Stoffregen, and Adafruit_NeoPixel.
This code sketch is a modified mashup of the code found for a Capacitive Sensor (https://create.arduino.cc/projecthub/amalmathewtech/touch-controlled-light-using-arduino-d2f878) and a basic Neopixel sketch introduced in course 3681C by Professor Thomas Asmuth.
The Code sketch is annotated and once loaded allows for a person to touch the foil tape which causes a measurable change in the capacitance of the circuit sensor and results in the LED Neopixel strip to turn on and due to random seeds generated for Red, Green and Blue, each time (in the code set for 500 Miliseconds) the loop processes the colors of the LED's and intensity change. Once the foil is no longer touched the LED's reset to an off condition and the program loops until the foil is touched again.
Downloads
Notes About This Project
The file included in this "Notes section" is the Neopixel sketch done in class, however, I did add a random seed into the code which is a deviation from the one presented to us. The code (from Step 2) is well annotated to ensure a novice such as myself can hopefully make sense of what is going on in the Sketch.As listed in the code in Step 2, the duration of the delay can be changed by increasing or decreasing the time (in milliseconds) in line 25 and the randomness can be removed from the sketch by changing "randNumber1,randNumber2,randNumber3" (which are the RGB values in order 1,2,3) to a value between 0 (off) to 255 in line 79.
Please note that I did not have success with the "pixels.clear(); // Set all pixel colors to 'off'" from the mashed sketches, which is why I chose to go with a; "pixels.setPixelColor(i, pixels.Color(0,0,0));// Set all pixel colors to 'off'" to turn the Neopixel strips off at the beginning of the loop and at the end of the loop.
Last thing to note is to run the code in a serial monitor mode to find out where about the measurements are for your particular setup and determine at what point (Value read as shown on the serial monitor) to activate the Neopixel LED's which can be modified in line 63. In this sketch it is set to 1500 as my slightest touch was in the 1500 value range up into the 4K+ range at full contact with the foil tape.
If the strip of 2812B Neopixel LED's are less than or greater than the number used for this project (which was an 8 LED strip) then the number of LED's will have to be updated in line 16.
In hind sight after looking at the schematic, pictures and videos the two jumper wires (Red and Black) from the positive and negative rails on both sides of the bread board could be removed and the jumper wires (Red +5V and Black GND) from the Arduino board to the bread board could run directly into the positive and negative rails of the breadboard with the capacitor. (As shown in the updated schematic in this section)
Downloads
Bibliography (Compiled With Zotero)
Asmuth, Thomas. Neopixel Sketch. 1 Nov 2021
Burgess, Phil. Adafruit NeoPixel Library. C++. 2012. Reprint, Adafruit Industries, 2021. https://github.com/adafruit/Adafruit_NeoPixel.
Evans, Brian W. Arduino Programing Notebook. San Francisco, California: Creative Commons, 2007. http://creativecommons.org/1 ice nses/by-nc-sa/3. 0/.
Mathew, Amal. “Touch Controlled Light Using Arduino.” Arduino Project Hub, January 27, 2018. https://create.arduino.cc/projecthub/amalmathewte...
Stoffregen, Paul. CapacitiveSensor Library. C++, 2021. https://github.com/PaulStoffregen/CapacitiveSenso...
Weddington, Eric B. AVR. C. 2015. Reprint, Synapseware, 2020. https://github.com/Synapseware/avr/blob/460e75ddf...