<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PlastiBots</title>
	<atom:link href="http://www.plastibots.com/index.php?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.plastibots.com</link>
	<description>My LEGO Robotics, DIY Hacks and other stuff</description>
	<lastBuildDate>Sat, 12 May 2012 12:42:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Red Light Camera Alerter</title>
		<link>http://www.plastibots.com/?p=2392</link>
		<comments>http://www.plastibots.com/?p=2392#comments</comments>
		<pubDate>Wed, 11 Apr 2012 01:08:58 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Microcontrollers]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2392</guid>
		<description><![CDATA[I had the chance to play with some new components &#8211; namely the Adafruit Monochrome 128&#215;32 OLED display and the Adafruit UP501 66 channel GPS receiver. As I was pondering ideas of what to build, I thought that it would be neat to be alerted when approaching a red light camera.  In my local area [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-2393" title="RedLightCamFinder1b" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/RedLightCamFinder1b.jpg" alt="" width="500" height="255" />I had the chance to play with some new components &#8211; namely the <a href="https://www.adafruit.com/products/661" target="_blank">Adafruit Monochrome 128&#215;32 OLED display</a> and the <a href="https://www.adafruit.com/products/660" target="_blank">Adafruit UP501 66 channel GPS receiver.</a> As I was pondering ideas of what to build, I thought that it would be neat to be alerted when approaching a red light camera.  In my local area (Southern Ontario), there are currently about a hundred or so of these cameras around the GTA.  However, it appears that new legislation may see this number grow much larger.   This is more of a proof of concept project to me than it is useful as, a) I don&#8217;t intend on trying to run any red lights, and b) there are only about 1 or 2 of them within the area.   However, it was fun to build and tweak to make it useful.  Read on&#8230;</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><span id="more-2392"></span></p>
<p>The general idea is that the GPS tracks the coordinates while driving,  the Arduino sketch has an array of red light camera location coordinates that it compares against the current reading.    On a regular basis, it checks the current position of the car against the array of red light camera locations.   With each check, it finds the closest red light camera location.  If that location is less than a pre-determined buffer distance (e.g. 3 km away), it will begin reporting on it via the OLED as well as the Status LED.</p>
<p>The Status LED flashes with 4 modes:</p>
<ul>
<li>green &#8211; indicates that the system is functional and GPS is returning results.</li>
<li>blue &#8211; early warning of approaching red light camera location less than 600 metres away.</li>
<li>yellow -warning of red light camera less than 200 metres away.</li>
<li>red &#8211; red light camera intersection less than 50 metres away.</li>
</ul>
<p><br class="spacer_" /></p>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Parts:</span></strong></p>
<ul>
<li><a href="https://www.adafruit.com/products/661" target="_blank">Adafruit Monochrome 128&#215;32 OLED display</a></li>
<li><a href="https://www.adafruit.com/products/660" target="_blank">Adafruit UP501 66 channel GPS receiver</a></li>
<li><a href="https://www.adafruit.com/products/589" target="_blank">Adafruit Perma-Proto Quarter Sized Breadboard</a></li>
<li>Atmega 328P with UNO Bootloader</li>
<li>10mm Diffused RGB LED</li>
<li>Other bits (5v/3.3v regulator, female headers, resistors etc)</li>
</ul>
<p><br class="spacer_" /></p>
<p>The OLED will display the distance to the Red Light Camera in Km, Direction that the vehicle is travelling, Speed, # of Satellites, Latitude and Longitude of the vehicle.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/SSD1306AdafruitOLED_2.jpg"><img class="aligncenter size-medium wp-image-2390" title="SSD1306AdafruitOLED_2" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/SSD1306AdafruitOLED_2-300x201.jpg" alt="" width="300" height="201" /></a></p>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Build:</span></strong></p>
<p><br class="spacer_" /></p>
<p>The main unit consists of an Atmega 328P mounted to an <a href="https://www.adafruit.com/products/589" target="_blank">Adafruit Perma-Proto Quarter sized breadboard</a>.   The board has both 5v and 3.3v rails running down either side to provide power for various components.  The rest is a spaghetti mess of wires for all the components.   I also decided to make this unit (somewhat) modular.   The main board has been fitted with female header pins to allow all components to be plugged/unplugged.  So, if I want to re-use the controller for another project, I can just unplug all the bits and I have a dual power supply-ready Arduino.     Given that I would likely want to re-use the GPS on other projects, I hacked in USB ports on the main unit as well as a mini-USB connector on the GPS module.</p>
<p><br class="spacer_" /></p>
<p style="text-align: center;"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/RedLightCamFinder3.jpg"><img class="aligncenter size-medium wp-image-2386" title="RedLightCamFinder3" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/RedLightCamFinder3-300x285.jpg" alt="" width="300" height="285" /></a></p>
<p style="text-align: center;"> </p>
<p style="text-align: left;">As noted above, the GPS module is modular.  With the mini-USB connector, I can move it over to other projects in a breeze.   There are only 4 connectors that need to be brought to the Arduino to use this unit, so USB cables do the trick.  Although there are more pins needed, the wiring can be done at the GPS module end itself (e.g resistor between two pins).  I also wanted a minimal USB cable, so I picked up one of those self-retracting flat cable USB dongle thingamabobs and just took out the self-retracting bit.  The cable is very flexible as well.</p>
<p><br class="spacer_" /></p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/RedLightCamFinder4.jpg"><img class="aligncenter size-medium wp-image-2387" title="RedLightCamFinder4" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/RedLightCamFinder4-300x169.jpg" alt="" width="300" height="169" /></a></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Verdict:</span></strong></p>
<p><strong>Adafruit UP501 GPS Module: </strong><strong>The UP501 is small, which makes it great for fitting into small packages.  Another nice feature is that you only require 4 wires between the controller and the GPS, which makes it a perfect candidate for using readily available USB cables.   I managed to get this one before the newer <a href="https://www.adafruit.com/products/746" target="_blank">Adafruit Ultimate GPS</a> that comes with a backup battery.  As a result, my unit takes up to 45 seconds to as it would cold start every time it is powered up.  This is negligible considering I don&#8217;t need the GPS functioning the moment I start my car.  However, for other projects, this could be an issue.  Once the unit acquires its first fix, it provides fast accurate updates.  It is also great at acquiring signals indoors..  When testing, I would put it on my window sill to get a fix, then once fixed, I could move the unit to my desk to continue testing.</strong></p>
<p><br class="spacer_" /></p>
<p><strong>Adafruit 128&#215;32 OLED Module:</strong><strong> </strong><strong>I won&#8217;t go into detail here as I have already done a review on this unit <a href="http://www.plastibots.com/?p=2296" target="_blank">here</a>.  However, I will say that this is a nice, crisp, small display that works very well with small projects. </strong></p>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Code:</span></strong></p>
<pre>(<strong><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/GPSRedLightTracker1_5.zip">download</a></strong>)
<pre class="brush: csharp; collapse: true; light: false; title: ; toolbar: true; notranslate">

// Select which PWM-capable pins are to be used.
int redPin = 9;
int greenPin = 3;
int bluePin = 10;

#include &lt;SoftwareSerial.h&gt;
//SoftwareSerial mySerial(rxPin, txPin)
//SoftwareSerial nss(2, 3);  //yellow wire = RX  Blue wire = TX
SoftwareSerial nss(0, 2);   //yellow wire = RX  Blue wire = TX

#include &lt;avr/pgmspace.h&gt;
#include &lt;SSD1306.h&gt;                  //for OLED
#include &lt;SPI.h&gt;                      //for OLED
#include &lt;string.h&gt;
#include &lt;TinyGPS.h&gt;

#define OLED_RESET 7
#define OLED_DC 8
#define OLED_CS 6     // SPI slave-select
#define OLED_MOSI 11   // hardware SPI MOSI
#define OLED_CLK 13    // hardware SPI clock

// Connect the GPS Power pin to 3.3V
// Connect the GPS Ground pin to ground
// Connect the GPS VBAT pin to 3.3V if no battery is used
// Connect the GPS TX (transmit) pin to Digital 2
// Connect the GPS RX (receive) pin to Digital 3
// For 3.3V only modules such as the UP501, connect a 10K
// resistor between digital 3 and GPS RX and a 10K resistor
// from GPS RX to ground.
TinyGPS gps;
//NewSoftSerial mySerial(rxPin, txPin);

//OLED
SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

const int GPSActive = 4;               // Indicates GPS is getting data
const int statusLED = 5;               //System hearbeat LED

int updateFreq = 1000;                 //frequency to update GPS polls.  Good not to go below 1000 ms.

float flat, flon;                      //lat and long variables used in calculations
unsigned long age;                     //GPS reading age variable
float spd;                             // GPS Speed
float minDist = 100000;                //preset the minDist to some very high value (in meters)

//
//int md[] = {600, 180, 35};
//int j = 0;
//

const float ToRad = PI / 180.0;        // for HaverSine function
const float R = 6371;                  // radius earth in Km - for HaverSine function
int mappedDist = 0;                    // mapped variable converted for placement of icons on OLED
int spdProRate = 0;                    // pro rated speed value movement of road graphic on OLED - to mimic speed changes
int i = 128;                           // used for the looping through animations of the OLED
int state = LOW;                       // The input state of the status LED
int gpsStatCounter = 0;
// setup variables for Tiny GPS
void gpsdump(TinyGPS &amp;gps);
bool feedgps();

char cVal[32];
int sats;
int hdop;
String cardinal;

//********************************************************************************************************
// use for testing
boolean debug = true;            //print debugging statements to the serial port.
//********************************************************************************************************

// different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz)
#define PMTK_SET_NMEA_UPDATE_1HZ  &quot;$PMTK220,1000*1F&quot;
#define PMTK_SET_NMEA_UPDATE_5HZ  &quot;$PMTK220,200*2C&quot;
#define PMTK_SET_NMEA_UPDATE_10HZ &quot;$PMTK220,100*2F&quot;
// turn on only the second sentence (GPRMC)
#define PMTK_SET_NMEA_OUTPUT_RMCONLY &quot;$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29&quot;
// turn on ALL THE DATA
//#define PMTK_SET_NMEA_OUTPUT_ALLDATA &quot;$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28&quot;
// to generate your own sentences, check out the MTK command datasheet and use a checksum calculator
// such as the awesome http://www.hhhh.org/wiml/proj/nmeaxor.html

//Define list of waypoints to search
//format WayPt[Lat][Long]
//multidimensional array [howmany dn] [howmany across]
const float wayPt[175][2] PROGMEM =
{
{43.25981,-79.88897},
PUT YOUR RED LIGHT CAMERA COORDINATES HERE
}; 

void setup()
{

  Serial.begin(115200);
  pinMode(statusLED, OUTPUT); 

  //setup the RGB LED
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  //set the RGB status LED to off which is HIGH (255) reason: Common-Annode.
  analogWrite(redPin, 255);
  analogWrite(greenPin, 255);
  analogWrite(bluePin, 255);

  //Serial.println(&quot;Adafruit MTK3329 NMEA test!&quot;);
  nss.begin(9600);  //needed to change this to 9600 baud for the UP501 GPS module

  //*********  OLED SETUP STUFF ******************************************************************/
  SPI.begin ();  //for OLED
  // OLED: By default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  oled.ssd1306_init(SSD1306_SWITCHCAPVCC);

  //*********  GPS SETUP STUFF ******************************************************************/
  // 9600 NMEA is the default baud rate
  // uncomment this line to turn on only the &quot;minimum recommended&quot; data for high update rates!
  nss.println(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate
  //mySerial.println(PMTK_SET_NMEA_OUTPUT_ALLDATA);
  // Set the update rate
  // 1 Hz update rate
  nss.println(PMTK_SET_NMEA_UPDATE_1HZ);
  // 5 Hz update rate- for 9600 baud you'll have to set the output to RMC only (see above)
  //nss.println(PMTK_SET_NMEA_UPDATE_5HZ);
  // 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above)
  //nss.println(PMTK_SET_NMEA_UPDATE_10HZ);
  //*********  END GPS SETUP STUFF ******************************************************************/

  //setupDisplay();

}

void loop()
{
  bool newdata = false;
  unsigned long start = millis();

  blinkLED();   // heartbeat to ensure system is working
  flat=0;
  flon=0;
  spd=0;
  sats=0;
  hdop=0;
  cardinal= &quot;&quot;;

  // Every xxxx milliseconds we print an update
  while (millis() - start &lt; updateFreq)
  {
    if (feedgps())
      newdata = true;
  }

  heartbeat(newdata);  //shows external heartbeat signal through GPS status LED

      if (newdata)
      {
                  feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
                  gps.f_get_position(&amp;flat, &amp;flon, &amp;age);
                  if (debug) {
                    Serial.print(&quot;Lat/Long(float): &quot;); Serial.print(flat, 5); Serial.print(&quot;, &quot;); Serial.print(flon, 5);
                    Serial.print(&quot; Fix age: &quot;); Serial.print(age); Serial.print(&quot;ms.&quot;);
                    Serial.print(&quot; (kmph): &quot;); Serial.print(gps.f_speed_kmph(),4); Serial.println();
                    //Serial.print(&quot; Sats: &quot;); Serial.print(gps.satellites()); Serial.println();
                    feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
                    Serial.print(&quot; Sats: &quot;); print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
                    Serial.print(&quot; HDOP: &quot;); print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
                    Serial.print(&quot; Course: &quot;); print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
                    Serial.print(&quot; Cardinal: &quot;); print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? &quot;*** &quot; : TinyGPS::cardinal(gps.f_course()), 6);

                  }
                  //compare the latest reading with the array of red light camera points and find which is closest.
                  minDist = getClosestPt(flat, flon);
                  //minDist = md[j];
                  //if (j == 2){j = 0;}else{j++;}

                  //indicate that GPS is active and receiving data
                  flash(1);  //flashes the LED on the project box showing GPS signal

                  if (debug) {
                    Serial.print(&quot;Delta = &quot;);Serial.print(minDist, 2);Serial.println(&quot; Meters   &quot;);
                  }

                  //Process alerts via various means based on pre-defined distance thresholds.

                  if (minDist &lt; 50)                 //Warning Alert &lt; 50 meters - in range if red light camera
                  {
                    //red
                    changeWarning(4);
                  }
                  else if (minDist &lt; 200)          //Approaching Alert &lt; 200 meters
                  {
                    //yellow
                    changeWarning(3);
                  }
                  else if (minDist &lt;= 600)          //Initial Alert - 600 meters
                  {
                    //blue - early warning
                    changeWarning(2);
                  }
                  else
                  {
                    //just show status that GPS is working.
                    changeWarning(1);
                  }

                  //for testing
                  //minDist = 40;
                  //updateDisplay(minDist, 65.00);
                  //end testing

                  //updateDisplay(minDist, gps.f_speed_kmph());

      }

      else
      {
          if (debug) {Serial.println(&quot;Polling GPS... waiting for fix...&quot;);}
      }

      oled.clear();

      //Distance to next red light
      oled.drawstring(0, 0, &quot;Dist:&quot;);
      if (minDist == 100000)
      {
        oled.drawstring(30, 0, &quot;?&quot;);
      }
        else
      {
        ftoa(cVal, minDist/1000, 2);
        oled.drawstring(30, 0, cVal);
      }
      oled.drawstring(55, 0, &quot;km&quot;);

      //Cardinal Direction of vehicle
      //strcpy ( cVal, TinyGPS::cardinal(gps.f_course()) );
      strcpy ( cVal, gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? &quot;?&quot; : TinyGPS::cardinal(gps.f_course()));
      oled.drawstring(75, 0, &quot;Dir:&quot;);
      oled.drawstring(100, 0, cVal);

      oled.drawline(0, 12, 128, 12, WHITE);

      //speed
      spd = gps.f_speed_kmph();
      if (spd &lt; 0) {spd=0;}
      ftoa(cVal, spd, 0);
      oled.drawstring(0, 2, &quot;Spd:&quot;);
      oled.drawstring(25, 2, cVal);

      //satellites
      itoa(gps.satellites(), cVal, 0);
      oled.drawstring(65, 2, &quot;Sats:&quot;);
      oled.drawstring(90, 2, cVal);

      //latitude
      ftoa(cVal, flat, 2);
      oled.drawstring(0, 3, &quot;Lat:&quot;);
      oled.drawstring(25, 3, cVal);
      //longitude
      ftoa(cVal, flon, 2);
      oled.drawstring(65, 3, &quot;Lng:&quot;);
      oled.drawstring(90, 3, cVal);

      //Display all the results
      oled.display(); 

      //reset minDist for the next round
      minDist = 100000;     //meters  

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
char *ftoa(char *a, double f, int precision)
{
  long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};

  char *ret = a;
  long heiltal = (long)f;
  itoa(heiltal, a, 10);
  while (*a != '&#92;&#48;') a++;
  *a++ = '.';
  long desimal = abs((long)((f - heiltal) * p[precision]));
  itoa(desimal, a, 10);
  return ret;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void setupDisplay()
{
    // Draw animated graphics to OLED - we will use the GPS speed to mimic changes in speed of the lanes.
    oled.clear();   // clears the screen and buffer
    //oled.drawbitmap(0, 2,  Road, 128, 32, 1);     //road - dash lines - draw the animating road
    //oled.drawbitmap(95, 4,  JukeIcon, 34, 40, 1);  //keep drawing the car icon in place
    oled.fillrect(0, 0, 128, 2, WHITE);            //keep drawing the top continuous line
    oled.fillrect(0, 30, 128, 2, WHITE);           //keep drawing the bottom continous line
    oled.display();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void updateDisplay(int minDist, float spd)
{
    if (i==0){i=128;}  //we have 128 pixels to loop through for animation of the road dashed lines. reset when it gets to 0.

    // Draw animated graphics to OLED - we will use the GPS speed to mimic changes in speed of the lanes.
    //oled.drawbitmap(i, 16,  Road, 128, 32, 1);     //road - dash lines - draw the animating road
    //oled.drawbitmap(i-128, 16,  Road, 128, 32, 1);  //road - dash lines - draw the road ahead to keep contents on the screen

    //map values based on dist from camera, min dist on ground of 20m, max dist on ground of 500m, min dist in px to car, max dist in px from car
    mappedDist = map(minDist, 20, 500, 40, 110);
    //oled.drawbitmap(mappedDist, 10,  RedLightCam, 10, 15, 1);  //move the red light camera as it approaches 

    //oled.drawbitmap(95, 12,  JukeIcon, 34, 40, 1);  //keep drawing the car icon in place
    oled.fillrect(0, 0, 128, 4, WHITE);            //keep drawing the top continuous line
    oled.fillrect(0, 61, 128, 4, WHITE);           //keep drawing the bottom continous line
    oled.display();
    oled.clear();   // clears the screen and buffer 

    // convert speed to an int so it can be used in the map funciton.  1.25 km/h = 125
    //Serial.println(int(spd*10));
    spdProRate = map(int(spd*10), 0, 900, 0, 30);
    //Serial.println(spdProRate);
    //i=i-10;
    i = i - spdProRate;
    if (i &lt; 0) {i=0;}

    //mappedDist = 0;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
float getClosestPt(float flat, float flon)
{
  float d;
  float d2;
  float md = 10000;
  //int minCoordIndex;
  //int coordsProcessed;

              if (flat != 0 &amp;&amp; flon != 0)
              {
                for (unsigned int x=0; x&lt;175; x++){
                      //In array lat is 2nd col, long is 1st col  e.g. lat:43.xxxx,long:-79.xxxxx - need to get right ones for calc
                      //flat2 =  pgm_read_float_near(&amp;wayPt[x][0]);
                      //flon2 = pgm_read_float_near(&amp;wayPt[x][1]);
                      //if (debug)
                      //{
                      //  Serial.print(&quot;Flat2:  &quot;);Serial.print(flat2, 5);
                      //  Serial.print(&quot;  Flon2:  &quot;);Serial.println(flon2, 5);
                      //}
                      //d = HaverSine(flat, flon, pgm_read_float_near(&amp;wayPt[x][0]), pgm_read_float_near(&amp;wayPt[x][1]));
                      d = gps.distance_between(flat, flon, pgm_read_float_near(&amp;wayPt[x][0]), pgm_read_float_near(&amp;wayPt[x][1]))/1000 ;
                      if (debug)
                      {
                        //Serial.print(&quot;DistanceCalcualted d1: &quot;);Serial.print(d, 4); Serial.print(&quot; d2:&quot;); Serial.print(d2, 4); Serial.println(&quot;&quot;);
                        //Serial.print(&quot;DistanceCalcualted d1: &quot;);Serial.print(d, 4); Serial.println(&quot;&quot;);
                      }
                      if (d &lt; md)
                      {
                        md = d;
                        //minCoordIndex = x;
                      }
                      //coordsProcessed++;
                  }

                  //convert to meters
                  md = md * 1000;

                  //Serial.print(&quot; Processed:&quot;);Serial.println(coordsProcessed);
                  /*
                  Serial.println(&quot;&quot;);
                  Serial.println(&quot;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&quot;);
                  Serial.print(&quot; Index:&quot;);Serial.println(minCoordIndex);
                  Serial.print(&quot; Processed:&quot;);Serial.println(coordsProcessed);
                  Serial.println(&quot;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&quot;);
                  Serial.println(&quot;&quot;);
                  */
                }
                //coordsProcessed = 0;
 return md;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 float HaverSine(float lat1, float lon1, float lat2, float lon2)
{
  //float ToRad = PI / 180.0;
  //float R = 6371;   // radius earth in Km

  float dLat = (lat2-lat1) * ToRad;
  float dLon = (lon2-lon1) * ToRad;

  float a = sin(dLat/2) * sin(dLat/2) +
	  cos(lat1 * ToRad) * cos(lat2 * ToRad) *
	  sin(dLon/2) * sin(dLon/2);

  float c = 2 * atan2(sqrt(a), sqrt(1-a));

  float d = R * c;
  return d;  //distance returned in Kilometers
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static void print_float(float val, float invalid, int len, int prec)
{
  char sz[32];
  if (val == invalid)
  {
    strcpy(sz, &quot;*******&quot;);
    sz[len] = 0;
        if (len &gt; 0)
          sz[len-1] = ' ';
    for (int i=7; i&lt;len; ++i)
        sz[i] = ' ';
    Serial.print(sz);
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val &lt; 0.0 ? 2 : 1);
    flen += vi &gt;= 1000 ? 4 : vi &gt;= 100 ? 3 : vi &gt;= 10 ? 2 : 1;
    for (int i=flen; i&lt;len; ++i)
      Serial.print(&quot; &quot;);
  }
  feedgps();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
void beep(int howmany, int itone) {

 if (itone == 0){itone=2200;}

 for (int i=0; i &lt; howmany; i++){
    tone(piezo, itone, 10);
    delay(100);
  }
}
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i&lt;len; ++i)
    Serial.print(i&lt;slen ? str[i] : ' ');
  feedgps();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void flash(int howmany) {
 for (int i=0; i &lt; howmany; i++){
    digitalWrite(GPSActive, HIGH);
    delay(100);
    digitalWrite(GPSActive, LOW);
    delay(100);
  }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void heartbeat(boolean nd){

  //show if there is no data - hearbeat of system - shows it is working.  Fast blink.
  if (nd == false){

    if (gpsStatCounter == 2)
      {
          analogWrite(redPin, 127);
          analogWrite(greenPin, 255);
          analogWrite(bluePin, 0);
          delay(50);
          analogWrite(redPin, 255);
          analogWrite(greenPin, 255);
          analogWrite(bluePin, 255);
          //delay(50);     

          gpsStatCounter = 0;
      }
      else
      {
      gpsStatCounter++;
      }
  }  

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void changeWarning(int stateLevel)
{
    switch (stateLevel) {

    case 1:
      //green LED - show for status that GPS is getting data
      analogWrite(greenPin, 155);
      delay(200);
      break;

     case 2:
      //early warning.
      analogWrite(bluePin, 155);
      delay(200);
      break;

    case 3:
      //yellow
      analogWrite(redPin, 0);
      analogWrite(greenPin, 190);
      delay(200);
      break;

    case 4:
      //in and just before red light camera
      analogWrite(redPin, 155);
      delay(200);
      break;  

    default:
      //all off
      analogWrite(greenPin, 255);
      analogWrite(bluePin, 255);
      analogWrite(redPin, 255);
      break;
    }

    //turn the LEDs back off
    analogWrite(greenPin, 255);
    analogWrite(bluePin, 255);
    analogWrite(redPin, 255);    

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, &quot;*******&quot;);
  else
    sprintf(sz, &quot;%ld&quot;, val);
  sz[len] = 0;
  for (int i=strlen(sz); i&lt;len; ++i)
    sz[i] = ' ';
  if (len &gt; 0)
    sz[len-1] = ' ';
  Serial.print(sz);
  feedgps();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void blinkLED()
{
state = !state;
digitalWrite(statusLED, state);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2392</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Arduino Temperature / Humidity Sensor</title>
		<link>http://www.plastibots.com/?p=2333</link>
		<comments>http://www.plastibots.com/?p=2333#comments</comments>
		<pubDate>Thu, 05 Apr 2012 21:06:14 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2333</guid>
		<description><![CDATA[The projects I do tend to fall in one of two buckets &#8211; either proof-of-concept (so I can learn new stuff) or items that have some sort of functional use.   The need for this project came about when my wife was prodding me about the humidity in the house and whether our humidifier was [...]]]></description>
			<content:encoded><![CDATA[<p>The projects I do tend to fall in one of two buckets &#8211; either proof-of-concept (so I can learn new stuff) or items that have some sort of functional use.  <img class="alignright size-full wp-image-2337" title="HuTmp1b" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp1b.jpg" alt="" width="300" height="131" /> The need for this project came about when my wife was prodding me about the humidity in the house and whether our humidifier was doing it&#8217;s job correctly.  Most people would just go out and buy a temp / humidity sensor and be done with it.  However, if you have a look around here, you will see that I don&#8217;t fit that mold.  Instead, I decided to build an accurate temp / humidity sensor with a Sensiron SHT11 to read the values, a RBBB Arduino kit to process everything and an Adafruit 128&#215;32 OLED to display the results &#8211; all wrapped up in&#8230; LEGO!   Read on for more&#8230;</p>
<p><br class="spacer_" /></p>
<p><span id="more-2333"></span></p>
<p>Admittedly, I would not normally spend the money required to outright build this gizmo (approx $95 incl shipping for all parts).  Instead, I was able to acquire the parts for a fraction of this price.   As a result, the purpose of this build is twofold. 1) Create a sensor that can be used in my house on an ongoing basis; 2) Review the parts to provide insight for those considering using them for similar or other projects.</p>
<p>Parts:</p>
<ul>
<li> <a href="https://www.adafruit.com/products/661" target="_blank">Adafruit Monochrome 128&#215;32 OLED Display</a> &#8211; ($17.50)</li>
<li><a href="http://canada.newark.com/sensirion/sht11/humidity-sensor/dp/69C4848?Ntt=sht11" target="_blank">Newark Sensiron SHT11 Humidity / Temperature Sensor</a> ($29.xx)</li>
<li><a href="http://shop.moderndevice.com/products/rbbb-kit" target="_blank">Modern Device RBBB Arduino Kit</a> (3.3v)  ($13.00)</li>
<li><a href="https://www.adafruit.com/products/504" target="_blank">Adafruit Through Hole 5-Way Navigation Switch</a> ($2.95)</li>
<li><a href="http://www.dipmicro.com/store/WIRE-K30BLK" target="_blank">Insulated Silver-Plated Copper 30Ga Wire</a> (~1.00)</li>
<li>The rest of the parts (caps, resistors, LED) I had as spares.</li>
</ul>
<p><br class="spacer_" /></p>
<p>There were a few goals that I wanted to achieve with this project.  Make it small and compact, easy to use, and conserve as little power as possible.    Getting it into a small package was aided by the RBBB.  I could have gone a step further by just making a standalone Atmega, but the LEGO shell was my starting place and everything fit fine within the space it had.   For power conservation, I used the sleep abilities of the chip and tied it to Interrupt2 tied to the toggle switch.  Pushing the switch &#8216;in&#8217; would trigger the interrupt and wake the unit.   I also have power for the OLED and the SHT11 sensor shut down just before it goes to sleep, and back on immediately after it wakes.  To do this, I used 2 digital pins set to HIGH / LOW as needed.    I am running the unit off 2x 3V 2032 cells in series, which are put through a 3.3v regulator to power the board and components.    When running with all components powered it pulls 12mA.  In sleep mode it pulls 0.6mA.  I&#8217;d like to get it lower, but think that my use of the regulator is partially killing it due to the voltage drop out.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p style="text-align: center;"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp1.jpg"><img class="size-medium wp-image-2323  aligncenter" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp1-300x131.jpg" alt="" width="300" height="131" /></a></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p style="text-align: center;"> </p>
<p style="text-align: center;"> </p>
<p><img class="size-full wp-image-2343 alignright" title="HuTmp11" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp11.jpg" alt="" width="198" height="200" />The key to the accurate humidity / temp readings is the Sensiron SHT11 sensor.  It&#8217;s tiny &#8211; really tiny.   There are 4 connections: 3.3V- 5V, GND, Data, CLK.  In order to protect the sensor, it has been mounted to the side of the unit inside a clear plastic housing.  The housing has a hole in the side to allow air to flow freely, but limits the any water that might find its way in there (because you never know when it might rain inside the house <img src='http://www.plastibots.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Since everything is so small, I used very fine 30 gauge silver plated copper wire for this.  It worked quite well for what I needed to do here.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Before migrating all the components into the project, I set everything up on a breadboard and used the Uno to test the sketches.     Interestingly, I found getting the 5-way switch working the most challenging.  It has a common anode I am using as both an Interrupt link (Pin2) as well as toggle switch for scrolling the OLED.</p>
<p><br class="spacer_" /></p>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p style="text-align: center;"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp3.jpg"><img class="size-medium wp-image-2327 aligncenter" title="HumidityTempSensor2" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp3-172x300.jpg" alt="" width="172" height="300" /></a></p>
<p>Below showing the completed RBBB kit.  Initially, this came with an earlier Bootloader, but I updated to the <a href="http://arduino.cc/en/Tutorial/ArduinoToBreadboard" target="_blank">Uno one with ease</a>.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp3B1.jpg"><img class="aligncenter size-medium wp-image-2357" title="HuTmp3B" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp3B1-300x113.jpg" alt="" width="300" height="113" /></a></p>
<p><br class="spacer_" /></p>
<p>The next step was to start fitting the components into the case.  The first parts to go in were the switch and red/green status LED.  The LED was a pull from an old portable DVD player. After that was done, one side was cut to make room for the length of the RBBB kit.  Being a die-hard LEGO fan and spending most of my life building, I was always against bastardizing LEGO for things like this &#8211; until I discovered Arduino / micro-controllers.  Sorry AFOL&#8217;s. <img src='http://www.plastibots.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />    The 3rd pic shows the bits all soldered together using that nice 30Ga wire.  The 4th shows a test fit with the RBBB inserted.  I made the mistake of completing the RBBB kit as per instructions only to realize that I did not want the rows of breadboard pins as would not need them.. So, out came the solder sucker and I removed them (hence the burn marks you see in other pics).  In the last picture, you can see a side view showing the SHT11 sensor.. Did I mention this thing is tiny!?</p>

<a href='http://www.plastibots.com/?attachment_id=2326' title='HumidityTempSensor4'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp4-150x150.jpg" class="attachment-thumbnail" alt="HumidityTempSensor4" title="HumidityTempSensor4" /></a>
<a href='http://www.plastibots.com/?attachment_id=2331' title='HumidityTempSensor6'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp7-150x150.jpg" class="attachment-thumbnail" alt="HumidityTempSensor6" title="HumidityTempSensor6" /></a>
<a href='http://www.plastibots.com/?attachment_id=2328' title='HumidityTempSensor7'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp5-150x150.jpg" class="attachment-thumbnail" alt="HumidityTempSensor7" title="HumidityTempSensor7" /></a>
<a href='http://www.plastibots.com/?attachment_id=2332' title='HumidityTempSensor8'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp8-150x150.jpg" class="attachment-thumbnail" alt="HumidityTempSensor8" title="HumidityTempSensor8" /></a>
<a href='http://www.plastibots.com/?attachment_id=2355' title='HuTmp2'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp21-150x150.jpg" class="attachment-thumbnail" alt="HuTmp2" title="HuTmp2" /></a>
<a href='http://www.plastibots.com/?attachment_id=2357' title='HuTmp3B'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HuTmp3B1-150x150.jpg" class="attachment-thumbnail" alt="HuTmp3B" title="HuTmp3B" /></a>

<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Verdict:</span></strong></p>
<p><strong>Adafruit 128&#215;32 OLED:</strong> If you are looking for a crisp display with a small footprint, then this is the unit for you.  Don&#8217;t expect to be able to read this thing from afar.  However, up close, the display is clear, and crisp.  Because it does not have a backlight, and each pixel is self- illuminated, it has low power consumption and is easy to read.   Out of the box, the display is slow to render for anything where rapid updates are necessary.  However, the driver can easily be modified to use the Arduino SPI hardware to speed up its response.  For this purpose, its not really necessary as I am not drawing rapid graphics or animating.  If you are doing that, then you want to do this easy mod.  Just remember that you must then also use the dedicated hardware SPI pins.</p>
<p><br class="spacer_" /></p>
<p><strong>Sensiron SHT11: </strong>Did I mention the sensor is small?  Ok, I know I did &#8211; so it&#8217;s small.   This is great for integrating it into small projects like this.   Sensiron claims the unit has a high degree of accuracy (+/- 0.4&#8242;C and +/-3% RH).  When pitching the results against other temperature gauges in our house, I had different readings on all of them.  When I tested the readings against a classic mercury unit, it was off by about 1 degree.   It also responded well to rapid temperature changes at about a 1-2 hz rate.  Not super fast, but good enough for measuring changes in room temperature.  I did some tests where I set the update frequency to less than 500 Ms and it still took about 1+ seconds to return a result &#8211; so it seems that the sensor requires this time to produce and return an accurate reading.</p>
<p><br class="spacer_" /></p>
<p><strong>Modern Device RBBB Kit:</strong> If you are looking for a small Arduino footprint, then this is a nice unit.  It is not the smallest out there, but good enough for most small projects.  For the price of about $13 plus shipping you can get a full setup in either 3.3v or 5v, the board, parts and an Atmega 328P with bootloader.  The only caveat is that it comes with the Diecimila Bootloader, but you can change it to whatever you like easily.  Yes, I could have put together a standalone kit with a little more soldering, but considering time and cost, it is not really worth it.</p>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Code:</span> </strong><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2012/04/HumidityTempSensor1_4.zip">(download it</a>)</p>
<p><br class="spacer_" /></p>
<p>Or click below to view it:</p>
<pre class="brush: csharp; collapse: true; light: false; title: ; toolbar: true; notranslate">
#include &lt;SSD1306.h&gt;                  //SSD
#include &lt;SPI.h&gt;                      //for OLED
#include &lt;avr/sleep.h&gt;
#include &lt;avr/power.h&gt;
#include &lt;SHT1x.h&gt;                    //HumidityTemp Sensor SHT11

//OLED PINS
#define OLED_RESET 7    // RST on OLED
#define OLED_DC 8       // S/C on OLED
#define OLED_CS 6       // CS on OLED  - SPI slave-select
#define OLED_MOSI 11    // DATA on OLED - hardware SPI MOSI
#define OLED_CLK 13     // CLK on OLED - hardware SPI clock

//SHT11 Tmp/Humidity Sensor
// Specify data and clock connections and instantiate SHT1x object
#define dataPin  9
//#define clockPin 11
#define clockPin 10
SHT1x sht1x(dataPin, clockPin);
float temp_c;
float temp_f;
float humidity;

//#define SHTPwrPin 4  -not used. When using this, current draw went from 0.6mA when off to 37mA when off!!!!  put back
//to 5V pin and back to 0.6mA when off - much better!
#define OLEDPwrPin 3
int redLED = A2;
int grnLED = A3;
int LEDcounter = 0;

int SHTReadCounter = 0;
int centerToggle = 2;
int upToggle = 12;
int dnToggle = 5;
//switch debouncing
long debounceDelay = 20;    // the debounce time; increase if the output flickers -
long lastDebounceTime = 0;  // the last time the output pin was toggled
//for up toggle
int upButtonState;             // the current reading from the input pin
int upLastButtonState = LOW;   // the previous reading from the input pin
//for down toggle
int dnButtonState;             // the current reading from the input pin
int dnLastButtonState = LOW;   // the previous reading from the input pin

//end switch debouncing

volatile int toggle = 1;
char cVal[32];

int displayState = 1;                         //up and down toggles will change the display to different states

long shutoffStartMillis = 0;                  //Store the value to start the shutoff timer from in Milliseconds.
//**********************************
//Change this to determine how long the device stays on - in MS
long shutOffDelayMS = 180000;                  //In Milliseconds - Determines how long to keep LED system on (after shutoff timer clicked) in Milliseconds  10000 (10sec), 60000 (1min) 600000 (10min)
//**********************************
boolean debug = false;                         //turn debugging on or off here

//OLED
SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

void (*restart)(void) = 0;

/***************************************************
 *  Name:        pin2Interrupt
 *
 ***************************************************/
void pin2Interrupt(void)
{
  /* This will bring us back from sleep. */

  /* We detach the interrupt to stop it from
   * continuously firing while the interrupt pin
   * is low.
   */

  //appears that the interrup is not working correctly and re-triggering things.  Try a restart instead
  restart();

  //  - removed while testing restart() function.  Put these back if restart removed
  //toggle = 1;
  //delay(100);

  detachInterrupt(0);

}

/***************************************************
 *  Description: Enters the arduino into sleep mode.
 ***************************************************/
void enterSleep(void)
{

  /* Setup pin2 as an interrupt and attach handler. */
  //attachInterrupt(interrupt, function, mode)
  //attachInterrupt(0, pin2Interrupt, LOW);
  attachInterrupt(0, pin2Interrupt, FALLING);

  delay(100);

  //Serial.println(&quot;Going to sleep....&quot;);  

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  sleep_enable();

  sleep_mode();

  /* The program will continue from here. */

  /* First thing to do is disable sleep. */
  sleep_disable();
}

void setup()
{
  Serial.begin(38400);
  pinMode(A5, OUTPUT);   //testing blink
  /* Setup the pin direction. */
  pinMode(centerToggle, INPUT);
  //pinMode(SHTPwrPin, OUTPUT);
  pinMode(OLEDPwrPin, OUTPUT);
  pinMode(redLED, OUTPUT);
  pinMode(grnLED, OUTPUT);
  digitalWrite(grnLED, HIGH);  //turn off the green LED - common annode - so they have to be high
  digitalWrite(redLED, HIGH);  //turn off the gred LED - common annode - so they have to be high

  digitalWrite(upToggle, LOW);
  digitalWrite(dnToggle, LOW);
  //digitalWrite(SHTPwrPin, LOW);
  digitalWrite(OLEDPwrPin, LOW);

  //*********  OLED SETUP STUFF ******************************************************************/
  SPI.begin ();  //for OLED
  // OLED: By default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
  //*********  OLED SETUP STUFF ******************************************************************/
  //oled.clear();
  //oled.display();

// displayState = 1;

  if (debug)
  {
    Serial.println(&quot;Initialisation complete.&quot;);
    Serial.println(&quot;Entering sleep&quot;);
  }
  //delay(200);
  //enterSleep();

  oled.clear();

}

void doHumTmp(void)
{

    // Read values from the sensor
    if (SHTReadCounter == 20)  //this is based on the delay at the bottom. if delay changes, this value should as well
    {
    temp_c = sht1x.readTemperatureC();
    temp_f = sht1x.readTemperatureF();
    humidity = sht1x.readHumidity();
    SHTReadCounter = 0;
      if (debug)
      {
        // Print the values to the serial port
        Serial.print(&quot;Temperature: &quot;);
        Serial.print(temp_c, DEC);
        Serial.print(&quot;C / &quot;);
        Serial.print(temp_f, DEC);
        Serial.print(&quot;F. Humidity: &quot;);
        Serial.print(humidity);
        Serial.println(&quot;%&quot;);
      }

    }

    oled.clear();

    if (temp_c &lt; 0 || temp_f &lt; 0 || humidity &lt; 0)
    {
      //calibrating
      //oled.drawstring([character position from left - by pixel], [line number 0,1,2,3], &quot;1&quot;);
      blinkLED(redLED);
      oled.drawline(0, 9, 128, 9, WHITE);
      oled.drawstring(0, 2, &quot;Calibrating...&quot;);
      oled.drawline(0, 30, 128, 30, WHITE);

    }
    else if(displayState == 1) //good readings show - 2 display states
    {
      blinkLED(grnLED);
      //Temp in C and F
      oled.drawstring(0, 0, &quot;Temp: &quot;);
      ftoa(cVal, temp_c, 1);
      oled.drawstring(35, 0, cVal);
      //oled.drawchar(65, 0, 9);
      //draw degree symbol
      //oled.drawcircle([x position px], [y pos line], [diameter units??], WHITE);
      oled.drawcircle(61, 1, 1.5, WHITE);
      oled.drawstring(64, 0, &quot;C&quot;);

      //degrees F
      ftoa(cVal, temp_f, 1);
      oled.drawstring(85, 0, cVal);
      //oled.drawchar(115, 0, 9);
      oled.drawcircle(110, 1, 1.5, WHITE);
      oled.drawstring(114, 0, &quot;F&quot;);

      //draw split line
      oled.drawline(0, 15, 128, 15, WHITE);

      /*
      int upstate = digitalRead(upToggle);
      itoa(upstate, cVal, 0);
      oled.drawstring(0, 2, &quot;up:&quot;);
      oled.drawstring(10, 2, cVal);

      int dnstate = digitalRead(dnToggle);
      itoa(dnstate, cVal, 0);
      oled.drawstring(45, 2, &quot;dn:&quot;);
      oled.drawstring(50, 2, cVal);
      */

      ftoa(cVal, humidity, 1);
      oled.drawstring(0, 3, &quot;Humidity:&quot;);
      oled.drawstring(60, 3, cVal);
      oled.drawstring(85, 3, &quot;%&quot;);

    }
    else if (displayState == 2)//display state would be 2 here
    {
     blinkLED(grnLED);
     oled.drawstring(0, 0, &quot;Sensor: Sensiron SHT11 Temp &amp; Humidity&quot;);
     oled.drawstring(0, 2, &quot;OLED:Adaft SSD1306 128x32&quot;);
    }

    else if (displayState == 3)
    {
     blinkLED(grnLED);
     oled.drawstring(0, 0, &quot;Board: Modern Device RBBB Kit&quot;);
     oled.drawstring(0, 2, &quot;Chip: Atmega 328P w/UNO Bootloader&quot;);
    }

    else if (displayState == 4)
    {
     blinkLED(grnLED);
     oled.drawstring(0, 0, &quot;Sketch:&quot;);
     oled.drawstring(0, 1, &quot;HumidityTempSensor1_4&quot;);
    }

    //Display all the results
    oled.display();
    delay(100);
    SHTReadCounter++ ;
}  

/***************************************************
 *  Name:        loop
 *  Description: Main application loop.
 *
 Operation
Our code will operate as follows:
1.  Set up the serial port and set pin 2 (INT0) as an input;
2.  Run the loop function which will:
3.  Stay awake for 3 seconds;
4.  Once the 3 seconds have elapsed, SLEEP_MODE_PWR_DOWN will be entered;
5.  All code execution stops;
6.  The user then pushes the switch and pin 2 (INT0) will become low;
7.  The INT0 interrupt will fire and bring the Arduino out of sleep mode;
8.  Code execution continues where it had previously stopped.

Circuit: 

http://donalmorrissey.blogspot.com/2010/04/arduino-external-interrupts.html

 ***************************************************/
//int seconds=0;
void loop()
{
  if (debug)
  {
   // Serial.println(&quot;Still awake....&quot;);
  }

   //Will put the unit to sleep after a pre-defined amount of time
  if (shutoffStartMillis != 0 &amp;&amp; millis() - shutoffStartMillis &gt; shutOffDelayMS)    //if shutoff time has elapsed, turn the LEDs off  1000ms = 1 second
  {
       //delay(100);

       shutoffStartMillis = 0;
       //power down the SHT11 Sensor and other ports
       digitalWrite(upToggle, LOW);
       digitalWrite(dnToggle, LOW);
       //digitalWrite(SHTPwrPin, LOW);

       //Power down the OLED
       oled.clear();
       oled.display();
       //digitalWrite(OLED_RESET, LOW);
       digitalWrite(OLEDPwrPin, LOW);

       //go to sleep
       if (debug) {Serial.println(&quot;Entering sleep&quot;);}
       delay(200);
       //seconds = 0;
       enterSleep();

  }

  //watch the up and down toggle

  //int upToggleReading = digitalRead(upToggle);
  //int dnToggleReading = digitalRead(dnToggle);

  //will be able to read each other toggle pin as LOW when it is pressed.
  if (debug)
  {
   // Serial.print(&quot;UpToggle: &quot;); Serial.print(digitalRead(upToggle));    // Read the pin and display the value
   // Serial.print(&quot;  DnToggle: &quot;); Serial.println(digitalRead(dnToggle));    // Read the pin and display the value
   // Serial.print(&quot;  DisplayState: &quot;); Serial.println(displayState);    // Read the pin and display the value
  }

  if (digitalRead(upToggle) == 0)
  {
    //displayState++;
    //if (displayState &gt; 2) {displayState = 1;}   //simple method to only go to 2 states
    displayState = 1;
    delay(100);
  }

  if (digitalRead(dnToggle) == 0)
  {

    //if (displayState &lt; 1) {displayState = 2;}   //simple method to only go to 2 states

    if (displayState &lt; 4)
    {
      displayState++;
    }  //dont let it go past a max value
    delay(100);
  }

  /*
     Serial.print(&quot;ButtonState: &quot;); Serial.print(upButtonState);
     Serial.print(&quot;  LastButtonState: &quot;); Serial.print(upLastButtonState);
     Serial.print(&quot;   DisplayState: &quot;); Serial.println(displayState);

     Serial.print(&quot;ButtonState: &quot;); Serial.print(dnButtonState);
     Serial.print(&quot;  LastButtonState: &quot;); Serial.print(dnLastButtonState);
     Serial.print(&quot;   DisplayState: &quot;); Serial.println(displayState);
*/

  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  //upLastButtonState = upToggleReading;
  //dnLastButtonState = dnToggleReading;

  if (toggle == 1)
  {
    shutoffStartMillis = millis();      //get a start value to start the countdown from.
    displayState = 1;  //ensure the display defaults to the main screen
    //digitalWrite(SHTPwrPin, HIGH);
    digitalWrite(OLEDPwrPin, HIGH);
    delay(1000);
    //*********  OLED SETUP STUFF ******************************************************************/
    //have to do this again with each power on state or the OLED does not come on.
    SPI.begin ();  //for OLED
    // OLED: By default, we'll generate the high voltage from the 3.3v line internally! (neat!)
    oled.ssd1306_init(SSD1306_SWITCHCAPVCC);
    //*********  OLED SETUP STUFF ******************************************************************/
    delay(500);
    //oled.clear();
    //oled.display();

    doHumTmp();

    //provide power to the toggle switch up and down.
    digitalWrite(upToggle, HIGH);
    digitalWrite(dnToggle, HIGH);

    delay(500); //give it some time to calibrate etc
    toggle = 0;

  }
  else
  {
    //show the temp and humidity values
    doHumTmp();
  }

  LEDcounter++;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
char *ftoa(char *a, double f, int precision)
{
  long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};

  char *ret = a;
  long heiltal = (long)f;
  itoa(heiltal, a, 10);
  while (*a != '&#92;&#48;') a++;
  *a++ = '.';
  long desimal = abs((long)((f - heiltal) * p[precision]));
  itoa(desimal, a, 10);
  return ret;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i&lt;len; ++i)
    Serial.print(i&lt;slen ? str[i] : ' ');
 }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, &quot;*******&quot;);
  else
    sprintf(sz, &quot;%ld&quot;, val);
  sz[len] = 0;
  for (int i=strlen(sz); i&lt;len; ++i)
    sz[i] = ' ';
  if (len &gt; 0)
    sz[len-1] = ' ';
  Serial.print(sz);
}

void blinkLED(int led)
{
 if (LEDcounter == 10)   //we do not want the LED blinking with every cycle as it is seizure enducing!
 {
    if (led == redLED)
    {
      digitalWrite(redLED, LOW);
      delay(50);
      digitalWrite(redLED, HIGH);
    }
    else
    {
      digitalWrite(grnLED, LOW);
      delay(50);
      digitalWrite(grnLED, HIGH);
    }
    LEDcounter = 0;
 }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2333</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adafruit Monochrome 128&#215;32 OLED graphic display</title>
		<link>http://www.plastibots.com/?p=2296</link>
		<comments>http://www.plastibots.com/?p=2296#comments</comments>
		<pubDate>Sun, 04 Mar 2012 21:57:58 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2296</guid>
		<description><![CDATA[I recently got my hands on the Adafruit Monochrome 128&#215;32 OLED graphic display for my next project.  This is a 128&#215;32 OLED B+W graphics chip and it&#8217;s tiny!  Don&#8217;t let its size fool you however. Being an OLED display,  text/graphics contrasts well against the black background.  My initial intent for this display was to use [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-2304 alignright" title="SSD1306AdafruitOLED_1" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/03/SSD1306AdafruitOLED_1-300x199.jpg" alt="" width="300" height="199" /> I recently got my hands on the <a href="https://www.adafruit.com/products/661" target="_blank">Adafruit Monochrome 128&#215;32 OLED graphic display</a> for my next project.  This is a 128&#215;32 OLED B+W graphics chip and it&#8217;s tiny!  Don&#8217;t let its size fool you however. Being an OLED display,  text/graphics contrasts well against the black background.  My initial intent for this display was to use it to provide information to you GPS Red Light Camera project.  It&#8217;s job would be to provide key information such as; the distance to the next red light camera location, the direction of the vehicle (and possibly direction of the camera later on), speed, # of satellites, as well as Lat and Log.  However, after some dry runs, I found that reading the information was too difficult if it was sunny out.  Of course the obvious holds true that I should not be taking the time to read this sort of info while driving anyhow.  The intent was more of an info display for viewing while stopped etc.   However, the purpose of this write-up is not to discuss the merits of these things, but rather the quality of this display. More info on the project will come soon.</p>
<p><span id="more-2296"></span></p>
<p>So, how about the quality.  My first test was take some graphics and try to render them to the tiny screen.   Keep in mind we are working with 128W x 32H pixels here folks.  The Adafruit <a href="http://ladyada.net/products/oled12864/" target="_blank">tutorial</a> references a handle little app called LCD Assist that allows you to convert a monochrome bitmap to a character array which you can dump directly into your sketch and have it display the image.  The image to the right shows a rendering of a car.  The pixelation that is showing is due to my resizing the original image down to something that I could fit on the screen.  The two lines are drawn using a built-in <em>drawline</em> function.   The second image shows the rendering of text and variables to the screen.</p>
<p><img class="size-medium wp-image-2305 alignright" title="SSD1306AdafruitOLED_2" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/03/SSD1306AdafruitOLED_2-300x201.jpg" alt="" width="300" height="201" /></p>
<p>Example (draws Latitude and Longitude and their related values):</p>
<p><br class="spacer_" /></p>
<div id="_mcePaste">//latitude</div>
<div id="_mcePaste">ftoa(cVal, flat, 2);</div>
<div id="_mcePaste">oled.drawstring(0, 3, &#8220;Lat:&#8221;);</div>
<div id="_mcePaste">oled.drawstring(25, 3, cVal);</div>
<div id="_mcePaste">//longitude</div>
<div id="_mcePaste">ftoa(cVal, flon, 2);</div>
<div id="_mcePaste">oled.drawstring(65, 3, &#8220;Lng:&#8221;);</div>
<div id="_mcePaste">oled.drawstring(90, 3, cVal);</div>
<p><br class="spacer_" /></p>
<p>Edit: I&#8217;ve recently added this display to my <a href="http://www.plastibots.com/?p=2333">Temp / Humidity Monitor</a>.</p>
<p><br class="spacer_" /></p>
<p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><strong><span style="text-decoration: underline;">The good:</span></strong></p>
<ul>
<li>At $17.xx, this is reasonably priced for a small, crisp, thin, OLED package.</li>
<li>As always, Adafruit does a great job with providing drivers, samples, and a tutorial to help even the newest of noobs get this thing up-and-running. </li>
<li>It&#8217;s thin &#8211; really thin.  Great for small projects where space is limited but you want to dump lots of info to the screen.</li>
<li>Four mounting holes are provided on the board.  It&#8217;s hard to tell, but the above OLED is mounted to a piece of clear acrylic.</li>
<li>Having the connections all broken out (and labeled) to a header is a must have for those of us who cant work with those tiny ribbon connectors.</li>
<li>Headers are also supplied &#8211; its nice to see small added touches like this and Adafruit does this with most all of their products.  The passion shows through.  It would be a shame to wait a week or so to find out you don&#8217;t have a spare header laying around and your favourite electronics store is closed for the day!</li>
<li>Support! Let&#8217;s not forget the intangibles &#8211; Adafruit had an excellent <a href="http://forums.adafruit.com/" target="_blank">forum </a>where you can post your questions and get answers fast.  It&#8217;s an excellent community and everyone there is very welcoming and want to help.  Even Adafruit staff often weigh in to offer support. </li>
</ul>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The not so good:</span></strong></p>
<ul>
<li>Wiring:  Rrequires a lot of wires &#8211; a total of 7.  However, this is to be expected given the nature of what it is.   I managed to find a flat-wired CAT5 cable in my search for something small and flexible.  (The options are limited if you want to keep the cable to a minimum).  The problem with this particular cable was that the encompassing insulator is moulded around all 8 internal wires.  After carefully stripping back all 8 on both ends, I figured I had to find something else if I was going to do this again (which I am &#8211; more in that in another post).  As irony would have it, I later came across <a href="http://www.dealextreme.com/p/network-retractable-cable-473" target="_blank">these</a>.  Already ordered 4 for next time around!  An aside note:  I like to look of people&#8217;s faces when they see me take apart things immediately after they arrive.  The look of  why!?  Then they get it once they know what I do for sh*ts and giggles&#8230; err&#8230; I mean my hobby. </li>
<li>Sunlight:  It was difficult to view the text in bright sunlight while in the vehicle.  This is part due to its size and secondly that you can only get so much contrast with this (or most any other) display.  I am sure that if I was able to inset the OLED in some sort of compartment, the result would be much better. </li>
<li>Size:  This is a tiny OLED.  However, I knew that going in so I can&#8217;t really complain.  I put this here as it is important to know what you need going into a project.  This unit works great if you are working with a project that needs to be small.  If you want something a little larger, Adafruit sells a <a href="https://www.adafruit.com/products/326" target="_blank">128&#215;64 OLED</a> that is the sibling to this one.  I decided to take another leap and am currently working with the <a href="https://www.adafruit.com/products/358" target="_blank">1.8&#8243; TFT LCD display</a>, and am already very impressed with the result.  More on this later.</li>
</ul>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">Other thoughts:</span></strong></p>
<ul>
<li>For simple displaying of text, the provied driver works fine.  However, as part of my project, I was animating a road against a vehicle icon and it was too slow for my needs.  I followed the simple instructions on this <a href="http://forums.adafruit.com/viewtopic.php?f=19&amp;t=19079&amp;start=15#p103938" target="_blank">simple tweak you can do</a> to use hardware SPI to speed things up.   Once I did this, it ran much faster and supported the necessary animations I was doing.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2296</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review &#8211; AVAGO &#8211; ASMT-LW60 &#8211; LED Fibre Optic Strip</title>
		<link>http://www.plastibots.com/?p=2260</link>
		<comments>http://www.plastibots.com/?p=2260#comments</comments>
		<pubDate>Sat, 14 Jan 2012 13:43:00 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2260</guid>
		<description><![CDATA[I&#8217;d say that LEDs have  been one of the fastest spreading new technologies in the last 10 years.   Consider now that most cars are being manufactured with LED lighting for all the turn/marker/brake/DRL lights.  They have even made an impact with home lighting &#8211; even though people are being gouged with inflated pricing (IMHO) [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-2275" title="NewarkAvagoLEDFibreOptic" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/NewarkAvagoLEDFibreOptic.jpg" alt="" width="222" height="200" />I&#8217;d say that LEDs have  been one of the fastest spreading new technologies in the last 10 years.   Consider now that most cars are being manufactured with LED lighting for all the turn/marker/brake/DRL lights.  They have even made an impact with home lighting &#8211; even though people are being gouged with inflated pricing (IMHO) from places like Home Depot, Rona, Lowes etc..  This will change as LEDs become mainstream&#8230; Just wish I had invested in those companies who first got on the bandwagon!</p>
<p>Anyway, I decided to go away from the typical LED strip and try something new.  The <a href="http://canada.newark.com/avago-technologies/asmt-lw60/led-strip-2-led-white/dp/05M6888" target="_blank"><strong>Avago ASMT-LW60&#8242;s</strong></a> are classified as LED strips, but I am not sure I agree.  They are unique in that they use fibre optics to provide the illumination while a tiny SMD LED is buried inside each end of the light unit.</p>
<p><span id="more-2260"></span></p>
<p>These little guys are about 15cm in length and the LED emitters are tiny.  They would fit well in tiny spaces.  As I write this, one use came to mind &#8211; if you are looking to illuminate things such as car ignition switches, or car AC/heater vents, these would be ideal as you can stick them around the inside as they are small and thin.   What is also nice is the fibre optic flex tube is clear when not illuminated.</p>

<a href='http://www.plastibots.com/?attachment_id=2269' title='NewarkAvagoLEDFibreOptic1'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/NewarkAvagoLEDFibreOptic11-150x150.jpg" class="attachment-thumbnail" alt="NewarkAvagoLEDFibreOptic1" title="NewarkAvagoLEDFibreOptic1" /></a>
<a href='http://www.plastibots.com/?attachment_id=2270' title='NewarkAvagoLEDFibreOptic2'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/NewarkAvagoLEDFibreOptic2-150x150.jpg" class="attachment-thumbnail" alt="NewarkAvagoLEDFibreOptic2" title="NewarkAvagoLEDFibreOptic2" /></a>
<a href='http://www.plastibots.com/?attachment_id=2275' title='NewarkAvagoLEDFibreOptic'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/NewarkAvagoLEDFibreOptic-150x150.jpg" class="attachment-thumbnail" alt="NewarkAvagoLEDFibreOptic" title="NewarkAvagoLEDFibreOptic" /></a>

<p>In order to use these guys, you can power from one or both sides.   This is easier to do if you wrap them around something circular and both ends meet at the same place &#8211; just parallel the connections to 12v and your&#8217;re done.  However, if you are setting them up in a linear fashion, you will need to run a set of leads to both ends to illuminate both LEDs.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><br class="spacer_" /></p>
<p><span style="font-weight: bold; text-decoration: underline;">Features / Specs:</span></p>
<ul>
<li>LED STRIP, 2 LED, WHITE</li>
<li> LED Module Type: Plug &amp; Play</li>
<li> LED Color: White</li>
<li> Power Module Configuration: Strip</li>
<li> Supply Voltage: 12V</li>
<li> Forward Current @ Test: 20mA</li>
<li> Power Rating: 363mW</li>
<li> Operating Temperature Range: -30°C to +60°C</li>
<li> Color: White</li>
<li> RoHS Compliant: Yes</li>
<li><a href="http://www.avagotech.com/docs/AV00-0112EN" target="_blank"><strong>Datasheet</strong></a></li>
</ul>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Good:</span></strong></p>
<ul>
<li>These things are cool.  Although I have not come up with a plan yet, I KNOW I will have a use for these at some point. </li>
<li>Each side of the end modules has a tiny hole, so you can string these together in series (the fibre cable part).</li>
<li>Each perf board has solder points for + and &#8211; clearly marked. </li>
<li>The light is a nice white light (no blue and no yellow).  Perfect for clear illumination of objects in the dark.</li>
</ul>
<ul>
</ul>
<p><strong><span style="text-decoration: underline;">The Not So Good:</span></strong></p>
<ul>
</ul>
<ul>
<li>They are fagile.  The fibre flex cable came out of one of the end units shortly after I unpacked them.  I know that I must have pulled the two apart, but it was not much force.  The rest of the connections were ok.  I fixed the problem with a little silicon and slipped the fibre cable back into the socket with ease. </li>
<li>At 12v, these little units are not bright &#8211; don&#8217;t go looking to provide oodles of illumination here.  However, they do illuminate the area they are around well enough.</li>
</ul>
<p><strong>Summary:</strong></p>
<p>I can&#8217;t wait to use these in something.   Look around my blog and you will see the variety of LED mods I have done to my 12&#8242; Juke.  I am sure these guys will find a place in my car.   There has been a lot of discussion around the lack of lighting for the door window/lock controls on the driver&#8217;s side.  These units may be a perfect solution for this since you can wind/run them around the innards due to their size and flexibility.  I just have to see if the stock buttons are the types that can be illuminated from behind&#8230;   As for pricing, these are about <a href="http://canada.newark.com/avago-technologies/asmt-lw60/led-strip-2-led-white/dp/05M6888" target="_blank"><strong>$6.50 USD</strong></a> at the time of writing.  Not bad for a specialized solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2260</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review &#8211; OPTEK &#8211; Warm White LED Strip</title>
		<link>http://www.plastibots.com/?p=2248</link>
		<comments>http://www.plastibots.com/?p=2248#comments</comments>
		<pubDate>Sat, 14 Jan 2012 12:58:28 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[MyDYI Hacks & Other Stuff]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2248</guid>
		<description><![CDATA[Lately, I&#8217;ve been toying around with different LED strips for my projects.   I&#8217;ve had the chance to use a variety of LED strips (both RGB, and single colour types).  They come in many flavours &#8211; water proof, 3m-backed, silcone encased, sealed, non-sealed, exposed etc.   All have their advantages / disadvantages. In this case, [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I&#8217;ve been toying around with different LED strips for my projects.   I&#8217;ve had the chance to use a variety of LED strips (both RGB, and single colour types).  They come in many flavours &#8211; water proof, 3m-backed, silcone encased, sealed, non-sealed, exposed etc.   All have their advantages / disadvantages.</p>

<a href='http://www.plastibots.com/?attachment_id=2250' title='NewarkOptek'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/NewarkOptek-150x150.jpg" class="attachment-thumbnail" alt="NewarkOptek" title="NewarkOptek" /></a>
<a href='http://www.plastibots.com/?attachment_id=2251' title='NewarkOptek1'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/NewarkOptek1-150x150.jpg" class="attachment-thumbnail" alt="NewarkOptek1" title="NewarkOptek1" /></a>
<a href='http://www.plastibots.com/?attachment_id=2252' title='NewarkOptek2'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/NewarkOptek2-150x150.jpg" class="attachment-thumbnail" alt="NewarkOptek2" title="NewarkOptek2" /></a>

<p><span id="more-2248"></span></p>
<p><br class="spacer_" /></p>
<p>In this case, I am reviewing the warm white LED strip from Optek.   The unit came well packaged from <a href="http://canada.newark.com/optek-technology/ovq12s30ww7/led-strip-30-led-warm-white/dp/19P2485" target="_blank"><strong>Newark</strong></a>.  Typically when you get strips like this, they come of a larger LED strip roll (usually 5 meters), so the product often looks like it was cut with a set of scissors &#8211; no big deal.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><strong><span style="text-decoration: underline;">Features / Specs:</span></strong></p>
<ul>
<li>Part #OVQ12S30WW7</li>
<li>LED STRIP, 30 LED, WARM WHITE</li>
<li>LED Module Type: Board + LED</li>
<li>LED Color: Warm White</li>
<li>CCT: 3300K</li>
<li>Luminous Flux @ Test: 60lm</li>
<li>Power Module Configuration: Strip</li>
<li>Supply Voltage: 12V</li>
<li>Power Rating: 1.6W</li>
<li>RoHS Compliant: Yes</li>
<li><a href="http://www.optekinc.com/datasheets/OVQ12S30B7.pdf" target="_blank">D<strong>atasheet</strong></a></li>
</ul>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Good:</span></strong></p>
<ul>
<li>Light colour is as specified &#8211; warm white.  This strip would serve well in locations where you want to cast a warm natural light (eg under kitchen cabinets). </li>
<li>Although, these are not as bright as their 5050 SMD counterparts, they are softer on the eyes.</li>
<li>Comes with 3M tape on the back.  I have not tried to secure the strip to anything since I haven&#8217;t decided a use for it yet.  I&#8217;m sure it&#8217;ll find its way in my car, or my workbench&#8230; somewhere&#8230;</li>
<li>The unit is less than 3mm high x 8mm wide, so they can be tucked away pretty much anywhere.</li>
<li>Price is very reasonable.</li>
</ul>
<p><strong><span style="text-decoration: underline;">The Not So Good:</span></strong></p>
<ul>
<li>These LEDs are not bright.  Don&#8217;t expect to use these where you are looking to illuminate objects from a distance.  Only a few feet max.</li>
<li>They are not waterproof.  Depending on your situation, this could make or break this buy.</li>
</ul>
<p><br class="spacer_" /></p>
<p><strong>Summary:</strong></p>
<p>If you are looking for a LED strip that can be stuck on pretty much any surface, that casts a nice warm glow and has a small footprint (width and height), this is a nice choice.   If you are looking to mount these in an environment that has to look clean, don&#8217;t forget that you will likely have to create some sort of carrier or barrier for these (so viewers won&#8217;t see the raw LEDs and the copper strip).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2248</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review &#8211; Optek LED Strip</title>
		<link>http://www.plastibots.com/?p=2229</link>
		<comments>http://www.plastibots.com/?p=2229#comments</comments>
		<pubDate>Sat, 07 Jan 2012 01:43:29 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2229</guid>
		<description><![CDATA[After completing my Juke footwell / glove box LED mod, I decided that the footwell LEDs just were not bright enough.   I came across these Optek 3 LED white lights from Newark that have just the right white light and luminosity.  These LED bars are built tough.  The LEDs appear to be set in [...]]]></description>
			<content:encoded><![CDATA[<p>After completing my<a href="http://www.plastibots.com/?p=2174"> Juke footwell / glove box LED mod</a>, I decided that the footwell LEDs just were not bright enough.   I came across these <a href="http://canada.newark.com/optek-technology/ovm12f3w7/led-strip-3-led-white-16lm/dp/19P2475" target="_blank">Optek 3 LED white lights</a> from <a href="http://www.newark.com/optek-technology/ " target="_blank">Newark</a> that have just the right white light and luminosity.  These LED bars are built tough.  The LEDs appear to be set in a hardened liquid plastic.  Wires run in one end and out the other &#8211; it seems that these strips were built as a series set of 3x LED bars and cut to order.  I ordered 2 and both were joined together.  Before installing them above the footwell area, I had to do something about the white.   After masking off the LEDs,  I gave them a few coats of Plastidip to make them black.</p>
<p><br class="spacer_" /></p>
<p style="text-align: center;"><img class="aligncenter size-medium wp-image-2293" title="Optek LED" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/OVM12F3R7-300x300.jpg" alt="" width="300" height="300" /></p>
<p>I am impressed with the end result.  I was after something that would provide nice white light when I am looking for something down in the footwell area during the dark&#8230;  They cast a bright wide swath of light to illuminate the entire footwell area.  They also cast enough light to see under the seats as well.</p>
<p>Illumination with the Optek 3x LED Bar:</p>

<a href='http://www.plastibots.com/?attachment_id=2235' title='JukeIntLEDsUpdated1'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/JukeIntLEDsUpdated1-150x150.jpg" class="attachment-thumbnail" alt="JukeIntLEDsUpdated1" title="JukeIntLEDsUpdated1" /></a>
<a href='http://www.plastibots.com/?attachment_id=2236' title='JukeIntLEDsUpdated2'><img width="150" height="150" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/JukeIntLEDsUpdated2-150x150.jpg" class="attachment-thumbnail" alt="JukeIntLEDsUpdated2" title="JukeIntLEDsUpdated2" /></a>

<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>The original LED illumination:</p>
<p><img class="alignnone" title="Original" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDRTfootwell.jpg" alt="" width="400" height="300" /><img class="alignnone" title="Original LED" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-frontLEDs21-300x225.jpg" alt="" width="300" height="225" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2229</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Nissan Juke &#8211; Footwell &amp; Glove Box LED Lightning</title>
		<link>http://www.plastibots.com/?p=2174</link>
		<comments>http://www.plastibots.com/?p=2174#comments</comments>
		<pubDate>Sat, 26 Nov 2011 00:10:07 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2174</guid>
		<description><![CDATA[Next on the block &#8211; adding LEDs to the foot wells and glove box.   (Prev mods: LED Tails and Rear Passenger LED mods) This mod can be especially useful this time of year up here on the 49th parallel since we are pretty much in darkness @ 5PM during November. All to often I drop [...]]]></description>
			<content:encoded><![CDATA[<p>Next on the block &#8211; adding LEDs to the foot wells and glove box.   (Prev mods: <a href="http://www.plastibots.com/?p=2092" target="_blank"> LED Tails</a> and <a href="http://www.plastibots.com/?p=2137" target="_blank">Rear Passenger LED</a> mods)</p>
<p><br class="spacer_" /></p>
<p>This mod can be especially useful this time of year up here on the 49th parallel since we are pretty much in darkness @ 5PM during November. All to often I drop something down near my feet and have to go looking for it.  The light that casts from the map lights does not reach the areas down near the front driver/passenger foot wells, so I decided to add a few tiny LEDs to shed some love in the area when needed.  In addition to this, the Juke comes with a MASSIVE glove box and no light.  So, it was natural to throw a small LED strip in there as well.  Both sets of LEDs are hooked up to a custom controller that uses an ATTiny85 and touch sensitive pins to control on/off states (I&#8217;m not one to go with status-quo, so the standard on/off switch would not cut it for me).</p>
<p><br class="spacer_" /></p>
<p>The switching unit (below) has 2 pairs of pins and 1 switch.  The switch is used to control the rear passenger LED and is discussed <a href="http://www.plastibots.com/?p=2137" target="_blank">here</a>.   Each pin pair make up a galvanic touch sensor that use the conductive abilities of skin to bridge the connection (reads &#8211; won&#8217;t work with gloves).  Touch them once and the LEDs ramp up (on), touch them again to power them off.  The top pair control the foot well LEDs, the bottom controls the glove box LED.</p>
<p><a href="http://www.plastibots.com/?p=2174"><img class="aligncenter size-medium wp-image-2141" title="Juke-IntLEDSwitch" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDSwitch-276x300.jpg" alt="" width="276" height="300" /></a></p>
<p><span id="more-2174"></span></p>
<p>The switch controller installed &#8211; top left.  Nissan was nice enough to leave us a blank, so naturally, I had to find a use for it!</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDSwitchInstalledInCar.jpg"><img class="aligncenter size-medium wp-image-2189" title="Juke-IntLEDSwitchInstalledInCar" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDSwitchInstalledInCar-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><br class="spacer_" /></p>
<p><strong><span style="font-size: medium;">LEDs:</span></strong></p>
<p>I&#8217;ve replaced the original LEDs with a set of Optek ones.  <a href="http://www.plastibots.com/?p=2229">Details here.</a></p>
<p>New:</p>
<p><img class="aligncenter size-medium wp-image-2293" title="OVM12F3R7" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/OVM12F3R7-300x300.jpg" alt="" width="300" height="300" /></p>
<p style="text-align: center;"> </p>
<p style="text-align: center;"><img class="size-medium wp-image-2235 aligncenter" title="JukeIntLEDsUpdated1" src="http://www.plastibots.com/wordpress/wp-content/uploads/2012/01/JukeIntLEDsUpdated1-300x169.jpg" alt="" width="300" height="169" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><span style="font-size: medium;"><strong>Old LEDs:</strong></span></p>
<p>Below are the first run LEDs I used for each foot well.    Yes, that is LEGO you see..  Have a look around this site to see why..   I can always rely on my LEGO inventory for parts when I need to do some sort of off hook-up, or mount.  In this case, the pivot connectors allow me to swivel the LEDs to different positions &#8211; yet they are strong enough to hold their set position.  They also allow me to quickly disconnect the LEDs in the event I have to remove something, such as the glove box.  Some Goop glue and it&#8217;s all good.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-frontLEDs21.jpg"><img class="aligncenter size-medium wp-image-2176" title="JukeIntLED - frontLEDs2" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-frontLEDs21-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Another pic showing the left and right foot well LEDs (old) .</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-frontLEDs11.jpg"><img class="aligncenter size-medium wp-image-2175" title="JukeIntLED - frontLEDs1" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-frontLEDs11-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Right footwell illuminiated (old):</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDRTfootwell.jpg"><img class="aligncenter size-medium wp-image-2218" title="Juke-IntLEDRTfootwell" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDRTfootwell-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><br class="spacer_" /></p>
<p><strong><span style="font-size: medium;">Controller:</span></strong></p>
<p>I did not take any pics of the controller, but it is loosely based on <a href="http://pcbheaven.com/circuitpages/Resistance_Touch_Button/index.php" target="_blank">this</a>. The idea being that the natural galvanic response of your skin acts to complete the circuit when touching the two touch pads/pins.  This triggers a state change that the micro controller can interpret and act on.  In this case, I have it watch the pin inputs for a voltage change and trigger the LEDs on (when the state is off) and vice-versa.</p>
<p><br class="spacer_" /></p>
<p>The code is pretty straight forward &#8211; monitor the 2 sets of touch pins for a change in voltage, when this happens to either, trigger the related LED output pin to ramp up to full brightness.  Touch a pin set again, turn the related LED output pin off.  A timer has also been used to automatically turn off either light after 5 minutes.</p>
<p>Code:</p>
<p><br class="spacer_" /></p>
<pre class="brush: csharp; collapse: true; light: false; title: ; toolbar: true; notranslate">&lt;/pre&gt;

&lt;p&gt;//uses button to dim LEDs in steps.  Coded toward ATTiny85&lt;br /&gt;
 //v6 updates to v5 include adding timer capabilities to allow LEDs to auto shut off after an elapsed time.  Will prevent from leaving lights on if not hooked up on accessory mode in car.&lt;/p&gt;

&lt;p&gt;#include       // important note - MS2Timer2 affects PWM of PIN 3 and 11, so don't use them for PWM output.&lt;br /&gt;
 #include &lt;br /&gt;
 #include&lt;/p&gt;

&lt;p&gt;//***********************&lt;br /&gt;
 //CONFIGURABLE VALUES&lt;/p&gt;

&lt;p&gt;int tchValSens = 990;                      //val 1023 is open circuit.  0 is closed.  Dry fingers use 900, humid, damp, use 100&lt;/p&gt;

&lt;p&gt;//************************&lt;/p&gt;

&lt;p&gt;#ifndef cbi&lt;br /&gt;
 #define cbi(sfr, bit) (_SFR_BYTE(sfr) &amp;= -_BV(bit))&lt;br /&gt;
 #endif&lt;br /&gt;
 #ifndef sbi&lt;br /&gt;
 #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))&lt;br /&gt;
 #endif&lt;/p&gt;

&lt;p&gt;#define statusLED PB2                        //Digital In D1 - used to show timer countdown.&lt;br /&gt;
 #define ledCtrlrA PB0                       //Digital In Pin 1  MUST BE A PWM PIN (oddly my PWM pin#11 does not work) - controls IRF530 transistor &gt; LED lights&lt;br /&gt;
 #define ledCtrlrB PB1                       //Digital In Pin 0  MUST BE A PWM PIN (oddly my PWM pin#11 does not work) - controls IRF530 transistor &gt; LED lights&lt;br /&gt;
 int tchPadA = 3;                            //defined as Pin 3 (analog input 3) - physical pin ? on ATT85&lt;br /&gt;
 int tchPadB = 2;                            //defined as Pin 4 (analog input 2) - physical pin 2 on ATT85&lt;/p&gt;

&lt;p&gt;int i = 0;&lt;br /&gt;
 int counterA = 0;                             //Counter used for dimming feature&lt;br /&gt;
 int counterB = 0;                             //Counter used for dimming feature&lt;br /&gt;
 int dlyTime = 20;                            //delay timer (for overall loop) in MS.&lt;br /&gt;
 int statCounter = 0;                         //counter for the status LED.&lt;br /&gt;
 int tchValA = 0;                            //Holder for tchValA&lt;br /&gt;
 int tchValB = 0;                            //Holder for tchValB&lt;/p&gt;

&lt;p&gt;int ledStateA = LOW;                          //Holds the current state of the LED lights (HIGH=on LOW=off)&lt;br /&gt;
 int ledStateB = LOW;                          //Holds the current state of the LED lights (HIGH=on LOW=off)&lt;/p&gt;

&lt;p&gt;int brightnessA = 0;                        //Brightness value for dimming the LED  0-255&lt;br /&gt;
 int brightnessB = 0;                        //Brightness value for dimming the LED  0-255&lt;br /&gt;
 int startBrightness = 0;                   //Initial brightness of the LED  0-255&lt;br /&gt;
 int statusLEDFlashDur = 100;                 //In Milliseconds - Flash period for MSTimer2 to flash the LED in ms.  100ms&lt;/p&gt;

&lt;p&gt;long previousMillis = 0;                      //Store last time LED was updated&lt;br /&gt;
 long shutoffStartMillis = 0;                  //Store the value to start the shutoff timer from in Milliseconds.&lt;br /&gt;
 long shutOffDelayMS = 300000;                  //In Milliseconds - Determines how long to keep LED system on (after shutoff timer clicked) in Milliseconds  10000 (10sec), 60000 (1min) 300000 (5min)&lt;/p&gt;

&lt;p&gt;//boolean sleepEnable = 1;&lt;/p&gt;

&lt;p&gt;void setup ()&lt;br /&gt;
 {&lt;br /&gt;
 //Serial.begin (9600);&lt;br /&gt;
 pinMode(tchPadA, INPUT);                   //Setup the tchPadA as an Input&lt;br /&gt;
 pinMode(tchPadB, INPUT);                   //Setup the tchPadB as an Input&lt;br /&gt;
 pinMode(statusLED, OUTPUT);                 //Setup the statusLED as an Output&lt;br /&gt;
 pinMode(ledCtrlrA, OUTPUT);             //Setup the ledCtrlrA as an Output&lt;br /&gt;
 pinMode(ledCtrlrB, OUTPUT);             //Setup the ledCtrlrA as an Output&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void system_sleep()&lt;br /&gt;
 {&lt;br /&gt;
 sbi(MCUCR,PUD);                                  //Disables All Internal Pullup Resistors&lt;br /&gt;
 sbi(GIMSK,PCIE);                                   //Enable Pin Change Interrupts Interrups&lt;br /&gt;
 //add interrupt on 2 pins:&lt;br /&gt;
 sbi(PCMSK,PCINT3);                              //Changes Interrupt to pin 2 on physical chip (PIN 3 Analog Input 3)   (see http://hlt.media.mit.edu/wiki/pmwiki.php?n=Main.ArduinoATtiny4585)&lt;br /&gt;
 sbi(PCMSK,PCINT4);                              //Changes Interrupt to pin 3 on physical chip (PIN 4 Analog Input 2)&lt;br /&gt;
 cbi(ADCSRA,ADEN);                              //switch Analog to Digital Converter OFF&lt;br /&gt;
 cbi(MCUCR,SM0);                                  //Power Down Mode&lt;br /&gt;
 sbi(MCUCR,SM1);                                  //Power Down Mode&lt;br /&gt;
 sbi(MCUCR,SE);                                    //sleep Mode Power down enable (Sleep_enable(); should set this-- not tested yet)&lt;br /&gt;
 sleep_enable();                                      //Sets the Sleep Enable bit in the MCUCR Register (SE BIT)&lt;br /&gt;
 sleep_mode();                                       //sleep begins here&lt;br /&gt;
 sleep_disable();                                     //Coming out of sleep&lt;br /&gt;
 sbi(ADCSRA,ADEN);                             //switch Analog to Digital Converter ON&lt;br /&gt;
 cbi(MCUCR,PUD);                                 //Enables Pullup Resistors Again (this should happen anyway, but i have it here for now just in case, haven't fully tested yet)&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void flash(byte howmany, byte dly) {&lt;br /&gt;
 for (i=0; i &lt; howmany; i++)&lt;br /&gt;
 {&lt;br /&gt;
 digitalWrite(statusLED, HIGH);&lt;br /&gt;
 delay(dly);&lt;br /&gt;
 digitalWrite(statusLED, LOW);&lt;br /&gt;
 delay(dly);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void rampLEDDownNoff(byte ledPin, byte lval, int dly, byte ledStateWhich)&lt;br /&gt;
 {&lt;br /&gt;
 //sleepEnable = 0;&lt;br /&gt;
 if (dly == 0)&lt;br /&gt;
 {&lt;br /&gt;
 analogWrite(ledPin,0);&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 flash(3, 60);&lt;br /&gt;
 while(lval &gt; 0)&lt;br /&gt;
 {&lt;br /&gt;
 analogWrite(ledPin,lval);&lt;br /&gt;
 lval--;&lt;br /&gt;
 delay(dly);&lt;br /&gt;
 }&lt;br /&gt;
 //make it is all the way off&lt;br /&gt;
 digitalWrite(ledPin, LOW);&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;if (ledStateWhich == 1)&lt;br /&gt;
 {&lt;br /&gt;
 ledStateA = LOW;&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 ledStateB = LOW;&lt;br /&gt;
 }&lt;br /&gt;
 //sleepEnable = 1;&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void rampLEDupOn(byte ledPin, byte lval, byte ledNormVal, int dly, byte ledStateWhich)&lt;br /&gt;
 {&lt;br /&gt;
 //sleepEnable = 0;&lt;br /&gt;
 if (dly == 0)&lt;br /&gt;
 {&lt;br /&gt;
 analogWrite(ledPin,255);&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 flash(3, 60);&lt;br /&gt;
 while(lval &lt; ledNormVal)&lt;br /&gt;
 {&lt;br /&gt;
 analogWrite(ledPin,lval);&lt;br /&gt;
 lval++;&lt;br /&gt;
 delay(dly);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 if (ledStateWhich == 1)&lt;br /&gt;
 {&lt;br /&gt;
 ledStateA = HIGH;&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 ledStateB = HIGH;&lt;br /&gt;
 }&lt;br /&gt;
 //sleepEnable = 1;&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void loop (){&lt;/p&gt;

&lt;p&gt;tchValA = analogRead(tchPadA);&lt;br /&gt;
 tchValB = analogRead(tchPadB);&lt;/p&gt;

&lt;p&gt;/*&lt;br /&gt;
 Serial.print(&quot;touchValA: &quot;);&lt;br /&gt;
 Serial.print(tchValA, DEC);&lt;br /&gt;
 Serial.print(&quot;  touchValB: &quot;);&lt;br /&gt;
 Serial.print(tchValB, DEC);&lt;br /&gt;
 Serial.print(&quot;  TriggerVal: &quot;);&lt;br /&gt;
 Serial.print(tchValSens, DEC);&lt;br /&gt;
 Serial.print(&quot;\n&quot;);&lt;br /&gt;
 */&lt;br /&gt;
 /*  continue to watch the touch for a capacitance change, when this happens determine&lt;br /&gt;
 *  what the intent is:&lt;br /&gt;
 *  a) user is holding finger on sensor, ramp LEDs up until they remove their finger.&lt;br /&gt;
 *  b) user tapped sensor, so turn lights on full (basic on/off)&lt;br /&gt;
 */&lt;/p&gt;

&lt;p&gt;//using a threshold value to determine when the touch sensor is being pressed/tapped.&lt;br /&gt;
 //average normal values hover around 480-490, then when tapped, are about 680.  However&lt;br /&gt;
 //seems to be some sort of leak or interferance in the circuit as sometimes the circuit&lt;br /&gt;
 //can be made to jump to higher values and trigger the below statement to execute.&lt;br /&gt;
 //this was noticed by simply waving hand near the transistors/touch sensor.&lt;/p&gt;

&lt;p&gt;if (tchValA &lt; tchValSens)        //use this if modified R3 (2.2K) and T2 Emitter grounded direct to 0V. Arduino pin to Collector out of T2 (will be HIGH)&lt;br /&gt;
 {&lt;br /&gt;
 //when the sensor is either touched or pressed for a longer perior, the below statement triggers.&lt;br /&gt;
 //when a finger is held to the sensor, the time difference between current and previous Millis is very small&lt;br /&gt;
 //(as its resetting through every cycle which is approx 50ms) so, the first statement executes which causes the&lt;br /&gt;
 //LED power to ramp down from high to low&lt;br /&gt;
 //when tapped quickly, the intent is to toggle the LED on/off.  This is triggered when the current and previous&lt;br /&gt;
 //Millis are further apart. Then the state of the LED is checked and toggled to determine if it needs to be switched&lt;br /&gt;
 //on or off.&lt;br /&gt;
 //flash(3, 60);&lt;/p&gt;

&lt;p&gt;//check state and turn led on or off -  if the LED is off turn it on and vice-versa:&lt;br /&gt;
 if (ledStateA == LOW)&lt;br /&gt;
 {&lt;br /&gt;
 brightnessA=startBrightness;&lt;br /&gt;
 counterA = 0;&lt;br /&gt;
 shutoffStartMillis = millis();      //get a start value to start the countdown from.&lt;br /&gt;
 MsTimer2::start();                  //start the timer to trigger the shutoff&lt;br /&gt;
 rampLEDupOn(ledCtrlrA, 0, 255, 2, 1); //5&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 brightnessA=startBrightness;&lt;br /&gt;
 counterA = 0;&lt;br /&gt;
 rampLEDDownNoff(ledCtrlrA, 255, 0, 1);  //10&lt;br /&gt;
 MsTimer2::stop();                    //shut off is reset any time user changes something&lt;br /&gt;
 }&lt;br /&gt;
 flash(3, 60);&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;if (tchValB &lt; tchValSens)&lt;br /&gt;
 {&lt;br /&gt;
 //Check on the second touch sensor&lt;br /&gt;
 //flash(3, 60);&lt;/p&gt;

&lt;p&gt;//check state and turn led on or off -  if the LED is off turn it on and vice-versa:&lt;br /&gt;
 if (ledStateB == LOW)&lt;br /&gt;
 {&lt;br /&gt;
 brightnessB=startBrightness;&lt;br /&gt;
 counterB = 0;&lt;br /&gt;
 shutoffStartMillis = millis();      //get a start value to start the countdown from.&lt;br /&gt;
 MsTimer2::start();                  //start the timer to trigger the shutoff&lt;br /&gt;
 rampLEDupOn(ledCtrlrB, 0, 255, 2, 2); //5&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 brightnessB=startBrightness;&lt;br /&gt;
 counterB = 0;&lt;br /&gt;
 rampLEDDownNoff(ledCtrlrB, 255, 0, 2);  //10&lt;br /&gt;
 MsTimer2::stop();                    //shut off is reset any time user changes something&lt;br /&gt;
 }&lt;br /&gt;
 flash(3, 60);&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;//this will shut down the LED after the ellapsed time period.  Rules - if the shutoffStartMilis has been set AND the time ellapsed is greater than the delay time. Shut off the LED&lt;br /&gt;
 if (shutoffStartMillis != 0 &amp;&amp; millis() - shutoffStartMillis &gt; shutOffDelayMS)    //if shutoff time has elapsed, turn the LEDs off  1000ms = 1 second&lt;br /&gt;
 {&lt;br /&gt;
 if (ledStateA  == HIGH)&lt;br /&gt;
 {&lt;br /&gt;
 rampLEDDownNoff(ledCtrlrA, 255, 10, 1);  //10&lt;br /&gt;
 }&lt;br /&gt;
 if (ledStateB  == HIGH)&lt;br /&gt;
 {&lt;br /&gt;
 rampLEDDownNoff(ledCtrlrB, 255, 10, 2);  //10&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;shutoffStartMillis = 0;&lt;br /&gt;
 MsTimer2::stop();&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;//we dont need to be polling with every cycle, so slow things down a bit. 20 original value.&lt;br /&gt;
 delay(dlyTime);&lt;/p&gt;

&lt;p&gt;//pulse the status LED every second.  Use the delay value to calculate into approx a flash every second.&lt;br /&gt;
 //if (statCounter * dlyTime &gt;= 1000)&lt;br /&gt;
 // {&lt;br /&gt;
 //  flash(1, 60);&lt;br /&gt;
 //  statCounter = 0;&lt;br /&gt;
 //}&lt;/p&gt;

&lt;p&gt;//statCounter++;&lt;/p&gt;

&lt;p&gt;// system_sleep();                                      //Runs the system_sleep() function&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2174</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Nissan Juke &#8211; Interior LED Illumination &#8211; Rear Passenger Light</title>
		<link>http://www.plastibots.com/?p=2137</link>
		<comments>http://www.plastibots.com/?p=2137#comments</comments>
		<pubDate>Sun, 13 Nov 2011 12:27:17 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2137</guid>
		<description><![CDATA[I just finished adding LEDs to the tail lights, and now its time to move on to the interior. For those of you who have a Juke, you can sympathize with me on this &#8211; the Juke is a great vehicle, but it is lacking in some very basic necessities (e.g. armrest, removable cup holders, [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished <a href="http://www.plastibots.com/?p=2092">adding LEDs to the tail lights</a>, and now its time to move on to the interior.    For those of you who have a Juke, you can sympathize with me on this &#8211; the Juke is a great vehicle, but it is lacking in some very basic necessities (e.g. armrest, removable cup holders, and&#8230;  <strong>a rear passenger light!</strong>).  This has been further compounded by the fact that I have 2 children in child seats that can&#8217;t quite do up their own seat belts yet. &#8230;and the seat buckles are buried flush with the seats! (NISSAN!) &#8230;and I can&#8217;t see squat!  Here is my solution to the problem:</p>
<p style="text-align: center;">LED Rear Passenger Light</p>
<p style="text-align: center;"><a href="http://www.plastibots.com/?p=2137"><img class="size-medium wp-image-2133 aligncenter" title="JukeIntLED - LEDOn" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-LEDOn-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><span id="more-2137"></span></p>
<p><br class="spacer_" /></p>
<p>This was a simple mod.  The hardest part was taking the plunge and cutting into the roof material.  Since I like the way the front map lights came on (and faded off) with the opening of the driver door, and that they also have a switch to turn them on permanently (or off), I wired the rear LED light to the center map light.    In addition to this, I also linked the light to a switch (detailed below) that I can used to separately control the rear passenger LED light only (e.g. when the kids are sleeping during a late night out and I dont want the rear light to come on when the door opens).</p>
<p><br class="spacer_" /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><strong>The Build:</strong></p>
<p>I picked up a <a href="http://www.superbrightleds.com/cgi-bin/store/index.cgi?action=DispPage&amp;Page2Disp=%2Fspecs%2Fmrl-smd.htm#photos" target="_blank">mini recessed LED</a> (MRL-xW9SMD &#8211; in warm white) from SuperBrightLEDs.  It was a perfect fit as it has a low profile and rubber surrounds so that it would fit without any glue.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/mrl-large.jpg"><img class="aligncenter size-medium wp-image-2146" title="mrl-large" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/mrl-large-300x130.jpg" alt="" width="300" height="130" /></a></p>
<p><strong><br />
 </strong></p>
<p><br class="spacer_" /></p>
<p>I have the Juke SL with a sunroof and needed to first make sure that there was enough room.  After pulling back the sunroof opening surround, I was able to peek back to see that, with the sunroof open, there was still about 1&#8243; clearance.   The only tweak I had to do is bend the wire coming out if the LED 90 degrees  and secure it to the roof inside.  The first step &#8211; measure to find center and score the cutting area with a protractor.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-Scoring.jpg"><img class="aligncenter size-medium wp-image-2134" title="JukeIntLED - Scoring" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-Scoring-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>The hardest part was doing the cut &#8211; not because it was hard, but  because it was a point of no return.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-Cutting.jpg"><img class="aligncenter size-medium wp-image-2130" title="JukeIntLED - Cutting" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-Cutting-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>The opening.  The nice thing about this LED is that you do not have to worry about a perfect cut since it has a wide trim around the outside.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-Hole1.jpg"><img class="aligncenter size-medium wp-image-2131" title="JukeIntLED - Hole1" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-Hole1-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><br class="spacer_" /></p>
<p>The final result.  To install the LED, I just had to push it up into the ceiling while putting pressure downward from the inside (you are going to want a pair of small arms for this &#8211; else a long piece of 1&#8243;x2&#8243; wood):</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-LEDMounted1.jpg"><img class="aligncenter size-medium wp-image-2151" title="JukeIntLED - LEDMounted" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-LEDMounted1-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><br class="spacer_" /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90 */
google_ad_slot = "9673113064";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Wiring the LED was pretty easy.  I ran the wiring around the driver&#8217;s side and used duct tape to secure it to the top of the ceiling panel. You can route the wires in such a way that they don&#8217;t interfere with the sunroof.   To handle the addition of the switch, I spliced a connection into the &#8220;+&#8221; line and took it down the front pillar and into the area of the switch plate, then ran the rest of the wire to the map light.</p>
<p><br class="spacer_" /></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-2153" title="wiring" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/wiring.jpg" alt="" width="512" height="205" /></p>
<p style="text-align: center;"><img class="aligncenter size-medium wp-image-2156" title="JukeIntLED-maplight" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-maplight-300x225.jpg" alt="" width="300" height="225" /></p>
<p>Removal of the map lights is easy.  First remove the clear surround by pulling down with your fingers around. To remove the light, there is a pressure tab on the right side that you just pull inward (toward the light) while pulling down.  The light will come out of the ceiling easily.</p>
<p><br class="spacer_" /></p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-maplighttab.jpg"><img class="aligncenter size-medium wp-image-2158" title="JukeIntLED-maplighttab" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-maplighttab-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>To wire up the rear LED, I simply soldered the two wires directly to the brass power bus bars inside.  You could choose to wire it up to any one of the 3 lights.  In my case, I wanted it wired  to the center light and also wanted to ensure that it would follow the same &#8216;rules&#8217; when you switch between the 3 power positions with the button that is available there.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-maplightsolderpoints.jpg"><img class="aligncenter size-medium wp-image-2157" title="JukeIntLED-maplightsolderpoints" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-maplightsolderpoints-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><br class="spacer_" /></p>
<p>As mentioned earlier, I also wanted to be able to separately turn the rear LED off when all other lights are on. The Juke comes with a blank switch plate to the lower left of the steering wheel (near the mirror controls0.  I popped it out to add the switch.   The switch is the black nub at the bottom.  A SPST latching switch so that it can be left on &#8216;always on&#8217; or &#8216;always off&#8217; position.  Note &#8211; the two sets of gold pins you see there are for my next LED mod. Stay tuned for more on that later.  (Spoiler &#8211; they are touch capacitive switches).<br />
 <a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDSwitch2.jpg"><img class="aligncenter size-medium wp-image-2140" title="Juke-IntLEDSwitch2" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDSwitch2-244x300.jpg" alt="" width="244" height="300" /></a></p>
<p>Another view showing the switch depth.  That black rubber pad is from an old Thinkpad UltraNav button that I had sitting around.  I also spray painted the shell of the unit with PlastiDip.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDSwitch.jpg"><img class="aligncenter size-medium wp-image-2141" title="Juke-IntLEDSwitch" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/Juke-IntLEDSwitch-276x300.jpg" alt="" width="276" height="300" /></a><br />
 This is the panel to the left of the steering wheel.  To get it out, you have to pull out along the top with your fingers.  It pops most of the way out, but I have not figured out how to completely pull it off (since it wraps around below the steering column).  This was not a problem since I only need to get at the tab to pop out the blank plate (just to the right of my finger).   BTW &#8211; if you want to remove the blank plate, use a small screwdriver to push down on the tab at the top and push the plate into the back (dont pull it out as it does not come out this way).<br />
 <a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-SwitchMountLoc.jpg"><img class="aligncenter size-medium wp-image-2139" title="JukeIntLED - SwitchMountLoc" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-SwitchMountLoc-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><br class="spacer_" /></p>
<p>I am impressed with the end result. Now there is enough light to see the seats, beside the seats and even in the foot area.  Not too bright either.  Note &#8211; the pictures don&#8217;t do it justice.  It is brighter than it appears and casts more light in areas that appear darker in the pics.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-result1.jpg"><img class="aligncenter size-medium wp-image-2159" title="JukeIntLED-result1" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-result1-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-result2.jpg"><img class="aligncenter size-medium wp-image-2160" title="JukeIntLED-result2" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeIntLED-result2-300x225.jpg" alt="" width="300" height="225" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2137</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Nissan Juke &#8211; Custom LED Tail Lights</title>
		<link>http://www.plastibots.com/?p=2092</link>
		<comments>http://www.plastibots.com/?p=2092#comments</comments>
		<pubDate>Wed, 09 Nov 2011 11:49:53 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[MyDYI Hacks & Other Stuff]]></category>
		<category><![CDATA[ATTiny85]]></category>
		<category><![CDATA[LED]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=2092</guid>
		<description><![CDATA[I&#8217;m a sucker for not conforming to status quo when it comes to my toys.. This includes my new Nissan (2012) Juke. In this mod, I added a set of LED light strips to the tail lights with a twist &#8211; I wanted to also monitor and react to braking to enhance the effect. I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a sucker for not conforming to status quo when it comes to my toys..  This includes my new Nissan (2012) Juke.  In this mod, I added a set of LED light strips to the tail lights with a twist &#8211; I wanted to also monitor and react to braking to enhance the effect.  I decided to go with an ATTiny85 using the Arduino core. It only needed 1 input from the 12V brake power and 1 PWM output to control a MOSFET which in turn powered the LED light strip @ 12V.  I built one controller per tail light.  Check out the video to see it in action:</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><span id="more-2092"></span></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<ul>
<p>Some pics of the final result:<br />
 <a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/RearTailLED_RtSideView2.jpg"><img class="aligncenter size-medium wp-image-2101" title="Juke-LEDTailsSideView" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/RearTailLED_RtSideView2-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/RearTailLED_RtSideView.jpg"><img class="aligncenter size-medium wp-image-2103" title="Juke-LEDTailsSideViewDusk" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/RearTailLED_RtSideView-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/RearTailLED_RearView.jpg"><img class="aligncenter size-medium wp-image-2102" title="Juke-LEDTailsRearView" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/RearTailLED_RearView-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><strong>The Build:</strong></p>
</ul>
<p>I Ebayed a pair of red LED side-emitting LED light strips from overseas.  Side-emitting are necessary due to the design of the Juke tail cluster lense.  The mounting of the strip allows these LEDs to shine toward the back of the car rather than out the side.<br />
 <a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/LEDstrip.jpg"><img class="aligncenter size-medium wp-image-2105" title="Juke-LEDstrip" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/LEDstrip-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Mounting the light strip was a bit of a challenge.  Not so much in the actual mounting/gluing but rather in the strip quality.  When mounting the first strip, it broke half way along the strip and killed power to the downstream LEDs.  Poor build quality as it broke along one of the &#8216;cut lines&#8217;.  I had to scrape away the clear rubber coating and solder 2 new tiny connectors and re-link the strip back together. All while half the strip was already glued to the tail light. Fun.  Guess this is what you get for buying overseas quality&#8230;</p>
<p>To mount the strip, I used a glue gun and tacked along every inch or so.  The strip itself also has an adhesive backing, but I dont imagine that will last long given that this LED strip will be exposed to the elements (yes, even though this appears to be inside the tail light, there is no rubber seal when mounted back to the vehicle &#8211; there is an open gap which will allow the elements in &#8211; this is by design, but not sure why Nissan did it this way.<br />
 <a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/RearTailLED_inside.jpg"><img class="aligncenter size-medium wp-image-2099" title="Juke-LEDTails-Mounting" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/RearTailLED_inside-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Locating connections for the controller was straight forward.  There is 12V main (from the parking light), 12V brake (from the brake light) and ground.  The following shows the wires for each of these:<br />
 <a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/PoweConnections.jpg"><img class="aligncenter size-medium wp-image-2104" title="Juke-LEDTail Power Connections" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/PoweConnections-300x225.jpg" alt="" width="300" height="225" /></a></p>
<ul>
<strong>The Electronics:</strong>
</ul>
<p>The circuit is pretty straight forward.  The heart of the unit is the ATTiny85.  12V power comes in when the parking lights are turned on.  This is dropped to 3.3V via a voltage regulator to power the ATTiny85.  When the brakes are applied, 12V comes into the optoisolator to allow the ATTiny to detect when the brakes are applied. Since the ATTiny85 can only accept input up to 5V, I needed a way to drop the 12V in from the brakes to something more manageable.  I could have used a voltage divider, but I decided the optoisolator approach as it allowed the brake circuit to be completely separate from the parking light circuit.  When 12V is applied to the optoisolator, it triggers its output to go low (0V) which is connected to the ATTiny85&#8242;s input pin (normally high).  This triggers the controller to go from 75% LED power to 100%.  The circuit also channels 12V directly to a MOSFET which is controlled by the ATTiny85&#8242;s PWM output pin.  On normal startup, it PWM&#8217;s the LEDs up to 75%.  When brakes are applied, it goes temporarily to 100% then back.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeTails_FriztingCircuit.png"><img class="aligncenter size-medium wp-image-2098" title="Juke-LED Tail Circuit" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeTails_FriztingCircuit-300x118.png" alt="" width="300" height="118" /></a></p>
<p>The controller.  In order to make the circuit weather resistant, I dipped it in PlastiDip.  I still have the ATTiny85 and optoisolator chips exposed as I may want to change the code before committing.</p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeTailLEDController3.jpg"><img class="aligncenter size-medium wp-image-2097" title="Juke-LED Tail Controller" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/11/JukeTailLEDController3-300x283.jpg" alt="" width="300" height="283" /></a></p>
<p><br class="spacer_" /></p>
<pre class="brush: csharp; collapse: true; light: false; title: ; toolbar: true; notranslate">&lt;/pre&gt;

&lt;p&gt;/*&lt;br /&gt;
 Control LED light strip via 12V power provided by parking lights (rear red).   Additionally,&lt;br /&gt;
 the actuation of the brake lights will also illuminate the LED strip at a brighter level to allow it to&lt;br /&gt;
 enhance the effectiveness and visibility of the rear brake lights&lt;br /&gt;
 Design:&lt;br /&gt;
 12V main to power the arduino (ATTiny85) (via 3.3v regulated circuit).  12V main also directly powers the LED light strip.&lt;br /&gt;
 However, the Arduino will be used to control a MOSFET via PWM to act as a light level controller.  On start&lt;br /&gt;
 the LEDs will automatically 'ramp up' to specific light intensity, but not 100% power.  When the brake lights&lt;br /&gt;
 are applied, the Arduino will detect this on an input pin and turn the LEDs on to full brightness, and then&lt;br /&gt;
 back off once the brakes are no longer applied.&lt;br /&gt;
 */&lt;/p&gt;

&lt;p&gt;byte ledMaxVal = 255;              //Full LED brightness level - to be applied when brakes are on.&lt;br /&gt;
 byte ledNormVal = 100;             //normal LED light level.&lt;br /&gt;
 boolean ledState = 0;              //The current state of the LEDs.  0=off 1=on&lt;br /&gt;
 boolean ledAtMax = 0;&lt;br /&gt;
 //boolean brakeState = 0;            //The current state of the brake detected on brakePin.  0=off 1=on&lt;br /&gt;
 //int brakeV = 0;                    //Mapped value converted read from brakePin mapped from 0-1023 to 0-5V.  Note Brake pin has a pull down resistor of 10K to have it read 0 by default.&lt;br /&gt;
 int flashCounter = 0;&lt;br /&gt;
 int brakeThresh = 500;              //brake threshold.  Pin is high. When brakes applied, pin drops to near 0V.  value in mV&lt;/p&gt;

&lt;p&gt;//Configurable values&lt;br /&gt;
 const int LEDPin = 1;              //output pin to control MOSFET switching to power the LED strip from 12V.&lt;br /&gt;
 const int brakePin = 3;            //pin that will detect when brake lights are on.&lt;br /&gt;
 const int LEDstatPin = 0;&lt;/p&gt;

&lt;p&gt;void flash() {&lt;br /&gt;
 digitalWrite(LEDstatPin, HIGH);&lt;br /&gt;
 delay(20);&lt;br /&gt;
 digitalWrite(LEDstatPin, LOW);&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void rampLEDDownNoff(byte lval, int dly)&lt;br /&gt;
 {&lt;br /&gt;
 while(lval &gt; 0)&lt;br /&gt;
 {&lt;br /&gt;
 analogWrite(LEDPin,lval);&lt;br /&gt;
 lval--;&lt;br /&gt;
 delay(dly);&lt;br /&gt;
 }&lt;br /&gt;
 //make sure they are all off&lt;br /&gt;
 digitalWrite(LEDPin, LOW);&lt;br /&gt;
 ledState = 0;&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void rampLEDupOn(byte lval, byte ledNormVal, int dly)&lt;br /&gt;
 {&lt;br /&gt;
 while(lval &lt; ledNormVal)&lt;br /&gt;
 {&lt;br /&gt;
 //give the LED a pulsing look&lt;br /&gt;
 //if (lval &gt; 20) {&lt;br /&gt;
 //analogWrite(LEDPin,20);&lt;br /&gt;
 //delay(5);&lt;br /&gt;
 //}&lt;br /&gt;
 //comment the above to get rid of the LED pulsing.&lt;/p&gt;

&lt;p&gt;analogWrite(LEDPin,lval);&lt;br /&gt;
 //analogWrite(LEDstatPin, lval);   //flash the status LED to show that the LEDs are ramping up.&lt;br /&gt;
 flash();&lt;br /&gt;
 lval++;&lt;/p&gt;

&lt;p&gt;//often, the brake lights will be applied on vehicle start.  If this is the case, then just go to full power on the LEDs and&lt;br /&gt;
 //stop the remp-up procedure&lt;br /&gt;
 if (analogRead(brakePin) &lt; brakeThresh) {      // bail out on sensor detect&lt;br /&gt;
 analogWrite(LEDPin,ledMaxVal);&lt;br /&gt;
 ledState = 1;&lt;br /&gt;
 break;&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;delay(dly);&lt;br /&gt;
 }&lt;br /&gt;
 ledState = 1;&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void setup()&lt;br /&gt;
 {&lt;br /&gt;
 //Serial.begin(9600);&lt;br /&gt;
 pinMode(LEDPin, OUTPUT);&lt;br /&gt;
 pinMode(LEDstatPin, OUTPUT);&lt;br /&gt;
 pinMode(brakePin, INPUT);&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;void loop()&lt;br /&gt;
 {&lt;/p&gt;

&lt;p&gt;if (ledState == 0)    //LEDs are not on, turn them on.&lt;br /&gt;
 {&lt;/p&gt;

&lt;p&gt;rampLEDupOn(0, ledNormVal, 20);&lt;br /&gt;
 analogWrite(LEDstatPin, 100);&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;else if(analogRead(brakePin) &lt; brakeThresh) //ledState would be 1&lt;br /&gt;
 //Optoisolator keeps brakePin Hi at 5V. When 12V applied (brake light), pulls brakePin low.  Hi=1023.  Just picked an arbitrary # of 500&lt;br /&gt;
 //if (analogRead(brakePin) &lt; brakeThresh  &amp;&amp; ledState == 1)&lt;br /&gt;
 {&lt;br /&gt;
 //brakeState = 1;&lt;br /&gt;
 analogWrite(LEDPin,ledMaxVal);&lt;br /&gt;
 ledAtMax = 1;&lt;br /&gt;
 }&lt;br /&gt;
 else if (ledAtMax)&lt;br /&gt;
 {&lt;br /&gt;
 //brakeState = 0;&lt;br /&gt;
 analogWrite(LEDPin,ledNormVal);&lt;br /&gt;
 ledAtMax = 0;&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;//Serial.print(&quot;brkState=&quot;);&lt;br /&gt;
 // Serial.print(brakeState, DEC);&lt;br /&gt;
 //Serial.print(&quot;  brkPinV=&quot;);&lt;br /&gt;
 // Serial.print(brakeV, DEC);&lt;br /&gt;
 //Serial.print(&quot;  brkPinRaw=&quot;);&lt;br /&gt;
 //Serial.print(analogRead(brakePin), DEC);&lt;br /&gt;
 // Serial.print(&quot;  flsCnt=&quot;);&lt;br /&gt;
 //Serial.print(flashCounter, DEC);&lt;/p&gt;

&lt;p&gt;//Serial.println();&lt;/p&gt;

&lt;p&gt;flashCounter++;&lt;/p&gt;

&lt;p&gt;if (flashCounter == 20)&lt;br /&gt;
 {&lt;br /&gt;
 flash();&lt;br /&gt;
 flashCounter = 0;&lt;br /&gt;
 }&lt;/p&gt;

&lt;p&gt;delay(20);  //give the processor some breathing time.&lt;br /&gt;
 //brakeV = 0;&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;</pre>
</p>
<p><br class="spacer_" /></p>
<p><strong>Lessons learned</strong>:  I should have learned this one a long time ago &#8211; don&#8217;t rush.  I figure I will have to re-mount the strips again as I don&#8217;t like the fit.  The Juke tail innards is too tight in some spots to allow the light strip to fit nicely and consistently inside and pointing to the rear.  I plan to take a dremmel in there next time to open it up a bit.  I also want to figure out why there is a lag in timing when the brake light is applied and when the LED goes to 100%. When being tested, it was immediate.</p>
<p>After watching the videos a few times, I noticed a lag in the time from when the LED strip comes on and when the actual brake light fully illuminates. I think this is due to the time it takes for the incandescent bulb to reach its max brightness. However, the LEDs are able to reach instantaneously.  I&#8217;ve re-programmed the ATTiny to delay the LED 75% to 100% trigger timing by a few hundred milliseconds to make up for the brake light bulb and come on at the same time.</p>
<p><br class="spacer_" /></p>
<p><strong>Future ideas </strong>- I am waiting to see if the digitally addressable RGB LEDs can be made thinner/less wide to fit the Juke tails.  I have some ideas about the power on phase (eg have the LEDs ramp up or down one LED at a time, allow interaction with the brakes (red) as well as the signals (amber)&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=2092</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Dual LED Desk Light Controller &#8211; Arduino</title>
		<link>http://www.plastibots.com/?p=1907</link>
		<comments>http://www.plastibots.com/?p=1907#comments</comments>
		<pubDate>Thu, 24 Mar 2011 02:14:05 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[MyDYI Hacks & Other Stuff]]></category>
		<category><![CDATA[Capacitive Touch]]></category>
		<category><![CDATA[LED]]></category>

		<guid isPermaLink="false">http://www.plastibots.com/?p=1907</guid>
		<description><![CDATA[I&#8217;ve been involved in microcontrollers for some time &#8211; but of the LEGO Mindstorms flavour (and BASIC Stamp to a lesser extent). Lately, I&#8217;ve jumped on the Arduino bandwagon. I&#8217;ve always had the natural nack to fix pretty much anything that has batteries or a plug running out of it.  As the Arduino revolution has [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_ControllerMainboard.jpg"><img class="size-medium wp-image-1900  alignright" title="ArduinoLED_ControllerMainboard" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_ControllerMainboard-300x162.jpg" alt="Main Board" width="300" height="162" /></a></p>
<p>I&#8217;ve been involved in microcontrollers for some time &#8211; but of the LEGO Mindstorms flavour (and BASIC Stamp to a lesser extent).  Lately, I&#8217;ve jumped on the Arduino bandwagon.  I&#8217;ve always had the natural nack to fix pretty much anything that has batteries or a plug running out of it.  As the Arduino revolution has picked up dramatically over the past few years, so to has my desire to do DIY projects around the house.  At some point in the future, we plan a kitchen reno.  Part of that reno will the addition of under-cabinet LED lighting.    Since that is far off, but I also had the need for better lighting in my office, I figured this would be a great time to proto something for the kitchen upgrade, while making something functional for the office.  So, here it is..</p>
<p><br class="spacer_" /></p>
<p><span id="more-1907"></span></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><center><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/ViBDuM0C-KM?hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/ViBDuM0C-KM?hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
</center></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90ImgOnly */
google_ad_slot = "4816127144";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div id="attachment_1921" class="wp-caption alignright" style="width: 160px"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_TouchPadMappedAreas.jpg"><img class="size-thumbnail wp-image-1921 " title="ArduinoLED_TouchPadMappedAreas" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_TouchPadMappedAreas-150x150.jpg" alt="TouchPad Mapped Areas" width="150" height="150" /></a><p class="wp-caption-text">TouchPad Mapped Areas</p></div>
<p><br class="spacer_" /></p>
<p>At first, I did not really have a plan.  I knew I wanted some sort of switchless control of the LEDs, and to illuminate the main part of my desk.  My initial prototype used a capacitive touch control using 2 copper tubes mounted on the project box.  The idea being bridging the two tubes with your finger, the LEDs would dim up/down.   You could also to a tap to turn them on (ramp up) and another tap to turn them off (ramp down).   I was nearly done, but while perusing the web, I came across someone using an <a title="Arduino TouchPad" href="http://www.instructables.com/id/The-5-Karduinoss-pad/?ALLSTEPS" target="_blank">arduino and a synaptics touchpad</a> together for another purpose &#8211; which got me thinking (smoke coming out of ears).   I also found the need to want to control more than one light at my desk.  I have multiple shelves and, even though the desk area can be illuminated, the shelf above are dark at night.  This is also the place where all my electronic bits manage to find themselves when Im tinkering &#8211; and I often have to go fishing around for a flashlight to find bits I&#8217;m looking for.   The addition of a touchpad provides many possibilities here.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>When connected to the Arduino, a Synaptics touchpad can be used in two modes.  Relative mode is the norm.  It works like you would expect it to on a laptop.  No matter where you put your finger and move it, your mouse will move from its current point in the direction you move your finger.   Well, I&#8217;m not using a computer or moving a mouse around.  I needed the unit to work in absolute mode.  I need to know the exact X/Y coordinates of where my fingers were moving. Knowing this, I could create mapped areas to monitor in the Sketch and perform various actions when movement was detected in those areas.  Thanks to this <a href="http://www.instructables.com/id/The-5-Karduinoss-pad/step3/Interfacing-to-the-arduino/?files#files" target="_blank">Instructable</a>,  the users Sketch contained the necessary commands to put the Synaptics touchpad in Absolute mode.  The sketch uses the PS2 library as well.  More on this later.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_TouchPadFront.jpg"><img class="size-thumbnail wp-image-1935 alignright" title="ArduinoLED_TouchPadFront" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_TouchPadFront-e1300560538551-150x94.jpg" alt="" width="150" height="94" /></a></p>
<p>After testing a touchpad from my old and trusty Compact N600c,  I decided to pickup a few extras from Ebay. I managed to pickup one from a Gateway W340UA and a Gateway Solo unit ($5 each).  Both units had the Synaptics chip I was looking for, but I am sure there are many other Laptops that have similar units (eg IBM T42 does), and quick<a href="http://sparktronics.blogspot.com/2008/05/synaptics-t1004-based-touchpad-to-ps2.html" target="_blank"> Google search</a> will yield lots of results.  I like this touchpad as it already has the arrow markers for the dimming feature that I wanted (more on this later re X/Y values).  The next image shows the pinouts and trace paths for the Gateway W340UA touchpad that I used for this project.  I have toyed with 4 different Synaptics touchpads and found them all very similar in their layout.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0955337107322324";
/* 728x90 */
google_ad_slot = "9673113064";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div id="attachment_1906" class="wp-caption alignleft" style="width: 310px"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_TouchPadPinouts.jpg"><img class="size-medium wp-image-1906 " title="ArduinoLED_TouchPadPinouts" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_TouchPadPinouts-300x158.jpg" alt="TouchPad Pinouts" width="300" height="158" /></a><p class="wp-caption-text">TouchPad Pinouts</p></div>
<p><br class="spacer_" /></p>
<p>The pinouts are straight forward:  +5V, GND, Data and Clock.  Most sample sketches out there (especially the PS2 library) will have info on where to hook each of these up to on the Arduino.  You can also download my sketch for this project further down below.  Synaptics was even nice enough to give us DIY&#8217;ers  little pads to solder to.  These are evident for the Data and Clock points below.  Note that, for the 5V power, you should track back as far to the ribbon connector as you can.  There is at least 1 resistor and capacitor along the path to the pin on the Synaptics chip.  Don&#8217;t bypass them if they are there.  The Data and Clock pins are ok to go direct to the Synaptics pins.  Also take note of the reference dot on the Synaptics chip &#8211; this typically refers to the starting location of PIN#1 on the chip.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>After soldering the pin connections on the back of the touchpad, I had to find a way to mount it.  I thought of different ways to do this (embedding it on the desk, on the side, etc etc).  Since I had a lot of metal mounting points aronund me (filing cabinet, side shelf beams, shelves), I just decided to put some magnets to the back of it.  Of course, since my roots are with LEGO I could not fore-go the bastardization of a LEGO plate to mask the circuit board and soldering I had done with that fine blue wire (figure it must be 30-something gauge &#8211; it&#8217;s like thread!).  So, I took to the dremmel and cut up a black plate and glued it to the back of the touchpad.  Now, if I want to in the future, I can build any type of mounting system I want &#8211; using LEGO!</p>
<p><br class="spacer_" /></p>
<div id="attachment_1903" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_TouchPadControllerBack.jpg"><img class="size-medium wp-image-1903 " title="ArduinoLED_TouchPadControllerBack" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_TouchPadControllerBack-300x189.jpg" alt="Touch Pad Back - Mounting" width="300" height="189" /></a><p class="wp-caption-text">Touch Pad Back - Mounting</p></div>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>I am a minimalist when it comes to designing circuits.  I don&#8217;t like large boxy control units.  One day, I will perfect my SMD abilities and make these things even smaller.  For now, I had to settle with a project box that I&#8217;m pretty happy with &#8211; approx 3&#8243; x 2&#8243; x 1&#8243;.   I managed to cram in an Arduino Nano, 12V power connector, regulated 5V supply,  4x IRF 530&#8242;s (to control the LEDs), status LEDs and a number of connectors.   It&#8217;s tight.  I know what you Arduino junkes are thinking..  What a waste of a Nano.  I&#8217;m cool with that.  This is the first, and in future projects, I plan on creating my own Atmega based circuits.  I&#8217;ve already cobbled together a staging board that I can use to program future chips.  In the case of this circuit, I needed to use the PWM abilities of the 168/328 chips.  I&#8217;m using all available PWM pins (4 of them).   Again, Arduino junkies, I know what you are thinking &#8211; there are more than 4 PWM pins.  Yes there are.  However, I&#8217;m using the MSTimer2 library which kills the PWM of pins 3 and 11 for this project &#8211; I could have used another for the secondary LED lights, so if you have any ideas, share them up in the comments.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div id="attachment_1899" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_ControllerCase.jpg"><img class="size-medium wp-image-1899 " title="ArduinoLED_ControllerCase" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_ControllerCase-300x225.jpg" alt="Project Box" width="300" height="225" /></a><p class="wp-caption-text">LED Light Controller project box.</p></div>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Looking at the Main Board below, I&#8217;ve labelled all the main parts.  I used IRF530 MOSFETs to allow the Arduino to cleanly regulate 0-12V to each of the R, G, B on the main LED light bar and 1 IRF530 to do the same for the second LED light.  In the case of the second LED light, I used a leftover strip of 3 RGB LEDs.  In this case, I did not care to individually control Red, Green and Blue.  What I did was simply use the IRF530 to power 0-12V to the LEDs on 2 wires.  On the LED strip itself, I bridged R+G and from RG added a 330 Ohm resistor to Blue.  This reduces the power output of blue which gives the light a warmer more natural light (not that bluish white light).</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div id="attachment_1900" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_ControllerMainboard.jpg"><img class="size-medium wp-image-1900 " title="ArduinoLED_ControllerMainboard" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_ControllerMainboard-300x162.jpg" alt="Main Board" width="300" height="162" /></a><p class="wp-caption-text">Main Board</p></div>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>I&#8217;ve also included a breadboard layout created i Fritzing.   Although <a href="http://fritzing.org/" target="_blank">Fritzing </a>has some bugs, its a great app for rapidly producing usable breadboard, PCB and Schamatics of your circuits.  I recommend it.  I almost forgot to mention the speaker.  This was a bit of an afterthought, but i had one laying around and thought it would be good to have some aural feedback when the touchpad was being used.  Glad I did it.  I have the LEDs ramp up/down and it can lead the user to wonder if it&#8217;s working as it can take a few seconds to complete its on/off cycle.  This way, I can add beeps and chirps to the interaction of the unit.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<div id="attachment_1902" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_Schematic.jpg"><img class="size-medium wp-image-1902 " title="ArduinoLED_Schematic" src="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/ArduinoLED_Schematic-300x166.jpg" alt="Breadboard Layout" width="300" height="166" /></a><p class="wp-caption-text">Breadboard Layout</p></div>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">The Sketch:</span></strong></p>
<p>There are a few interesting things I thought I would point out about the sketch:</p>
<ul>
<li>To turn the Main LED on off &#8211; touch the center of the touchpad.  The Main LEDs will ramp up to max brightness (more on this later).  If they LED is on, it will ramp down to an OFF position.</li>
<li>To manually control Main LED brightness, just slide your finger up/down along the right side of the touchpad (where the arrows are).  There was an added bonus to the X values that Synaptics returned to the unit.  Any touch to the area of the right band returns an X value of 8176. This way, my conditional check only has to check the 1 X value and a range of Y values.  The Y values are mapped between 0 &#8211; 255 (the range of power to the LEDs)</li>
<li>Delayed Time off &#8211; I have a feature that when the Main LED is on, clicking the top center will initiate a countdown timer of 10 minutes.  After which the Main LEDs will turn off.</li>
<li>Secondary LED on/off &#8211; clicking the top left corner of the touchpad will toggle the Secondary LED on or off (depending on its current state).   I had to play around a bit with debouncing here as the loop cycle is ~20ms as it was catching multiple on/off states (even with fast finger taps).  I used a simple delay in the code on this (did not want to get into fancy debouncing &#8211; will save that for the kitchen project)</li>
<li>LED Brightness Save &#8211; I thought it would be cool to be able to save the Main LED brightness state.  Using the right slider, you can adjust the brightness of the Main LEDs.  When the desired level is reached, touching (and holding for approx 3 seconds) the bottom left area of the touchpad will save the brightness to EEPROM within the Arduino.    The next time the unit is powered up, it will only ramp up to the saved max brightness value.   This is persistent even if the Arduino looses power.   The only issue is that I can only do it up to approx 100,000 times.  Shucks&#8230;</li>
</ul>
<p><br class="spacer_" /></p>
<p>Arduino Sketch:  <a href="http://www.plastibots.com/wordpress/wp-content/uploads/2011/03/LEDLightDimmer11.zip">LEDLightDimmer11</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.plastibots.com/?feed=rss2&#038;p=1907</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

