//Reads data from a sensor and sends it to the serial port //Created by Gleb Bulygin for FabAcademy. //Based on this tutorial: https://itp.nyu.edu/physcomp/labs/labs-serial-communication/serial-output-from-an-arduino/ #include const int pResistor = A3; //sensor pin uint16_t value; // Store value from photoresistor (0-1023) // *** // *** Define the RX and TX pins. Choose any two // *** pins that are unused. Try to avoid D0 (pin 5) // *** and D2 (pin 7) if you plan to use I2C. // *** #define RX A0 // *** D3, Pin 2 #define TX A1 // *** D4, Pin 3 SoftwareSerial mySerial(RX, TX); void setup() { while (!mySerial) { ; // wait for serial port to connect. Needed for native USB port only } // set the data rate for the SoftwareSerial port mySerial.begin(9600); pinMode(pResistor, INPUT);// Set pResistor - A3 pin as an input (optional) } void loop() { int value = analogRead(pResistor); // map(value, 0, 1023, 0, 255); //mapping to fit in one bit of data. mySerial.write(value); // sends the value to serial port in bin }