Showing posts with label Bluetooth. Show all posts
Showing posts with label Bluetooth. Show all posts

Saturday, August 8, 2020

Part Prices

I was looking at laying out a prototype board, something better than the proto board I am using now. I really like the MAX6675 for the thermocouples. The protoboard is looking good with 4 of the Arduino modules on there. I've built some braces for the modules, and it should be good for ground testing. 



I can buy the Arduino modules with the cap from the data sheet, 0.1" pins and a screw terminal for about $4.00 all day long. If I want to buy the bare chip, it is $9.00-$11.00! Why? I thought the Arduino modules might be using a clone chip, but when I magnify the chip, it clearly says MAX6675ISA. Is it counterfeit? I would thing MAXIM, or whoever would be catching these at customs if that were true. I just don't get it. 

I need to do some more research. Find out if there is some magic I am missing. I am sure I could request samples, and probably get what I need for very little, but if someone were to want to reproduce my work, well, it could get very expensive. 

I know I said I ordered 3 meter thermocouples, I was wrong. I ordered 2 meter cables, and boy are they long! I could have gotten away with meter and a half cables for the two front (rear) cylinders, and 1 meter for the back cylinders. Anyway, they aren't built well, so I may need to modify them anyway. The crimp joints don't have any strain relief, and that is where things are likely to break. I 3D printed a brace to support the modules.


The code has been modified for talking to all 4 modules. I think I'll only have 4 on this board, due to space. Eventually I'd like to use 4 more of the same module for the EGT temperature measuring. I am also using the Hall Effect Linear Current Sensor Module ACS712 for Arduino for measuring current to the panel. I haven't the software for that yet. 

I am printing a proto mount for the firewall now. I use tinkercad for these parts. The links are here, if you want to use them. Let me know if you do. 


ProtoMount                       ModuleBrace




      

Tuesday, July 28, 2020

Trying Things Out on An Airplane.

I finally did it. I have an ESP32 talking to a thermocouple connected to a Lycoming O-360!

I am using bayonet K type thermocouples, on the CHT ports built into the cylinder heads of the engine. They are in a 3/8-24 hole that is about 2 inches deep on the bottom of the cylinder near the bottom spark plug.

This is cylinder 1 near the prop. The bayonet adapter is the shiny metal part, just below the sparkplug. The tube on the left is the intake for the cylinder.

The temperature measurement is working, and seems pretty accurate. For now it is only reading one thermocouple, since that is all I have. I am using the MAX6675 Arduino module available from all the usual outlets for about $5 each. I have 4, but one isn't like the others, and doesn't seem to work. I'll have to order a couple more.

I only have one of these thermocouples, but I have 4 on order. The thermocouple I have only has about and 18inch wire coming out of it. The thermocouples I have on order have 3 meter wires, and should be more suitable for mounting the control box on the firewall.

The ESP32 controller I have now was hanging down between the USB cord and the thermocouple wire. It isn't suitable for use during the engine run. I ran the engine for about 3-4 minutes to get it up to about 200degrees F. I do have 2 sparkplug ring type thermocouples connected to an analog gauge that I can use while the engine is running. I can only read one CHT and EGT at a time, using a rotary switch.

After shutting down the engine, and ensuring all switches were off, I connected the esp32 to a laptop, and the thermocouple to the bayonet adapter. Then I used the Arduino serial monitor to read the output of the serialthermocouple example program that is available with the Adafruit MAX6675 library. The only changes I needed to make to the example program was tell it what pins the three SPI wires connect to.

A screen shot of the Arduino Monitor compares well with the analog gauge:

About 180-190 degrees F showing, while looking at cylinder 4 the opposite of cylinder 1 where the ESP32/MAX6675 was connected. (A Lycoming O-360 is a 4 cylinder boxer type engine, with cylinders 1 and 3 on onside of the engine and cylinders 2 and 4 on the other side of the engine).

The breadboad has expansion capabilities for up to 4 of these MAX6675 modules, a couple voltage dividers allowing the Oil and Fuel pressure analog sensor readings. The ESP32 WROOM module has capabilities for multiple SPI devices, all the analog readings that I may want, and more. It can do bluetooth, or WiFi.

