For a fun project using the proximity sensor available in this kit, see our light-up Halloween Mask Project >
The ROHM Sensor Shield is an Arduino-compatible expansion board that allows users to quickly add any of a variety of sensors to their projects. Its straightforward layout and compactness makes it a great prototyping tool for both beginner and advanced Arduino enthusiasts.
The Sensor Evaluation Kit comes with the Sensor Shield and 8 different ROHM sensors: an accelerometer, a barometric pressure sensor, a geomagnetic sensor, an ambient-light/proximity sensor, a color sensor, a hall-effect sensor, a temperature sensor, and an ultraviolet light sensor.
The website, http://www.rohm.com/web/global/sensor-shield-support, provides detailed documentation about the sensor shield and each of the sensors, along with links to downloadable Arduino libraries for the individual sensors. The user-manual for the kit, which comes in the box and can also be found on the website, and it provides instructions on using the sensor shield with the sensors.
In this article, we will provide an overview of setting up and using the sensor shield for the first time and then demonstrate a simple IoT projects using the sensor shield along with some other components.
Figure 1. ROHM Sensor Shield (top right) with 8 different compatible sensors / @CoreStaff
Out of the box, two features stand out in particular. First, the board is designed so that users can work with more than one sensor simultaneously. For a project that involves two separate forms of sensing, users can prototype the whole system at once instead of in multiple separate steps. Convenient, isn’t it?!
Figure 2. More than one sensor can be plugged into the Sensor Shield at the same time (the picture shows both the temperature sensor and the proximity/ambient light sensor connected)
Second, the different sensors can all be plugged into the shield directly. This makes prototyping more compact and makes large projects more manageable. As the Analog, GPIO, and I2C communication connections are all made within the shield PCB itself, this eliminates the need for multiple jumper wires.
Take the I2C protocol for example. A standalone sensor communicating with the Arduino via I2C would require at least four separate connections (SDA, SCL, Power, and Ground) and 2 pull-up resistors on the SDA and SCL lines. Using the sensor shield, a user only has to plug the equivalent ROHM sensor into one of the I2C connections available on the shield.
The sensor shield has a row of male headers that run along one of its long edges. Most of these pins allow the user to configure a variety of hardware interrupts. As beginners, we’ll only focus on the first 3 rows starting from the edge of the board labeled “1.8V,” “3V,” and “5V” respectively. These three pins indicate voltage settings for the connected sensors. Because some of the sensors can only be operated at specific voltage levels, different voltage settings are available to choose from. To make a selection, the user must connect the pair of pins corresponding to that voltage level using a jumper pin. The jumper pin and an example 3V selection are shown here.
Figure 3. 3V power selection with jumper pin mounted
On the body of the board between the two rows of female headers that connect to the Arduino’s pins, there are eight different sets of female headers surrounded by some dotted lines. These are the connections for the different sensors.
It is important to note that to use a sensor, the user must plug it into a set of headers that corresponds to its method of communication. For example, the temperature sensor outputs an analog value, and therefore, it can only be connected to any of the two sets of headers that indicate analog connections. The manual provides a nice diagram of which headers correspond to each of the communication protocols.
Blue: Analog; Red: Digital GPIO; Green: I2C
The two sensors provided that output analog values are the temperature sensor and the ultraviolet light sensor. Choosing the temperature sensor as an example, we’ll first have to download the appropriate Arduino library to use the sensor, titled BD1020HFV (the name of the temperature sensor module).
Open up the example sketch provided with the library. At the top of the program below the library include statement, a variable tempout_pin is set to the value A2. In void setup(), the BD1020 object (the temperature sensor object) is initialized with this value, indicating that the sensor’s output values should be read from analog pin 2. This means that we must connect the temperature sensor module to the Analog_2 header on the sensor shield.
Figure 4.Temperature Sensor Connected to Analog 2 header (lower right of board)
Upload the sample sketch to the Arduino and open up the Serial Monitor. You should see a constant feed of messages indicating the current temperature being measured. To test if the sensor is working as expected, pinch your finger on the metal contact on the sensor. The messages should now indicate that the temperature has risen!
Figure 5. The metal contact of the temperature sensor is labeled “PAD1”
Here is a sample line of output: “BD1020HFV Temp=23.59 [degrees Celsius], ADC=277”
The “ADC” value indicates the integer conversion of the analog value (voltage) output by the sensor.
Next we’ll look at the sensors that communicate via the I2C protocol. These sensors are the accelerometer, the pressure sensor, the geomagnetic sensor, the ambient-light/proximity sensor, and the color sensor. Choosing the accelerometer as an example, we’ll first have to download the appropriate Arduino library to use the sensor, titled KX022.
Open up the example sketch provided with the library. Connect the accelerometer module to any of the I2C headers on the sensor shield and upload the example sketch. You may need to type in “#define byte uint8_t” as the first line of the program (above the #include statements) because the Arduino compiler may not recognize “byte” as a valid data type.
Figure 6. Accelerometer module connected to the I2C headers
Open up the Serial Monitor. You should see a constant feed of messages indicating the accelerations measured in X, Y, and Z. the axes are indicated on the accelerometer by a small drawing.
Figure 7. Accelerometer Module with directions of 3 axes shown
To test the accelerometer, move it suddenly in one of the axes. You should note a change in the acceleration component for that direction.
Here is a sample block of output:
“KX022 (X) = -0.02 [g]
KX022 (Y) = -0.00 [g]
KX022 (Z) = 1.00 [g]”
This output indicates that at the moment the values were recorded, the object on which the accelerometer is placed is experiencing virtually no acceleration in the X or Y direction and gravitational acceleration (towards the earth) in Z.
Finally, we’ll look at the only sensor that communicates via a GPIO connection, the hall-effect sensor. The hall effect sensor detects only the presence or lack of a magnetic field. Therefore, its output is a digital signal, either a “low” indicating the presence of a magnetic field, or a “high” indicating the lack of a magnetic field.
Digital signal input and output (IO for short) occurs at the 5V level on the Arduino, so we’ll have to move the jumper pin to the 5V setting.
Figure 8. 5V Power Selection
We’ll first have to download the appropriate Arduino library to use the sensor, titled BD7411. Open up the example sketch provided with the library. There is only one slot for digital-output sensors like the hall-effect sensor on the sensor shield, labeled GPIO. Upload the sketch to the Arduino and open up the Serial monitor. In the presence of a magnetic field, the line “BD7411G Magnet field Detect!” will appear on the Serial Monitor.
To implement the sensor shield in your own projects, just download and include the libraries for the sensors that you plan to use, then use the different methods from these libraries to communicate with the sensors. You can refer to the example sketches that come with each library and the libraries’ source .cpp and .h files to see exactly how these methods are used.
Some simple projects that I made using different sensors and their libraries:
1. Light an LED when a magnetic field is present near the hall effect sensor
Figure 9. The finished hall-effect sensor project
Parts:
This project lights up an LED whenever a magnetic field is present near the hall-effect sensor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include <BD7411.h> int led_pin = 12; int hallout_pin = 0; // use D0 pin BD7411 bd7411; void setup() { bd7411.init(hallout_pin); pinMode(led_pin, OUTPUT); } void loop() { int hallout; hallout = bd7411.readoutpin(); if (hallout == 0) { digitalWrite(led_pin, HIGH); } else { digitalWrite(led_pin, LOW); } delay(500); } |
2. Graph temperature over time using Processing
Figure 10. Temperature sensor mounted to Analog_2 headers of the Sensor Shield (lower right)
Parts:
This project graphs temperature over time using a Processing Sketch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import processing.serial.*; Serial arduinoPort; // The serial port int currentX = 0; // horizontal position of the graph float data = 0; void setup () { size(1000, 300); arduinoPort = new Serial(this, Serial.list()[1], 9600); //"intercept" serial print messages arduinoPort.bufferUntil('\n'); background(0); } float oldData =0; void draw () { stroke(0, 255, 0); if (currentX++ >= width) //start at the left of the window with a blank screen when the screen has been filled { currentX=0; background(0); } if (Math.abs(data-oldData) < 30) //prevent the program from drawing noise spikes { line(currentX, height - oldData, currentX++, height - data); } else { stroke(0, 0, 0); line(currentX, height - oldData, currentX++, height - data); } oldData = data; } void serialEvent (Serial arduinoPort) { String serialInput = arduinoPort.readStringUntil('\n'); if (serialInput != null) { serialInput = trim(serialInput); data = int(serialInput); println(data); data = map(data, 0, 1023, 0, height); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <BD1020.h> int tempout_pin = A2; BD1020 bd1020; void setup() { Serial.begin(9600); while (!Serial); bd1020.init(tempout_pin); } void loop() { float temp; bd1020.get_val(&temp); Serial.println(bd1020.temp_adc); delay(500); } |
For a fun project using the proximity sensor available in this kit, see our light-up Halloween Mask Project >