Slave Blue

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <SoftwareSerial.

h>

SoftwareSerial bluetooth(2, 3); // RX, TX pins for Bluetooth module


int sensorPin = A0; // Analog input pin for your sensor
int numReadings = 50; // Number of readings to average
int sensorSum = 0; // Variable to store the sum of readings
int averageValue = 0; // Variable to store the average value

void setup() {
Serial.begin(9600);
bluetooth.begin(9600); // Initialize Bluetooth module
analogReference(DEFAULT);
// Set the reference voltage to the default (typically 5V)
}

void loop() {
// Read the sensor values and add them to the sum
for (int i = 0; i < numReadings; i++) {
sensorSum += analogRead(sensorPin);
delay(50); // Optional delay between readings
}

// Calculate the average value


averageValue = sensorSum / numReadings;

// Reset the sum for the next set of readings


sensorSum = 0;

// Print the average value for debugging


Serial.println("Average Value: " + String(averageValue));

// Send the average value to the Bluetooth terminal


bluetooth.println(("Average Value: " + String(averageValue)));
bluetooth.println(";");

// You can add a delay here if needed


delay(5000); // Delay for 5000 milliseconds before the next reading
}

You might also like