In this tutorial we will build a simple FSM (Finite State Machine) example with Arduino Uno and HC-06 Bluetooth module
TheoryA finite state machine is a computational model that can be in exactly one of a finite number of states at any given time. It stays in one state until it is triggered by a specific input. The change from one state to another is called transition.
In this example each state is represented by a LED. We have three states RED, GREEN, BLUE. The transition is made by three inputs R G and B.
HC-06 is a bluetooth module designed to establish communication between two devices and acts only as slave device. The pins we use are VCC, GND, TX and RX
- VCC is connected to 3.3 Volts
- GND to ground
- TX to RX pin of Arduino
- RX to TX pin of Arduino
RX pin must be connected through a voltage divider because a direct connection to 5V may damage it.
Android applicationIn order to interface the android device with the Arduino I designed a simple application using the MIT app inventor.
After the first initialization the android device connects to the HC-06's MAC address. Then we hit each button to trigger the FSM and force the transitions. Bear in mind that the android protocol uses ASCII code in decimal format and thus we have to set the bluetooth accordingly.
From the above table we find that the ASCII codes for R G and B characters are 82, 71 and 66 respectively.
Circuit operation
Each LED represent a state. The transition among the states becomes through the commands, sent by the HC-06. Initially the machine starts at RED.
Comments