Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Thursday, July 28, 2016

Arduino Based 7 Segment Display Clock


I will show you how to make your own Arduino based 7 segment display (4 digits) clock with sound activation feature!!

The circuit uses the ATmega328p micro controller (the same as the Arduino UNO board) and the DS1302 clock IC. You can easily set/change the time by pressing the setup buttons. The clock can be activated by pressing an button or by making a sound (e.g. clap, blowing, whistle) near the microphone. It can be powered on with two AA batteries (3V) or with an USB cable from your computer (or cellphone's charger, max 5V).







Step 1: What You Need?

1 x USB Type-B Cable
1 x Computer with Arduino IDE installed
Male-to-Male Jumper Wires 
Female-to-Male Jumper Wires


Optional

2 x 1.5V AA Battery & 1 x 4xAA Battery Holder
1 x 9V Battery & 9V Battery Holder
1 x Mini Breadboard or Breadboard
4 Digits Segment LED
Cable Cover
Arduino Compatible UNO Ultimate Starter Kit / Learning Kit
USB To Power Jack Cable



Don't have components? Don't worry. Just click the component's name. 


Step 2: Build Your Circuit.



The connections are easy, see the image above with the breadboard circuit schematic.

Buttons:

  • Select/Set function button to Arduino pin A0
  • Change time/min function button to Arduino pin A1
  • Show time button to Arduino pin A2

Microphone:

DS1302:

LEDs:

7 segment displays:

Connect the same letters of 7 seg digits pins with others


Common cathode pins:

------------------------------------------

Tip: Make your circuit on breadboard first 



Step 3: Upload The Code To Board.




If you have any problems with sound activation feature change the values 660 and 750 (line 127):

if ((digitalRead(showBT) == LOW) || (sound<660 || sound>750))


Step 4: Make The Box.

I used plexiglass pieces to build my clock box.




Step 5: Done!!

You have successfully completed this guide and now you have your own Arduino clock with sound activation feature in your desk!
7 segment display Arduino UNO R3 button clock DS1302 easy LED mic project

Thursday, July 14, 2016

State Change Detection (Edge Detection) for pushbuttons


Once you've got a pushbutton working, you often want to do some action based on how many times the button is pushed. To do this, you need to know when the button changes state from off to on, and count how many times this change of state happens. This is called state change detection or edge detection. In this tutorial we learn how to check the state change, we send a message to the Serial Monitor with the relevant information and we count four state changes to turn on and off an LED.

Step 1: What You Need?

1 x Arduino Board (Arduino UNO used in this tutorial)
1 x 10k ohm resistor
1 x Button / Toggle Switch 
1 x Breadboard
Male-to-Male Jumper Wires 

Optional 
1 x LED(RED)
1 x 220 Ohm Resistor 

Don't have components? Don't worry. Just click the component's name. 

Step 2: Build Your Circuit.

Connect three wires to the board. The first goes from one leg of the pushbutton through a pull-down resistor (here 10k ohm) to ground. The second goes from the corresponding leg of the pushbutton to the 5 volt supply. The third connects to a digital I/O pin (here pin 2) which reads the button's state.

Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.



2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.

Select the right port: Tools >> Port >> Select the port number.


3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 02.Digital >> StateChangeDetection

Click press the "upload" button (see the button with right arrow mark).

Step 4: Test Your Circuit.

When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to voltage, so that we read a HIGH. (The pin is still connected to ground, but the resistor resists the flow of current, so the path of least resistance is to +5V.)

If you disconnect the digital I/O pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, not connected to either voltage or ground. It will more or less randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit.

Arduino Arduino UNO R3 Basic button LED library

Input Pullup Serial


This example demonstrates the use of INPUT_PULLUP with pinMode(). It monitors the state of a switch by establishing serial communication between your Arduino and your computer over USB.

Additionally, when the input is HIGH, the onboard LED attached to pin 13 will turn on; when LOW, the LED will turn off.



Step 1: What You Need?

1 x Arduino Board (Arduino UNO used in this tutorial)
1 x Button / Toggle Switch 
1 x Breadboard
Male-to-Male Jumper Wires 

Optional 
1 x LED
1 x 220 Ohm Resistor 

Don't have components? Don't worry. Just click the component's name. 

Step 2: Build Your Circuit.


Connect two wires to the Arduino board. The black wire connects ground to one leg of the pushbutton. The second wire goes from digital pin 2 to the other leg of the pushbutton.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. Because the internal pull-up on pin 2 is active and connected to 5V, we read HIGH when the button is open. When the button is closed, the Arduino reads LOW because a connection to ground is completed.


Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.

2.  Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3. 

Select the right port: Tools >> Port >> Select the port number.


3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 02.Digital >> DigitalInputPullup

Click press the "upload" button (see the button with right arrow mark).


In the program below, the very first thing that you do will in the setup function is to begin serial communications, at 9600 bits of data per second, between your Arduino and your computer with the line:
Serial.begin(9600);

Next, initialize digital pin 2 as an input with the internal pull-up resistor enabled:
pinMode(2,INPUT_PULLUP);

The following line make pin 13, with the onboard LED, an output :

pinMode(13, OUTPUT);

Now that your setup has been completed, move into the main loop of your code. When your button is not pressed, the internal pull-up resistor connects to 5 volts. This causes the Arduino to report "1" or HIGH. When the button is pressed, the Arduino pin is pulled to ground, causing the Arduino report a "0", or LOW.

The first thing you need to do in the main loop of your program is to establish a variable to hold the information coming in from your switch. Since the information coming in from the switch will be either a "1" or a "0", you can use an int datatype. Call this variable sensorValue, and set it to equal whatever is being read on digital pin 2. You can accomplish all this with just one line of code:

int sensorValue = digitalRead(2);

Once the Arduino has read the input, make it print this information back to the computer as a decimal (DEC) value. You can do this with the command Serial.println() in our last line of code:

Serial.println(sensorValue, DEC);

Now, when you open your Serial Monitor in the Arduino environment, you will see a stream of "0"s if your switch is closed, or "1"s if your switch is open.

The LED on pin 13 will illuminate when the switch is HIGH, and turn off when LOW.




Arduino Arduino UNO R3 Basic button library

Debounce


Pushbuttons often generate spurious open/close transitions when pressed, due to mechanical and physical issues: these transitions may be read as multiple presses in a very short time fooling the program. This example demonstrates how to debounce an input, which means checking twice in a short period of time to make sure the pushbutton is definitely pressed. Without debouncing, pressing the button once may cause unpredictable results. This sketch uses the millis() function to keep track of the time passed since the button was pressed.

Step 1: What You Need?

1 x Arduino Board (Arduino UNO used in this tutorial)
1 x 10k ohm resistor
1 x Button / Toggle Switch 
1 x Breadboard
Male-to-Male Jumper Wires 

Optional 
1 x LED(RED)
1 x 220 Ohm Resistor 

Don't have components? Don't worry. Just click the component's name. 

Step 2: Build Your Circuit.



Connect three wires to the board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10k ohm) to ground. The other leg of the button connects to the 5 volt supply of Arduino board.


Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.




