Lab submission 4 - Photocell and FSR

Submitted by stlim on Mon, 02/25/2013 - 22:26

Description

A chain reaction system of FSR - LED - photocell - LED is implemented on an arduino board. As an FSR senses pressure, a red LED turns on. A photocell by the LED senses the LED's brightness and a blue LED turns on.

 

The final step of the chain reaction is represented as telegraph signals on processing. It displays Morse code from the FSR telegraph.

 

Video Demo

http://youtu.be/IotCFvzf9ik

 

Components Used

- 1 red LED
- 1 blue LED
- 2 220  ohm resistor
- 2 10k ohm resistor
- 1 photocell
- 1 force sensitive resistor
- 1 Arduino Uno board
 

Arduino Code: Chain Reaction

 

 

int photocellPin = 0;   // select the input pin for the potentiometer
int fsrPin = 5;
int bPin = 9;
int rPin = 10;   // select the pin for the LED
 
int fsrVal;
int photocellVal;      // variable to store the value coming from the sensor
 
int counter;
 
int THRESHOLD = 500;
 
void setup() {
  photocellVal = 0;
  fsrVal = 0;
  counter = 0;  
  Serial.begin(9600);
}
 
void loop() {
  fsrVal = analogRead(fsrPin);    // read the value from the sensor, between 0 - 1024
 
  analogWrite(rPin, fsrVal/4);
  
  photocellVal = analogRead(photocellPin);
  
  if(photocellVal>THRESHOLD)
  {
    analogWrite(bPin, photocellVal/4);
    if(counter%300==0)
    {
//      Serial.print(photocellVal);
      Serial.print("1");
    }
  }
  else
  {
    analogWrite(bPin, 0);
    if(counter%300==0)
    {
      Serial.print("0");
    }
  }
  
  counter++;
}
 

Processing Code: Telegraph

 

 

import processing.serial.*;
 
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbmodem411";
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
 
int radius = 50;
int gapX = 1;
int gapY = 3;
int windowX = 1200;
int windowY = 720;
int marginX = 40;
int marginY = 40;
int x = marginX;
int y = marginY;
 
boolean gap = false;
boolean init = true;
 
void setup() {
  size(windowX, windowY);
  frameRate(24);
  smooth();
  background(40,40,40);
  noStroke();
  port = new Serial(this, portname, 9600); 
}
void draw() {
}
 
/*void keyPressed() {
  if(key == ' ') {
    background(40,40,40);  // erase screen
  }
  else {
    int x = int(random(0,width));
    int y = int(random(0,height));
    drawball();
  }
}*/
 
// draw balls
void drawball() {
  ellipse(x,y,radius,radius);
  x+=3;
//  x += 2*radius + gapX;
  
  if(x>windowX-marginX) {
    x = marginX;
    y += 2*radius + gapY;
  }
}
// called whenever serial data arrives
void serialEvent(Serial p) {
  int c = port.read();
  
  if(c=='0' && init) {
  }
  else if(c=='0') {
    if(!gap) {
      x += 2*radius + gapX;
    }
    
    gap = true;
  }
  else {
    init = false;
    gap = false;
    drawball();
    x+=radius/5;
  }
}
0
Your rating: None
Drupal theme by Kiwi Themes.