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.
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.
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.
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