2.  Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3. 

Select the right port: Tools >> Port >> Select the port number.


3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 02.Digital >> Debounce

Click press the "upload" button (see the button with right arrow mark).

The sketch is based on Limor Fried's version of debounce, but the logic is inverted from her example. In her example, the switch returns LOW when closed, and HIGH when open. Here, the switch returns HIGH when pressed and LOW when not pressed.


Arduino Arduino UNO R3 Basic button library

Button


Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button.



Step 1: What You Need?

1 x Arduino Board (Arduino UNO used in this tutorial)
1 x 10k ohm resistor
1 x Button / Toggle Switch 
1 x Breadboard
Male-to-Male Jumper Wires 

Optional 
1 x LED(RED)

1 x 220 Ohm Resistor 

Don't have components? Don't worry. Just click the component's name. 

Step 2: Build Your Circuit.


Connect three wires to the board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10k ohm) to ground. The other leg of the button connects to the 5 volt supply of Arduino board.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that the pin reads as HIGH, or 1.

If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it doesn't have a solid connection to voltage or ground, and it will randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit.


Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.


2.  Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3. 

Select the right port: Tools >> Port >> Select the port number.



3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 02.Digital >> Button

Click press the "upload" button (see the button with right arrow mark).

Arduino UNO R3 Basic button library

Digital Read Serial


This example shows you how to monitor the state of a switch by establishing serial communication between your Arduino and your computer over USB.

Step 1: What You Need?

1 x Arduino Board (Arduino UNO used in this tutorial)
1 x 10k ohm resistor
1 x Button / Toggle Switch 
1 x Breadboard
Male-to-Male Jumper Wires 

Don't have components? Don't worry. Just click the component's name. 

Step 2: Build Your Circuit.


Connect three wires to the board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10k ohm) to ground. The other leg of the button connects to the 5 volt supply of Arduino board.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that the pin reads as HIGH, or 1.

If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it doesn't have a solid connection to voltage or ground, and it will randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit.


Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used. 


2.  Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3. 

Select the right port: Tools >> Port >> Select the port number.



3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 01.Basics >> DigitalReadSerial


