Fab Academy 2018

Arduino

Today Guillem from FabLab Barcelona gave us a great introduction to Arduino, programming and some basics on electronics, programming and computation.

Arduino IDE

IDE stands for Integrated Development Environment

Arduino Toolchain

In programming a toolchain is just a series of tools that work together to complete the task. Think of this like making a carrot soup for example. The tools you need for making carrot soup are:

Together and used in sequence these tools make a toolchain that is necessary make a carrot soup.

The Arduino IDE is like our text editor. Here we write out code in C++ which is human readable code.

Pulse Width Modulation (PWM)

PWM is a technique of switching voltages at a pin from HIGH to LOW extremely fast. This is useful if we want to fade an LED or change the speed of a DC motor.

HIGH voltage is usually 5 voltage while LOW voltage is 0 volts. The length of time that the pulse is HIGH is called the DUTY CYCLE. See here

PWM

This means that the apparent voltage, or the voltage that is seen by the circuit is going to be proportional to the length of the duty cycle. So if the duty cycle is 50%, this means that the apparent voltage will be half of the HIGH, so half of 5 volts. If it is 25% then we get 1.25 volts or for 75% 1.75 etc. So why is this useful?

This basically allows us to set the voltage at an Arduino pin anywhere we want between 0 to 5 volts using a function called analogWrite.

This has nothing to do with the analogue pins on the Arduino by the way. All analogWrite function does is allows you to set any pins with the ~ symbol on them (pins 3, 5, 6, 9, 10, 11) to use PWM.

analogWrite requires two parameters, a pin number and a duty cycle. For the duty cycle we can set the pin anywhere between 0 to 100% using values between 0 and 255:

dutycycle

With analog write we usually do not have to declare the pinMode as OUTPUT in the setup function. Also with PWM and LED’s the dimming is not due to more or less voltage providing more or less brightness but actually a “dimming effect” of the LED cycling on and off so fast due to our persistence of vision we actually perceive this dimming effect.

Using Serial Communications

analogRead()