Fab tool : Electronic Prototyping with Arduino#

My experience#

This is my first time working with kind of microcontroller kits like these, so the sheer amount of information dump took a while to get used to. In spite of the theory needed to get started, Arduino has a very hands-on way of learning, which I think is its most appealing factor.

Starting out#

Arduino is an open source programmable circuit board released under a Creative Commons license. It can be integrated into a wide variety of makerspace projects, from simple alarm clocks to complex robotics.

Pros: - Low cost - Flexibility - Easy to use - Active user community (librairies, support)

Cons: - Limited to run only a single program at a time - Not optimized for performance - Mostly programmed in C or C++ - Limited memory storage

At its core, an Arduino is a microcontroller board, essentially an entire computer on a chip. It has a processing core, memory, and input and ouput signals in one chip. The board you see contains the actual microcontroller chip (integrated chip) and all the extra bits you need to make it work, i.e. power management, timing modules, input and ouput header, etc.

We used the Arduino UNO, which looks like this :

The USB connector allows it to connect to a power source (like your PC). You can’t use a power supply greater than 20 Volts without destroying your Arduino. So preferably, between 6 and 12 Volts for most models.

Pins are where you connect wires to build a circuit, probably with a breadboard. They usually have black plastic headers allowing you to just plug the wire right into the board. There are different kinds of pins, which each their own function :

  • Ground pins (GND) : they’re essential for the board to measure and set any voltage. A voltage is a difference of electric potential between 2 points, you take the ground and another point. You should always connect all grounds of a circuit together.

  • Power pins (5V, 3.3V): to power external components plugged to your board. The Arduino UNO operates under 5V, so don’t accidently plug a 3.3V component to a 5V power source and damage the component like I did.

  • Digital pins : there are 14 digital pins (0 to 13). They allow to read data from some components (sensors) and write data to other components (actuators). A digital pin can only 2 states : LOW (meaning the voltage on the pin is 0V) or HIGH (Vcc). Before using a digital pin, you have to configure its mode, i.e. INPUT (for reading) or OUTPUT (for writing).

  • Some digital pins can be used to write PMW (Pulse Width Modulation)
  • Pins 2 and 3 can be used as interrupt pins

  • Analog pins : there are 6 (A0 to A5) near the power pins. An analog pin is useful to read values that can’t be just 0 or 1.

Then there are communication protocols over Arduino UNO pins allowing you to use more advanced sensors and actuators, to create more complex applications. The 3 main protocols are : UART, SPI, and I2C (which I’ll use in the final project for the LCD).

Programming the microcontroller#

I first installed the Arduino IDE from here. Opening up the IDE for the first time will show this code :

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

We can notice two functions that are present in every Arduino script : setup() and loop(). Instructions in setup() are executed once when the microcontroller receives the code in its memory. After setting up, instructions in loop() will be run in a loop for as long as we don’t stop it by unplugging the power source or uploading another script.

To upload your code, you’d have to click on the Upload button (arrow), which compiles the script first then uploads it. You can also verify your script first (check).

Analog In, Out Serial example#

To get the hang of things, I ran a few examples in File, then Examples. This example shows you how to read an analog input pin to set the PWM of an output pin to change an LED’s brightness.

The circuit looks like this :

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {

  // initialize serial communications at 9600 bps:

  Serial.begin(9600);
}

void loop() {

  // read the analog in value:

  sensorValue = analogRead(analogInPin);

  // map it to the range of the analog out:

  outputValue = map(sensorValue, 0, 1023, 0, 255);

  // change the analog out value:

  analogWrite(analogOutPin, outputValue);

  // print the results to the Serial Monitor:

  Serial.print("sensor = ");

  Serial.print(sensorValue);

  Serial.print("\t output = ");

  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop for the analog-to-digital

  // converter to settle after the last reading:

  delay(2);
}

First, two variables analogInPinand analogOutPinfor pin assignments, and two variables sensorValueand outputValue are declared. setup() here just begins serial communication.

In loop(), sensorValue is assigned to store the raw analog value read from the potentiometer. To convert this value, map() is called. The newly mapped sensor data is then output to analogOutPin. Serial.println() prints into the serial monitor window.

Debounce a Pushbutton example#

Humidity and Temperature sensing with the DHT20#

The DHT20 is a low cost humidity and temperature sensor that uses a standard I2C data output signal format. To learn how to use it with the Arduino UNO, you’d first have to learn about its working principles and characteristics in its datasheet.

This datasheet contains information like sensor specs, expansion performance, electrical characteristics, interface definition, etc.

Pins VDD and GND are for the tension source and the ground, respectively. The SDA pin is for data to travel to the microcontroller, in our case the data we’re trying to measure is the surrounding humidity and temperature. SCL is for synchronizing the microcontroller with the sensor.

SDA and SCL should be plugged in to the same ones on the board. To see which pins are what, we can look at the documentation.

Setting up the IDE#

We first have to include the library for the sensor. In Sketch, then Include a library, Manage libraries. Or just click on the library button on the side of the IDE. I used the DHT20 library by Rob Tillaart.

Physical circuit#

  • Power supply : orange (5v) and white (GND) cables
  • Serial Data Port (SDA) : blue cable
  • Serial Clock Port (SCL) : green cable

For the Arduino UNO, the SDA pin is for port A4, and SCL is for port A5.

#include "Arduino_SensorKit.h"

#define Environment Environment_I2C

void setup() {
  Serial.begin(115200);
  Environment.begin();
}

void loop() {
  // Serial.print("Temperature = ");
  Serial.print(Environment.readTemperature());
  Serial.print(" ,");
  // Serial.print("Humidity = ");
  Serial.print(Environment.readHumidity());
  Serial.println();
  delay(2000);
}