Assignment 11: Input Devices

As an input device I used a piezo disk. I connected the piezo to an unused pin PB3 of the ATtiny45. The 1M resistor to the ground keeps the input low if the piezo is still. I also connected the pin PB4 via a capacitor to the piezo. The Idea was, that the piezo works as a knock sensor, and if it detects a knock or vibration, the same piezo can be used as a buzzer by driving it via a capacitor. So, pin PB3 is input, and PB4 is output. The 4-pin connector can be used for other sensors too.




The outcome? The concept works. When I tap the piezo, it beeps. This was recorded with my mobile phone. I can hear the beep at least from 10 meters away.
Actually it could be louder. If the direction of the originally an input pin is changed to an output, the piezo could be driven by two pins with opposite phases.
Now the piezo is off half the time.

The python software for the light sensor was applicable here. I had to start Ubuntu linux in a VMWare virtual machine to have python programming tools. The first run of the python program gave an error indicating that python-tk package was missing. After installing it:
sudo apt-get install python-tk
I got the indicator bar.


I edited the code for the light sensor:

#define piezo_pin_out (1 << PB4)
...
// if the value exceeds a preset limit, make some noise
        chr = ((chrh << 8) + chrl);        // combine high and low bits
        if (chr > 255) {
            for (i = 0;i < 300 ; i++) {
                PORTB |= (piezo_pin_out);
                _delay_us(100);                // these delays make a nice and irritating beep of 5 kHz
                PORTB &= ~(piezo_pin_out);
                _delay_us(100);
            }
        }


Files:
Schema
Layout
Code


Home