background image

Not Quite Working

 Sorry to sound like a broken 

record but it is probably 

something as simple as  a 

crossed wire.

17

CIRC-05

Code 

(no need to type everything in just)

Not Working? 

(3 things to try)

More, More, More:

More details, where to buy more parts, where to ask more questions.

http://tinyurl.com/dkjno3

Making it Better

The Arduino’s Power 

LED goes out

 

 This happened to us a couple 

of times, it happens when the 

chip is inserted backwards. If 

you fix it quickly nothing will 

break.

milliseconds to delay 

Doing it the hard way:

                       //between LED updates

An Arduino makes rather complex actions very easy, shifting out data 

  for(int i = 0; i < 8; i++){

is one of these cases. However one of the nice features of an 

    changeLED(i,ON);
    delay(delayTime);

Arduino is you can make things as easy or difficult as you like. Lets 

  }
  for(int i = 0; i < 8; i++){

try an example of this. In your loop switch the line.

    changeLED(i,OFF);

updateLEDs(i) -> updateLEDsLong(i);

    delay(delayTime);

Upload the program and notice nothing has changed. If you look at 

  }

the code you can see how we are communicating with the chip one 

bit at a time. (for more details http://tinyurl.com/3augzd )

And upload this will cause the lights to light up one after another and then 

off in a similar manner. Check the code and wikipedia to see how it works, 

Controlling Individual LEDs:

or shoot us an e-mail if you have questions.

Time to start controlling the LEDs in a similar method as we did in 

CIRC02. As the eight LED states are stored in one byte (an 8 bit 

More Animations:

value) for details on how this works try http://tinyurl.com/6vz53. An 

Now things get more interesting. If you look back to the code from CIRC02 

Arduino is very good at manipulating bits and there are an entire set 

(8 LED Fun) you see we change the LEDs using digitalWrite(led, state), this 

of operators that help us out. Details on bitwise maths ( 

is the same format as the routine we wrote changeLED(led, state). You can 

http://tinyurl.com/br8dd )

use the animations you wrote for CIRC02 by copying the code into this 

sketch and changing all the digitalWrite()'s to changeLED()'s. Powerful? 

Our implementation.

Very. (you'll also need to change a few other things but follow the compile 

Replace the 

loop()

 code with

  

 int delayTime = 100; //the number of 

errors and it works itself out)

Frustration?

Shoot us an e-mail, this circuit 

is both simple and complex at 

the same time. We want to 

hear about problems you have 

so we can address them in 

future editions.

 [email protected]

Download the Code from ( http://tinyurl.com/cv4fjt )

(copy the text and paste it into an empty Arduino Sketch)

//Pin Definitions

 

//The 74HC595 uses a protocol called SPI 
//Which has three pins
int data = 2; 

 digitalWrite(latch, LOW);

int clock = 3;

     

int latch = 4;

//Pulls the chips latch low
  shiftOut(data, clock, MSBFIRST, value);   

void setup()  //runs once

     //Shifts out 8 bits to the shift register 

{

 

 

 

 

 

  pinMode(data, OUTPUT);

  

  pinMode(clock, OUTPUT);    

digitalWrite(latch, HIGH);   

  pinMode(latch, OUTPUT);  }

     //Pulls the latch high displaying the data
}

void loop()   // run over and over again
{

  ---------- More Code Online ----------

  int delayTime = 100; 
     //delay between LED updates
  for(int i = 0; i < 256; i++){
   updateLEDs(i);
   delay(delayTime);   }
}

/*
 * updateLEDs() - sends the LED states set
 * in value to the 74HC595 sequence
 */
void updateLEDs(int value){

16

CIRC-05

What We’re Doing:

.:8 More LEDs:.

.:74HC595 Shift Register:.

Time to start playing with chips. Or integrated circuits (ICs) as they like to be 

called. The external packaging of a chip can be very deceptive for example the 

chip on the Arduino board (a micro controller) and the one we will use in this 

circuit (a shift register) look very similar but are in fact rather different, for 

example the price of the Atmega chip on the arduino board is a few dollars while the 

74hc595 is a couple dozen cents. It's a good introductory chip, and once your comfortable playing around with it and its 

datasheet (available online http://tinyurl.com/pr42xe ) the world of chips will be your oyster. The shift register (also called 

a serial to parallel converter), will give you an additional 8 outputs (to control LEDs and the like) using only three arduino 

pins. They can also be linked together to give you a nearly unlimited number of outputs using the same four pins. To use 

it you “clock in” the data and then latch lock it in (latch it). To do this you set the data pin to either HIGH or LOW, pulse 

the clock, then set the data pin again and pulse the clock repeating until you have shifted out 8 bits of data. Then you 

pulse the latch and the 8 bits are transferred to the shift registers pins. It sounds complicated but is really simple once 

you get the hang of it. 

(for a more in depth look at how a shift register works visit: http://tinyurl.com/56uvv7 )

The Circuit:

Wire

 

Shift Register
74HC595
x1

560 Ohm Resistor
Green-Blue-Brown
x8

2 Pin Header
x4

CIRC-05 
Breadboard sheet
x1

Parts:

Red LED
x8

Schematic:

L

E

D

re

si

st

o

(5

6

0

o

h

m

)

g

n

d

(g

ro

u

n

d

(-

)

pin 

4

pin 

3

pin

2

0
1
2
3
4
5
6
7

data
clock
latch

+5V

gnd

74HC595

+5 volts

There is a half moon 
cutout, this goes at the top

.:download:.

breadboard layout sheet

http://tinyurl.com/d8xepz.

.:view:.

assembling video

http://tinyurl.com/c2enkv

The Internet

Summary of Contents for ARDX

Page 1: ...Arduino Experimenter s Guide ARDX ARDX arduino experimentation kit ...

Page 2: ...der a Creative Commons By Share Alike license This means you must credit oomlout in your design and share your developments in a similar manner Why We grew up learning and playing with open source software and the experience was good fun we think it would be lovely if a similar experience was possible with physical things more details on the Creative Commons CC By Share Alike License can be found ...

Page 3: ...ircuits CIRC01 Getting Started Blinking LED 08 CIRC02 8 LED Fun Multiple LEDs 10 CIRC03 Spin Motor Spin Transistor and Motor 12 CIRC04 A Single Servo Servos 14 CIRC05 8 More LEDs 74HC595 Shift Register 16 CIRC06 Music Piezo Elements 18 CIRC07 Button Pressing Pushbuttons 20 CIRC08 Twisting Potentiometers 22 CIRC09 Light Photo Resistors 24 CIRC10 Temperature TMP36 Temperature Sensor 26 CIRC11 Larger...

Page 4: ...M assembling the pieces Breadboard x1 Arduino x1 3mm x 10mm bolt x2 3mm nut x4 Arduino Holder x1 c A usin c c p Putting It Together Thi It For an introduction to what an Arduino is visit http tinyurl com 9txjmh ...

Page 5: ...e plug your Arduino board into a free USB port Wait for a box to pop up Step 5 Add new Hardware Skip searching the internet click the next box when prompted to do so Install from a Specific destination click Install from a list or specific location Advanced Choose the Location c program files arduino 00rr drivers FTDI USB Drivers Finished Step 2 Open The dmg Open mount arduino 00 mac dmg rr rr ver...

Page 6: ...etup has finished After it has run once it will be run again and again until power is removed Syntax semicolon Each line of code must be ended with a semicolon a missing semicolon is often the reason for a programme refusing to compile One of the slightly frustrating elements of C is its formating requirements this also makes it very powerful If you remember the following you should be alright mul...

Page 7: ...Used when you would like to repeat a chunk of code a number of times can count up i or down i or use any variable Digital digitalWrite pin value Once a pin is set as an OUTPUT it can be set either HIGH pulled to 5 volts or LOW pulled to ground pinMode pin mode Used to set a pins mode pin is the pin number you would like to address 0 19 analog 0 5 are 14 19 the mode can either be INPUT or OUTPUT in...

Page 8: ...gh it only in one direction Things to watch out for Identifying Will only work in one direction Looks like a mini light bulb Requires a current limiting resistor More Details on Wikipedia http tinyurl com zhpyv P P I P C P Exam gree red R Resistors What it Does No of Leads Restricts the amount of current that can flow 2 through a circuit Things to watch out for Identifying Easy to grab the wrong v...

Page 9: ... read Photo Resistor What it Does No of Leads Produces a variable resistance dependant on 2 the amount of incident light Things to watch out for Identifying Remember it needs to be in a voltage Usually a little disk with a clear top and a divider before it provides a useful input curvy line underneath More Details http tinyurl com c2wdkw Component Details cont Pushbutton What it Does No of Leads C...

Page 10: ...his plug the Arduino board into your USB port Then select the proper port in Tools Serial Port the comm port of your Arduino Next upload the program by going to File Upload to I O Board ctrl U Finally bask in the glory and possibility that controlling lights offers If you are having trouble uploading a full trouble shooting guide can be found here http tinyurl com 89s2po The Circuit Wire 10mm LED ...

Page 11: ...is connected to pin 13 but we can use any of Along with digital on off control the Arduino can control the Arduino s pins To change it take the wire plugged some pins in an analog brightness fashion more details on into pin 13 and move it to a pin of your choice from 0 this in later circuits To play around with it 13 you can also use analog 0 5 analog 0 is 14 Change the LED to pin 9 also change th...

Page 12: ...rduino works Along with controlling the LEDs we start looking into a few simple programming methods to keep your programs small for loops used when you want to run a piece of code several times arrays used to make managing variables easier its a group of variables The Circuit 5mm Green LED x8 560 Ohm Resistor Green Blue Brown x8 2 Pin Header x4 CIRC 02 Breadboard sheet x1 Parts download breadboard...

Page 13: ...herNoLoop Will light one then delay for delayTime then light the next LED it Not Working 3 things to try More More More More details where to buy more parts where to ask more questions http tinyurl com d2hrud Making it Better Some LEDs Fail to Light It is easy to insert an LED backwards Check the LEDs that aren t working and ensure they the right way around Switching to Loops in the loop function ...

Page 14: ...2222AG a rather common general purpose transistor The important factors in our case are that its maximum voltage 40 v and its maximum current 600 milliamp are both high enough for our toy motor full details can be found on its datasheet http tinyurl com o2cm93 note the transistor we use has a in order Base Collector Emitter pinout differing from some other popular transistors The 1N4001 diode is a...

Page 15: ... 50 because our eyes are not quick enough to would like to change the speed of acceleration change the see it flashing on and off The same feature works with variable delayTime larger means a longer acceleration time transistors Don t believe me Try it out Still Not Working Sometimes the Arduino board will disconnect from the computer Try un plugging and then re plugging it into your USB port int ...

Page 16: ...tioning is controlled through a timed pulse between 1 25 milliseconds 0 degrees and 1 75 milliseconds 180 degrees 1 5 milliseconds for 90 degrees Timing varies between manufacturer If the pulse is sent every 25 50 milliseconds the servo will run smoothly One of the great features of the Arduino is it has a software library that allows you to control two servos connected to pin 9 or 10 using a sing...

Page 17: ...rduino s included our favorites library sometimes it is fun to figure out how to program something yourself Try it We re controlling the pulse directly Xmas Hit Counter so you could use this method to control servos on any of the http tinyurl com 37djhq Arduino s 20 available pins you need to highly optimize this code before doing that Open Source Robotic Arm uses a servo controller as well as the...

Page 18: ...Ds and the like using only three arduino pins They can also be linked together to give you a nearly unlimited number of outputs using the same four pins To use it you clock in the data and then latch lock it in latch it To do this you set the data pin to either HIGH or LOW pulse the clock then set the data pin again and pulse the clock repeating until you have shifted out 8 bits of data Then you p...

Page 19: ...r details on how this works try http tinyurl com 6vz53 An Now things get more interesting If you look back to the code from CIRC02 Arduino is very good at manipulating bits and there are an entire set 8 LED Fun you see we change the LEDs using digitalWrite led state this of operators that help us out Details on bitwise maths is the same format as the routine we wrote changeLED led state You can ht...

Page 20: ...element makes a clicking sound each time it is pulsed with current If we pulse it at the right frequency for example 440 times a second to make the note middle A these clicks will run together to produce notes Lets get to experimenting with it and get your Arduino playing Twinkle Twinkle Little Star C N M M P T a t c C o T I t c t a u i M T a g T m w n c d e f g a b C h int int char int int void f...

Page 21: ...eir values in the tones array up or down 1 1 2 4 Happy Birthday first line until they sound right each note is matched by its name int length 13 char notes ccdcfeccdcgf in the names array ie c 1915 int beats 1 1 1 1 1 2 1 1 1 1 1 2 4 Tired of Twinkle Twinkle Little Star The code is written so you can easily add your own songs check out the code below to get started Melody cleft 2005 D Cuartielles ...

Page 22: ... LOW The button is set up to pull the Arduino s pin LOW when it is pressed however when the button is unpressed the voltage of the pin will float causing occasional errors To get the Arduino to reliably read the pin as HIGH when the button is unpressed we add the pull up resistor note the first example program uses only one of the two buttons The Circuit Wire Pushbutton x2 560 Ohm Resistor Green B...

Page 23: ...sy to put it in the wrong way Give it a 90 degree twist and see if it starts working On button off button Fading up and down The initial example may be a little underwhelming ie I Lets use the buttons to control an analog signal To do this you don t really need an Arduino to do this lets make it a will need to change the wire connecting the LED from pin 13 to little more complicated One button wil...

Page 24: ...hen it is connected with 5 volts across its outer pins the middle pin will read some value between 0 and 5 volts dependent on the angle to which it is turned ie 2 5 volts in the middle We can then use the returned values as a variable in our program The Circuit Wire Potentiometer 10k ohm x1 560 Ohm Resistor Green Blue Brown x1 2 Pin Header x4 CIRC 08 Breadboard sheet x1 Parts Green LED x1 Schemati...

Page 25: ...nge the loop code to Sometimes you will want to switch an output when a void loop int value analogRead potPin 4 value exceeds a certain threshold To do this with a analogWrite ledPin value potentiometer change the loop code to Upload the code and watch as your LED fades in relation to void loop int threshold 512 your potentiometer spinning Note the reason we divide the if analogRead potPin thresho...

Page 26: ...tp tinyurl com 2sunta The exact voltage at the sensing pin is calculable but for our purposes just sensing relative light we can experiment with the values and see what works for us A low value will occur when the sensor is well lit while a high value will occur when it is in darkness The Circuit Wire Photo Resistor x1 560 Ohm Resistor Green Blue Brown x1 2 Pin Header x4 CIRC 09 Breadboard sheet x...

Page 27: ...ied Using the full range of your servo response to light lets instead turn it on or off based on a You ll notice that the servo will only operate over a limited threshold value Change the loop code with void loop portion of its range This is because with the voltage dividing int threshold 300 circuit we use the voltage on analog pin 0 will not range from if analogRead lightPin threshold digitalWri...

Page 28: ...we will use some of the Arduino s maths abilities Then to display it we ll use one of the IDE s rather powerful features the debug window We ll output the value over a serial connection to display on the screen Let s get to it One extra note this circuit uses the Arduino IDE s serial monitor To open this first upload the program then click the button which looks like a square with an antennae The ...

Page 29: ... before Serial println temperature Upload the sketch turn on the serial monitor then change the More informative output speed from 9600 baud to 115200 baud in the pull down menu Lets add a message to the serial output to make what is You are now transmitting data 12 times faster appearing in the Serial Monitor more informative To do Temperature Value is Unchanging Try pinching the sensor with your...

Page 30: ...point is fun sometimes you just want to wire up a hundred switches to control something magnificent Relays give you the ability to dream it up then control it with your Arduino Now to using todays technology to control the past The 1N4001 diode is acting as a flyback diode for details on why its there visit http tinyurl com b559mx The Circuit 2 Pin Header x4 CIRC 11 Breadboard sheet x1 Schematic 2...

Page 31: ...Working The included relays are designed to be soldered rather than used in a breadboard As such you may need to press it in to ensure it works and it may pop out occasionally Controlling a Motor In CIRC 03 we controlled a motor using a transistor However if you want to control a larger motor a relay is a good option To do this simply remove the red LED and connect the motor in its place remember ...

Page 32: ... the Creative Commons Attribution Share Alike 3 0 Unported License To view a copy of this licence visit http creativecommons org licenses by sa 3 0 or send a letter to Creative Commons 171 Second Street Suite 300 San Francisco California 94105 USA www oomlout com ...

Reviews: