From ArduinoInfo
Jump to: navigation, search

SHED: ARDUINO-101 Article 2

  • This is about 1400 words BUT there will be quite a few graphics. There is a lot of content for the readers but much of the software details are in the comments in the software examples. This allows us to cover a lot of ground, with the print material providing a strong organized view of the subjects without bogging in excessive detail. I think. Let Me Know if you think we can fit any more words; I condensed a lot of stuff that could be a little more illuminated. I will put a Word doc up after first-pass with just the text. Let me know..
  • There will be several [graphics] in this; I will do ROUGH drawings and insert them here soon.
  • We will need several small SIDEBARS with reference information. Need to collaborate SOON.
  • There will be detailed [Software Sketches] referenced in this article, that will be located temporarily on this WIKI, later on the SHED site. Please give me access / FTP to some space on your site. Need to discuss this. Under Construction. On your pages I would like to have a short section of text, in some cases, followed by the colored IDE version that can be cut and pasted by readers.
  • Typography is your bailiwick; I have tried to show my desired emphasis here.
  • Please make sure we show the YourduinoRobo1 with its YourDuino sticker or Photoshopped label. do NOT show "Duemilanove" or "Arduino" trademarks.


Last month you got familiar with Arduino and its free IDE software. Now it's time to dig in and understand how you can make more complex and useful things with Arduino. We will use many Software Sketch examples located on the SHED magazine site that you can view and cut/paste into the Arduino IDE on your computer.

We will look at every part of the SHED Starter Kit.

PINS-BITS, ONES and ZEROS, HIGH and LOW: You'll Know!
Here's how we will think about Arduino and how all these things work together:

[Sensor Inputs | Software Behavior | Action Outputs]
All automatic systems, from a simple thermostat to the Mars Rover have those 3 parts.

Sensor Inputs:

These can be simple like a pushbutton switch or complex like a GPS receiver. There are hundreds of possibilities for sensing things in the Real World.

Action Outputs:

These can be simple like an LED or complex like the motors and motion control of a Robot.

Software Behavior:

This is where you decide what Sensor Inputs Arduino will look at, what Decisions it will make, and what Action Outputs it will cause to happen.


Oh, um.. what's a BIT anyway? It is a </span> Binary InTeger</span> which is a </span> number</span> which has only two possible values: 0 and 1. Each Arduino Input or Output PIN is one BIT inside the Arduino chip. (A GROUP of 8 BITS is called a BYTE. Bet you knew that!).</span>

Arduino has 14 Digital Pins [0 to 13] that can be used as either Inputs or Outputs. In your software, in Setup you tell Arduino how they will be used.
See the photo on the right for the Digital Pins on the YourDuinoRobo1 in your kit.

  • Pins 0 to 13 and Gnd are at the top (right to left) These are female sockets.
  • There are 3-pin connectors for pins 3,5,6,9,10,11. Each has Ground, Voltage and Signal pins (bottom to top). This makes it easy to connect many devices. A small Servo can plug directly on a 3-pin connector. This convention of G-V-S (Ground, Voltage, Signal) connectors is widely used.

On the YourDuinoRobo1 the Black pins are Ground, the Red pins are +5 and the other pins are Signal.
yourduino-robo1-A-Pins-512.jpgThere are also 6 Analog Input Pins which can be used to measure voltages from 0.0 to 5.0 volts.

  • There are 6 female sockets across the bottom for A0 to A5
  • There are also six 3-pin connectors in the G-V-S pattern (Top to Bottom in this case).
  • These 'analog' pins may also be used as Digital Pins if needed. Also some special functions are on pins A4 and A5.

Now, let's get practical and look at the contents of the Shed Starter Kit. Take each component out and get a good look at it, especially its connections. We'll use the following chart to see how things work together. On the left are the Sensor Inputs. On the right are the Action Outputs.

[We will provide [/SHED-Article2-Software1 short Software Sketches] (LINK) on the SHED site which you can cut and paste to test with and learn about the different Kit components.]

Making Connections:

Let's look at Arduino in more electrical detail. The diagram below shows how we will connect things to Arduino and what it means if something is connected or switched to HIGH=5V or LOW=0.0V :

(Sidebar: Digital VS Analog)


