Connect Raspberry Pi to Arduino Nano by TTL Serial

Several days ago, I had received my low price pulse sensors. Today, I am working on using them. The sensors are very easy to use. By connect 3 pins to my Nano, it works fine. Then I am trying to connect my Nano to Raspberry Pi 3 B+ by TTL serial.

First, write a little code to run Nano. Reading pulse sensor’s analog output from pin A0. Map the analog value to digit output pin D9, and power on a LED with changing brightness.

 int sensorPin = A0;    // select the input pin for the sensor
int brightness = 0;
int ledPin = 9; // select the pin for the LED
int sensorValue = 0; // store the value coming from the sensor
unsigned long delayMillis = 20;

void setup() {
pinMode(ledPin, OUTPUT);

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// mapping and shifting
brightness = map(sensorValue, 0, 1023, 0, 255) - 80;
// write to the ledPin
analogWrite(ledPin, brightness);
// print the results to the Serial line:
// delay for milliseconds and resample:

When you put your finger on the sensor, the LED blinks with your heart beat, and the HB amplifications are sent to serial line.

Final setup that powers on

Then, connect Nano to Raspberry Pi in next 3 steps.

  • Step 1: Power on Nano by Rpi’s +5V pin;
  • Step 2: Connect Rpi’s pin 10 to Nano’s TX1. Remember to convert Nano’s +5V signal to 3V3 level. Do NOT connect the two pins directly;
  • Step 3: Open ‘screen’ or ‘minicom’ on Rpi, connect to ttyS0 or ttyAMA0 or something else to get the sensor values.

Leave a Reply

Your email address will not be published. Required fields are marked *