breadboard

Fritzing

Recently, I’ve been spending a bit of time with Fritzing. It’s a piece of software that allows you to document prototypes, design circuits and manufacture PCBs. So far, I have only used the breadboard view to generate wiring diagrams for my Arduino and Sensors class, but I am still very impressed.

One of the circuits in my class involves wiring an accelerometer and a switch to an Arduino. Here was my attempt to photograph the circuit:

IMG_6845

From the photograph, it’s not very clear on how to wire the accelerometer. There are too many wires in the photograph and it’s not easy to see where each wire terminates. Of course, I could try to recreate this circuit using wires with less slack, but there is a simpler solution – use Fritzing! The image generated by Fritzing makes it much easier to understand how the accelerometer is wired:

accelerometer_cal

It’s fast and simple to generate the wiring diagrams. Fritzing has a bunch of predefined components (such as breadboards, switches, resistors and Arduinos) that you can drag and drop together. There’s also a great snap-to-grid functionality that ensures that components are connected. Fritzing allows you to import component libraries from other vendors so that you can prototype with correct representations of the components. For example, the accelerometer object comes from the Adafruit Fritzing library.

I’m really glad to see that there are excellent open-source tools available for this kind of thing. It makes sharing knowledge much easier. I’m already impressed by the breadboarding functionality, so I am looking forward to tinkering with the schematic and PCB views!

Arduino and Sensors

I’ve been busy putting the finishing touches on a class I am teaching at NYC Resistor called Arduino and Sensors. The purpose of this class is to teach people how to use common sensors with Arduino so they can build awesome interactive projects. The class features the Adafruit Sensor Pack 900, as this pack contains a nice selection of common sensors. I’ve written some sample code for each of the sensors in the pack. We will discuss both digital signal and analog signal sensors.

Sensors!

Digital signal sensors are the simplest to use. They simply return a 1 or a 0 based on the reading of the sensor (just like a switch, it’s on or off). Therefore, reading the state of one of these sensors is as simple as hooking the output of the sensor to a digital pin on the Arduino (pins 2-13 on the Uno) and calling digitalRead() on that pin. Here is a simple example – an IR sensor:

IMG_6848

Analog signal sensors are more complex. These sensors return a voltage on an analog pin somewhere from 0 volts to the max voltage of the microcontroller (with the Uno, it’s 5 volts). In order to read an analog sensor value, the sensor output needs to be connected to an analog pin on the Arduino (pins A0-A5 on the Uno). In the code, calling analogRead() on the analog pin will give you the sensor reading. The Arduino automatically converts the voltage on the analog pin to an integer between 0 (no power) and 1023 (full power). Generally, the reading can be mapped back to some meaningful value. For example, here is a simple analog sensor – a temperature sensor:

IMG_6832

According to the datasheet, this sensor returns 0 volts at -50 degrees Celsius and 1.75 volts at 125 degrees Celsius. It has a scale of 10 millivolts per degree Celsius. To get the raw voltage reading, we take our reading value, divide it by 1024 (to get the percentage of the full voltage) and then multiply that by 5 (since the microcontroller is supplying 5 volts). To scale the voltage to the range, we can simply multiply the voltage by 100 (according to our scale factor, 1/100 volt is 1 degree Celsius) and then subtract 50 (since zero volts is -50 degrees Celsius).

Of course, many sensors are more complex than just reading a simple pin. We’ll discuss a number of different scenarios and how to handle them. Did you ever wonder what the AREF pin is for? It’s the analog voltage reference pin and we will be discussing how to use it. We’re also going to use potentiometers to tune the sensitivity of some of the sensors.

The class is already almost sold out! If all goes well, I will hopefully teach it again soon!