09: Electronic Output Devices
Lab Day 9
Today the focus of lab was on electronic output devices. During lecture, we discussed many different types of output devices, such as motors, sollenoids, and RGB LED’s. My idea was to turn on individual LED lights on a strip of LED’s. First, I cut a piece of carboard that was the same length as the strip of eight LED’s using an x-acto knife. I then put a piece of copper tape along the carboard and labeled with blue sharpie where each LED section was.
To make this a position sensor, I decided to varry the amount of layers of insulation tape. I put no layers of insulation tape on the first section, and then for every subsequent section, I added an additional layer of insulation tape, all the way up to seven layers on the eigth section.
Then, I soldered a wire to one end of the copper. I also soldered a 1 Mega-Ohm resistor to the other end of the wire. I did this because I planned to a similar setup to the touch sensor setup we used in class last week. This setup requires that you put one end of the resistor into digital pin seven and the other end of the resistor along with the wire soldered to the copper pad into digital pin five.
For today’s lab, I decided to use the basic touch sensor code to measure the relative sensor value on each of the eight sections on the copper and then use a series of condiional statements to power the individual LED’s. The code I used is below.
#include <CapacitiveSensor.h> CapacitiveSensor Sensor = CapacitiveSensor(7,5); void setup() { Serial.begin(9600); // put your setup code here, to run once: } void loop() { long sensorValue = Sensor.capacitiveSensor(300); Serial.println(sensorValue); // if (sensorValue > 100) analogWrite(11,100); //else analogWrite(11,0); delay(10); }
After uploading this code to my board with the 1 Mega-Ohm resistor and the wire attached to the copper strip, I put my finger on each section and used the serial monitor to get a general sense of what the range of values was for that particular section of the copper strip. The data that I found and implemented into my next code is shown below.
Next, I used those values to create a series of conditional statements for my code. I attached my code below.
#include <CapacitiveSensor.h> #include <Adafruit_NeoPixel.h> #define NUMPIXELS 8 Adafruit_NeoPixel pixels(8, 6, NEO_GRB + NEO_KHZ800); CapacitiveSensor Sensor = CapacitiveSensor(7, 5); void setup() { Serial.begin(9600); pinMode(LED_BUILTIN, OUTPUT); pixels.begin(); } void loop() { pixels.clear(); for (int i = 0; i < NUMPIXELS; i++) { long sensorValue = Sensor.capacitiveSensor(300); Serial.println(sensorValue); delay(10); if (sensorValue >= 20 && sensorValue <= 85) { pixels.setPixelColor(i, pixels.Color(0, 150, 0)); } if (sensorValue > 85 && sensorValue <= 110) { pixels.setPixelColor(i, pixels.Color(0, 150, 0)); } if (sensorValue > 110 && sensorValue <= 123) { pixels.setPixelColor(i, pixels.Color(0, 150, 0)); } if (sensorValue > 123 && sensorValue <= 150) { pixels.setPixelColor(i, pixels.Color(0, 150, 0)); } if (sensorValue > 150 && sensorValue <= 200) { pixels.setPixelColor(i, pixels.Color(0, 150, 0)); } if (sensorValue > 200 && sensorValue <= 240) { pixels.setPixelColor(i, pixels.Color(0, 150, 0)); } if (sensorValue > 240 && sensorValue <= 320) { pixels.setPixelColor(i, pixels.Color(0, 150, 0)); } if (sensorValue > 320 && sensorValue <= 40000) { pixels.setPixelColor(i, pixels.Color(0, 150, 0)); pixels.show(); } else { digitalWrite(LED_BUILTIN, LOW); } delay(100); } }
To set up my circuit, I essentially combined the setup from the touch sensor and for the RGB LEDs (one wire to 5V, one wire to pin 6, and one wire to ground). A picture of my circuit is shown below.
When I uploaded my code to my arduino, it did not do what I had intended exactly, but I was happy with the result. I found that if you hold the bare copper tape down the LED lights will go through a cycle turing on and off. Also, if you press near the LEDs, they will turn on. I think part of the issue was the proximity of the LEDs and that there were not LEDs that were specifically attached to one copper section. That said, I think it turned out pretty well.
I also found that by switching around the numbers inside of the pixel parentheses, I could modify the colors of the lights! A small diagram of some color examples along with videos of my circuit are shown below.