#include "SoftwareSerial.h" // Declare and initialize UART pins const int rx_pin = 4; const int tx_pin = 5; // Declare and initialize led and hall sensor pin const int led_pin = 9; const int hall_pin = 8; // Create new serial with specified UART pins SoftwareSerial mySerial(rx_pin , tx_pin); void setup(){ // Set the pin modes of UART pins pinMode(rx_pin, INPUT); // Receiving requires input pinMode(tx_pin, OUTPUT); // Transmitting requires output // Set led as output pinMode(led_pin, OUTPUT); // Set sensor as input pinMode(hall_pin, INPUT); // Start the serial communication at 9600 bits/sec mySerial.begin(9600); } void loop(){ // Read the analog value of the pin and send it via serial communication int val = analogRead(hall_pin); mySerial.println(val); // Flash the LED digitalWrite(led_pin,HIGH); delay(100); digitalWrite(led_pin,LOW); // Wait some time (500ms in total) delay(400); }