As I work on this, I will add connectors for the additional modules. The USB connector is used for power and data transfer now. When I mount this in the airplane, I will supply power to the 5V input pin, and only use the USB connector for programming.

One thing I learned, the breadboard I bought was a terrible choice. There are a set of buses running the full length of the board. I need to cut traces like crazy. I forgot to cut the traced in the middle of the ESP32, and when I first powered it up, I could smell something. I hadn't soldered each pin in the socket, so I am sure that saved me, but a few power and ground pins ran into each other or other pins.



The scratches in the middle of the socket are where I needed to break the traces. I have to isolate the pads for the MAX6675 adapters since they are arranged longitudinally.

I've added the capability to display the temperature output via Bluetooth. The code is 90% the example code modified to output Bluetooth.


// this example is public domain. enjoy!
// https://learn.adafruit.com/thermocouple/
//
// Modified to output Bluetooth

#include "max6675.h"
#include "BluetoothSerial.h"

int thermoDO = 12;
int thermoCS = 14;
int thermoCLK = 27;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

float tempC, tempF, tempK;
char *titleTemp; 

BluetoothSerial  SerialBT;

void setup() {
  Serial.begin(115200);

  SerialBT.begin("ESP32_EngMon");    // Pair to this device

  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
  
   tempC = thermocouple.readCelsius();
   tempF = thermocouple.readFahrenheit(); 
   Serial.print("C = ");
   SerialBT.print("C = ");
   Serial.println(tempC);
   SerialBT.println(tempC);
   Serial.print("F = ");
   SerialBT.print("F = ");
   Serial.println(tempF);
   SerialBT.println(tempF);
   
   // For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
   delay(1000);
}


The output can be displayed on an Android device using the Bluetooth Terminal application available from the playstore.


Until next time...


Thursday, August 13, 2015

Garage Project Update

I completed this a couple months ago. I just didn't get to posting it. Check out the other posting if you want to know what this is updating.  Of course, I updated the GUI, so it isn't just "Big Door", "Little Door" and made the app a little more robust. It remembers the last Bluetooth device, so pairing is a little more automatic. The change to the GUI allows users to click on the door they want open, and it opens. Someday, I may put in sensors so the GUI could show the current state of the doors (so when I go to bed, I can look, and know if I left any doors open). The app inventor project is at this link.



 I re-did the wiring in the garage as well. I used to have a spiderweb in the ceiling with droopy wires from the access door to the openers. Who ever installed the openers or the wiring must have run out of staples, and there were like 3 for the two openers. Now all the wiring goes through the attic, with the central wiring on a barrier strip.

The sketch I didn't change, but I noticed I didn't upload that either. I'll give that a go as well. The sketch isn't doing anything really complex. It is still based on ardudroid.


