(Bob and Richard) Smiling Tips Box

For this week myself and Richard Channing created a smiling customer tips box. It’s composed of the heartbeat sensor from my week 2 post, the relay from Richards week 2 post, the led array from week 3, and a motor, as well a resistor and 2 LEDs.

The Code

Link to our code for this project (Arduino Create)

The code for this project got quite complicated quite quickly. We used 1 library (the ledcontrol library from github previously mentioned). as well as 7 global variables, 2 arrays of byte variables, 1 of our own functions (printFace(bool)), 2 if / else statements, and 2 for loops. For a total of 68 lines of code.

The printFace(bool) function:

Capture - printFace.PNG

Rather that re-typing the for loops every time we want to change the LED array’s display, I’ve given it’s own function with 1 parameter; doesSmile. If I were to type:


Then the led array would be set to display the smile. (the for loops are explained in greater depth in week 3’s post).

The main loop():

Capture - Main Loop.PNG

The main loop is where all the action happens:

Initially we we’re going to keep the LED array and motor on by using the millis() function. However instead we decided to use delay(), to avoid complication if a second coin were to be inserted before the timer had reached 2000 milliseconds.

Next we read the pin for the IR emitter/receiver (heartbeat) sensor. and stored this in the int sensorValue which was globally defined. If the value read by the sensor is significantly higher than the background infrared noise, then a series of events happens:

  1. The time of the event triggering is stored to lastRun.
  2. The LED verification pin is triggered (so I know if the array isn’t working).
  3. The LED array is changed to a smile.
  4. The relay is switched on.
  5. A 2 second delay is triggered.

In the else statement the LED verification pin, LED array, and relay are all switched off.

The Electronics


In our circuit we used the relay to close our second circuit with the motor and 9V battery.  The LED array took 5V from the Uno, the heartbeat sensor also. Occasionally the array glitches out because it doesn’t get a high enough current from the board.

Initially we had a big problem with the relay switch. After one or two clicks while attached to the motor it would get stuck in the closed position. Reasons to this could have been the back e.m.f. (electro magnetic force) generated by the motor, so we stuck in a diode on the output of the switch, however this didn’t seem to change anything apart from making the behaviour of the switch more predictable. Every fourth click of the relay it was still getting stuck.

We concluded that the back e.m.f. must be greater than the peak inverse voltage (PVI). We added in a second diode (this time an led) and the circuit now works perfectly.

The rest of the components were fairly easy to use. The heartbeat sensor had 3 pins, +, -, S (signal). The led array was a little more complicated with 5 pins, VCC, GND, DIN, CS, and CLK. These 3 pins create a Serial Peripheral Interface Bus (SPI), this is a serial connection to the MAX7219CNG chip on the array board which controls the array.


(Bob and Richard) The Smiling Matrix: MAX7219 LED Dot Matrix

Hi, welcome to the first week of our group project.

This week I am researching the MAX7219 LED Dot Matrix shown below.

MAX7219 LED Dot Matrix

It is a small serial input display driver that uses microprocessors to control the 8×8 LED display and It operates off of 5v. It can power up to 64 individual LEDs over up to 7 cascaded (linked together) arrays.

The datasheet for the MAX7219 serial interface can be found here:

Link to the MAX7219 datasheet


Getting the MAX7219 Array Working:

To get the LED array working a library for the MAX7219 was used (GitHub Manual for LedControl Library). This enabled easy-use of the MAX7219 chip.

The functions we used to get the library working were:

LedControl(DATA-IN pin, CLK-pin, CS-pin, number of arrays) – This is to define our array object, listing the pin connections and the number of arrays that are cascaded

shutdown(array number, true/false) – This is used to switch on the matrix, since it is initially set to off.

clearDisplay(array number) – Used to wipe the data on the array

setRow(array number, array row, byte) – Used to set a whole row of LEDs at once, this was used to draw the faces

setLed(array number, array row, true/false) – Used to set individual LEDs, this was used in the scrolling light code.

Initially we just wanted to understand how to switch on and off LEDs so I tried making an LED scroll across the screen. To do so we used the following code:

Link to Our ArduinoCreate Code

Using a for loop between i = 0 and 7, we could set the array to colour the LED in column i. After this the LED before it had to be switch off, which was simple enough using i – 1. The only complex part was where the LED was 0 or 7. When it was 0, we didn’t need to switch of the LED before. If it was 7 we set a delay, then switched of the 8th LED.

