Friday 20 April 2012

Version 3 Development: the manual switch

To make a switch which closes when the bears hands close i will need two long wires to place within the bear, and two metal buttons or conductive fabric for the user to push and hold together.

Below is an annotated drawing of the teddy bear


Below is a description and drawings of how the manual switch should work as well as a component diagram.


To test this manual switch i built it on my breadboard. Below is a fritzing diagram of how this looks.

The code that i'll be using is simple pushbutton code. I am using an LED and the serial monitor.

The code checks to see if the circuit is closed, and turns the LED off if it is. It sends a '0' to the serial monitor if the circuit is open and a '1' if it is closed. It works perfectly.

 A larger surface area is required, so metal discs or conductive material will be used in the version 3 prototype once it is installed.

int indicatorVar = 0; //this is set to either 1 or 0 depending
//on if the circuit is close or open
//this will be useful in communicating with the other arduino

const int buttonPin = 2;     // the number of the pushbutton pin
//constant variable stay the same
const int ledpin = 7;

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

void setup() {
  // initialize the LED pin as an output:

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    
    pinMode(ledpin, OUTPUT);    
 Serial.begin(9600); //initialises the serial monitor
}

void loop(){

  buttonState = digitalRead(buttonPin);   // reads the state of the pushbutton value:
  Serial.println(indicatorVar); //this continuously prints the value of the status indicator

  //code to test whether circuit is closed or not
  if (buttonState == HIGH) {     
    // turn LED on:    
 digitalWrite(ledpin, HIGH); 

  indicatorVar = 0;
  } 
  else {
    // turn LED off:
  digitalWrite(ledpin, LOW); 
 indicatorVar = 1;
  }
}


How that this is working, i can move onto the next task: removing the delay and setting the system so that once it is pressed it stays on for a certain amount of time, then goes off. I will develop this on a single board then move it across to two boards.

No comments:

Post a Comment