what-is-arduino

The Arduino project started around 2005 with the goal of making interactive technology accessible to a wide range of people without a programming background and to be inexpensive for students. It has gained enormous popularity world-wide with an active and diverse community of enthusiasts. The place to begin with Arduino is at their official site: Link

The Arduino is a microcontroller.

mcu-vs-mpu

 

Arduino Variants

arduino_variants

Arduino Nano

nnnano

nano_pinout

nano-tech-specs

Coding

bare-minimum

The minimum ‘boiler plate’ that every sketch needs is illustrated above. The Arduino Reference page is the best place to learn the commands and how to use them; as well as the many example codes in the IDE.

handson

Most everything going forward is all hands on!

The first step to entering the world of Arduino is to set up its Integrated Development Environment (IDE) on your computer. The IDE is simply a special editor in which to compose, compile and upload code to the Arduino module. It is a nice editor, with syntax highlighting, a serial monitor for debugging and lots of example code. If you prefer to work from the Cloud, there is a browser-based beta version available as well. Instructions for various platforms are found on their Software page.

Drivers

Linux typically already has the required USB-serial drivers. For Windows, try this link.

IDE Setup

ard-setup-1

On the Arduino IDE set the board to “Arduino Nano”.

ard-setup-2

Next select the serial port your computer assigned it to. In Windows, it will probably be the highest Com port listed (if in doubt, check the Device Manager).

Load a Sketch

ard-setup-3

Then under File/Examples/Basics open the ‘Blink’ sketch. (Sketch is just another name for program).

blink1

If your Nano is already blinking about once a second after you plugged in the mini USB cable that means the factory used the blink sketch to check it out before shipment (good for them!) However, we want to check our connection and computer set up; so change the delays in the blink sketch from 1000 to 100 each (from 1 second to a tenth of a second).

blink2

top tool bar.png

Then go to the top tool bar and click on the ‘Check’ mark to precompile check the code; and if there are no error messages, click on the arrow under ‘Edit’ to upload the code. If this was successful the LED on the Nano should be blinking very fast now.

Change Pin Assignment

ard-pin-3-ftz

Add a wire from port D3 on the Nano to the top of the red LED. Change the code so the pin assignment changes from ‘Internal LED’ to D3 like this and upload the sketch:

change-pin-assignment

The red LED should now be blinking instead of the one on the Nano.

Analog Read Voltage

fz-analog-pot

Connect a wire from the Nano’s A0 (analog 0) port to the center leg of the potentiometer. Also connect the Panel Voltmeter to the same point.

ide-analog-read-voltage

From the IDE’s top toolbar, select File/Examples/Basics/ReadAnalogVoltage sketch. Upload it to the Nano.

serial-monitor

Rotate the pot to the highest voltage reading on the Panel meter. On the IDE click on the magnifying glass-looking icon in order to open the serial monitor.

voltage-readings1

The serial monitor is reading 5.00V; but my panel meter is reading 4.54V: which is right? My trusted digital multimeter read 4.60V on the rails of my breadboard. This is like asking, “What time is it?” and getting 3 different answers. I measured my USB cable and it was putting out 5.01V. Then I looked at the Nano’s schematic, particularly the diode input protection circuit:

sky-diode

The Nano may be getting 5.01V from my USB cable; but according to the specs of the Schottky diode; that diode protection costs the nano 0.5V! The code as written assumes the analog-to-digital (A/D) converter is referenced to 5.0V; but it is really seeing 4.5V. I also noticed that the code divided the supply voltage by 1023 (a 10-bit A/D converter covers a range of 0 to 1023 which is 1024 numbers. Therefore, the supply Voltage should be divided by 1024 for each step.

Correct the code in accordance with this example:

corrected-code

Now you should be seeing closer harmony and a truer voltage in the readings. The panel voltmeter should track the serial monitor fairly closely. If you require greater accuracy; here is an article on internal and external references: Link.

CDS Cell Light Sensor

Move the Nano’s A0 analog input wire from the potentiometer to the bottom of the CDS Cell (also known as a Light-Dependent-Resistor, or LDR). Add a wire to the top of the sensor to +5V. Shine a flashlight on the sensor and then cover it with your hands to see the range in voltage readings.

arduino-n-cds

cds-and-nano-sch

Of course, you could also use the panel voltmeter and get the same readings. The advantage of using a microcontroller is that you could potentially log data over an extended period along with other sensor input like humidity and temperature to do some real science. Once I had an engineer ask me to stay all night taking readings of his project in a thermal chamber; I built him a data-logger and went home in peace. Adafruit’s Data Logger shield has a real-time clock so every reading gets a date-time stamp. It also has an SD card to save the readings as a coma-separated value (CSV) that any spreadsheet program can turn into a nice graph.

image007

Data Conversion: Measure Centigrade and Display Fahrenheit

temperature-conversion-wiki

Let us modify our code and circuit to read the ambient temperature in C and F.

arduino-n-lm35-sensor

c-f-code

Why did we alternate between Serial.print and Serial.println?

c-f-readings

Digital Sensors

dht11-module

The photodiode, the CDS  cell, the LM35 temperature sensors that we have examined so far are in the class of analog sensors. Their output could of been interpreted by an analog voltmeter. There is a whole range of other sensors that only a microcontroller can make sense of; digital sensors. These use a wide range of serial chip-to-chip protocols: 2W (for 2 wire), 1W, I2C (“eye-squared-see”), CAN Bus, SPI. Then there are some custom digital protocols that hackers have had to reverse engineer. The DHT11 Temperature/Humidity Sensor has such a protocol. I hardly understand how it works; but due to people committed to open source and knowledge sharing you and I can download an Arduino library and make use of this sensor with little effort.

400px-dht11-wiring-with-arduino

combinedtiming

adafruit-logo

Go to GitHub and download the zipped library from here: Link  Leave the library zipped.

add-zipped-library

On the Arduino IDE navigate to File/Sketch/Include Library and select the library you just downloaded.

this-one

Then in File/Examples/DHT sensor library open the DHTtester sketch.

comment-out-dht11

In the code, uncomment the DHT11 and comment out the other sensors as shown.

dht11-fritzing

Connect the center pin to D2 on the Nano. Upload the code and open the serial monitor.

temp-humid-serial-monitor

Other digital sensor that work somewhat like this are 3-Axis Accelerometers, Magnetometer/Compass modules, and GPS receivers.

 

 

Advertisements