Posts

Showing posts from October, 2018

Seismic Code

/* determines the times of possible seismic events. */ #include <stdio.h> #define FILENAME "seismic1.txt" #define MAX_SIZE 1000 float THRESHOLD = 0; int x = 0; int main(void) { /* Declare variables and function prototypes. */ while(THRESHOLD <=2 1){ printf("Enter Threshold: \n"); scanf(" %f ", &THRESHOLD); printf("Threshold: %f \n", THRESHOLD); } int k, npts, short_window, long_window; double sensor[MAX_SIZE], time_incr, short_power, long_power, ratio; FILE *file_ptr; double power_w(double *ptr,int n); /* Read sensor data file. */ file_ptr = fopen(FILENAME,"r"); if (file_ptr == NULL) printf("Error opening input file. \n"); else { fscanf(file_ptr,"%d %lf",&npts,&time_incr); if (npts > MAX_SIZE) printf("Data file too large for array. \n"); else { /* Read data into an array. */ for (k=0; k<=npts-1; k++) fscanf(file_ptr,"%l...

Temperature Sensor + Potentiometer

const int POT = 0; double val = 0; double voltage = 0; float temp = 0; int red = 7; int green = 6; int blue = 5; void setup() {   // put your setup code here, to run once:  Serial.begin(9600); } void loop() {   // put your main code here, to run repeatedly:  val = analogRead(A0);  voltage = (val)*5;  temp = (voltage-500)/10;  Serial.println(val);  delay(500);  if (val<140){   digitalWrite(blue, HIGH);    }  else if (140<=val<= 150){     digitalWrite(green, HIGH);    }   if (150 < val){   digitalWrite(red, HIGH);  } }

I^2C Temperature Sensor Configured with LCD screen and Buttons

//Reads Temp from I2C temperature sensor and prints it on the serial port //Include Wire I2C library #include <Wire.h> #include <LiquidCrystal.h> //Initialize the library with the numbers of the interface pins LiquidCrystal lcd(8, 9, 4, 5, 6, 7); int temp_address = 72; //1001000 written as decimal number int speaker = 8; void setup() {  //Start serial communication at 9600 baud Serial.begin(9600);  //Create a Wire object  Wire.begin();  lcd.begin(16,2); } void loop() {  //Send a request//Start talking to the device at the specified address  Wire.beginTransmission(temp_address);  //Send a bit asking for register zero, the data register  Wire.write(0);  //Complete Transmission  Wire.endTransmission();  //Read the temperature from the device  //Request 1 Byte from the specified address  Wire.requestFrom(temp_address, 1);  //Wait for response  while(Wire.available() == 0); ...

Inclinometer Sketch

#include <math.h> #include <LiquidCrystal.h> LiquidCrystal lcd(8, 9, 4, 5, 6, 7); const int xpin = A2; // x-axis of the accelerometer const int ypin = A1; // y-axis const int zpin = A3;// z-axis int x_data; int y_data; int z_data; float x_rad; float y_rad; float degree; unsigned long time; void setup() {  // initialize the serial communications:  Serial.begin(57600);  lcd.begin(16,2);  lcd.print("Angle:"); } void loop() {  x_data = analogRead(xpin);  y_data = analogRead(ypin);  z_data = analogRead(zpin); // // /*time = millis(); //// //// Serial.print(time); //prints time since program started //// ////Serial.print("\t"); */ // // // print the sensor values: // // // // print a tab between values: // // Serial.print(x_data); // // Serial.print("\t"); // // // // // print a tab between values: // // Serial.print(y_data); // // Serial.print("\t"); // Serial.println(z_data); ...

Peaks And Valleys Code

#include <stdio.h> #include <math.h> #define N 25 #define FILENAME "grid1.txt" int main(void) { /* Declare variables. */ int nrows, ncols, i, j, num_peaks=0, num_valleys = 0; int highest, lowest; int row_highest, row_lowest, col_highest, col_lowest; double location =0; double elevation[N][N]; FILE *grid; /* Read information from a data file. */ grid = fopen(FILENAME,"r"); if (grid == NULL) printf("Error opening input file\n"); else { fscanf(grid,"%d %d",&nrows,&ncols); for (i=0; i<=nrows-1; i++) for (j=0; j<=ncols-1; j++) fscanf(grid,"%lf",&elevation[i][j]); /* Determine and print peak locations. */ printf("Top left point defined as row 0, column 0 \n"); for (i=1; i<=nrows-2; i++){ for (j=1; j<=ncols-2; j++){ if ((elevation[i-1][j]<elevation[i][j]) && (elevation[i+1][j]<elevation[i][j]) && (elevation[i][j-1]<elevation[i][j]) && (...

Balloon Code

#include <stdio.h> #include <math.h> #define PI 3.141593 #define FILENAME "data.txt" int main(void) { /*  Declare variables.  */     double t; double inc_time; double altitude, velocity; int x =0; int i; int end, start, status; float al, vel; char m;     printf("Enter start time (hrs) and end time\n "); scanf(" %i %i", &start, &end);     printf("Enter time increment \n"); scanf(" %lf",&inc_time); while (start >48 || start<0 || end<0|| (end<=start) || end>48 || inc_time>48){ printf("Error: Please input within range 0-48 hrs, and endtime>starttime) \n"); printf("Enter start time (hrs) and end time\n "); scanf(" %i %i", &start, &end);      printf("Enter time increment \n"); scanf(" %lf",&inc_time);     }   FILE *data; /*  Open output file.  */ data = fopen(FILENAME,"w...

ENSO code

#include <stdio.h> #include <math.h> #define FILENAME "ENSO1.txt" #define MAX_SIZE 1000 int main(void) { /* Declare variables and function prototypes. */ int k=0, year[MAX_SIZE], qtr[MAX_SIZE], max_k=0, min_k = 0, zero_k=0; double index[MAX_SIZE]; FILE *enso; /* Read sensor data file. */ enso = fopen(FILENAME,"r"); if (enso == NULL) printf("Error opening input file. \n"); else { while (fscanf(enso,"%d %d %lf", year+k,qtr+k,index+k)==3) { if (*(index+k) > *(index+max_k)){ max_k = k; } if(*(index+k) < *(index+min_k)){ min_k = k; } if(fabs(*(index+k)) < fabs(*(index+min_k))){ zero_k = k; } k++; } /* Print data for maximum El Nino condition. */ printf("Maximum El Nino Conditions in Data File \n"); printf("Year: %d, Quarter: %d \n",*(year+max_k),*(qtr+max_k)); printf("Maximum El Nina Conditions in Data File \n"); printf("Year: %d, Q...

Accelerometer Lab

SKETCH: const int xpin = A0; // x-axis of the accelerometer const int ypin = A1; // y-axis const int zpin = A2;// z-axis int x_data; int y_data; int z_data; unsigned long time; void setup() {  // initialize the serial communications:  Serial.begin(57600); } void loop() {  time = millis();  Serial.print(time); //prints time since program started Serial.print("\t");  // print the sensor values:  x_data = analogRead(xpin);  // print a tab between values:  Serial.print(x_data);  Serial.print("\t");  y_data = analogRead(ypin);  // print a tab between values:  Serial.print(y_data);  Serial.print("\t");  z_data = analogRead(zpin);  Serial.println(z_data);  // delay before next reading:  delay(3); } 8188 393 393 326 8193 386 381 328 8197 381 373 329 8201 381 379 328 8205 380 381 329 8209 379 373 328 8213 378 368 329 8217 381 375 327 8221 385 383 326 8225 388 381 32...