Arduino Code

Programming in C

Sam on July 24th, 2017

The Arduino microprocessor was used to
bring together the functionality of an Adafruit FONA board as well as the custom circuitry

The microprocessor was tasked with four goals, each achieved through a specific block of C.

1: Acquire analog data from the attached sensors, and convert into a digital output.
2: Interface with the Ting SIM chip installed on the FONA board and acquire a wireless signal.
3: When the signal is strong enough download the current Time, GPS coordinates, and digital sensor values, and convert them into a character array for SMS output.
4. Notify the user of the board's current status (Connecting, Collecting, and Sending)

Digital Conversion

The first step of acquiring data was relatively easy in terms of software: A simple percentage based conversion between an analog value (0-1023) to a digital value of 0-5 volts was performed for the turbidity sensor. The Temperature sensor provided data in digital format. Most of the difficulty of working with these sensors was in their physical design, which can be seen here.

Acquiring a Signal

Over half of the code relates to the initial handshake protocol for connecting to the FONA board, and then acquiring a wireless signal. After opening a connection to the FONA board, the arduino microprocessor patiently waits for a 3D GPS fix to be made. This process can take up to a few minutes depending on the strength of the connection. This process occured only once, after which the rest of the code operated in a 30 second loop.

Sending a text

After the initial GPS fix is acquired, the current GPS location is saved to a local variable and the GPS is disabled. On a 30 second loop, fresh sensor data is collected and converted into character arrays. The limitations of the FONA SMS service forced a process of cascading character array merges in order to create one coherent 140 character array.

User Feedback

The expectation was for the user in the field to not have access to a computer or Serial Monitor connection to the board. Therefore, a method of external feedback was programmed into the device, using a series of standarized tone codes and a buzzer attached to the arduino board.