Click press the "upload" button (see the button with right arrow mark).

In the program below, the very first thing that you do will in the setup function is to begin serial communications, at 9600 bits of data per second, between your board and your computer with the line:
Serial.begin(9600);

Next, initialize digital pin 2, the pin that will read the output from your button, as an input:

pinMode(2,INPUT);

Now that your setup has been completed, move into the main loop of your code. When your button is pressed, 5 volts will freely flow through your circuit, and when it is not pressed, the input pin will be connected to ground through the 10k ohm resistor. This is a digital input, meaning that the switch can only be in either an on state (seen by your Arduino as a "1", or HIGH) or an off state (seen by your Arduino as a "0", or LOW), with nothing in between.

The first thing you need to do in the main loop of your program is to establish a variable to hold the information coming in from your switch. Since the information coming in from the switch will be either a "1" or a "0", you can use an int datatype. Call this variable sensorValue, and set it to equal whatever is being read on digital pin 2. You can accomplish all this with just one line of code:

int sensorValue = digitalRead(2);

Once the bord has read the input, make it print this information back to the computer as a decimal value. You can do this with the command Serial.println() in our last line of code:

Serial.println(sensorValue);

Now, when you open your Serial Monitor in the Arduino Software (IDE), you will see a stream of "0"s if your switch is open, or "1"s if your switch is closed.

Download: 

Arduino software

Sources:[https://www.arduino.cc/en/Tutorial/DigitalReadSerial]
Arduino Arduino UNO R3 Basic button library

Sunday, July 10, 2016

Electronic Safe with Arduino



This project includes a 6 digit password (123142), that must be entered if you want to unlock the safe. There are 4 buttons to submit characters (1, 2, 3 or 4), an enter button, and a clear screen/ lock screen button. When the safe is unlocked, it will remain unlocked until the button to lock it is pressed. 


The locking mechanism is simple - a servo motor is mounted to the shoe box, and a slit is cut in the shoe box and the door flap. When in the locked position, the motor is turned in between the openings, making it not possible to open. 


Step 1: What You Need?

Electronic Parts List:
1 x Arduino UNO R3 
2 x Mini Breadboard 
1 x 9V Battery 
1 x 9V Battery Snap 
1 x Standard Servo Motor
1 x 100uF Capacitor 
1 x 220 Ohm Resistor
6 x Push Buttons 
1 x 16x2 LCD Screen 
Jumper Wires (30) 

Other Parts:
5 x Washer
1 x Plastic Washer
5 x Screw 
5 x Nut
1 x Shoe Box
1 x 3/4th inch Conduit Strap 
Spare Cardboard 
Duct Tape

Tools:
Screwdriver 
Ruler 
Knife/Blade

All the electronic parts can be found at Robotshop at lelong or just click the components' name.
 

Step 2: Upload The Code.

(NOTE: Don't forget to set your own password.)

Step 3: Attaching The Buttons.

There are 6 buttons in this project - 4 buttons to type in a password, 1 button to enter it, and 1 button to clear the screen or lock the door. 
Connect a wire from the GND pin of Arduino UNO to a ground strip on the breadboard. Then, connect each button to that ground strip. After that, connect each button to PWM pins on the Arduino UNO as shown.

 Step 4: Powering The LCD Screen.  

The next step here would be to attach the LCD screen. Send a wire from the 5V on the Arduino UNO to the positive rail on the breadboard, and then attach the pins to the ground and power rails as shown. 

  

Step 5: Connecting LCD Screen To Arduino. 

Now, you need to connect the screen to the Arduino PWM pins. The LCD screen will display what you typed in with the buttons in real time.  


Step 6: Connect The Servo Motor. 

The Servo Motor is what will lock and unlock the safe. You have the same on as me, the wires are grouped to a three piece ribbon cable, and there are female headers on the end. You can solder male pins to them, but I chose not to for this project because I needed the wires to reach farther. So, plug in 3 jumper cables to the female pins. Send the red and black to separate power and ground rails than everything else (as shown), and the white cable to Analog Pin 1. make sure to use a 100uF capacitor between that power and ground rail. 



Step 7: Mount Everything.
Now, you have assembled the circuit and you have the code. The next step is to mount everything to the shoe box. 




Download: 

Arduino software


Source:[https://create.arduino.cc/projecthub/chummer1010/electronic-safe-with-arduino-25d039?ref=platform&ref_id=424_trending___&offset=48]
Arduino Arduino UNO R3 button easy LCD lock servo motor

 

  • Copyright © Arduino Tutorial ™ is a registered trademark.
    Designed by Templateism. Hosted on Blogger Templates.