Saturday, April 11, 2015

Arduino LM35 Temperature Sensor

One of the least expensive and simplest ways to measure temperature is with a LM35. This is another component found in our SainSmart kit. This transistor looking device has 3 pins, 5v, Signal out, and Gnd. The signal is an analog voltage that connects directly to a Arduino analog input. In this example we will use A0.

Now the LM35 outputs 0-1v for it's range of -55C to 150C. Since the Arduino defaults to a 5v reference for analog to digital conversion, we are losing 80% of the sensors range, so we are switching to the internal reference which is 1.1v. This is a better match for this sensor. We are also doing a Celsius to Fahrenheit conversion in the code.

With the pins down, and the flat face of the sensor facing you, the pins, from left to right are:

V- S - G

Where V connects to +5, S connects to A0, and G connects to ground. The data sheet can be found at

The code looks like this:

float tempC;
float tempF;
int reading;
int tempPin = 0;

void setup() {
  // put your setup code here, to run once:
  analogReference(INTERNAL); //changing from a 5v reference to a 1.1v reference

void loop() {
  // put your main code here, to run repeatedly:
  reading = analogRead(tempPin);
  tempC = reading / 9.31;
  tempF=tempC * 9/5 + 32;

Arduino Relay Control

Previously I have blogged about using relays with an Arduino, and SainSmart relays specifically. A while back I received a 4 relay, and a 8 relay board, and both of them used negative logic, i.e. a LOW activated them, and a HIGH deactivated them. Yesterday I received a single relay module as part of a kit, and found that this module uses positive logic, i.e. a High activates it, and a LOW deactivates it.

Being a 5v relay, it's able to be driven directly from the arduino power. If you have a lot of additional hardware, you may want to consider a separate 5v supply, and common ground.

We are printing the relay state to the serial monitor, but the LED on the relay board also signifies whether it's active or not.

Only 3 pins are used, 5v ("V"), Gnd ("G"), and a data pin. We are using pin 7 in this example, and connects to the relay "S" (signal) pin.

Here is my test code:

void setup() {
  // put your setup code here, to run once:
pinMode(7, OUTPUT); //don't forget to declare the pin as output!

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(7, HIGH);
digitalWrite(7, LOW);


Tuesday, April 7, 2015

Adafruit RGB I2C LCD Keypad Shield

This project is a bit more complicated than some we have done recently. Adafruit makes a very nice LCD Keypad Shield, that unlike most of the others, has a 2 wire I2C interface (covers the lcd and the keypad), and a multi-color RGB backlight. This frees up 7 I/O pins over the typical LCD Keypad Shield. It comes in a kit, and all the components need to be soldered on the board. Fortunately Adafruit provides a very comprehensive tutorial that is easy to understand.

Monday, April 6, 2015

Adafruit RTC / SD Data Logger

Many of our projects require logging the sensor data to a sd card, and some of those projects require a time / date stamp. We used to use discrete modules to do this, but Adafruit has a very nice Proto shield with a real time clock and a sd module on board. As you can see, this takes a regular size sd card, or a micro sd in a conversion carrier. At under $20, this is a cost effective replacement for discrete RTC and SD modules, and a proto shield. It does not come with extended headers, so it either has to be the top shield in a stack, or get a pack of extended headers and solder those on instead of the normal headers included (but not installed). We have several projects coming up using this shield, so stay tuned.

Will the Real Arduino, Please Stand Up?

For years we have been receiving these wonderful blue Arduino boards with printed on the back.

Imagine my surprise, when this time, it's a green (teal) board and says ARDUINO.ORG on the back. Not only that, but it comes up with warning's it's an UNCERTIFIED board when you use it.

Yes, it's a knock-down drag-out fight between two founders of Arduino, one in charge of manufacturing, the other in charge of software development, and both trying to keep the community in their pocket by claiming they are the real Arduino. Who wins? I don't know, but the real losers could be the hundreds of thousands of enthusiasts using these products. Stop fighting, kids, or I'm calling the Super Nanny!

Proto Screw Shields - Continued

Last week I built a Proto Screw Shield from Sparkfun. Although it's a very nice piece, and easily assembled, I received one from Adafruit today that I believe to be a bit better. First of all, It's REV 3 compliant, which the Sparkfun piece was not. Second, it also came with the pass through extended headers for the traditional ICSP block. Construction time and ease was essentially identical. Sparkfun still has the better shipping rates, so if you order from Adafruit, you better have a large order. I get charged $15 S&H for a $3 transistor or $100 worth of boards.

Related Posts Plugin for WordPress, Blogger...