Introduction to Arduino

Arduino Sketches used in the course (mostly same as examples on Arduino IDE, small modification)


What we cover:

LED (Light Emitting Diode)
LED has direction. Be careful!
you can check the direction by looking at:
– the length of the legs. The longer one is + (Anode)
– the size of the Leadframe in the plastic casing. The smaller leadframe is + (Anode)

Add second LED
Blink them in alternative sequence
1st LED on >> off >> on >> off
1nd LED off >> on >> off >> on

Push Button

inside of a push button

How to use a breadboard

How to connect push button
pull up resistor (10k ohm or bigger)


introduced functions:

Let’s open an example code State Change Detection from File/Examples/Digital/StateChangeDetection
With this Sketch, the button behavior is mapped differently to the behavior of the LED than the first example.

Analog Read
“A potentiometer, informally a pot, is a three-terminal resistor with a sliding contact that forms an adjustable voltage divider. If only two terminals are used, one end and the wiper, it acts as a variable resistor or rheostat.”
from wikipedia

inside of a potentiometer

Let’s connect the potentiometer to multimeter, and read out the resistance change as you turn the knob. Connect multimeter’s proves to the first pin and the middle pin of the potentiometer.

We work on this example: Analog Read Serial

introduced functions:

Serial Monitor

Analog Input Pins:
it will map input voltages between 0 and 5 volts into integer values between 0 and 1023

Analog Write
We open AnalogInOutSeiral

What does it do?
Reads an analog input pin, maps the result to a range from 0 to 255 and uses the result to set the pulsewidth modulation (PWM) of an output pin.

The microcontroller’s pins can only output 0V or 5V, and not 1.2V or 2.4V. So, to output voltage between 0V-5V smoothly, in another word to do “fading” affect, it mimics the 1.2V and 2.4V by pulsing 5V and 0V quickly and change the width of the pulsation. This called PWM.

You can read the explanation at Arduino site: Pulse Width Modulation (PWM)

Connection example:

introduced functions:

“A photoresistor or light-dependent resistor (LDR) or photocell is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity.”
from wikipedia

Measure the photocell’s resistance change with Multimeter.
What do you measure?

How to connect analog sensors
voltage divider

How to connect resistive analog sensors

or if this was connected on the breadboard, it will be something like this

More sensors

Soft pot Round (resistive)

Soft Pot straight (resistive)

Flex (bend) sensor (resistive)

Proximity Sensor (this works a bit differently, check the tutorial)

Tilt Switch (This is a digital sensor, like push button)

servo motor

“A servomotor is a rotary actuator that allows for precise control of angular position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors.”
(from wikipedia>

“As the name suggests, a servomotor is a servomechanism. More specifically, it is a closed-loop servomechanism that uses position feedback to control its motion and final position. The input to its control is some signal, either analogue or digital, representing the position commanded for the output shaft.”
(also from wikipedia)

RC (hobby) Servo motors often comes with 3 colored cables; Black (GND) RED (5V) and Yellow/orange (data). This types of servomotors includes the servomechanism controller inside, which you can send the angle controlling signal from the data line.

Arduino has implemented a library to control the servomotor, called servo library. You can read more about it here

Open the Knob sketch from Examples/Servo/knob
This sketch will allow you to control potentiometer connected to A0 pin to control a servo motor connected to Pin9.

Here is how you connect:

introduced function:


Now, we can connect small speaker and use TONE library to make music!
Well, it does not make a great sound, but it is a good start.

Open tonePitchFollower from Examples/Digital/tonePitchFollower

This sketch will “play a pitch that changes based on a changing analog input”
Let’s first play sound with potentiometer

Here is how you to connect:

introduced function:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">