Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
public:crocs:arduino [2014-10-24 23:11] – [How to connect everything together] lnemecpublic:crocs:arduino [2014-10-29 12:30] lnemec
Line 1: Line 1:
-====== Arduino ======+====== OpenLab 2014/07 | Hands on Arduino ====== 
 + 
 +  * Date: 31. 10. 2014 
 +  * Workshop by: Lukáš Němec 
 +  * Cake: we will see... 
 +  * Cake by: Mirek Jaroš 
 +  * Discussion on A403 wallpainting 
 + 
 +===== What to expect ===== 
 + 
 +Introduction to microcontroller programming, focused mainly on Arduino platform. We will start with basics, what to expect from Arduino and what is Arduino capable of with some examples. Then theoretic part, how to connect everything together and mainly how to write programs. Thus everything from using basic C skills to Arduino specific functions.  
 + 
 +As we learn enough of theoretic background, you will get your hands on Arduino boards and you will have chance to program your own blinking LED or something similar, depending on your time, skill and enthusiasm.
  
 ===== What to prepare ===== ===== What to prepare =====
Line 88: Line 100:
  
 <note important>When connecting LED, remember that LEDs are like all other diodes, so electricity flows in one direction only. The longer lead is positive (anode) needs to be connected to power and shorter leg (cathode) to ground.</note>  <note important>When connecting LED, remember that LEDs are like all other diodes, so electricity flows in one direction only. The longer lead is positive (anode) needs to be connected to power and shorter leg (cathode) to ground.</note> 
-<note warning>LEDs are not capable of handling arduino's 5V power, so resistor is required. Usually one which has 220Ω is used, but in this case it is not necessary to be exact, so you can use 200Ω or 300Ω as well and it will slightly affect brightness of LED, but nothing more.</note>+<note warning>LEDs are not capable of handling arduino's 5V power, so resistor is required. Usually one which has 220Ω is used, but in this case it is not necessary to be exact, so you can use 200Ω or 300Ω as well and it will slightly affect brightness of LED, but nothing more. Generally more resistance does no harm, less resistance could burn the LED.</note>
  
 {{ :public:crocs:arduino:led_blink.png?direct&700 |}} {{ :public:crocs:arduino:led_blink.png?direct&700 |}}
 +
 +=== Sensors, Analog input and Serial monitor ===
 +
 +Next example will show, how to read values from sensors and how to obtain debugging information from Arduino board.
 +
 +In order to receive value from sensor, we have to use analog input pins (Arduino UNO has range from A0 to A5) and read values with analogRead function. There are many posibilities what to use as a source of input, you can choose from whatever is avaiable, rotary potentiometer, light resistor (changes resistivity based on light) or any other option you choose. 
 +
 +Every sensor (save he more complicated ones) has basically three connections, power (Arduino's 5V), ground and output. Output is connected to analog input pin, in case of image below, two options are illustrated, one light resistor (with another 10KΩ resistor for better results) and one rotary potentiometer, both produce analog values from 0 to 1023, while read with analogRead function. 
 +
 +Next is serial output, which can be used either for debugging or logging values. Output needs to be inicialized in setup phase with following ''Serial.begin(9600);'' where 9600 means frequency in bauds. Then you can use ''Serial.println("text");'' anywhere in code. This messages can be captured, if you open Serial monitor from IDE (shortcut CTRL+Shift+M) and select same frequency as previously. 
 +
 +<code C>
 +int sensorPin = A0;    // select the input pin for the potentiometer
 +int sensorValue = 0;  // variable to store the value
 +
 +void setup() {
 +  //initialize both pin and Serial
 +  pinMode(sensorPin, INPUT);    
 +  Serial.begin(9600);
 +}
 +
 +void loop() {
 +  // read the value
 +  sensorValue = analogRead(sensorPin);    
 +  //print value on serial
 +  Serial.println(sensorValue);    
 +  //wait
 +  delay(1000);                  
 +}
 +</code>
 +
 +{{ :public:crocs:arduino:arduino_analog.png?direct&700 |}}
 +
 +<note important>Image shows two possible options, connected to pins A0 and A1, code shows reading input only from A0.</note>
 +
 +===== How to continue =====