Arduino Projects
lets learn some projects on arduino an open source electronic prototyping platform
Thursday, July 24, 2014
Sunday, July 13, 2014
Arduino Ultrasonic Proximity Sensor
This is an Arduino-based Proximity Sensor circuit wired using the popular HC-SR04 Ultrasonic ranging module,used here for non-contact object detection purpose. The HC-SR04 module includes ultrasonic transmitters, receiver and control circuit. You only need to supply a short pulse to the trigger input to start the ranging, and then the module will send out burst of ultrasound at 40 kHz and raise its echo.
The set-up process is very simple, and best understood by referring the wiring diagram. If everything goes right,you should see the burning eye of the red LED when there is no object in the safe-zone (within 5 cm from the HC-SR04 module), and an ear-splitting beep from the piezo-buzzer otherwise.
Arduino Ultrasonic Sensor Wiring Diagram
Arduino Sketch
- /*
- Project: Ultrasonic Proximity Sensor
- Sensor: HC-SR04
- Courtesy Note: Inspired by the Arduino Ping Sketch
- Tested At: TechNode Protolabz / June 2014
- */
- //Pins for HC-SR04
- const int trigPin = 13;
- //Pin which delivers time to receive echo using pulseIn()
- int echoPin = 12;
- int safeZone = 5;
- // Pins for Indicators
- int statusLed = 11;
- int pzBzr = 10;
- void setup() {
- }
- void loop()
- {
- //raw duration in milliseconds, cm is the
- //converted amount into a distance
- long duration, cm;
- //initializing the pin states
- pinMode(trigPin, OUTPUT);
- pinMode(statusLed, OUTPUT);
- pinMode(pzBzr, OUTPUT);
- //sending the signal, starting with LOW for a clean signal
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- //setting up the input pin, and receiving the duration in uS
- pinMode(echoPin, INPUT);
- duration = pulseIn(echoPin, HIGH);
- // convert the time into a distance
- cm = microsecondsToCentimeters(duration);
- //Checking if anything is within the safezone
- // If not, keep status LED on
- // Incase of a safezone violation, activate the piezo-buzzer
- if (cm > safeZone)
- {
- digitalWrite(statusLed, HIGH);
- digitalWrite(pzBzr, LOW);
- }
- else
- {
- digitalWrite(pzBzr, HIGH);
- digitalWrite(statusLed, LOW);
- }
- delay(100);
- }
- long microsecondsToCentimeters(long microseconds)
- {
- // The speed of sound is 340 m/s or 29 microseconds per centimeter
- // The ping travels forth and back
- // So to calculate the distance of the object we take half of the travel
- return microseconds / 29 / 2;
- }
Thursday, July 3, 2014
Turn signal biking jacket
This tutorial will show you how to build a jacket with turn signals that will let people know where you're headed when you're on your bike. We'll use conductive thread and sewable electronics so your jacket will be soft and wearable and washable when you're done. Enjoy!
Step 1: Supplies
Get your supplies. You need:
-- LilyPad Arduino main board
-- FTDI connector
-- mini USB cable
-- LilyPad power supply
-- 16 LilyPad LEDs (note: these aren't available from SparkFun yet, but will be soon)
-- 2 push button switches
-- a spool of 4-ply conductive thread
-- a digital multimeter with a beeping continuity tester. This is the one I have.
-- a garment or a piece of fabric to work on
-- a needle or two, a fabric marker or piece of chalk, puffy fabric paint, a bottle of fabric glue, and a ruler
(Available at your local fabric shop or Joann Stores.)
-- a pair of scissors
-- double sided tape (optional)
-- a sewing machine (optional)
-- LilyPad Arduino main board
-- FTDI connector
-- mini USB cable
-- LilyPad power supply
-- 16 LilyPad LEDs (note: these aren't available from SparkFun yet, but will be soon)
-- 2 push button switches
-- a spool of 4-ply conductive thread
-- a digital multimeter with a beeping continuity tester. This is the one I have.
-- a garment or a piece of fabric to work on
-- a needle or two, a fabric marker or piece of chalk, puffy fabric paint, a bottle of fabric glue, and a ruler
(Available at your local fabric shop or Joann Stores.)
-- a pair of scissors
-- double sided tape (optional)
-- a sewing machine (optional)
Step 2: Design
Plan the aesthetic and electrical layout of your piece.
Decide where each component is going to go and figure out how you will sew them together with as few thread crossings as possible. Make a sketch of your design that you can refer to as you work. The photos below show the sketches for my jacket. Stitching for power (+) is shown in red, ground (-) in black, LEDs in green, and switch inputs in purple.
Important note about the power supply
As you design, plan to keep your power supply and LilyPad main board close to each other. If they are too far apart, you are likely to have problems with your LilyPad resetting or just not working at all.
Why? Conductive thread has non-trivial resistance. (The 4-ply silver-coated thread from SparkFun that comes with the LilyPad starter kit has about 14 ohms/foot.) Depending on what modules you're using in your construction, your LilyPad can draw up to 50 milliamps (mA) of current, or .05 Amps. Ohm's law says that the voltage drop across a conductive material--the amount of voltage that you lose as electricity moves through the material--is equal to the resistance of the conductive material times the amount of current that is flowing through it.
For example, if your LilyPad is a foot away from the power supply, the total resistance of the conductive material that attaches your LilyPad to your power supply is about 28 ohms. (14 Ohms in the conductive thread that leads from the negative terminal of the power supply to the negative petal on the LilyPad and 14 Ohms in the conductive thread that ties the positive terminals together). This means we can expect a drop of 1.4 Volts (28 Ohms * .05 Amps.) This means that while 5 Volts is coming out of the power supply, the LilyPad will only be getting 3.6 Volts (5 Volts - 1.4 Volts). Once the voltage at the LilyPad drops below about 3.3 Volts, it will reset. The resistance of the traces from + on the power supply to + on the LilyPad and - on the power supply to - on the LilyPad should be at most 10 Ohms. Plan the distance accordingly.
If all of this was confusing, don't worry! Just keep the LilyPad and power supply close to each other in your design.
Transfer the sketch to your garment.
Use chalk or some other non-permanent marker to transfer your design to the garment. If you want, use a ruler to make sure everything is straight and symmetrical.
Use double sided tape to temporarily attach LIlyPad pieces to your garment. This will give you a good sense of what your final piece will look like. It will also keep everything in place and, as long as the tape sticks, make your sewing easier.
Decide where each component is going to go and figure out how you will sew them together with as few thread crossings as possible. Make a sketch of your design that you can refer to as you work. The photos below show the sketches for my jacket. Stitching for power (+) is shown in red, ground (-) in black, LEDs in green, and switch inputs in purple.
Important note about the power supply
As you design, plan to keep your power supply and LilyPad main board close to each other. If they are too far apart, you are likely to have problems with your LilyPad resetting or just not working at all.
Why? Conductive thread has non-trivial resistance. (The 4-ply silver-coated thread from SparkFun that comes with the LilyPad starter kit has about 14 ohms/foot.) Depending on what modules you're using in your construction, your LilyPad can draw up to 50 milliamps (mA) of current, or .05 Amps. Ohm's law says that the voltage drop across a conductive material--the amount of voltage that you lose as electricity moves through the material--is equal to the resistance of the conductive material times the amount of current that is flowing through it.
For example, if your LilyPad is a foot away from the power supply, the total resistance of the conductive material that attaches your LilyPad to your power supply is about 28 ohms. (14 Ohms in the conductive thread that leads from the negative terminal of the power supply to the negative petal on the LilyPad and 14 Ohms in the conductive thread that ties the positive terminals together). This means we can expect a drop of 1.4 Volts (28 Ohms * .05 Amps.) This means that while 5 Volts is coming out of the power supply, the LilyPad will only be getting 3.6 Volts (5 Volts - 1.4 Volts). Once the voltage at the LilyPad drops below about 3.3 Volts, it will reset. The resistance of the traces from + on the power supply to + on the LilyPad and - on the power supply to - on the LilyPad should be at most 10 Ohms. Plan the distance accordingly.
If all of this was confusing, don't worry! Just keep the LilyPad and power supply close to each other in your design.
Transfer the sketch to your garment.
Use chalk or some other non-permanent marker to transfer your design to the garment. If you want, use a ruler to make sure everything is straight and symmetrical.
Use double sided tape to temporarily attach LIlyPad pieces to your garment. This will give you a good sense of what your final piece will look like. It will also keep everything in place and, as long as the tape sticks, make your sewing easier.
Step 3: Sew your power supply and LilyPad to your jacket
First, trim the leads off of the back of the power supply
Get out your LilyPad power supply piece and trim the metal parts that are sticking out the back of it. Small clippers like the ones shown in the photo work well, but you can also use scissors.
Stabilize your battery on the fabric.
Generally, you want to do everything you can to keep the power supply from moving around on the fabric. I recommend gluing or sewing the battery down before starting on the rest of the project. You may also want to glue or sew something underneath the power supply to help prevent it from pulling on the fabric and bouncing around as you move.
If you are working on a thin or stretch piece of fabric--first of all, reconsider this choice! It's much easier to work on a heavy piece of non-stretchy fabric. If you are determined to forge ahead with a delicate fabric, choose the location for your power supply wisely. It's the heaviest electronic module, so put it somewhere where it will not distort the fabric too badly. definitely glue or sew something underneath the power supply.
Sew the + petal of the power supply down to your garment.
If you are new to sewing, check out this great introduction before you start for info on how to thread a needle, tie knots and make stitches. Cut a 3-4 foot length of conductive thread. Thread your needle, pulling enough of the thread through the needle that it will not fall out easily. Tie a knot at the end of the longer length of thread. Do not cut the thread too close to the knot or it will quickly unravel.
Coming from the back of the fabric to the front, poke the needle into the fabric right next to the + petal on the power supply and then, from the front of the fabric, pull it through. The knot at the end of the thread will keep the thread from pulling out of the fabric. Now make a stitch going into the hole in the hole in the + petal on the power supply. Do this several more times, looping around from the back of the fabric to the front, going through the + petal each time.
Pay special attention to this stitching. It is the most important connection that you'll sew in your project. You want to make sure you get excellent contact between the petals on the power supply and your conductive thread. Go through the hole several times (at least 5) with your stitching. Keep sewing until you can't get your needle through anymore. Do not cut your thread, just proceed to the next step.
Sew from the battery to the LilyPad.
Once you've sewn the + petal of the battery down, make small neat stitches to the + petal of your LilyPad. I used a jacket with a fleece lining and stitched only through the inner fleece lining so that no stitches were visible on the outside of the jacket.
Sew the + petal of your LilyPad down, finishing the connection.
When you reach the LilyPad, sew the + petal down to the fabric with the conductive thread. Just like you were with the battery petal, you want to be extra careful to get a robust connection here. This stitching is making the electrical connection between your power supply and LilyPad.
When you are done with this attachment, sew away from the LilyPad about an inch along your stitching, tie a knot, and cut your thread about an inch away from the knot so that your knot won't come untied.
Put fabric glue on each of your knots to keep them from unraveling.
Once the glue dries, trim the thread close to each knot.
Get out your LilyPad power supply piece and trim the metal parts that are sticking out the back of it. Small clippers like the ones shown in the photo work well, but you can also use scissors.
Stabilize your battery on the fabric.
Generally, you want to do everything you can to keep the power supply from moving around on the fabric. I recommend gluing or sewing the battery down before starting on the rest of the project. You may also want to glue or sew something underneath the power supply to help prevent it from pulling on the fabric and bouncing around as you move.
If you are working on a thin or stretch piece of fabric--first of all, reconsider this choice! It's much easier to work on a heavy piece of non-stretchy fabric. If you are determined to forge ahead with a delicate fabric, choose the location for your power supply wisely. It's the heaviest electronic module, so put it somewhere where it will not distort the fabric too badly. definitely glue or sew something underneath the power supply.
Sew the + petal of the power supply down to your garment.
If you are new to sewing, check out this great introduction before you start for info on how to thread a needle, tie knots and make stitches. Cut a 3-4 foot length of conductive thread. Thread your needle, pulling enough of the thread through the needle that it will not fall out easily. Tie a knot at the end of the longer length of thread. Do not cut the thread too close to the knot or it will quickly unravel.
Coming from the back of the fabric to the front, poke the needle into the fabric right next to the + petal on the power supply and then, from the front of the fabric, pull it through. The knot at the end of the thread will keep the thread from pulling out of the fabric. Now make a stitch going into the hole in the hole in the + petal on the power supply. Do this several more times, looping around from the back of the fabric to the front, going through the + petal each time.
Pay special attention to this stitching. It is the most important connection that you'll sew in your project. You want to make sure you get excellent contact between the petals on the power supply and your conductive thread. Go through the hole several times (at least 5) with your stitching. Keep sewing until you can't get your needle through anymore. Do not cut your thread, just proceed to the next step.
Sew from the battery to the LilyPad.
Once you've sewn the + petal of the battery down, make small neat stitches to the + petal of your LilyPad. I used a jacket with a fleece lining and stitched only through the inner fleece lining so that no stitches were visible on the outside of the jacket.
Sew the + petal of your LilyPad down, finishing the connection.
When you reach the LilyPad, sew the + petal down to the fabric with the conductive thread. Just like you were with the battery petal, you want to be extra careful to get a robust connection here. This stitching is making the electrical connection between your power supply and LilyPad.
When you are done with this attachment, sew away from the LilyPad about an inch along your stitching, tie a knot, and cut your thread about an inch away from the knot so that your knot won't come untied.
Put fabric glue on each of your knots to keep them from unraveling.
Once the glue dries, trim the thread close to each knot.
Step 4: Test your stitching
Measure the resistance of your stitching.
Get out your multimeter and put it on the resistance measuring setting. Measure from power supply + to LilyPad + and power supply - to LilyPad -. If the resistance of either of these traces is greater than 10 ohms, reinforce your stitching with more conductive thread. If you're not sure how to measure resistance, check out this tutorial.
Put a AAA battery into the power supply and flip the power supply switch to the on position. The red light on the power supply should turn on. If it doesn't and you're sure you flipped the switch, quickly remove the battery and check for a short between your + and - stitches. (Most likely there is a piece of thread that's touching both the - and + stitching somewhere.) You can test for a short between + and - by using the beeping continuity tester on your multimeter. See this tutorial for information on how to use the continuity tester.
Also check the resistance between the + and - stitching. If the resistance is less than 10K Ohms or so, you've got a mini-short (probably a fine conductive thread hair that is touching both + and -) that you need to find and correct.
If the power supply does turn on, look at your LilyPad. It should blink quickly each time you press its switch. Once these connections are working properly, turn off the power supply and remove the battery.
Insulate your power and ground stitching
So, your jacket is now full of uninsulated conductive stitches. This is fine when a body is inside of it. A body will prevent sewn traces from contacting each other. But when the jacket is off of a person and you bend or fold it, traces will touch each other and short out. To fix this problem, cover your traces with puffy fabric paint (or another insulator like a satin stitch in regular thread). But, you don't want to cover traces until you're sure that everything works! So, use good judgment in when to coat traces.
Get out your multimeter and put it on the resistance measuring setting. Measure from power supply + to LilyPad + and power supply - to LilyPad -. If the resistance of either of these traces is greater than 10 ohms, reinforce your stitching with more conductive thread. If you're not sure how to measure resistance, check out this tutorial.
Put a AAA battery into the power supply and flip the power supply switch to the on position. The red light on the power supply should turn on. If it doesn't and you're sure you flipped the switch, quickly remove the battery and check for a short between your + and - stitches. (Most likely there is a piece of thread that's touching both the - and + stitching somewhere.) You can test for a short between + and - by using the beeping continuity tester on your multimeter. See this tutorial for information on how to use the continuity tester.
Also check the resistance between the + and - stitching. If the resistance is less than 10K Ohms or so, you've got a mini-short (probably a fine conductive thread hair that is touching both + and -) that you need to find and correct.
If the power supply does turn on, look at your LilyPad. It should blink quickly each time you press its switch. Once these connections are working properly, turn off the power supply and remove the battery.
Insulate your power and ground stitching
So, your jacket is now full of uninsulated conductive stitches. This is fine when a body is inside of it. A body will prevent sewn traces from contacting each other. But when the jacket is off of a person and you bend or fold it, traces will touch each other and short out. To fix this problem, cover your traces with puffy fabric paint (or another insulator like a satin stitch in regular thread). But, you don't want to cover traces until you're sure that everything works! So, use good judgment in when to coat traces.
Step 5: Sew on your turn signal LEDs
Sew in your left and right signals.
Using the same techniques you used to sew the power supply to the LilyPad, attach all of the + petals of the lights for the left turn signal together and to a petal on the LilyPad (petal 9 for me) and all of the + petals for the right signal together and to another LilyPad petal (11 for me). Attach all of the - petals of the lights together and then to either the - petal on the LilyPad or another LilyPad petal (petal 10 for me). Refer back to my design sketches if any of this is confusing.
Remember to seal each of your knots with fabric glue to keep them from unraveling. Be careful to avoid shorts; don't let one sewn trace touch another. In this case, the - traces for the LEDs are all connected, but you want to make sure that the + traces for the left and right signals do not touch the - trace or each other.
Test your turn signals.
Load a program onto your LilyPad that blinks each turn signal to make sure all of your sewing is correct.
Note, if you don't know how to program the LilyPad, work through a few of these introductory tutorials before proceeding.
Here's my test program:
int ledPin = 13; // the LED on the LilyPad
int leftSignal = 9; // my left turn signal is attached to petal 9
int rightSignal = 11; // my right turn signal is attached to petal 11
int signalLow = 10; // the - sides of my signals are attached to petal 10
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(leftSignal, OUTPUT); // sets the leftSignal petal to be an output
pinMode(rightSignal, OUTPUT); // sets the rightSignal petal to be an output
pinMode(signalLow, OUTPUT); // sets the signalLow petal to be an output
digitalWrite(signalLow, LOW); // sets the signalLOW petal to LOW (-)
}
void loop() // run over and over again
{
delay(1000); // wait for 1 second
digitalWrite(leftSignal, LOW); // turn the left signal off
delay(1000); // wait for 1 second
digitalWrite(rightSignal, HIGH); // turn the right signal on
delay(1000); // wait for 1 second
digitalWrite(rightSignal, LOW); // turn the right signal off
delay(1000); // wait for 1 second
}
If your layout is the same as mine, you can just copy and paste this program into your Arduino window.
If your turn signals don't work, use your multimeter (and the instructions from the last step) to test for shorts or bad connections and make sure that your program matches your physical layout.
insulate your turn signal stitches
Cover your traces with puffy fabric paint. Remember, you don't want to cover traces until you're sure that everything works! Use good judgment in when to coat traces.
Using the same techniques you used to sew the power supply to the LilyPad, attach all of the + petals of the lights for the left turn signal together and to a petal on the LilyPad (petal 9 for me) and all of the + petals for the right signal together and to another LilyPad petal (11 for me). Attach all of the - petals of the lights together and then to either the - petal on the LilyPad or another LilyPad petal (petal 10 for me). Refer back to my design sketches if any of this is confusing.
Remember to seal each of your knots with fabric glue to keep them from unraveling. Be careful to avoid shorts; don't let one sewn trace touch another. In this case, the - traces for the LEDs are all connected, but you want to make sure that the + traces for the left and right signals do not touch the - trace or each other.
Test your turn signals.
Load a program onto your LilyPad that blinks each turn signal to make sure all of your sewing is correct.
Note, if you don't know how to program the LilyPad, work through a few of these introductory tutorials before proceeding.
Here's my test program:
int ledPin = 13; // the LED on the LilyPad
int leftSignal = 9; // my left turn signal is attached to petal 9
int rightSignal = 11; // my right turn signal is attached to petal 11
int signalLow = 10; // the - sides of my signals are attached to petal 10
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(leftSignal, OUTPUT); // sets the leftSignal petal to be an output
pinMode(rightSignal, OUTPUT); // sets the rightSignal petal to be an output
pinMode(signalLow, OUTPUT); // sets the signalLow petal to be an output
digitalWrite(signalLow, LOW); // sets the signalLOW petal to LOW (-)
}
void loop() // run over and over again
{
delay(1000); // wait for 1 second
digitalWrite(leftSignal, LOW); // turn the left signal off
delay(1000); // wait for 1 second
digitalWrite(rightSignal, HIGH); // turn the right signal on
delay(1000); // wait for 1 second
digitalWrite(rightSignal, LOW); // turn the right signal off
delay(1000); // wait for 1 second
}
If your layout is the same as mine, you can just copy and paste this program into your Arduino window.
If your turn signals don't work, use your multimeter (and the instructions from the last step) to test for shorts or bad connections and make sure that your program matches your physical layout.
insulate your turn signal stitches
Cover your traces with puffy fabric paint. Remember, you don't want to cover traces until you're sure that everything works! Use good judgment in when to coat traces.
Step 6: Sew in your control switches
Place your switches
Find a spot for your switches where they'll be easy to press when you're riding your bike. I mounted mine on the underside of my wrists. I found a good spot by trying out different places. Check out the photos to see what I mean.
Once you've found a good position, push the legs of the switch through the fabric and bend them over on the inside of the fabric.
Sew in your switches.
Sew your switches into the garment. Sew 1 leg to the switch input petal on the LilyPad and another leg, one that is diagonally across from the first , to ground or another LilyPad petal. I used petal 6 for the switch input on the left side and petal 12 for switch input on the right side. I used - for the - connection on the left side, but petal 4 for the - connection on the right side. Refer back to my design drawings if any of this is confusing.
When you're done sewing, go back and reinforce the switch connections with glue. You don't want your switches to fall out of their stitching.
Find a spot for your switches where they'll be easy to press when you're riding your bike. I mounted mine on the underside of my wrists. I found a good spot by trying out different places. Check out the photos to see what I mean.
Once you've found a good position, push the legs of the switch through the fabric and bend them over on the inside of the fabric.
Sew in your switches.
Sew your switches into the garment. Sew 1 leg to the switch input petal on the LilyPad and another leg, one that is diagonally across from the first , to ground or another LilyPad petal. I used petal 6 for the switch input on the left side and petal 12 for switch input on the right side. I used - for the - connection on the left side, but petal 4 for the - connection on the right side. Refer back to my design drawings if any of this is confusing.
When you're done sewing, go back and reinforce the switch connections with glue. You don't want your switches to fall out of their stitching.
Step 7: Sew in your indicator LEDs
Sew a single LED onto the sleeve of each arm.
These will give you essential feedback about which turn signal is on. They'll flash to tell you what the back of your jacket is doing, so make sure they're in a visible spot. Sew the + petals of each LED to a LilyPad petal and the - petals of each LED to the - side of the switch (the - trace you sewed in the last step). I used petal 5 for the LED + on the left side and petal 3 for the LED + on the right side. Again, refer back to my design drawings if any of this is confusing.
As always, remember to glue and trim knots and be careful not to create any shorts.
Once you sew both wrist LEDs, you're done with the sewing phase of the project! Now, on to programming...
These will give you essential feedback about which turn signal is on. They'll flash to tell you what the back of your jacket is doing, so make sure they're in a visible spot. Sew the + petals of each LED to a LilyPad petal and the - petals of each LED to the - side of the switch (the - trace you sewed in the last step). I used petal 5 for the LED + on the left side and petal 3 for the LED + on the right side. Again, refer back to my design drawings if any of this is confusing.
As always, remember to glue and trim knots and be careful not to create any shorts.
Once you sew both wrist LEDs, you're done with the sewing phase of the project! Now, on to programming...
Step 8: Program your jacket
Decide on the behavior you want.
I wanted the left switch to turn on the left turn signal for 15 seconds or so, and the right switch to do the same thing for the right signal. Pressing a switch when the corresponding turn signal is on should turn the signal off. Pressing both switches at the same time should put the jacket into nighttime flashing mode. The wrist mounted LEDs should provide feedback about the current state of the jacket. Here's the code I wrote to get that behavior.
Program your jacket
To program your garment, copy and paste my code into an Arduino window and load it onto the LilyPad. You may have to make some small adjustments first depending on where you attached lights and switches. Play with delays to customize your blinking patterns. Follow my LilyPad introduction instructions if you need more information on how to program the LilyPad or how to make sense of my code.
Plug your battery back in and see if it works and...go biking!
Insulate the rest of your traces
Cover the rest of your traces with puffy fabric paint. Again, don't coat anything until you're sure it works.
About washing
Your creation is washable. Remove the battery and wash the garment by hand with a gentle detergent.
Note: silver coated threads will corrode over time and their resistance will gradually increase with washing and wear. To limit the effects of corrosion, insulate and protect your traces with puffy fabric paint or some other insulator. You can also revive exposed corroded traces with silver polish. Try this on a non-visible area first to see what it does to your fabric!
I wanted the left switch to turn on the left turn signal for 15 seconds or so, and the right switch to do the same thing for the right signal. Pressing a switch when the corresponding turn signal is on should turn the signal off. Pressing both switches at the same time should put the jacket into nighttime flashing mode. The wrist mounted LEDs should provide feedback about the current state of the jacket. Here's the code I wrote to get that behavior.
Program your jacket
To program your garment, copy and paste my code into an Arduino window and load it onto the LilyPad. You may have to make some small adjustments first depending on where you attached lights and switches. Play with delays to customize your blinking patterns. Follow my LilyPad introduction instructions if you need more information on how to program the LilyPad or how to make sense of my code.
Plug your battery back in and see if it works and...go biking!
Insulate the rest of your traces
Cover the rest of your traces with puffy fabric paint. Again, don't coat anything until you're sure it works.
About washing
Your creation is washable. Remove the battery and wash the garment by hand with a gentle detergent.
Note: silver coated threads will corrode over time and their resistance will gradually increase with washing and wear. To limit the effects of corrosion, insulate and protect your traces with puffy fabric paint or some other insulator. You can also revive exposed corroded traces with silver polish. Try this on a non-visible area first to see what it does to your fabric!
HERE WE GO ON TO DO SOMETHING MUCH INTRESTING WITH OUR ARDUINO
Make a 24X6 LED matrix
Step 1: Getting All The Right Things
So you will need the basic set of tools for this project : a soldering iron, some solder wire, a cutter, a needle nosed plier,some wire, wire striper, and some desoldering tools if you need them.
For the matrix you will:
For the matrix you will:
1. 144 LEDs
2. 24 resistors( The value is determent by the type of LEDs, in my case 91 ohm)
3. 4017 decade counter
4. 6 1KOhm resistors
5. 6 2N3904 transistors
6. A long Perfboard
7. Arduino
8. 3 x 74HC595 shift register
10. some pin headers
2. 24 resistors( The value is determent by the type of LEDs, in my case 91 ohm)
3. 4017 decade counter
4. 6 1KOhm resistors
5. 6 2N3904 transistors
6. A long Perfboard
7. Arduino
8. 3 x 74HC595 shift register
10. some pin headers
Step 2: How it works?
The tricky behind the display is multiplexing and the idea is the same as withe the 8x10 LED matrix: It is basically a way to split information in to little peaces and send it one by one.
this way you can save a lot of pins on the Arduino and keep your program quite simple.
Now this time we have 3 shift registers which multiply the number of outputs and save lots of arduino pins.
Each shift register has 8 outputs and you only need 3 arduino pins to control almost an limited numbers of shift registers.
We also use the 4017 decade counter to scan the rows, and you can scan up to 10 rows with it because you have only 10 outputs but to control it you need only 2 pins.
The 4017 is a very useful chip and it's a good idea to know how to work with it(http://www.doctronics.co.uk/4017.htm)
Like I said the scanning is done with the 4017, by connecting one row at a time to ground and sending the right data via the shift registers to the columns
this way you can save a lot of pins on the Arduino and keep your program quite simple.
Now this time we have 3 shift registers which multiply the number of outputs and save lots of arduino pins.
Each shift register has 8 outputs and you only need 3 arduino pins to control almost an limited numbers of shift registers.
We also use the 4017 decade counter to scan the rows, and you can scan up to 10 rows with it because you have only 10 outputs but to control it you need only 2 pins.
The 4017 is a very useful chip and it's a good idea to know how to work with it(http://www.doctronics.co.uk/4017.htm)
Like I said the scanning is done with the 4017, by connecting one row at a time to ground and sending the right data via the shift registers to the columns
Step 3: Schematics
The only thing I didn't specified in the schematics is the value of the current limiting resistors because they change from each type of LEDs, so you will need to calculate them by your self.
Now to calculate the value of the 24 resistors you can use this site :
http://led.linear1.org/1led.wiz
You should first get some specs on your LEDs, you should know their forward voltage and forward current, you can get this info from the seller. The circuit operates on 5V so your Source voltage is 5V.
Download the original file to see the schematics better.(press the "i" icon in the top left corner of the picture)
I have added a PCB layout of the control board, and i want to thanks Willard2.0 who made this layout and let me use it so thanks a lot mate!
Now to calculate the value of the 24 resistors you can use this site :
http://led.linear1.org/1led.wiz
You should first get some specs on your LEDs, you should know their forward voltage and forward current, you can get this info from the seller. The circuit operates on 5V so your Source voltage is 5V.
Download the original file to see the schematics better.(press the "i" icon in the top left corner of the picture)
I have added a PCB layout of the control board, and i want to thanks Willard2.0 who made this layout and let me use it so thanks a lot mate!
Step 4: Soldering The LEDs
Soldering 144 LEDs in a matrix formation can be a little tricky if you don't have a general idea how.
The last time I soldered a matrix I used lots of little wire jumpers which was a pain to solder, so this time I was a little more creative and came up with this way.
You need to bend the positive lead of the LED down towards the other ones and make a column, and snip off the leads you didn't use and try to make the connections as low as you can get, and you do this to all of the positive leads.
Now the negative leads are connected in a column and thats make soldering tricky because the positive rows are in the way, so you will need to make a 90 degrees bend with the negative lead and make a bridge over the positive row to the next negative lead, and so on to the next LEDs.
Now I will not explain how to solder the shift registers and all the parts because every one has hes own style and methods
The last time I soldered a matrix I used lots of little wire jumpers which was a pain to solder, so this time I was a little more creative and came up with this way.
You need to bend the positive lead of the LED down towards the other ones and make a column, and snip off the leads you didn't use and try to make the connections as low as you can get, and you do this to all of the positive leads.
Now the negative leads are connected in a column and thats make soldering tricky because the positive rows are in the way, so you will need to make a 90 degrees bend with the negative lead and make a bridge over the positive row to the next negative lead, and so on to the next LEDs.
Now I will not explain how to solder the shift registers and all the parts because every one has hes own style and methods
Step 5: Programming The Display
We are almost there, the only thing thats left is the program.
So far I wrote two programs for it that do pretty much the same thing.
I have added the program that gets a word or a sentence from the arduino IDE serial monitor and displays it on the matrix, my code is very basic and may be not the best in the world but it does the work, and you are free to write your own code and modify mine as you wish.
I have added an excel file so you can create your own symbols and characters.
The way it works is like so:
You create the symbol you want pixel by pixel(don't worry it's very easy) and copy the output line like so - #define {OUTPUT LINE}
I will add in the future a code for animations and a nice game of snake as soon as I have more time on my hands.
So far I wrote two programs for it that do pretty much the same thing.
I have added the program that gets a word or a sentence from the arduino IDE serial monitor and displays it on the matrix, my code is very basic and may be not the best in the world but it does the work, and you are free to write your own code and modify mine as you wish.
I have added an excel file so you can create your own symbols and characters.
The way it works is like so:
You create the symbol you want pixel by pixel(don't worry it's very easy) and copy the output line like so - #define {OUTPUT LINE}
I will add in the future a code for animations and a nice game of snake as soon as I have more time on my hands.
Step 6: We Are Done!
Congratulations you made yourself a 24x6 matrix and now you can display anything you like on the fly.
Now try to play with it and come up with a new program and a better interface
Now try to play with it and come up with a new program and a better interface
Saturday, June 28, 2014
This is a beginners project for the Arduino. I am using the Arduino Uno but should work with little or no modification on other arduino models.
Setting up the hardware is very easy. This project is more of a training tool for learning how to program a timer list while listening for a button press.
Parts you will need.
- Arduino
- Solder-less Breadboard
- 10 LEDs
--- 2 Red
--- 2 Yellow
--- 2 Green
--- 2 Small Red
--- 2 Small Green
- 2 1Kohm Resistors
- 2 Momentary Switches (normally open)
- Jumper Wires
Step 1: The Circuit
Step 2: Setup LEDs
Setup the lights on the breadboard like a traffic light. Red on top, then yellow, and then green. The small red and green are the pedestrian crossing signals. Again red on top and green just below.
In my images I am using the right side positive run of the breadboard as negative because its easier to put in the LED.
Put the cathode (-) into the negative run of the breadboard and the anode (+) into a hole next to it.
Step 3: Buttons
Put the buttons in so you have at least 2 pin holes space to add the wires and resistors. Place the 1kohm resistor between one side of the button and the negative run on the breadboard.
Step 4: Wire up LEDs
There are a lot of wire in this project so try to keep it neat so you know where everything is going.
Start by linking the two power rails of the breadboard and giving the breadboard power from the arduino.
An easy way to wire the lights is to just start from the top and work your way down.
Wire guide:
LED / Pin
Side A
Red = 4
Yellow = 3
Green = 2
Small Red = 7
Small Green = 6
Side B
Red = 10
Yellow = 9
Green = 8
Small Red = 13
Small Green = 12
Step 5: Wire up Buttons
A wire on the same side of the resistor will go to pins 5 (Side A) and 11 (Side B)
On the opposite side a wire will go to power (+3.5v)Step 6: Make the program
// Traffic Lights
// By Ben Hovinga http://ben.hovinga.me/
// Lights {GREEN, YELLOW, RED, PEDGREEN, PEDRED}
int light [2][5] = {{2,3,4,6,7},{8,9,10,12,13}};
// Buttons {light[0],light[1]}
int btn [] = {5,11};
// Timers
int tgreen = 30000; // 30s
int tyellow = 3000; // 3s
int tred = 3000; // 3s
int tpedwarn = 5000; // 5s (must be less than tgreen)
int tpedwarnint = 500; // 0.5s (must be less than tpedwarn)
// Other Vals. Don't Change
int btnval = 0;
boolean pedwait [] = {false,false};
boolean pedactive [] = {false,false};
int direct = 0;
int stp = 1;
boolean stpset = false;
unsigned long now = 0;
unsigned long changeat = -1;
unsigned long changeatped = -1;
boolean pedredon = true;
// SETUP
void setup() {
// Assign all Pins
for (int x = 0; x < 2; x++){
for (int y = 0; y < 5; y++){
pinMode(light[x][y], OUTPUT);
}
// Start everything stopped (red)
digitalWrite(light[x][2], HIGH);
digitalWrite(light[x][4], HIGH);
}
// Assign buttons
for (int x = 0; x < 2; x++){
pinMode(btn[x], INPUT);
}
}
// RUN
void loop() {
// Update Time
now = millis();
// Check if button pressed
for (int x = 0; x < 2; x ++){
btnval = digitalRead(btn[x]);
if (btnval == HIGH){
pedwait[x] = true; // We have someone waiting to cross
}
}
// Get into it
switch (stp){
// Green
case 1:
// Setup
if (stpset == false){
changeat = now + tgreen - tpedwarn; // Set timer
// Turn on Ped
if (pedwait[direct] == true){
// Lights change for ped
digitalWrite(light[direct][3], HIGH);
digitalWrite(light[direct][4], LOW);
// Set some vars
pedwait[direct] = false;
pedactive[direct] = true;
pedredon = false;
}
// Turn on Green
digitalWrite(light[direct][0], HIGH);
// Turn off Red
digitalWrite(light[direct][2], LOW);
stpset = true; // We are setup
}
// Run
else{
if (now > changeat){ // Times up
if (pedactive[direct] == true){
// Turn off Ped
digitalWrite(light[direct][3], LOW);
digitalWrite(light[direct][4], HIGH);
pedredon = true;
}
// Next step
stp++;
stpset = false;
}
}
break;
// Warn ped (if possible)
case 2:
// Setup
if (stpset == false){
changeat = now + tpedwarn;
changeatped = now + tpedwarnint;
stpset = true;
}
// Run
else{
// Flash Ped Red
if (pedactive[direct] == true){
if (pedredon == true && changeatped < now){
digitalWrite(light[direct][4], LOW);
pedredon = false;
changeatped = now + tpedwarnint;
}
if (pedredon == false && changeatped < now){
digitalWrite(light[direct][4], HIGH);
pedredon = true;
changeatped = now + tpedwarnint;
}
}
if (now > changeat){ // Times up
// Turn off
digitalWrite(light[direct][0], LOW);
digitalWrite(light[direct][4], HIGH);
pedredon = true;
pedactive[direct] = false;
// Next step
stp++;
stpset = false;
}
}
break;
// Yellow
case 3:
// Setup
if (stpset == false){
changeat = now + tyellow;
digitalWrite(light[direct][1], HIGH);
stpset = true;
}
// Run
else{
if (now > changeat){ // Times up
// Turn off
digitalWrite(light[direct][1], LOW);
// Next step
stp++;
stpset = false;
}
}
break;
// Red
case 4:
// Setup
if (stpset == false){
changeat = now + tred;
digitalWrite(light[direct][2], HIGH);
stpset = true;
}
// Run
else{
if (now > changeat){ // Times up
// Start over
stp = 1;
stpset = false;
// Change Direction
if (direct == 1){
direct = 0;
}
else {
direct = 1;
}
}
}
break;
}
}
// By Ben Hovinga http://ben.hovinga.me/
// Lights {GREEN, YELLOW, RED, PEDGREEN, PEDRED}
int light [2][5] = {{2,3,4,6,7},{8,9,10,12,13}};
// Buttons {light[0],light[1]}
int btn [] = {5,11};
// Timers
int tgreen = 30000; // 30s
int tyellow = 3000; // 3s
int tred = 3000; // 3s
int tpedwarn = 5000; // 5s (must be less than tgreen)
int tpedwarnint = 500; // 0.5s (must be less than tpedwarn)
// Other Vals. Don't Change
int btnval = 0;
boolean pedwait [] = {false,false};
boolean pedactive [] = {false,false};
int direct = 0;
int stp = 1;
boolean stpset = false;
unsigned long now = 0;
unsigned long changeat = -1;
unsigned long changeatped = -1;
boolean pedredon = true;
// SETUP
void setup() {
// Assign all Pins
for (int x = 0; x < 2; x++){
for (int y = 0; y < 5; y++){
pinMode(light[x][y], OUTPUT);
}
// Start everything stopped (red)
digitalWrite(light[x][2], HIGH);
digitalWrite(light[x][4], HIGH);
}
// Assign buttons
for (int x = 0; x < 2; x++){
pinMode(btn[x], INPUT);
}
}
// RUN
void loop() {
// Update Time
now = millis();
// Check if button pressed
for (int x = 0; x < 2; x ++){
btnval = digitalRead(btn[x]);
if (btnval == HIGH){
pedwait[x] = true; // We have someone waiting to cross
}
}
// Get into it
switch (stp){
// Green
case 1:
// Setup
if (stpset == false){
changeat = now + tgreen - tpedwarn; // Set timer
// Turn on Ped
if (pedwait[direct] == true){
// Lights change for ped
digitalWrite(light[direct][3], HIGH);
digitalWrite(light[direct][4], LOW);
// Set some vars
pedwait[direct] = false;
pedactive[direct] = true;
pedredon = false;
}
// Turn on Green
digitalWrite(light[direct][0], HIGH);
// Turn off Red
digitalWrite(light[direct][2], LOW);
stpset = true; // We are setup
}
// Run
else{
if (now > changeat){ // Times up
if (pedactive[direct] == true){
// Turn off Ped
digitalWrite(light[direct][3], LOW);
digitalWrite(light[direct][4], HIGH);
pedredon = true;
}
// Next step
stp++;
stpset = false;
}
}
break;
// Warn ped (if possible)
case 2:
// Setup
if (stpset == false){
changeat = now + tpedwarn;
changeatped = now + tpedwarnint;
stpset = true;
}
// Run
else{
// Flash Ped Red
if (pedactive[direct] == true){
if (pedredon == true && changeatped < now){
digitalWrite(light[direct][4], LOW);
pedredon = false;
changeatped = now + tpedwarnint;
}
if (pedredon == false && changeatped < now){
digitalWrite(light[direct][4], HIGH);
pedredon = true;
changeatped = now + tpedwarnint;
}
}
if (now > changeat){ // Times up
// Turn off
digitalWrite(light[direct][0], LOW);
digitalWrite(light[direct][4], HIGH);
pedredon = true;
pedactive[direct] = false;
// Next step
stp++;
stpset = false;
}
}
break;
// Yellow
case 3:
// Setup
if (stpset == false){
changeat = now + tyellow;
digitalWrite(light[direct][1], HIGH);
stpset = true;
}
// Run
else{
if (now > changeat){ // Times up
// Turn off
digitalWrite(light[direct][1], LOW);
// Next step
stp++;
stpset = false;
}
}
break;
// Red
case 4:
// Setup
if (stpset == false){
changeat = now + tred;
digitalWrite(light[direct][2], HIGH);
stpset = true;
}
// Run
else{
if (now > changeat){ // Times up
// Start over
stp = 1;
stpset = false;
// Change Direction
if (direct == 1){
direct = 0;
}
else {
direct = 1;
}
}
}
break;
}
}
Step 7: Upload and Run
Connect your arduino to your computer and upload the program. After it has uploaded you will see it cycle through the lights.
When you press a button it will wait for the next pass for that side to be green before turning the pedestrian light on. It will then give a warning flash before the light turns yellow
Leave a comment tell me about your success.
Subscribe to:
Posts (Atom)