Pololu + LCD display

An external power supply is connected to a pololu power switch. The power switch is then connected to pin 7 on the arduino and the external power connecter for the arduino board. A button, which is connected to the pololu power switch, is set to the normally open setting. When the button is pushed, the pololu switch is connected and supplies power to the arduino board. The sketch then displays a message on the LCD screen. After 10 seconds, pin 7 is set to HIGH, which turns the pololu switch off, severing the connection to the power supply and turning the arduino off.

Posted in Uncategorized | Leave a comment

Button Switch

In the previous post, I learned how to wire a button to control an LED. However, this sample was limited because the state of the button directly controlled the state of the LED.

I wish to have the LED turn on/off each time a button is pressed and released. The wiring remains the same, however its the logic of the programming that can now solve the problem.

As you can see, it works pretty well.  Source code, as always, can be found at the bottom of this post. Here are the improvements:

I added a boolean variable called tester. Each time the light toggles on/off, so does the variable toggle true/false. In this way we can keep track of the state of the LED.

Since the arduino runs in an infinite loop, if the button is held down long enough, the status of the light changes back and forth. This is not wanted. Therefore I put in the while loop to delay and check the status of the button.  This way, the status of the light changes the moment the button is depressed, and no matter how long it is held, it will not affect the LED.


/*

ButtonSwitch

Button presses toggle an LED on/off.

The circuit:

* LED attached from pin 13 to ground

* pushbutton attached to pin 2 from +5V

* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board

attached to pin 13.

created 5/16/2010

Jordan LeGrand

https://arduinostudy.wordpress.com

This is a modification of the sample button sketch bundled with the arduino IDE.

*/

// constants won't change. They're used here to

// set pin numbers:

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  13;      // the number of the LED pin

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

boolean tester =false;       // variable storing the state of the LED (false = off, true = on)

void setup() {

// initialize the LED pin as an output:

pinMode(ledPin, OUTPUT);

// initialize the pushbutton pin as an input:

pinMode(buttonPin, INPUT);

}

void loop(){

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin);

//if the button is pressed...

if (buttonState == HIGH) {

//if the light is currently on, turn it off, and set the boolean to false.

if (tester == true){

digitalWrite(ledPin,LOW);

tester = false;

}

//if the light is off, turn it on, and set the boolean to true.

else{

digitalWrite(ledPin,HIGH);

tester = true;

}

//while the button is held down, pause the main loop until it is released.

while(buttonState==HIGH){

delay(10);

buttonState=digitalRead(buttonPin);

}

}

}

Posted in Uncategorized | Leave a comment

Button: Normally Open vs. Normally Closed

The button I had purchased has two wiring options: Normally Open and Normally Closed (NO and NC). The following video demonstrates the results of each wiring scenario.

With NO, the circuit is open by default. When the button is fully depressed and held, the circuit is closed and the light will come on. With NC, the opposite is true. The light is always on, and only turns off when the button is fully depressed.

The code from this sketch is a sample code that came bundled with the Arduino IDE. You can find the code at the end of this post.

Circuit Design:

An LED is connected to the digital 13 pin  and ground. The button is connected to the digital 2 pin and ground via a 10k amp resistor.

Here is a picture:

Here is the code:

/*

Button

Turns on and off a light emitting diode(LED) connected to digital

pin 13, when pressing a pushbutton attached to pin 7.

The circuit:

* LED attached from pin 13 to ground

* pushbutton attached to pin 2 from +5V

* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board

attached to pin 13.

created 2005

by DojoDave <http://www.0j0.org>

modified 17 Jun 2009

by Tom Igoe

http://www.arduino.cc/en/Tutorial/Button

*/

// constants won't change. They're used here to

// set pin numbers:

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  13;      // the number of the LED pin

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

// initialize the LED pin as an output:

pinMode(ledPin, OUTPUT);

// initialize the pushbutton pin as an input:

pinMode(buttonPin, INPUT);

}

void loop(){

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.

// if it is, the buttonState is HIGH:

if (buttonState == HIGH) {

// turn LED on:

digitalWrite(ledPin, HIGH);

}

else {

// turn LED off:

digitalWrite(ledPin, LOW);

}

}

Posted in Uncategorized | Leave a comment

Introduction

Welcome! Over the next few months I will be delving into the realm of Arduino Microcontrollers. Each time I learn something new, I will post a detailed writeup explaining the principles, wiring, and code used to complete the task. The goal of each mini project is to gain a firm grasp on a tool required for my final project.

Taking inspiration from Mikal Hart’s Reverse Geocache Puzzle, I wil be constructing a gps scavenger hunt. Upon completion, the box will be locked from the inside out. An LCD screen will read a current clue and the arduino will read a gps signal, and determine if the box is in the appropriate location. If so, the screen will display the next clue. Upon completion of the final clue, the box will be unlocked, and the user will receive a prize.

Posted in Uncategorized | Leave a comment