Training Session 2:

Interfacing serial devices with the Arduino and use of XOD.

Monday 25 June, 6pm – 8pm, Postdoc Centre, 16 Mill Lane, Cambridge (Register here)

1. The piezo buzzer

We will be using the same shield as the first training session (Keyestudio Easy Module Shield V1: see right). This shield contains a passive piezo buzzer that is connected to port D5. Marco Aita has encapsulated the Arduino tone library in a XOD node that can be used to switch on and control the pitch of the buzzer.

The Training Session TWO software will be available as a xodball file that can be downloaded from this site.

Identify the buzzer node, copy into a patch and experiment with the use of inputs from other devices on the shield, such as the variable resistor and photoresistor. The buzzer provides a useful device for audible alarms. Next, we'll wire up a digital sensor.

 

 Keyestudio Multipurpose shield for Arduino

Keyestudio Multipurpose shield for Arduino

 Demo code for control of the passive buzzer c/o Marco Aita.

Demo code for control of the passive buzzer c/o Marco Aita.

2. Digital thermometer

The DS18B20 chip is a digital thermometer that provides 9-bit to 12-bit Celsius temperature measurements (and has an alarm function with nonvolatile user-programmable upper and lower trigger points). You will be provided with a waterproof sealed unit with a 1M lead. The DS18B20 chip is contained in the stainless steel tip, and communicates over a 1-Wire bus that requires only one data line (and ground) for communication with the Arduino. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply. Each DS18B20 has a unique 64-bit serial code, which allows multiple sensors to be placed on the same 1-Wire bus. XOD provides a node in the "common hardware" library that can read single 18DSB20 devices in a circuit.

 Download Arduino UNO and Multipurpose Shield pinouts (PDF. 1. MB)

Download Arduino UNO and Multipurpose Shield pinouts (PDF. 1. MB)

DS18B20error.png

The sensor measures temperatures from -55°C to +125°C with better than ±0.5°C Accuracy from -10°C to +85°C (see graph) - the chip is internally calibrated and returns a digital measurement that can be displayed directly. (For more information, see: https://create.arduino.cc/projecthub/TheGadgetBoy/ds18b20-digital-temperature-sensor-and-arduino-9cc806)

Your challenge is to devise and implement in XOD a temperature alarm system using the Arduino prototyping system, DS18B20 sensor, LCD panel readout and buzzer.

DS18B20_XOD.png
DS18B20unit.jpg
 How to wire the DS18B20 sensor to an Arduino. (You will be using a waterproof, encapsulated version with connecting wires: red = 5V. black = GND, yellow = DATA)

How to wire the DS18B20 sensor to an Arduino. (You will be using a waterproof, encapsulated version with connecting wires: red = 5V. black = GND, yellow = DATA)

 

3. Sonar device

XOD contains a node that supports use of an ultrasonic sonar distance sensor, the HC-SR04. For more information about the device, see: (https://components101.com/ultrasonic-sensor-working-pinout-datasheet).

How-ultrasonic-sensor-works.jpg

The ultrasonic transmitter emits an sound waves at 40 000 Hz which travel through the air and if there is an object or obstacle on its path It will bounce back to the module. The module also has a receiver that allows measurement of the travel time. Knowing the speed of the sound allows calculation of the distance. The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The GND and the VCC pins of the module need to be connected to ground and the 5 volts pins on the Arduino board and the trig and echo pins to any Digital I/O pin on the Arduino Board.

There are two XOD nodes that allow calculation of (i) the travel time of for an acoustic pulse (hc-sr04-ultrasonic-time) and (ii) the range of an object in metres (hc-sr04-ultrasonic-range).

Can you use this code to create a theremin-like device, using different forms of input to control the (potentially) tuneful passive buzzer output device?

SonarWiring.jpg
HC-SR04.png
HC-SR04_image.jpg

4. Timing for XOD: traffic light

The programming of timing sequences in XOD is not as straightforward as in standard text languages. The developers of XOD have provided a very useful example and step-by-step tutorial. Marco Aita and Carlos Lugo have rewritten this for use with the shield and RGB LED. Please find the tutorial online at:

https://xod.io/docs/guide/simple-traffic-light/

...and the code in the Training Session TWO library.