Advice 1: How to connect a piezo buzzer (petapixel) to Arduino

To generate sound with Arduino a variety of ways. The simplest way to connect a piezo buzzer to the Board (or plesiopidae). But as always, there is nuances. In General, let's deal.
Connect the piezo buzzer to the Arduino
You will need
  • Computer;
  • - Arduino;
  • - piezo (plesiopidae).
Instruction
1
Piezo buzzer, or piezoelectric transducer, or plesiopidae is electroacoustic audio playback device that uses the reverse piezoelectric effect. If to explain in simple words - under the influence of an electric field occurs mechanical movement of the membrane, which causes us audible sound waves. Typically, these sound emitters are installed in household electronics as a sound alarm, in case of desktop personal computers, phones, toys, loudspeakers and many far more.
The piezo has 2 output, and the polarity matters. So the black terminal is connected to ground (GND) and the red to any digital pins with PWM function (PWM). In this example, the positive terminal of the emitter is connected to pin D3.
Connecting to Arduino petapixel
2
Petapixel you can use in different ways. The simplest way is to use the function analogWrite. An example of a sketch in the illustration. This sketch alternately enables and disables the sound with a frequency of 1 time per second.
Set a room pin, define it as an output. The function analogWrite() takes as arguments the number of output and the level can be from 0 to 255. This value will change the volume of petapixel within a small range. Sending to the port a value of "0", turn off petapixel.
Unfortunately, to change the tone of the sound using the function analogWrite(), it is impossible. The piezo will always sound at a frequency of approximately 980 Hz, which corresponds to the frequency-to-pulse-width modulated signal (PWM) on the Arduino UNO and the like.
Use the built-in function "analogWrite()"
3
Now extract the sound from the piezo via the built-in tone(). An example of a simple sketch is shown in the illustration.
Tone function takes as arguments the number of the pin and the audio frequency. The lower limit of the frequency - 31 Hz, the upper limit is restricted by the parameters of the piezo oscillator and the human ear. To mute the sound that is sent in the port command, not one().
Please note that if the Arduino is connected to several pietistically, a lump sum will work only one. To turn the emitter on the other conclusion, you need to interrupt the sound at the current, causing the function not one().
Important point: tone() is superimposed on the PWM signal to "3" and "11" the findings of the Arduino. Keep this in mind when you design your device, because the function tone(), caused by, for example, for Pina "5", can interfere with the conclusions "3" and "11".
Use the built-in function "tone()"

Advice 2: How to connect a LCD display for Nokia 5110 for Arduino

Deal with connecting a LCD monochrome display with a resolution of 84х48 points from the Nokia 5110 to the Arduino.
LCD screen for Nokia 5110
You will need
  • - Arduino;
  • LCD display for Nokia 5110/3310;
  • - connecting wires.
Instruction
1
Connect LCD from Nokia 5110 Arduino according to the diagram above.
Connection diagram of LCD screen Nokia 5110 for Arduino
2
To work with this LCD screen written a lot of libraries. I suggest to use this: http://www.rinkydinkelectronics.com/library.php?id=44 (the downloading of the file LCD5110_Basic.zip).
To install rotaryforum the file to the directory of Arduino IDE/libraries/.
The library supports the following features.
LCD5110(SCK, MOSI, DC, RST, CS); - the announcement LCD screen showing the matching Arduino pins;
InitLCD([contrast]); - initialization of the 5110 display with optional indication of the contrast (0 to 127), the default value is 70;
setContrast(contrast); sets the contrast (0 to 127);
enableSleep(); - puts the screen to sleep mode;
disableSleep(); - displays a screen from sleep mode;
clrScr(); - clears the screen;
clrRow(row, [start], [end]); - clear the selected line number of the row, from position start to end;
invert(true); invert(false); - disabling and enabling the inversion of the contents of the LCD screen;
print(string, x, y); - displays the character string with the specified coordinates; the x-coordinates you can use LEFT, CENTER and RIGHT; the height of the standard font is 8 points, so the line should go, with intervals of 8;
printNumI(num, x, y, [length], [filler]); - print the number on the screen at the given position (x, y); length - the desired length of the number; filler - the character to fill the "voids" if the number is less than the desired length; the default is an empty space " ";
printNumF(num, dec, x, y, [divider], [length], [filler]); - display a floating-point number; dec - number of decimal places divider - sign decimal separator, by default a period ".";
setFont(name); - choose the font; the built-in font called SmallFont and TinyFont; you can define your fonts in the sketch;
invertText(true); invertText(false); - invert text on/off.off;
drawBitmap(x, y, data, sx, sy); - bring a picture to the screen coordinates x and y; data - an array containing the image; sx and sy are the width and height of the picture.
3
Write this sketch. First, attach the library, then declare an instance of the class LCD5110 with the terminal assignment.
In the procedure setup() initialize the LCD screen.
In the procedure loop() clear the screen and write in the small print arbitrary text underneath - medium font, display seconds counter.
The sketch to display text on the LCD screen Nokia 5110
4
Let's display picture. To do this, prepare a monochrome image that you want to display Nokia 5110. Remember that the screen resolution is 48 by 84 points, and the picture should be no more. On the page http://www.rinkydinkelectronics.com/t_imageconverter_mono.php convert image to array of bits. Download the resulting file with the extension "*.c" and add it to the project via the menu: Sketch -> Add file... or just put the file in the sketch directory, and then restart the Arduino development environment IDE.
Add the image file to the Arduino project
5
Now we need the code to declare an array with the image data (in my code this line extern uint8_t mysymb[];) and then use the function drawBitmap() to display the image in the desired location on the screen.
Output to LCD Nokia 5110
6
Upload the sketch in Arduino. Now the text is replaced by the picture, and every time the counter increases its value.
Text and image on the LCD screen Nokia 5110
Search
Is the advice useful?