prachi612
Published

Interactive Poster

A poster that changes content when the viewer gets closer. Using proximity sensors for distance and piezoelectric sensors to act as buttons.

IntermediateShowcase (no instructions)2 hours1,411
Interactive Poster

Things used in this project

Story

Read more

Schematics

Circuit diagram

Code

Processing JS

Processing
Uses the serial input from arduino to change the gallery from which photos are to be displayed. Each gallery has three images that are visible when the user is at three different distances from the sensor. The gallery can be changed by pressing the piezo sensors.
import processing.serial.*;
  

Serial myPort;  // Create object from Serial class
int val; // Data received from the serial port 
int num;
PImage img11;
PImage img12;
PImage img13;
PImage img21;
PImage img22;
PImage img23;
PImage img1d;
PImage img2d;
PImage img31;
PImage img32;
PImage img33;
PImage img3d;

int gallery=1;
String filename;


void setup() 
{
  size(1440, 800);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  //println(Serial.list());
  myPort = new Serial(this, portName, 9600);
  img11 = loadImage("testa.jpg");
  img12 = loadImage("testb.jpg");
  img13 = loadImage("testc.jpg");
  
  img21 = loadImage("teste.jpg");
  img22 = loadImage("testf.jpg");
  img23 = loadImage("testg.jpg");
  
  img11.resize(524, 742);
  img12.resize(524, 742);
  img13.resize(524, 742);
  
  img21.resize(524, 742);
  img22.resize(524, 742);
  img23.resize(524, 742);
  
  background(#000000);

}

void draw()
{
  if ( myPort.available() > 0)  // If data is available,
     {
       val = myPort.read();         // read it and store it in val
     }
     

     fill(#000000);

    if (val<75)
    {
switch (gallery){
  case(1):
        image(img11, 422, 0);
        break;
  case(2):
        image(img21, 422, 0);
        break;
}
    }
    
     else if (val<120)
    {
switch (gallery){
  case(1):
        image(img12, 422, 0);
        break;
  case(2):
        image(img22, 422, 0);
        break;
}
    }
    
     else if (val<170)
    {
switch (gallery){
  case(1):
        image(img13, 422, 0);
        break;
  case(2):
        image(img23, 422, 0);
        break;
}
    }
 
     else if (val > 200 ) {
       if (val==208) gallery=1;
       else if (val==232) gallery=2;
     }
}

Arduino

Arduino
Arduino code serial prints the distance that the ultrasonic measures at quick intervals along two specific numbers - 1000 & 2000 which indicate piezo button pressed.
/*
* PRACHI KNOCK + ULTRASONIC
*/

// defines pins numbers for ultrasonic
const int trigPin = 9;
const int echoPin = 10;


// defines variables for ultra
long duration;
int distance;

//const int knockSensor = A0;
const int project1 = A0;
const int project2 = A1;
const int threshold = 100;
int pr1 = 0;
int pr2 = 0;


void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}

void loop() {
 
// Clears the trigPin

digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculating the distance
distance= duration*0.034/2;

pr1 = analogRead(project1);
pr2 = analogRead(project2);
//Serial.print(pr1);
//Serial.print("\t");
//Serial.println(pr2);
//Serial.print("\n");

if (distance <= 150) 
{
  Serial.write(distance);
//  Serial.print(distance);
//  Serial.print("\n");
}
 
if (pr1 >= threshold){
  Serial.write(1000);
//  Serial.print(1000);
//  Serial.print("\n");
//  Serial.print(pr1);
//  Serial.print("\t");
}

if (pr2 >= threshold) 
{
  Serial.write(2000);
//  Serial.print(2000);
//  Serial.print("\n");
//  Serial.print(pr2);
//  Serial.print("\n");
}

delay(200);
}

Credits

prachi612

prachi612

1 project • 0 followers

Comments