/*
 PROJECT: Garage 
 PROGRAMMER: T Brusehaver
 DATE: May 31, 2015
 FILE: garage.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking. 
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

String inText;

void setup() {
  Serial.begin(9600);
  Serial.println("Garage By T. Brusehaver (2015)");
  Serial.flush();
}

void loop()
{
  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().

  // parse incoming command start flag 
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command
  
  // parse incoming pin# and value  
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value
  
  Serial.print("Ard_command ");
  Serial.print(ard_command);
  Serial.print("  Pin=");
  Serial.print(pin_num);
  Serial.print("  Val=");
  Serial.println(pin_value);

  // 1) GET TEXT COMMAND FROM ARDUDROID
  if (ard_command == CMD_TEXT){   
    inText =""; //clears variable for new input   
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }              
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c; 
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ARDUDROID
  if (ard_command == CMD_DIGITALWRITE){  
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return. 
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use 
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ARDUDROID
  if (ard_command == CMD_ANALOGWRITE) {  
    analogWrite(  pin_num, pin_value ); 
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ARDUDROID
  if (ard_command == CMD_READ_ARDUDROID) { 
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    Serial.print(" Analog 0 = "); 
    Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
  case 13:
    pinMode(13, OUTPUT);
    digitalWrite(13, pin_value);  
    // add your code here      
    break;
  case 12:
    pinMode(12, OUTPUT);
    digitalWrite(12, pin_value);   
    // add your code here       
    break;
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);         
    // add your code here 
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);         
    // add your code here 
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);         
    // add your code here 
    break;
  case 8:
    pinMode(8, OUTPUT);
    //digitalWrite(8, pin_value);
    // add your code here 
    digitalWrite(8, HIGH);   // sets the LED on
    delay(1000);                  // waits for a second
    digitalWrite(8, LOW);    // sets the LED off
    break;
  case 7:
    pinMode(7, OUTPUT);
    //digitalWrite(7, pin_value);         
    // add your code here 
    digitalWrite(7, HIGH);   // sets the LED on
    delay(1000);                  // waits for a second
    digitalWrite(7, LOW);    // sets the LED off
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);         
    // add your code here 
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value); 
    // add your code here       
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);         
    // add your code here 
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);         
    // add your code here 
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value); 
    // add your code here       
    break;      
    // default: 
    // if nothing else matches, do the default
    // default is optional
  } 
}

The relays are connected to the Arduino using an NPN transistor. One relay each on pins 7 and 8. The power supply is my old Motorola Razr charger (mini USB). The HC05 is connected using the TX and RX serial pins, so they need to be disconnected if connecting to the USB port to program the Arduino. Also Have a look at the Ardudriod page for the resistors and 3.3V connection. (Don't try 5V and don't forget the resistor on the RX pin). Remember the module is receiving on RX but sending to the TX pin.

There have been a few things I don't like about it, but overall it is serving it's purpose. Pairing basic HC05 modules with and Arduino isn't as quick or automatic as I'd like it to be. Of course, sometimes the signal is going through an aluminium door on the way to the module, so I can't blame anything but circumstances.

If you are thinking of trying this yourself, I recommend it. If nothing else, this is a good place to start.



Friday, December 12, 2014

Bluetooth or WiFi

Ever since I started the engine monitor project, I've had this nagging feeling in the back of my head about using Bluetooth for the engine monitor. Sure there are a lot of things that use Bluetooth for diagnostics and such on a smart phone. I rarely see anything permanently connected except car audio.

Bluetooth's biggest problem for this application comes with the idea of pairing. The only one (sometimes two) device can be paired with a tablet or phone. If you want to listen to audio from the tablet and get engine monitoring inputs to the same tablet, Bluetooth isn't the answer.

I've often thought that WiFi or USB might be a better solution. USB OTG is very common on most Android devices. OTG means the phone or tablet can be a host as well as a client. As a host, the phone can have a USB keyboard and mouse plugged in, and be useful (not portable though). Having the tablet or phone talking to the Arduino could be done for monitoring things, and using a USB hub, probably even charge while displaying engine settings.

USB's biggest drawback for this application is wire. There will need to be about 12 feet of USB cable from the front of the aircraft where the tablet would be to the back of the aircraft where the engine monitor would be (I have a Cozy that is a pusher). Putting a USB hub in the middle of the airplane would give me 2 six foot runs, but it still is inconvenient, and another point of failure.

WiFi, until recently, was a financial challenge. With Aurduino boards costing under $20 for what I want to do, and WiFi shields costing about $40 (sometimes they can be had for $30) it just didn't make sense. I am still trying to come up with a budget device that anyone can put in anything from a $10,000 homebuilt to a $500,000 production aircraft.

Recently a Chinese manufacturer has starting selling $3-5 wifi modules that will talk SPI and will run on the Arduino and other systems. The ESP8266 is available today for about $5. There are tutorialslibraries and sample applications for the Arduino. The module has an onboard processor that people are taking advantage of to make standalone projects, no Arduino required. It could be the thing that makes IoT a reality for many more consumer applications.

The module supports WiFi Direct (P2P) meaning I don't need a WiFi hub in the aircraft. The tablet or phone can talk directly with the module. If there is a hub in the aircraft, then that will work as well. It makes the whole wireless modules in the aircraft more of a reality.

I've ordered one of these modules, it may be a couple weeks before I get it. It will probably be a little while before I integrate it in the engine monitor as well. I'll keep you up to date on my progress.

Sunday, July 14, 2013

Amarino - Again

So I switched back to Amarino. Nothing wrong with the Andruino, in fact long term I'll probably base things off of that, I just need a GUI on the Android now, and Andruino doesn't let me do that. Code that I write for Amarino will be portable for the most part, so I should be able to write a gage module and use it for both environments.

So I rewound... I didn't go to the trouble of connecting the old PC hard disk to the new computer. I thought I would learn more if I did it the hard way. So far I think I have. Amarino isn't very flexible. The code must be hard coded for your bluetooth cards address. Finding the numeric address was a challenge. Initially when the pairing starts it displays the address, but then it changes to the name of the device. I looked in settings, thinking it might list the address there. It turns out the Amarino app has the address in the connect dialog. It took a little while, but I have it.

When I installed the ADK, it defaulted all my targets to 4.2.2. That works great on the emulator, but none of my devices are that advanced. I only have 4.1.2 on them, and some older phones have 2.3.3 or something. (If you aren't familiar with Android, the 2.x OS was pre-tablet version, but you can find some off brand tablets running 2.x, then the 3.x OS was for the early tablets, and Google quickly came up with an OS to satisfy their needs, and it only ran on tablets. The 4.x and above OS is the unified phone/tablet OS that is very current, and is more distributed, so most situations only need a new app, not a whole new OS to get almost all the latest features). The different OS targets APIs are also numbered (IE 4.1.2 is API 16, 2.3.3 is API API 10, sort of like Java versions). 

I installed the 4.0, 4.1 and 2.3 APIs so I can test things out on all my devices. This is done in the Android SDK manager app. Just a few clicks, to select what do download, and press install packages and the ADK is app updated! I didn't download the MIPs or Intel versions, thinking it would save time, and I don't really need them. The older tablets I gave the kids are MIPs based tablets, I may get a version another day for them, if I decide the app is suitable for older tablets (probably, I am not doing anything too complicated, but I don't think those devices have bluetooth).

Loading a bunch of new devices still didn't let me change targets. I had to restart Eclipse. Now I have a large collection of usable APIs. It still can't find my phone, only the emulators. It turns out I needed some new Samsung USB driver for it. I am not sure if Samsung is pushing the boundaries, or if they are being evil requiring a new driver. I'll look into that another day. I installed the app, but now touchwiz keeps crashing. I am rebooting the device, hoping whatever mess I created will get fixed.

Uh oh, now what? Well rebooting didn't fix anything, touchwiz keeps crashing. The phone is useless right now. At least the GUI. It isn't anything malicious, like a virius, just my dopey version of SensorGraph. I can use the notification bar to get to email, and that works (if there is a notification to select). Now when I exit email to go back to the home screen, when touchwiz crashes, I end up back at the email program.

Ooof, sitting here thinking about things, I think I know what I did. The SensorGraph came with an Icon defined in the original package. When I started putting the package together, it couldn't find that icon, so I created a 0byte file for it. I am guessing touchwiz is trying to draw a zero byte icon, and is getting a null pointer exception. I'll change the app to use some other icon, and then download that. It is just touchwiz, so that makes as much sense as anything.

Yes, that fixed that trouble, but now SensorGraph quit at startup. I thought it was because Amarino wasn't running. I started Amarino and connected to the board, then SensorGraph, but it still crashes. The LogCat was enabled, and I see a runtime exception, no class found at.abraxas.amarino.Amarino. It almost sounds like I don't have the amarino libs installed on the phone? Hmmm...

"With great power..." I had the amarino libs included in the build, but not in the deploy. Under the project->properties->buildpath->order and export, I had to check the box to export the amarino libraries. Now it works! Well it is connected, and well, 1 active connection. It says "hello world, sensor graph". I still need to upload the sensor graph software to the arduino. I had already loaded the code to the arduino library. Here is a screen shot of the stock MeetAndroid sketch output on the phone (random noise on analog pin 5)
Then I went and changed the sketch to read the input from the LM34 that was on the board at pin 15
It started at ambient temperatures, then I put my sweaty fingers on it, and you can see where it jumped up.

Now on to redoing my GUI work.






Tuesday, July 9, 2013

I Am Having Fun Now

Okey doke, I am just trying things, and well, it is working. Kinda silly, but at the same time, my juices are starting flowing. The bluetooth is pretty reliable, once I figure out the switches, and such. I've tweaked the Arduino code, and have it doing something interesting.

First the bluetooth, I have the iTead Studio v2.1 bluetooth shield, which seems to be obsolete. There are two switches on the board, voltage selection, and serial port selection. The voltage selection seems to work in either 3.3V or 5V on the Arduino Mega that I am using. The input MUST be set to FT232 for uploading sketches, and in the "To Board" setting to communicate with the Android. Handy to know.

Just as a datapoint, the phone (Samsung Galaxy Note II) seems to pair with the Arduino shield better than the tablet (Samsung Galaxy Note 10.1). I don't know why. The tablet works well once connected, it is just sometimes it is finicky.

I tweaked the sketch to read from the LM34 that I have on the prototyping board from before. This is connected to the A15 pin on the Mega. I have the get data read the value and convert the voltage into something like a temprature. It is running probably 20 degrees warmer than reality if I assume the analog reference is 5V or 10 degrees cool if I assume 3.3V. All I did was put a 1K bias resistor on it, which may be too much, the datasheet shows 50-75ohm. Probably that 3.3V is fine.

 Here is my tweaked code:

/*
 PROJECT: Andruino 0.1 Alpha
 PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
 DATE: July1, 2013
 FILE: Andruino.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUINO 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking. 
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

String inText;

void setup() {
  Serial.begin(9600);
  Serial.println("Andruino 0.1 Alpha by Tommyb (2013).");
  Serial.flush();
}

void loop()
{
  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;
  int temp = 0;    // temprature
  float a15 = 0;  // analog pin 15 input.
  float maxAnalog = 1024;
  float trueTemp = 0.0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().

  // parse incoming command start flag 
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command
  
  // parse incoming pin# and value  
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value

  // 1) GET TEXT COMMAND FROM ANDRUINO
  if (ard_command == CMD_TEXT){   
    inText =""; //clears variable for new input   
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }              
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c; 
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ANDRUINO
  if (ard_command == CMD_DIGITALWRITE){  
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return. 
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use 
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ANDRUINO
  if (ard_command == CMD_ANALOGWRITE) {  
    analogWrite(  pin_num, pin_value ); 
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ANDRUINO
  if (ard_command == CMD_READ_ARDUINO) { 
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    a15 = analogRead(A15);
    // Serial.print(" Analog 15 = "); 
    // Serial.print(a15);  // Example: Read and send Analog pin value to Arduino
    trueTemp = maxAnalog;
    trueTemp = (a15 / trueTemp); 
    Serial.print("  Temp = ");
    Serial.println(trueTemp*330.0);
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
  case 13:
    pinMode(13, OUTPUT);
    digitalWrite(13, pin_value);  
    // add your code here      
    break;
  case 12:
    pinMode(12, OUTPUT);
    digitalWrite(12, pin_value);   
    // add your code here       
    break;
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);         
    // add your code here 
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);         
    // add your code here 
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);         
    // add your code here 
    break;
  case 8:
    pinMode(8, OUTPUT);
    digitalWrite(8, pin_value);         
    // add your code here 
    break;
  case 7:
    pinMode(7, OUTPUT);
    digitalWrite(7, pin_value);         
    // add your code here 
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);         
    // add your code here 
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value); 
    // add your code here       
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);         
    // add your code here 
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);         
    // add your code here 
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value); 
    // add your code here       
    break;      
    // default: 
    // if nothing else matches, do the default
    // default is optional
  } 
}





Whatcha think, any thing I ought to be fiddling with?