A video of our first test:


Making our Matrix Smile 🙂

To make our matrix smile we needed to explore arrays of bytes. A byte is a binary number made from 8 bits (1s and 0s), which has a maximum value of 255: 11111111.

An array is simply a list of variables. In our case bytes. To create our face we needed two arrays, each of 8 bytes; one for the frowning face, one for the smiling face.

We could have figured out the bytes manually, however instead we used this online tool which creates the array for me:  Byte Array Sketching Tool. All we had to do was draw on our smile and copy and paste the list of bytes over.

Our code for the smile Matrix is here: Code for the smiling matrix

Creating the images was fairly simple. Using a for loop like before we could get the row (0-7) from the pre-defined global variables. Then going through from i=0 to i=7 we got the byte for that row and wrote it to the MAX7219 using setRow().

Using a simple button circuit which we read from pin 6, we could get user input to make the matrix smile. In our final design we’ll use the IR sensor as the input signal.


Next Week:

Next week we’re creating our smiley face tip jar to encourage customers to tip.

Preview Sketch:

Basic concept001.jpg

Voltage Regulator L7809CV

Hi, this is a second post for week 2 of the mini project, focusing on the L7809CV voltage regulator.

Voltage regulators explained

Voltage regulators do pretty much what they say on the tin, they decrease the voltage (and current) to a certain level. In the case of this component it limits the output to 9V and 1.5A. And can take a maximum input voltage of 35V, with a recommended minimum of 15V.[1] This voltage regulator wasn’t really suited fora 9V battery, but the circuitry is valid nonetheless.

There are 3 types of voltage regulator: linear, switching, and zenner diode[3]. Linear diodes give a constant voltage output, by using a potential divider circuit (essentially just a resistor). Switching regulators have a much higher efficiency than linear reguators 85% compared to 50% respectfully. However they produce electrical noise which can be complicated to overcome in a circuit. Zenner diodes can also be appropriated as regulators for very low voltage applications, with the output pulled from across the diode. The diode shunts all voltage above it’s breakdown voltage, acting as a regulator.

The circuit

Regulators need a capacitor to ground on the input and output of the component. The capacitor on the output is most important, this is to increase the stability of the output current.[2] The capacitor on the input is to reduce the source impedance (resistance of the input source).




[1] – http://www.farnell.com/datasheets/2307057.pdf?_ga=2.103517824.1809073407.1519564850-527651698.1512323702&_gac=1.207744294.1518449837.EAIaIQobChMI5Lmssdqg2QIVzRXTCh3P9ARlEAYYASABEgKJyfD_BwE

[2] – https://electronics.stackexchange.com/questions/232935/why-is-there-always-a-capacitor-on-input-and-output-of-a-voltage-regulator

[3] – https://www.lifewire.com/types-of-voltage-regulators-818851

Heartbeat Sensor

Hi, this is my second week blog post. The sensor I have this week is the heartbeat sensor. It was very difficult to get working, mainly because of the poor design of the sensor. However I got it to work and this is how I did it:

heartbeat sensor.jpg

The Sensor

The heartbeat sensor is made from an infrared (IR) emitter and receiver. When you put your finger over the receiver the sensor can register the slight differences in how much IR light passes through your finger, when blood passes through your finger due to your pulse there is a slight dip in the amount of the IR light that passes though.

To find your heartbeat a finger is lightly placed on the receiver pad. If you stay very still and do it underneath a bright light, then you can register differences in the IR signal. The signal is an analogue electrical signal you can interpret with the Arduino Uno.

Attempt 1

The code: ArduinoCreate Sensor Fail 1 Code

This code was based off of code found from Stack Overflow

This code was way too sensitive to changes in the signal from the sensor. It ended up just flashing at really fast speeds not relevant to my heart rate.

Attempt 2

The code: ArduinoCreate sensor fail 2 code

This code was based off of code found from Stack Overflow

This attempt worked in a similar way to the last, with slightly altered way of processing the data. It was closer to finding my heartbeat but then I realised when I took my finger away it just carried on flashing.

Attempt 3 (Success)

The code: ArduinoCreate sensor success code

After my numerous failures I decided to mess around with the physical environment as well as the code. I found that placing a bright light above my thumb increased the accuracy, and if I’m honest I’m not sure entirely why.

