Introduction: Attiny85-shiftlcd Direction Detection

About: Electronic Technician, U.S. Navy veteran. Trying to keep up to date on the new tech.

This instructable combines a few instructables projects that I have done into one. It starts off with a 5v power supply I breadboard with a 9V battery, 7805 regulator, switch, 2 10uF electrolytic caps, 103 ceramic cap and just for visual confirmation a led and 330 resistor to detect when the power is on. Then the LCD is wired up to a 74HC595 shift register. The LCD via shift register is attached to the attiny85 along with a 100k Ohm potentiometer. Before I actually hooked up to the attiny I had to wire up a little attiny programmer to the Arduino and upload the sketch. Then i could transfer the ATtiny to the project breadboard. (I uploaded and transferred too many times during debugging)

If you have questions or want to discuss this project please comment. I would love to get some feedback.

Step 1: Hardware

This instructable consist of several smaller instructables working together.

5v 7805 power supply

1602 LCD

74HC595 shift register for LCD*

Attiny85 micro controller over Arduino programmer

*I've noticed while I was making the shift register for the LCD that there is a transistor that the shift register controls when to turn on/off the backlight of the LCD. I wasn't sure if it would be needed as I elected to have my LCD backlight stay on.

Step 2: Software

Other than the code itself, the only additional need is the LiquidCrystal595.h library which you can download and install to your arduino IDE. There are several sources.

LiquidCrystal595 library

There are a few different ways to load the code to the Attiny85 microcontroller but in this instructable the Arduino as ISP method was used.

I've seen in some publications that a 10uF capacitor was needed but for me it was not. To save yourself some hassle, be sure to connect your arduino USB directly to your computer, double check the following:

Board: ATtiny

Processor: ATtiny85

Clock: 1MHz internal (##DO NOT SELECT EXTERNAL UNLESS YOU KNOW WHAT YOU'RE DOING##)

Port: this may vary

Programmer: Arduino as ISP*

*Follow directions on how to use the Arduino as ISP. Don't connect the ATtiny85 for programming until all of the above conditions are met.

Sketch

#include <LiquidCrystal.h> // include this library

LiquidCrystal595 lcd(0,1,2);  // datapin, latchpin, clockpin
int pot = A2;                //Input potentiometer
int val;                    //current pot value
int prev;                  //previous pot value

void setup() { 
lcd.begin(16,2);            // 16 characters, 2 rows
lcd.clear();                // clear screen
pinMode(pot, INPUT);       //declares A2 an INPUT
}

void loop() {
 prev = val;
 val = analogRead(pot);     //read the pot as value to be mapped
 val = map(val, 0, 1023, 0, 99);   //maps the val to 0-99, this could be any range you choose
 
lcd.setCursor(0,1);          //2nd row far left
if(val < prev) {             //CCW direction
lcd.print("<<<<");
}else lcd.print("----");
lcd.setCursor(6,1);          //2nd row middle
if(val==prev)  {              //no turn
lcd.print("STOP");
} else lcd.print("----");
lcd.setCursor(11,1);        //2nd row far right
if (val > prev) {            //CW direction
lcd.print(">>>>");
} else lcd.print("----");
lcd.setCursor(7,0);
lcd.print(val);            //prints the mapped val
delay(10);
lcd.print(" ");           //doesnt print what isnt suppose to
delay(1);
}

Step 3: Results

The potentiometer's analog reading is sent to the LCD via the shift register noting direction of left/CCW or right/CW (to potentiometers orientation) by comparing 2 variables of current value and previous value. When both variables are identical representing no change, the LCD displays STOP.

I like my breadboards to be neat and modular for easy storage and hookup. It helps when you're trying to troubleshoot and if other people are trying to do the same. I'm not posting any schematics because all of the different hardware modules are fairly common and there are instructables on them. I may at a later time if requested. Just leave a comment. I'm not sure of any real world applications this instructable would relate to, but I'm sure with some modification to the code you could display any kind of analog reading whether it be temperature, light intensity, distance, pressure, etc.

*If you replace the pot with a joystick and modify the code to display the analog reading, you can get single axis center of the joystick. I've noticed some joysticks with center readings that were 513 (Dominion-Network's Arduino Joystick with LCD) My parallax joystick was at 509 and 523.

Here's a video demonstration via Instagram @kayohzee

Displays potentiometer rotation direction and analog value on LCD #arduino #attiny85

Displays potentiometer rotation direction and analog value on LCD #arduino #attiny85

A video posted by John Cosgrove II (@kayohzee) on Jun 18, 2015 at 12:22am PDT