We finally moved on to circuits! Woohoo! We borrowed a neon pixel LED from a fellow classmate and tried it with Arduino.

We looked at the Adafruit Neopixel Arduino library to make things happen, but it wasn’t as easy as it seemed.

Here’s the circuit on a breadboard:

2015-11-24 12.57.02

Neopixel soldering was done, we tried to connect it this way and another, but it didn’t work! We consulted with few other classmates and it appeared that probably we had soldered the wrong side of the strip (that’s how we got it). We resoldered and it worked!

2015-11-24 12.57.11

To test it we used one of the examples in the Arduino library.

After we got it going, we wanted to add a photocell to control the light (turn it on and turn it off). We tried it before with a regular LED but now we struggled a bit with code as the one we knew and the one from Arduino library for neon pixel strip was a bit different. Good that one of ITP’s residents Pedro was walking nearby, so we asked for his help.

Finally, together me made it work. Here’s a circuit:

2015-11-24 14.01.26

And here’s the code:

//---------------------------------------------------------------------------------------------- Neopixel
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            6
#define NUMPIXELS      3
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
//---------------------------------------------------------------------------------------------- Photocell
int photoPin = A0;
int sensorValue = 0;
int brightness = 0;
int offset = 0;
void setup() {
  //Start Serial
  Serial.begin(9600);
  //Start Neopixel
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  pixels.begin();
}
void loop() {
    sensorValue = analogRead(A0);
    brightness = map(sensorValue, 10, 40, 0,255);
    if(brightness <= 10){
      brightness = 0;
    }
    if(brightness >= 240){
      brightness = 255;
    }
    pixels.setPixelColor(0, pixels.Color(0, 0, brightness)); // Moderately bright green color.
    pixels.setPixelColor(1, pixels.Color(0, brightness, 0)); // Moderately bright green color.
    pixels.setPixelColor(2, pixels.Color(brightness, 0 ,0)); // Moderately bright green color.
    Serial.println(brightness);
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(50);
}

And here’s the video:

We also then tried to add the second photocell — because after all the idea is that each photocell would control the different piece.

2015-11-24 15.10.01

Code is the same with the second lines added for the second photocell:

//---------------------------------------------------------------------------------------------- Neopixel
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            6
#define NUMPIXELS      3
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
//---------------------------------------------------------------------------------------------- Photocell
int photoPin1 = A0;
int photoPin2 = A1;
int sensorValue1 = 0;
int sensorValue2 = 0;
int brightness1 = 0;
int brightness2 = 0;
void setup() {
  //Start Serial
  Serial.begin(9600);
  //Start Neopixel
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  pixels.setPixelColor(2, pixels.Color(0, 0, 0));
  pixels.begin();
}
void loop() {
    sensorValue1 = analogRead(photoPin1);
    brightness1 = map(sensorValue1, 10, 40, 0,255);
    sensorValue2 = analogRead(photoPin2);
    brightness2 = map(sensorValue2, 10, 40, 0,250);

    if(brightness1 <= 11){
      brightness1 = 0;
    }
    if(brightness1 >= 255){
      brightness1 = 250;
    }
///////////////////////////////////
    if(brightness2 <= 11){
      brightness2 = 0;
    }
    if(brightness2 >= 240){
      brightness2 = 250;
    }
    pixels.setPixelColor(0, pixels.Color(0, 0, brightness1)); // Moderately bright green color.
    pixels.setPixelColor(1, pixels.Color(0, brightness2, 0)); // Moderately bright green color.
    pixels.setPixelColor(2, pixels.Color(0, 0, 0));
    Serial.print(brightness1);
    Serial.print(" | ");
    Serial.println(brightness2);
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(50);
}

The real struggle with photocells is that you have to remap the values every single time. Even now it took us 5-6 times until we could find a good value reading.

To avoid this, Pedro mentioned, there is a bunch of different ways to achieve the same result but will less frustration. One of such ways is using a resistor.

2015-11-24 15.32.11

The resistor would be a final component in closing the circuit; just as you see in the picture above, adding right resistor lets LED to light up, whereas if we added a stronger resistor, LED would remain silent.

For us this is still unexplored territory, so what we’ll do next is play some more with possible options and only then choose the final one.

We also want to buy a longer neon pixel strip that would fit the perimeter of our base round and see how it works (the piece that we borrowed still doesn’t look very stable).

Leave a Reply

Your email address will not be published. Required fields are marked *