Difference between revisions of "Arduino basics workshop"

From Interaction Station Wiki
Jump to: navigation, search
(Intro)
 
(39 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  
== Arduino Basics Workshop ==
+
=Intro=
 +
 
 +
[[File:Smelling-color-lg.jpg | 700 px]] <br>
 +
 
 +
[https://trendcurve.com/trend/color-you-can-smell/ Smelling color]
 +
<br>
 +
[https://www.designboom.com/technology/knock-knock-interactive-wooden-calculator-by-khalil-klouche/ Knock Calculator] <br>
 +
 
 +
[[File:Thumb01.PNG]]
 +
<br>
 +
 
 +
[https://www.youtube.com/watch?v=i1TkiN309_4 Video of the thumb]<br>
 +
 
 +
[https://www.daniclodedesign.com/thethirdthumb The Third Thumb]<br>
 +
 
 +
[http://automato.farm/portfolio/politics_of_power/ Politics of Power ]<br>
 +
 
 +
[[File:TactileControls.jpg | 700 px]]<br>
 +
 
 +
[https://www.creativeapplications.net/member-submissions/expressive-tactile-controls/ Expressive Tactile Controls]<br>
 +
 
 +
[[File:Separate-Togetherness.jpg]]<br>
 +
 
 +
[https://www.dezeen.com/2015/01/29/penny-webb-homeware-mirror-lamp-curtain-colour-change-touch-breath-movement-dutch-design-week-2014/ Separate Togetherness]
 +
 
 +
=Arduino Uno=
 +
 
 +
[[File:Aqrduino_ide.PNG | 900 px]]
 +
==Overview==
 +
Hello everyone hello hello hello,
 +
 
 +
now what is an Arduino ...well...find a detailed introduction here [[http://interactionstation.wdka.hro.nl/wiki/Arduino_Introduction]] <br>
 +
Computer and processor are generic terms for the anything that can run a program, basically.
 +
<br>Controller or microcontroller usually refers to a simple processor that does only one task, like listening to sensors. In explaining microcontrollers, we’ll distinguish them from computers, which contain more powerful processors that can run an operating system.
 +
<br>
 +
Arduino is an open source physical computing platform based on a simple input/output (I/O) board and a development environment that implements the Processing language. Arduino can be used to develop standalone interactive objects
 +
or can be connected to software on your computer.<br>
 +
The Arduino contains a microcontroller.<br>
 +
Most electronic devices today have a microcontroller at their core. Microcontrollers are optimized for control of general input and output. 
 +
What Is Physical Computing?
 +
Physical Computing uses electronics to prototype new materials for ( in our case ) designers and artists.
 +
<br>
 +
Arduino is composed of two major parts: the Arduino board, which is the piece of hardware you work on when you build your objects; and the Arduino IDE, the piece of software you run on your computer. You use the IDE to create
 +
a sketch (a little computer program) that you upload to the Arduino board. The sketch tells the board what to do.
 +
 
 +
In the meantime, [https://www.arduino.cc/ HERE] you can find ANYTHING about Arduino, including download the software
 +
 
 +
'''NOW''',
 +
<br>
 +
The pins on your Arduino are the places where you connect wires to construct a circuit (probably in conjunction with a breadboard and some wire. They usually have black plastic ‘headers’ that allow you to just plug a wire right into the board. The Arduino has several different kinds of pins, each of which is labeled on the board and used for different functions.
 +
<br>
 +
[[File:Board_layout.PNG | 900 px]]
 +
 
 +
<br>
 +
 
 +
 
 +
 
 +
== First things first, Blink it==
 +
 
 +
 
 +
we start by figuring put if our Arduino is all good or it is somehow damaged ...it is a basic test to check and run a simple script at the same time.
 +
 
 +
=== Go to File ---> Examples ---> Basics --->Blink ===
 +
so we have something like this
 +
 
 +
<syntaxhighlight lang=c style="border:3px dashed blue">
 +
/*
 +
  Blink
 +
  Turns on an LED on for one second, then off for one second, repeatedly.
 +
 
 +
  Most Arduinos have an on-board LED you can control. On the Uno and
 +
  Leonardo, it is attached to digital pin 13. If you're unsure what
 +
  pin the on-board LED is connected to on your Arduino model, check
 +
  the documentation at http://www.arduino.cc
 +
 
 +
  This example code is in the public domain.
 +
 
 +
  modified 8 May 2014
 +
  by Scott Fitzgerald
 +
*/
 +
 
 +
 
 +
// the setup function runs once when you press reset or power the board
 +
void setup() {
 +
  // initialize digital pin 13 as an output.
 +
  pinMode(13, OUTPUT);
 +
}
 +
 
 +
// the loop function runs over and over again forever
 +
void loop() {
 +
  digitalWrite(13, HIGH);  // turn the LED on (HIGH is the voltage level)
 +
  delay(1000);              // wait for a second
 +
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
 +
  delay(1000);              // wait for a second
 +
}
 +
</syntaxhighlight>
 +
 
 +
GOOOD! lets dissect this
 +
 
 +
* commenting / one line and multiple lines
 +
*setup
 +
*loop
 +
===Choose board===
 +
 
 +
[[File:Board.png | 900 px]]
 +
 
 +
===Choose port===
 +
 
 +
[[File:Port.png  | 900 px]]
 +
 
 +
 
 +
 
 +
===''Lets compile this'' ===
 +
--- Press/ Click upper most left button, looks like a '''Tick'''. Observe the messages appearing in the bottom of the Arduino software window ( there must be a sentence '''Done Compiling ''' <br>
 +
[[File:Compile.png ]]
 +
 
 +
 
 +
===''Lets upload this'' ===
 +
 
 +
[[File:Upload.png ]] <br>
 +
 
 +
And we should have a Blinking aka Flashing on board LED
 +
 
 +
 
 +
[[File:Arduino-LED-Overview.jpg | 900 px]]
 +
 
 +
==Let's add a trough hole led==
 +
[[File:LED pinout.jpg | 400 px]]
 +
 
 +
[[File:Schematic_wiriting.PNG  | 900 px]]
 +
 
 +
===OK, wait...the BREADBOARD===
 +
 
 +
OK, first, what's with the name....bread board? Bread, like in food?
 +
Well yes, kind of.
 +
<br>
 +
[[File:Breadboard.jpg ]]
 +
 
 +
This terminology goes way back in the days.
 +
Generally, you would mount electronic components to a piece of wood (the actual "breadboard"), and do all the wiring with point-point wire and the components just hanging between the various devices.
 +
<br><br>
 +
[[File:Breadboardreal.jpg | 00 px]]
 +
<br><br>
 +
The story goes that an engineer had an idea for a vacuum tube device late one night. Looking around the house, the only base for his prototype that he found was indeed his wife's breadboard, from the breadbox.
 +
<br><br>
 +
[http://www.youtube.com/watch?feature=player_embedded&v=HrG98HJ3Z6w A video by the Make magazine people ]
 +
<br>
 +
<br>
 +
 
 +
Ok, but why do we need to breadboard?
 +
<br>
 +
Well, they are useful for making temporary circuits and prototyping, and they require absolutely no soldering.
 +
<br>
 +
Prototyping is the process of testing out an idea by creating a preliminary model from which other forms are developed or copied, and it is one of the most common uses for breadboards.
 +
<br>
 +
The best way to explain how a breadboard works is to take it apart and see what’s inside.
 +
[[File:Breadboard02.jpg]]
 +
 
 +
connections lines are connected like this
 +
<br>
 +
[[File:Breadboard03.jpg]]
 +
 
 +
=== so Hello world on the breadboard===
 +
 
 +
[[File:Ledblinkbradboard.png | 500px]]
 +
 
 +
<br>
 +
 
 +
=Sensors / Input=
 +
 
 +
[[File:Interaction_sensor.PNG |900 px]]
 +
 
 +
''Digital Sensors''
 +
<br>
 +
 
 +
Digital sensors are the sensors that gives 2 state (on/off, 5V/0V). You will connect them to digital Pins and set it as INPUT.
 +
<br>
 +
Digital data consists exclusively of 0s and 1s .
 +
<br>
 +
For example, consider a push button switch. This is one of the simplest forms of sensors. It has two discrete values. It is on, or it is off. Other 'discrete' sensors might provide you with a binary value.
 +
<br>
 +
Another example of a digital sensor is an accelerometer, which sends a series of data points (speed, direction, and so on) to the Arduino. Usually digital sensors need a chip in the sensor to interpret the physical data.
 +
<br>
 +
''Analog Sensors''
 +
<br>
 +
Analog sensors on the other hand, gives range. You connect this types of Analog sensors to Analog Input pins which is measuring the incoming voltage between 0V-5V*. Arduino converts this incoming voltage into the number between 0-1023.
 +
<br>
 +
Analog data is transmitted as a continuous signal, almost like a wave. In other words, an analog sensor doesn’t send a burst of 1s and 0s like digital sensors do; instead, the sensor modulates a continuous signal to transmit data.
 +
<br>
 +
Microcontrollers are capable of detecting binary signals: is the button pressed or not? These are digital signals. When a microcontroller is powered from five volts, it understands zero volts (0V) as a binary 0 and a five volts (5V) as a binary 1. The world however is not so simple and likes to use shades of gray. What if the signal is 2.72V? Is that a zero or a one? We often need to measure signals that vary; these are called analog signals. A 5V analog sensor may output 0.01V or 4.99V or anything inbetween. Luckily, nearly all microcontrollers have a device built into them that allows us to convert these voltages into values that we can use in a program to make a decision.<br>
 +
An Analog to Digital Converter ('''ADC''') is a very useful feature that converts an analog voltage on a pin to a digital number. By converting from the analog world to the digital world, we can begin to use electronics to interface to the analog world around us.
 +
<br>
 +
Not every pin on a microcontroller has the ability to do analog to digital conversions. On the Arduino board, these pins have an ‘A’ in front of their label (A0 through A5) to indicate these pins can read analog voltages.
 +
<br>
 +
ADCs can vary greatly between microcontroller. The ADC on the Arduino is a 10-bit ADC meaning it has the ability to detect 1,024 (210) discrete analog levels. Some microcontrollers have 8-bit ADCs (28 = 256 discrete levels) and some have 16-bit ADCs (216 = 65,536 discrete levels).
 +
 
 +
 
 +
==The knob==
 +
 
 +
[[File:Analogreadserial.png]]
 +
 
 +
<syntaxhighlight lang=c style="border:3px dashed pink">
 +
 
 
   
 
   
 +
/*
 +
  AnalogReadSerial
 +
 +
  Reads an analog input on pin 0, prints the result to the Serial Monitor.
 +
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
 +
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 +
 +
  This example code is in the public domain.
 +
 +
  http://www.arduino.cc/en/Tutorial/AnalogReadSerial
 +
*/
 +
 +
// the setup routine runs once when you press reset:
 +
void setup() {
 +
  // initialize serial communication at 9600 bits per second:
 +
  Serial.begin(9600);
 +
}
 +
 +
// the loop routine runs over and over again forever:
 +
void loop() {
 +
  // read the input on analog pin 0:
 +
  int sensorValue = analogRead(A0);
 +
  // print out the value you read:
 +
  Serial.println(sensorValue);
 +
  delay(1);        // delay in between reads for stability
 +
}
 +
 +
</syntaxhighlight>
 +
 +
[[File:Led pot.PNG]]
 +
 +
<syntaxhighlight lang=c style="border:3px dashed pink">
 +
 +
int potPin = A0;
 +
int potValue = 0;
 +
int ledPin = 9;
 +
 +
 +
void setup() {
 +
  // put your setup code here, to run once:
 +
 +
Serial.begin(9600);
 +
}
 +
 +
void loop() {
 +
  // put your main code here, to run repeatedly:
 +
potValue = analogRead(potPin);
 +
Serial.println(potValue);
 +
analogWrite(ledPin, potValue);
 +
}
 +
 +
</syntaxhighlight>
 +
 +
'''Now MAP the values'''
 +
 +
<syntaxhighlight lang=c style="border:3px dashed pink">
 +
 +
int potPin = A0;
 +
int potValue = 0;
 +
int ledPin = 9;
 +
 +
 +
void setup() {
 +
  // put your setup code here, to run once:
 +
 +
  Serial.begin(9600);
 +
}
 +
 +
void loop() {
 +
  // put your main code here, to run repeatedly:
 +
  potValue = analogRead(potPin);
 +
  int mappedValue = map(potValue, 0, 1023, 0, 255);
 +
  analogWrite(ledPin, mappedValue);
 +
}
 +
 +
</syntaxhighlight>
 +
 +
==Button==
 +
 +
[[File:Arduinobutton.jpg]]
 +
 +
<syntaxhighlight lang=c style="border:3px dashed pink">
 +
// constants won't change. They're used here to set pin numbers:
 +
const int buttonPin = 7;    // the number of the pushbutton pin
 +
const int ledPin =  13;      // the number of the LED pin
 +
 +
// variables will change:
 +
int buttonState = 0;        // variable for reading the pushbutton status
 +
 +
void setup() {
 +
  // initialize the LED pin as an output:
 +
  pinMode(ledPin, OUTPUT);
 +
  // initialize the pushbutton pin as an input:
 +
  pinMode(buttonPin, INPUT);
 +
}
 +
 +
void loop() {
 +
  // read the state of the pushbutton value:
 +
  buttonState = digitalRead(buttonPin);
 +
 +
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
 +
  if (buttonState == HIGH) {
 +
    // turn LED on:
 +
    digitalWrite(ledPin, HIGH);
 +
  } else {
 +
    // turn LED off:
 +
    digitalWrite(ledPin, LOW);
 +
  }
 +
}
 +
</syntaxhighlight>
 +
 +
==LDR==
 +
 +
[[File:Arduinolrd.jpg]]
 +
 +
 +
== Stretch sensor ==
 +
 +
 +
[[File:Stretchsensor01.jpg | 500 px]]
 +
 +
=Output=
 +
 +
==Servo==
 +
Now we will hookup a '''servo motor''' and instruct it to behave a certain way.
 +
 +
[[File:Micro-servo.jpg]]
 +
<br>
 +
This is a servo, a very small one
 +
==Hookup==
 +
The servo has 3 wires, we need to connect them all to the arduino.
 +
===''red'' is for 5V===
 +
you will find it easy to plug one end of a jumper wire inside the connectors of the servo motor, and the other end to the corresponding pin of the Arduino
 +
make sure you use corresponding colors for the jumpers, in bigget setups messy wire can cause you more time to debug
 +
===''black'' is for GND===
 +
to GND of the Arduino
 +
===and ''orange'' is for signal===
 +
signal is going into the pin of the Arduino we will use to control the servo motor
 +
We will look for a pin that has a wave next to the number ( look at the Arduino board). Those pins are able to output Pulse Width Modulation (PWM) is a fancy term for describing a type of digital signal. Pulse width modulation is used in a variety of applications including sophisticated control circuitry. Also in our case control the servo motor.  The control wire is used to send this pulse.
 +
For more info how servos work look here [[https://www.servocity.com/how-does-a-servo-work]]
 +
 +
 +
 +
[[File:Oneservo hello.png | 900 px]]
 +
<br>
 +
We will use another example to see if our servos work
 +
 +
 +
==DC==
 +
we will follow this guide for the shields we have [https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/using-dc-motors]
 +
 +
==Stepper==
 +
<br>
 +
A good source to learn how steppers work  [https://learn.adafruit.com/all-about-stepper-motors HERE]
 +
<br>
 +
we will follow the guide for the shield at hand [https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/using-stepper-motors]
 +
 +
=Input & Output =
 +
==Servo and Pot==
 +
[[File:Servo pot.png]]
 +
<syntaxhighlight lang=c style="border:3px dashed blue">
 +
/*
 +
Controlling a servo position using a potentiometer (variable resistor)
 +
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
 +
 +
modified on 8 Nov 2013
 +
by Scott Fitzgerald
 +
http://www.arduino.cc/en/Tutorial/Knob
 +
*/
 +
 +
#include <Servo.h>
 +
 +
Servo myservo;  // create servo object to control a servo
 +
 +
 +
int val;    // variable to read the value from the analog pin
 +
 +
void setup() {
 +
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 +
}
 +
 +
void loop() {
 +
  val = analogRead(A0);            // reads the value of the potentiometer (value between 0 and 1023)
 +
  val = map(val, 0, 1023, 0, 180);    // scale it to use it with the servo (value between 0 and 180)
 +
  myservo.write(val);                  // sets the servo position according to the scaled value
 +
  delay(15);                          // waits for the servo to get there
 +
}
 +
</syntaxhighlight>
 +
 +
==Servo and LDR==
 +
 +
where problems with data start to appear. <br>
 +
constraining...and then...
 +
 +
<syntaxhighlight lang=c style="border:3px dashed blue">
 +
 +
#include <Servo.h>
 +
 +
Servo myservo;  // create servo object to control a servo
 +
 +
 +
int val;    // variable to read the value from the analog pin
 +
int mappedVal;
 +
int constrainedVal;
 +
 +
void setup() {
 +
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 +
}
 +
 +
void loop() {
 +
  val = analogRead(A0);            // reads the value of the potentiometer (value between 0 and 1023)
 +
  mappedVal = map(val, yourMinVal, yourMaxVal, 0, 180);    // scale it to use it with the servo (value between 0 and 180)
 +
  // in case the sensor value is outside the range seen during calibration
 +
  constrainedVal = constrain(mappedVal, 0, 180);
 +
  myservo.write(constrainedVal);                  // sets the servo position according to the scaled value
 +
  delay(15);                          // waits for the servo to get there
 +
}
 +
</syntaxhighlight>
 +
 +
 +
 +
<syntaxhighlight lang=c style="border:3px dashed blue">
 +
 +
#include <Servo.h>
 +
 +
Servo myservo;  // create servo object to control a servo
 +
 +
 +
int val;    // variable to read the value from the analog pin
 +
int mappedVal;
 +
int constrainedVal;
 +
int newval;
 +
int oldval;
 +
 +
void setup() {
 +
  Serial.begin(9600);
 +
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 +
}
 +
 +
void loop() {
 +
  val = analogRead(A0);            // reads the value of the potentiometer (value between 0 and 1023)
 +
  mappedVal = map(val, 470, 840, 0, 180);    // scale it to use it with the servo (value between 0 and 180)
 +
  newval = constrain(mappedVal, 0, 180);
 +
  if (newval < (oldval - 15) || newval > (oldval + 15)) { //dead band setup
 +
    myservo.write(newval);
 +
    Serial.println(newval);
 +
    oldval = newval;
 +
    delay(15);
 +
  }
 +
 +
}
 +
 +
</syntaxhighlight>
 +
 +
And further reading  [https://www.arduino.cc/en/tutorial/smoothing HERE on smoothing data]
 +
 +
= Arduino Basics Workshop =
 +
-
 
'''Workshop notes''' <br/>
 
'''Workshop notes''' <br/>
 
Here you will find a PDF with diagrams from the Arduino Basics Workshop.  
 
Here you will find a PDF with diagrams from the Arduino Basics Workshop.  
  
 
[[Media:arduino_basics_workshop.pdf]]
 
[[Media:arduino_basics_workshop.pdf]]

Latest revision as of 19:34, 15 October 2019

Intro

Smelling-color-lg.jpg

Smelling color
Knock Calculator

Thumb01.PNG

Video of the thumb

The Third Thumb

Politics of Power

TactileControls.jpg

Expressive Tactile Controls

Separate-Togetherness.jpg

Separate Togetherness

Arduino Uno

Aqrduino ide.PNG

Overview

Hello everyone hello hello hello,

now what is an Arduino ...well...find a detailed introduction here [[1]]
Computer and processor are generic terms for the anything that can run a program, basically.
Controller or microcontroller usually refers to a simple processor that does only one task, like listening to sensors. In explaining microcontrollers, we’ll distinguish them from computers, which contain more powerful processors that can run an operating system.
Arduino is an open source physical computing platform based on a simple input/output (I/O) board and a development environment that implements the Processing language. Arduino can be used to develop standalone interactive objects or can be connected to software on your computer.
The Arduino contains a microcontroller.
Most electronic devices today have a microcontroller at their core. Microcontrollers are optimized for control of general input and output. What Is Physical Computing? Physical Computing uses electronics to prototype new materials for ( in our case ) designers and artists.
Arduino is composed of two major parts: the Arduino board, which is the piece of hardware you work on when you build your objects; and the Arduino IDE, the piece of software you run on your computer. You use the IDE to create a sketch (a little computer program) that you upload to the Arduino board. The sketch tells the board what to do.

In the meantime, HERE you can find ANYTHING about Arduino, including download the software

NOW,
The pins on your Arduino are the places where you connect wires to construct a circuit (probably in conjunction with a breadboard and some wire. They usually have black plastic ‘headers’ that allow you to just plug a wire right into the board. The Arduino has several different kinds of pins, each of which is labeled on the board and used for different functions.
Board layout.PNG



First things first, Blink it

we start by figuring put if our Arduino is all good or it is somehow damaged ...it is a basic test to check and run a simple script at the same time.

Go to File ---> Examples ---> Basics --->Blink

so we have something like this

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc
 
  This example code is in the public domain.
 
  modified 8 May 2014
  by Scott Fitzgerald
 */
 
 
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}
 
// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

GOOOD! lets dissect this

  • commenting / one line and multiple lines
  • setup
  • loop

Choose board

Board.png

Choose port

Port.png


Lets compile this

--- Press/ Click upper most left button, looks like a Tick. Observe the messages appearing in the bottom of the Arduino software window ( there must be a sentence Done Compiling
Compile.png


Lets upload this

Upload.png

And we should have a Blinking aka Flashing on board LED


Arduino-LED-Overview.jpg

Let's add a trough hole led

LED pinout.jpg

Schematic wiriting.PNG

OK, wait...the BREADBOARD

OK, first, what's with the name....bread board? Bread, like in food? Well yes, kind of.
Breadboard.jpg

This terminology goes way back in the days. Generally, you would mount electronic components to a piece of wood (the actual "breadboard"), and do all the wiring with point-point wire and the components just hanging between the various devices.

00 px

The story goes that an engineer had an idea for a vacuum tube device late one night. Looking around the house, the only base for his prototype that he found was indeed his wife's breadboard, from the breadbox.

A video by the Make magazine people

Ok, but why do we need to breadboard?
Well, they are useful for making temporary circuits and prototyping, and they require absolutely no soldering.
Prototyping is the process of testing out an idea by creating a preliminary model from which other forms are developed or copied, and it is one of the most common uses for breadboards.
The best way to explain how a breadboard works is to take it apart and see what’s inside. Breadboard02.jpg

connections lines are connected like this
Breadboard03.jpg

so Hello world on the breadboard

Ledblinkbradboard.png


Sensors / Input

Interaction sensor.PNG

Digital Sensors

Digital sensors are the sensors that gives 2 state (on/off, 5V/0V). You will connect them to digital Pins and set it as INPUT.
Digital data consists exclusively of 0s and 1s .
For example, consider a push button switch. This is one of the simplest forms of sensors. It has two discrete values. It is on, or it is off. Other 'discrete' sensors might provide you with a binary value.
Another example of a digital sensor is an accelerometer, which sends a series of data points (speed, direction, and so on) to the Arduino. Usually digital sensors need a chip in the sensor to interpret the physical data.
Analog Sensors
Analog sensors on the other hand, gives range. You connect this types of Analog sensors to Analog Input pins which is measuring the incoming voltage between 0V-5V*. Arduino converts this incoming voltage into the number between 0-1023.
Analog data is transmitted as a continuous signal, almost like a wave. In other words, an analog sensor doesn’t send a burst of 1s and 0s like digital sensors do; instead, the sensor modulates a continuous signal to transmit data.
Microcontrollers are capable of detecting binary signals: is the button pressed or not? These are digital signals. When a microcontroller is powered from five volts, it understands zero volts (0V) as a binary 0 and a five volts (5V) as a binary 1. The world however is not so simple and likes to use shades of gray. What if the signal is 2.72V? Is that a zero or a one? We often need to measure signals that vary; these are called analog signals. A 5V analog sensor may output 0.01V or 4.99V or anything inbetween. Luckily, nearly all microcontrollers have a device built into them that allows us to convert these voltages into values that we can use in a program to make a decision.
An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a pin to a digital number. By converting from the analog world to the digital world, we can begin to use electronics to interface to the analog world around us.
Not every pin on a microcontroller has the ability to do analog to digital conversions. On the Arduino board, these pins have an ‘A’ in front of their label (A0 through A5) to indicate these pins can read analog voltages.
ADCs can vary greatly between microcontroller. The ADC on the Arduino is a 10-bit ADC meaning it has the ability to detect 1,024 (210) discrete analog levels. Some microcontrollers have 8-bit ADCs (28 = 256 discrete levels) and some have 16-bit ADCs (216 = 65,536 discrete levels).


The knob

Analogreadserial.png

 
/*
  AnalogReadSerial
 
  Reads an analog input on pin 0, prints the result to the Serial Monitor.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 
  This example code is in the public domain.
 
  http://www.arduino.cc/en/Tutorial/AnalogReadSerial
*/
 
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
 
// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}

Led pot.PNG

int potPin = A0;
int potValue = 0;
int ledPin = 9;
 
 
void setup() {
  // put your setup code here, to run once:
 
Serial.begin(9600);
}
 
void loop() {
  // put your main code here, to run repeatedly:
 potValue = analogRead(potPin);
 Serial.println(potValue);
 analogWrite(ledPin, potValue);
}

Now MAP the values

int potPin = A0;
int potValue = 0;
int ledPin = 9;
 
 
void setup() {
  // put your setup code here, to run once:
 
  Serial.begin(9600);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  potValue = analogRead(potPin);
  int mappedValue = map(potValue, 0, 1023, 0, 255);
  analogWrite(ledPin, mappedValue);
}

Button

Arduinobutton.jpg

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 7;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
 
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
 
void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}
 
void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
 
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

LDR

Arduinolrd.jpg


Stretch sensor

Stretchsensor01.jpg

Output

Servo

Now we will hookup a servo motor and instruct it to behave a certain way.

Micro-servo.jpg
This is a servo, a very small one

Hookup

The servo has 3 wires, we need to connect them all to the arduino.

red is for 5V

you will find it easy to plug one end of a jumper wire inside the connectors of the servo motor, and the other end to the corresponding pin of the Arduino make sure you use corresponding colors for the jumpers, in bigget setups messy wire can cause you more time to debug

black is for GND

to GND of the Arduino

and orange is for signal

signal is going into the pin of the Arduino we will use to control the servo motor We will look for a pin that has a wave next to the number ( look at the Arduino board). Those pins are able to output Pulse Width Modulation (PWM) is a fancy term for describing a type of digital signal. Pulse width modulation is used in a variety of applications including sophisticated control circuitry. Also in our case control the servo motor. The control wire is used to send this pulse. For more info how servos work look here [[2]]


Oneservo hello.png
We will use another example to see if our servos work


DC

we will follow this guide for the shields we have [3]

Stepper


A good source to learn how steppers work HERE
we will follow the guide for the shield at hand [4]

Input & Output

Servo and Pot

Servo pot.png

/*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
 
 modified on 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob
*/
 
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
 
int val;    // variable to read the value from the analog pin
 
void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop() {
  val = analogRead(A0);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

Servo and LDR

where problems with data start to appear.
constraining...and then...

#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
 
int val;    // variable to read the value from the analog pin
int mappedVal; 
int constrainedVal;
 
void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop() {
  val = analogRead(A0);            // reads the value of the potentiometer (value between 0 and 1023)
  mappedVal = map(val, yourMinVal, yourMaxVal, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
   // in case the sensor value is outside the range seen during calibration
  constrainedVal = constrain(mappedVal, 0, 180);
  myservo.write(constrainedVal);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}


#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
 
int val;    // variable to read the value from the analog pin
int mappedVal;
int constrainedVal;
int newval;
int oldval;
 
void setup() {
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop() {
  val = analogRead(A0);            // reads the value of the potentiometer (value between 0 and 1023)
  mappedVal = map(val, 470, 840, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  newval = constrain(mappedVal, 0, 180);
  if (newval < (oldval - 15) || newval > (oldval + 15)) { //dead band setup
    myservo.write(newval);
    Serial.println(newval);
    oldval = newval;
    delay(15);
  }
 
}

And further reading HERE on smoothing data

Arduino Basics Workshop

- Workshop notes
Here you will find a PDF with diagrams from the Arduino Basics Workshop.

Media:arduino_basics_workshop.pdf