Thursday 13 November 2014

ATTiny85 – Tutorial 10 – Detecting Knocks and Vibration

This tutorial in it’s original form sends the detection of knocks and vibrations from the Freetronics ”Sound” module to the serial monitor. As we don’t have access to a serial monitor from the ATTiny85, instead we are going straight to the extended tutorial, monitoring our knocks and vibrations with an LED.

ATTiny85 Pin Project 10

For this tutorial, the Piezo (Sound module) is connected on A1 (ATTiny85 pin 7) and an LED is connected to 0 (ATTiny85 pin 5).

The Piezo is read using the analogRead Arduino function and, when the analog value read from the Piezo is > 5, it will light up our LED (with a pull down resistor).

/* Project 10: Detecting Vibrations and Knocks */

int knock = 0;

void setup()
{
  pinMode(0, OUTPUT);
}

void loop()
{
  knock = analogRead(A1);
  if(knock>5)
  {
    digitalWrite(0, HIGH);
    delay(300);
    digitalWrite(0, LOW);
  }
}

The sketch is pretty straight forward … the variable knock is assigned the value of analogRead and, if it’s value is > 5 the ATTiny85 turns the LED on with digitalWrite, then waits 300 milliseconds, and then turns the LED off again with digitalWrite.

Tutorial10

You can see from the above image that the wiring is pretty straight forward. Top right of the breadboard is  the 5V regulator. The ATTiny85 was programmed using the ATTiny85 ICSP.

ATTiny85–Detecting Knocks and Vibrations with Freetronics “Sound” module

This is the 10th Freetronics Experimenters Kit tutorial that I’ve converted to the ATTiny85.

Check out the rest of the tutorials here.

No comments:

Post a Comment

Paypal Donations

Donations to help me to keep up the lunacy are greatly appreciated, but NOT mandatory.