For my computation class, we were asked to give a presentation and some sample code for smoothing an IR sensor in the Arduino environment. I wrote this code that averages the values of the last ten readings. It drops the highest and lowest values, to help control the noise and make sure...
particleSensor.setup(); //Configure sensor with default settings particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED } void loop(){ long irValue = particleSensor.getIR(); if (checkForB...
}voidloop() {intuvLevel = averageAnalogRead(UVOUT);intrefLevel = averageAnalogRead(REF_3V3);//Use the 3.3V power pin as a reference to get a veryaccurateoutput value from sensorfloatoutputVoltage =3.3/ refLevel * uvLevel;floatuvIntensity = mapfloat(outputVoltage,0.99,2.9,0.0,15.0); Serial...
//Serial.begin(115200); //Initialize baud rate particleSensor.begin(Wire, I2C_SPEED_FAST); //Use default I2C port, 400kHz speed particleSensor.setup(); //Configure sensor with default settings particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running }...
constintnumReadings=10; intreadings[numReadings];// the readings from the analog input intreadIndex=0;// the index of the current reading inttotal=0;// the running total intaverage=0;// the average intinputPin=A0; voidsetup(){
//Take average of readings beatAvg = 0; for(bytex = 0 ; x < RATE_SIZE ; x++) beatAvg += rates[x]; beatAvg /= RATE_SIZE; } } Serial.print("IR="); Serial.print(irValue); Serial.print(", BPM="); Serial.print(beatsPerMinute); ...
intReadUVintensityPin = A0;//Output from the sensor voidsetup() { pinMode(ReadUVintensityPin, INPUT); Serial.begin(9600);//open serial port, set the baud rate to 9600 bps Serial.println("Starting up..."); } voidloop() { intuvLevel = averageAnalogRead(ReadUVintensityPin); ...
MAX30105 particleSensor; const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good. byte rates[RATE_SIZE]; //Array of heart rates byte rateSpot = 0; long lastBeat = 0; //Time at which the last beat occurred
//Output from the sensor int REF_3V3 = A1; //3.3V power on the Arduino board void setup(){ Serial.begin(9600); pinMode(UVOUT, INPUT); pinMode(REF_3V3, INPUT); Serial.println("MP8511 example"); } void loop(){ int uvLevel = averageAnalogRead(UVOUT); int refLevel = averageAnalog...
int lightSensorRight = A0; // Analog sensor reading int sensorValue = 0; // Values int sensorValueLeft = 0; int sensorValueRight = 0; int left = 0; int right = 0; // Change the following value to decrease or increase the sensitivity. ...