The code was also far better (and simpler).  It worked by reading the pin. finding the change and applying a modulus to it (abs()). Then if the change is greater than 0 (i.e if there is a significant change), then flash the led. The value 0 can be changed to vary it’s sensitivity.


This sensor was a nightmare to get working, but it is very useful. Not so much for detecting heartbeats, but for use as a short range motion sensor. The IR emitter/receiver pairing on one board is very useful.

New code I learnt during this week:

abs() – Used to find the magnitude of a number
&& || – AND and OR logic statements
float – float variable type, used to store decimal numbers

Tilt Switch

Hi, this is my first week blog post.

For my initial component I have been given a mercury tilt switch. It is a pretty simple component consisting of a blob of mercury in a glass tube, with two electrodes at the end [1].

When tilted the mercury covers the electrodes and completes the circuit, allowing for a current to flow.




tilt switch image

An advantage of a tilt switch above all other types of switch is that it is non-degrading. [2] It also has a very low resistance, so can be used in high current applications.

Meaning it should last indefinitely as long as the electronics don’t corrode or the glass smash.


History and Uses

The mercury tilt switch is an extinct component. It used to be used for a variety of uses: Machinery tilt detection, lighting control for car boot lids, anti-mine tampering, and vending machines [3].

The mercury tilt switch has been replaced by the tilt switch using a ball bearing, this is because of mercury’s toxicity. The only disadvantage of the ball bearing is that it requires debouncing, since the ball bearing bounces when tilted, creating an initially jittery connection. Since mercury is a liquid debouncing isn’t needed. [4]


Test and Coding

A link to my code: My Tilt Switch Code

Fritzing didn’t have my tilt switch with 3 pins (GND, Signal, IN) so I used their 2 pin tilt switch and just put the wires on the breadboard nearby.

Tilt Switch_bb.pngTilt Switch_schem.png

The code for this was very simple, as were the electronics. All that had to be done is digitally reading pin 8, detecting whether there was a current. If yes, then the LED was switched on.

A potential project to use this in would be an alarm clock which you push over to turn off the alarm.



[1] – http://www.russell-scientific.co.uk/mercury-switches-21-c.asp

[2] – https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Mercury_switch.html

[3] – United States, Mercury study report to Congress, DIANE Publishing, 1997 ISBN 1-4289-0372-0, page 2-11

[4] – https://en.wikipedia.org/wiki/Mercury_switch

SRD-05VDC-SL-C Relay research


My name is Richard Channing. I am a student at UWE studying Product Design technology.

In this Blog I will be sharing with you my assignment for my physical computing module, this module is very exciting as it is based around learning how to use and program with Arduino.

For this project I have been given this:

Relay Sensor

It is a SRD-05VDC-SL-C Relay,

The datasheet for the songle relay is here – http://elecfreaks.com/estore/download/EF03052-SRD(T73).pdf

Now what is a relay?

“A relay is an electrically operated switch of mains voltage.” [1] It uses electromagnetism in a way that allows you to control a circuit using 5v from an Arduino and on the other end of this circuit control up to a 240V appliance.

How does it do this?

By using electromagnetism when the relay coil is energised it begins to act like a magnet and changes the position of a switch. The circuit which energises the coil is completely isolated from the part which switches on and off (as this is done using a magnet) providing what is called “Electrical isolation” Due to this you can use a relay using 5 volts from an Arduino and on the other end of the circuit be powering an appliance from the mains as the two circuits will be isolated from each other.[3]

The relay has 3 main pins these are:

COM – Common pin this is usually connected to ground

NO – Normally open pin this has no contact between the COM and itself normally until activation.

NC – Normally closed this pin is normally connected to the COM pin. [2]


My plan with this project is to use the relay as a switch so that i might power an apply that requires a higher voltage through electrical isolation. Below is an image of how to connect a 4 relay module to an arduino:

4 relay fritz[3]



“Guide for Relay Module with Arduino,” Random Nerd Tutorials, [Online]. Available: https://randomnerdtutorials.com/guide-for-relay-module-with-arduino/.


S. Kian, “Identify Terminal Pins of A Relay Without Reference to Datasheet,” 01 Aug 2012. [Online]. Available: https://tutorial.cytron.io/2012/08/01/identify-terminal-pins-of-a-relay-without-reference-to-datasheet-2/.


Hobbyist, “Step 2: Interfacing the relay modules to the Arduino,” Hobbyist.co, [Online]. Available: http://www.hobbyist.co.nz/?q=interfacing-relay-modules-to-arduino.