This sketch shows how to connect a GSR sensor (in this case penny) to Arduino. I recommend using a 10k resistor for this setup.
GSR connections sketch
Posted in arduino, sketch
Leave a comment
Arduino code for bluetooth
// based on Dan O’Sullivan’s code
int gsr;
void setup() {
Serial.begin(9600);//Serial.println(“Start”);
}
void loop() {
gsr = analogRead(0);// reads gsr data
Serial.println(gsr); // prints the data in serial port
Serial.flush(); // flushes the data
delay(200); // delay for 200 milisec. You can adjust this according to your needs, but don’t make it to fast. If you //are not using handshaking method or delay, bluetooth locks itself.
}
int xr;
void setup() {
Serial.begin(9600);
//Serial.println(“Start”);
}
void loop() {
//if (Serial.available() ){
//Serial.read();
xr = analogRead(0);
Serial.println(xr);
//Serial.write();
Serial.flush();delay(200);//}
}
simple Processing serial read
//this is based on simple read example on processing.
import processing.serial.*; //includes serial library to processing
Serial myPort; // Create object from Serial class
int val = 0; // Data received from the serial port
int preVal = 0; //stores the previous sensor data
int xCoor = 0 ;//x coordinate for drawing line
int preXCoor = 0;//previous x coordinate for drawing line
void setup()
{
size(900, 900); //size of the sketch
// 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.
//println(Serial.list());//if you want to see possible ports that you can use you can use this line
String portName = Serial.list()[0];//we are connecting to port “0″
myPort = new Serial(this, portName, 9600);//this should match with Arduino’s baudrate
}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
// background(255); // Set background to white
xCoor++; //x position increases one pixel
line(preXCoor, preVal, xCoor, val); //draws a line graph //line(x1, y1, x2 , y2)
if( xCoor > 900){// if line is out of the screen cleans the screen and starts from zero
xCoor = 0;
background(255);
}
preXCoor = xCoor; //x coordinate stored, we will use it as previous coordinate in the next frame.
preVal = val; //val stored, we will use it as previous val in the next frame.
//if you want to draw a rectangle that changes it’s color according to sensor values, comment out the line and //include fill and rect.
//fill(val*10,val*20, val);//”10″ and “20″ added randomly, you can change them to have different colors
// rect(50, 50, 100, 100);
}
}
simple Arduino analog input
int sensorPin = 0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600); //starts the serial communication and defines the boudrate as 9600
}
void loop() {
sensorValue = analogRead(sensorPin);// read the value from the sensor:
sensorValue = (sensorValue/4);//sensor values are between 0-1023 , but we are sending them as bytes. So //simply diving them with 4 will keep the range between 0-255
Serial.print(sensorValue,BYTE);//sends sesnor values to serial port
delay(100);//100 milliseconds of delay, you can adjust this to according to your needs.
}