Home > Projects > Interfacing(USB – RS232 – I2c -ISP) Projects > Serial Call and Response using Arduino

Serial Call and Response using Arduino

Summary of Serial Call and Response using Arduino


This Arduino sketch implements multi-byte serial communication using a call-and-response handshake. Upon startup, it repeatedly sends the ASCII character 'A' until receiving a signal from the computer. Once triggered, it transmits three sensor values (two analog and one digital) as single bytes each time a byte is received. The system supports viewing data via the Serial Monitor or software like Processing and Max/MSP.

Parts used in the Serial Call and Response Project:

  • Arduino Board
  • (2) analog sensors (potentiometer, photocell, FSR, etc.)
  • (1) momentary switch/button
  • (3) 10K ohm resistors
  • breadboard
  • hook-up wire

This example demonstrates multi-byte communication from the Arduino board to the computer using a call-and-response (handshaking) method.

Serial Call and Response using Arduino

This sketch sends an ASCII A (byte of value 65) on startup and repeats that until it gets a serial response from the computer. Then it sends three sensor values as single bytes, and waits for another response from the computer.

You can use the Arduino serial monitor to view the sent data, or it can be read by Processing (see code below), Flash, PD, Max/MSP (see example below), etc.

Software Required

Circuit

Connect analog sensors to analog input pin 0 and 1 with 10K ohm resistors used as voltage dividers. Connect a pushbutton or switch to digital I/O pin 2 with a 10Kohm resistor as a reference to ground.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic

Serial Call and Response using Arduino schematic

Code

/*
Serial Call and Response
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three sensor values whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
* potentiometers attached to analog inputs 0 and 1
* pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 24 April 2012
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialCallResponse
*/
int firstSensor = 0;    // first analog sensor
int secondSensor = 0;   // second analog sensor
int thirdSensor = 0;    // digital sensor
int inByte = 0;         // incoming serial byte
void setup()
Major Components in Project

Hardware Required

  • Arduino Board
  • (2) analog sensors (potentiometer, photocell, FSR, etc.)
  • (1) momentary switch/button
  • (3) 10K ohm resistors
  • breadboard
  • hook-up wire

Quick Solutions to Questions related to Serial Call and Response:

  • What does the Arduino send on startup?
    The program sends an ASCII A with a byte value of 65.
  • How long does the Arduino repeat sending the initial character?
    It repeats the character until it receives some data from the computer.
  • What triggers the transmission of sensor values?
    Sending three sensor values occurs whenever the Arduino gets a byte in the serial port.
  • Which software can read the sent data besides the Serial Monitor?
    Data can be read by Processing, Flash, PD, or Max/MSP version 5.
  • How are the analog sensors connected to the board?
    Analog sensors connect to analog input pins 0 and 1 using 10K ohm resistors as voltage dividers.
  • Where should the pushbutton be connected?
    The pushbutton connects to digital I/O pin 2 with a 10Kohm resistor as a reference to ground.
  • What type of components are required for the analog inputs?
    You need two analog sensors such as potentiometers, photocells, or FSRs.
  • Does the code handle multi-byte communication?
    Yes, the example demonstrates multi-byte communication using a call-and-response method.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top