Often an actual circuit (like the Arduino and Breadboard hookup) gets to be a confusing bunch of wires and components going in all directions. To keep our heads together, we draw </span> Circuit Diagrams</span>  (like the one above) to show what we're trying to do. Notice the </span> Symbols</span>  used in the diagram for things like: </span> SWITCH, RESISTOR, LED.</span>  And there are </span> Labels</span>  on connections, like </span> GND, INPUT, OUTPUT, ARDUINO</span>  etc. Note the parallel lines of </span> +5V HIGH</span>  on the diagram, and </span> GND - LOW</span>  on the diagram which are labelled "RAILS". These are much like Railroad RAILS across the top and bottom. Almost everything that happens on Arduino is between the +5V HIGH RAIL and the GND-LOW (0.0V) RAIL.</span>

Wires and Cables:

The SHED Starter Kit comes with a strip of wires with female ends, plus a strip of pins. You can use these to connect to the Breadboards or directly to Input and Output Devices. [Graphic??]

Digital Input Examples:

The Arduino Digital pins are either ON or OFF. Terminology: ON=1=HIGH=+5v and OFF=0=LOW=0.0v=Ground
  • Pushbutton Switches: We will connect these to a Digital Input and use them with a "Pulldown Resistor" (shown above) that will keep the input pulled LOW=0=OFF until you push the button and the switch pulls the input HIGH=1=ON. (Sidebar: Resistors) (Software: It'sON-OFF) (Sidebar: The "Serial Monitor")
  • PhotoResistors: These change their resistance to be low when light hits them. We will connect them just like the pushbutton and when enough light hits them they will pull the input HIGH. (Breadboard Photo) (Software: ItsON-OFF)

Analog Input Examples:

With Digital Inputs, whatever won the "pullup-pulldown wars" decided if it was 1 or 0. With Analog Inputs, Arduino can see all the VALUES in between HIGH and LOW and make decisions based on those values. An Analog input can sense the Value of things like light levels, battery voltage, or potentiometer position.
  • Potentiometer: Look Closely Now at the Potentiometer in the Kit. (Photo/drawing) It has 3 terminals that are connected to: (+5V HIGH) (Gnd LOW) and "Wiper" that you move to any voltage in between +5V and Gnd=0. Connect a Pot (Potentiometer) and run (Software: AnalogLevel) The "Pot" acts as a Voltage Divider . Turn it clockwise towards the Top=HIGH=5V or Bottom=LOW=0v and see the values change on Serial Monitor.
  • PhotoResistor: Now we'll use this same component and pulldown resistor, as in the diagram above, but connect it to an Analog Input so we can see all the values as the light level changes. (See Software: 2AnalogInputs)

Voltage Dividers:

Now let's figure out this Voltage Divider stuff. Look at the diagram on the right. A Voltage Divider has 2 resistors connected in Series, connected to a source of (V)oltage and a (G)round or common point. The connection in the middle between the two resistors is the (S)ignal Output, and is some fraction of the Input Voltage. So we can connect a pot used as a Voltage Divider to one of our 3-wire cables that have (-)(+)(S) connections as marked on the YourDuino . As we move the pot, the output voltage going to Yourduino varies from 0 to 5 Volts and all the values in between. The way Arduino works gives values from 0 to 1023. If we have a photoresistor connected in series with a resistor, we have a voltage divider that changes with the light intensity, giving us a varying voltage.
Measuring other voltages: What if you want to measure voltages that are more than 5 volts? You use a Voltage Divider to reduce the voltage. If you make a 3 to 1 ratio voltage divider (say, 20K for the top section and 10K for the bottom), then you can read voltages from 0 to 15 volts. Good for automotive batteries.

Making Decisions:

Now we have Values so we can make comparisons like < (less than) or > (greater that) etc. and make decisions. Let's make an Adjustable Light Level Sensor which controls when a light comes on as it gets dark. It would this work like this:
    • Read Potentiometer value
    • Read Photoresistor value
    • Is Photoresistor value < (less than) Potentiometer value? (Darker)
    • Turn Lights on

(See software: LightingControl) Read the comments in the software to understand the details of how this works. If you use some wire to extend the Photosensor to see outdoor light and connect the Relay Board to the same pin as the LED and have it control the light, you have a practical working system.

Digital Output Examples:

Digital Outputs are only ON or OFF. We have shown examples of LEDs and the Buzzer, but sometimes you want to turn on or off higher-power devices like room lights, heaters, pumps, motors etc. The Kit includes a 2-channel RELAY board. A relay is a switch that is thrown by an electromagnet, and the switch can handle quite a bit of power. Let's look at some details:
On the left you see the end of the board with pins to connect to Arduino. We'll show it connected later. On the right you see the relay output connections that you'd use to switch something like 12V or 240V lights, small motors etc. The relay is rated at 10 amps up to 250 VAC or 30 VDC.

How Relay Contacts Work:</span>

Look at the photo of the relay above. Notice the two sets of 3 screw-type terminals. They are arranged this way:</span>



  • NO: Normally Open</span>
  • COM: Common Connection</span>
  • NC: Normally Closed</span>
Look at the diagram on the right. This shows the switch that is inside the relay. This switch is "thrown" by the electromagnet inside. The diagram shows that COM is connected to the Normally Closed contact. That's the case when the relay is </span> off.</span>  When the relay is turned </span> on</span>  the electromagnet flips the switch up and COM is then connected to Normally Open. So, if we want a lamp to be on when the relay is on, we connect our circuit from COM to NO.</span>

Analog Output Examples:

In Article 1 you blinked an LED so fast it seemed constant. And by changing the % of time it was on, you could dim it. Arduino has a built-in capability (PWM=PulseWidthModulation) on the 6 pins that the Yourduino brings out to 3-pin connectors. Try it: (See Software: LED_Dimmer) Read the detailed comments in the software to understand how this works and what you can use it for.
How would this work? Like this:
  • READ SENSORS (Read Potentiometer value)
  • MAKE DECISIONS (Adjust 0 to 1023 Pot value to 0 to 255 PWM dimmer value)
  • TAKE ACTIONS (Change the dimmer value)

You can also connect the RGB three-color LED and run this to make different colors. You need to connect the RBG LED's 3 sections with 3 200 ohm current-limiting resistors like this: [GRAPHIC]
Load and try the (Software: RGB_Dimmer). This looks best when the light hits a diffused object like a white ping-pong ball or small plastic bottle from inside.

Beeper: This component doesn't make sound by itself like the Buzzer. You use the Tone command to decide what sounds it will make. Connect your Beeper to Yourduino pin 10 and GND. Try it with: (Software: BeeperSounds) Read the comments in the software and try some changes.

(SideBar: Using the always-available Arduino reference information)


Many complex and useful devices do much more than turn ON or OFF or DIM. They communicate with Arduino by sending or receiving a series of 1's and 0's that convey information according to some protocol. The software to do this is more complex and we will usually use "libraries" of software that the Arduino team or other people have written for us. When we figure out how to do something cool, we may put our code in a Library and share it with others. (Sidebar: Libraries ) 
  • Servomotor: (Signal Output) Standard servos like the one in the SHED Starter Kit are controlled by pulses sent to them. You can connect your servo directly to a 3-pin connector on the YourDuino [PIN??] Use the (software examples that come with your regular Arduino software): Mouse over File>Examples>Servo and pick Sweep. Connect your servo to Pin 9 on the YourDuino 3-pin connector. Then try Knob with your Pot connected to Analog Pin 0 (First Analog pin) for an example where the servo follows your pot position.
  • Temperature Sensor: (Signal Input) The DS18B20 temperature sensor in the Kit is an example of the low-cost but complex and accurate sensors that are available. To connect this sensor, see the photo and the details in the software comments. You also need to find, download and install two libraries that do not come with Arduino itself. You will want to learn how to do this to take advantage of the dozens of very useful libraries of software that other Arduino users have shared online. See the sidebar "Libraries". (Software: [Modified version of: ] [Graphic: Breadboard connection for Temperature Sensor]


You now have the building blocks and concepts to make many different devices with an Arduino. Could you make these??
  • Temperature control of a chicken coop with both heat lamps and ventilation fan. [Temperature sensor and 2-channel relay]
  • A flickering camp fire made with red and yellow LEDs
  • A 6 inch diameter "Dial Thermometer" with a moving pointer showing your living room temperature. [Temperature sensor, Servo]
  •  ?? What are your ideas ??


We will be looking at what you need to do more complex projects. You will use more software libraries, get and use other sensors and actuators, and start communicating from Arduino to the Web. You might even send yourself an SMS. We'll also cover power: power for Arduino from regular outlets, power from batteries, power for devices that need more than the USB connection can provide, and controlling high power devices from Arduino. We'd also like to hear your suggestions. Happy Building!