61 lines
1.8 KiB
Arduino
Raw Normal View History

2024-10-13 03:45:19 -05:00
//
// ADC Data Transmission Program
//
// Author: Alex Spataru
//
// This program reads data from six analog input pins (A0 to A5) on an Arduino.
// It scales the raw analog readings (0-1023) to 8-bit values (0-255) and
// transmits them as binary data over the serial port.
2024-10-13 03:45:19 -05:00
//
// Required Components:
// - 6 analog sensors connected to the Arduino's analog pins (A0 to A5)
//
// Connections:
// - Connect the signal outputs of the sensors to the analog pins A0 to A5 on
2024-10-13 03:45:19 -05:00
// the Arduino.
//
// Baud Rate:
// - Serial Monitor: 115200 baud
//
//-----------------------------------------------------------------------------
// Initialization function
//-----------------------------------------------------------------------------
void setup() {
// Initialize the serial communication at a baud rate of 115200
Serial.begin(115200);
// Wait for the serial port to initialize
while (!Serial)
;
// Configure the ADC pins (A0 to A5) as input pins
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
}
//-----------------------------------------------------------------------------
// Main loop function
//-----------------------------------------------------------------------------
void loop() {
// Read the analog values from pins A0 to A5
// Show each one of them over a range of values
Serial.write("$");
2024-10-13 03:45:19 -05:00
Serial.write(map(analogRead(A0), 0, 1023, 0, 255));
Serial.write(map(analogRead(A1), 0, 1023, 0, 255));
Serial.write(map(analogRead(A2), 0, 1023, 0, 255));
Serial.write(map(analogRead(A3), 0, 1023, 0, 255));
Serial.write(map(analogRead(A4), 0, 1023, 0, 255));
Serial.write(map(analogRead(A5), 0, 1023, 0, 255));
Serial.write(";");
2024-10-13 03:45:19 -05:00
// Small delay to manage the sampling rate
2024-10-13 23:33:59 -05:00
delay(1);
2024-10-13 23:23:09 -05:00
}