ARDUINO KEYBOARD
OVERVIEW
Keyboard are great way to let user interacts with your project
In this tutorial,you will be constructing something called a resistor ladder.
DETAILS
This is a way to read a number of switches using the analog input. It’s a helpful
technique if you find yourself short on digital inputs. You’ll hook up a number of
switches that are connected in parallel to analog in 0. Most of these will connect
to power through a resistor. When you press each button, a different voltage level
will pass to the input pin. If you press two buttons at the same time, you’ll get a
unique input based on the relationship between the two resistors in parallel.This can be use for door bell
Wire up your breadboard with power and ground. Connect one end of the piezo to ground.
Connect the other end to pin 8 on your Arduino.
Place your switches on the breadboard as shown in the circuit.
The arrangement of resistors and switches feeding into an
analog input is called a resistor ladder. Connect the first one
directly to power. Connect the second, third and fourth switches
to power through a 220-ohm, 10-kilo ohm and 1-mega ohm resistor,
respectively. Connect all the switches’ outputs together in one
junction. Connect this junction to ground with a 10-kilo ohm
resistor, and also connect it to Analog In 0. Each of these acts as
a voltage divider.
COMPONENTS
Arduino Uno
Full Size Breadboard – 1
Piezzo buzzer – 1
Switches – 4
220-Ohms resistor — 1
10K ohm resistor – 2
1M ohm resistor – 1
Jumper wires
const byte KEYBOARD = A0; // connect keyboard to A0 const byte PIEZO_PIN =8; // connect buzzer to 8 // Global constants const int NOTES[] = { 262, 294, 330, 349 }; // C, D, E, F frequencies const unsigned int BAUD_RATE = 9600; // serial monitor's baud rate // Global variables unsigned int key_val; void setup() { Serial.begin(BAUD_RATE); // start the serial monitor pinMode(PIEZO_PIN, OUTPUT); // set PIEZO_PIN as OUTPUT } void loop() { // read and print KEYBOARD value key_val = analogRead(KEYBOARD); Serial.print("key_val = "); Serial.println(key_val); if (key_val >= 1019) { tone(PIEZO_PIN, NOTES[0]); // first switch ~ key C } else if ((key_val >= 990) && (key_val <= 1010)) { tone(PIEZO_PIN, NOTES[1]); // second switch ~ key D } else if ((key_val >= 505) && (key_val <= 515)) { tone(PIEZO_PIN, NOTES[2]); // third switch ~ key E } else if ((key_val >= 5) && (key_val <= 10)) { tone(PIEZO_PIN, NOTES[3]); // fourth switch ~ key F } else { noTone(PIEZO_PIN); // no switch ~ no sound } }
SCHEMATICS
CONCLUSION
We hope you enjoyed the tutorial and this little lesson will purport you into great levels. Enjoy yourself in electronics. For more tutorials and questions, please leave your comments in the comment area. See other components on the site www.inventelectronics.com. Inspiring ingenuity.