View the Project on GitHub tahafarhan1/PHY-S-12-DOCUMENTATION
by
In this lab session our assignment was to build a circuit that included any sensor of our choice and to show its readings via the serial plotter on the Arduino app.
In the previous class on the 18th we had constructed circuits that used two copper foils and the serial plotter was showing the electric field between them. The graph was showing deviations whenever the two foils were rubbed on each other or were moved. Even the slightest movements were showing big deviations on the plotter. The code we used is available below.
#include <CapacitiveSensor.h>
CapacitiveSensor Sensor = CapacitiveSensor(7,5);`
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
long sensorValue = Sensor.capacitiveSensor(300);
Serial.println(sensorValue);
// if (sensorValue > 100) analogWrite(11,100);
//else analogWrite(11,0);
delay(10);
}
Unfortunately, I did not make a video of the plot or the circuit that I used.
On the 22nd I constructed a basic circuit at first which consisted of a Piezoelectric sensor that was taped on a piece of plywood. It was measuring vibrations whenever I tapped the sensor or struck the wood. A Piezoelectric sensor is basically a device that measures changes in pressure or force by converting them into an electrical charge. The code I used for this is the same as the following code except I did not use the if/else and the delay.
After I had successfully built this circuit I began to add more components and make it more advanced. I added an LED, a couple of resistors and an if/else loop into the code. The LED was programmed to turn on whenever the charge exceeded 670 on the plotter. When I first set it up, the charge was exceeding the threshold but the LED was not turning on. This was because the charge only went up for a split second so the LED was not lighting up. Because of this, I inserted a 1000 milisecond delay into the code that made the LED remain on for a second after the charge fell below 670. The code I used for can be seen below.
int N=1;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
float sum = 0;
for (int i = 0; i < N; ++i) {
int val = analogRead(0);
sum += val;
}
sum /= N;
Serial.println(sum);
if (sum > 670) {
digitalWrite(3,HIGH);
delay(1000) ;
else {
digitalWrite(3,LOW);
}
}\
The following video shows how the LED was flashing when the threshold was crossed. The LED was faint so you will have to look at the breadboard closely.
This device can be used as a Seismic activity detector that will flash once vibrations are detected.
tags: