Categories

Arduino more Easy Module Shield examples

In our previous look at the Easy Module Shield v1 – Arduino Easy Module Shield v1. We took a look at the shield and had a simple example looking at the LDR and the pot. In this example we will show examples for the LM35 and the DHT11. In both examples we will output via the serial monitor but we will also switch an LED on if the temperature rises above a certain value.

Here is the shield and you can clearly see the DHT11, LM35 and the red and blue LEDs

multi-purpose-shield-v1

Code

Example 1 : LM35 example

#define lm35Pin A2
#define ledPin 12
 
 
//this sets the ground pin to LOW and the input voltage pin to high
void setup()
{
Serial.begin(9600);
pinMode(ledPin, INPUT);
digitalWrite(ledPin,0);
}
 
//main loop
void loop()
{
  int rawvoltage= analogRead(lm35Pin);
  float millivolts= (rawvoltage/1024.0) * 5000;
  float celsius= millivolts/10;
  Serial.print(celsius);
  Serial.print(" degrees Celsius, ");
  Serial.print((celsius * 9)/5 + 32);
  Serial.println(" degrees Fahrenheit");
  if(celsius >25)
  {
    digitalWrite(ledPin,1);
  }
  else
  {
    digitalWrite(ledPin,0);
  }
  delay(1000);
 
}

Open up the serial monitor and you should see something like this, put your hand on the LM35 and that should push the temperature higher than 25 degrees and the LED will light

25.39 degrees Celsius, 77.70 degrees Fahrenheit
25.88 degrees Celsius, 78.58 degrees Fahrenheit
26.37 degrees Celsius, 79.46 degrees Fahrenheit
26.86 degrees Celsius, 80.34 degrees Fahrenheit
25.88 degrees Celsius, 78.58 degrees Fahrenheit
25.39 degrees Celsius, 77.70 degrees Fahrenheit
25.39 degrees Celsius, 77.70 degrees Fahrenheit
25.39 degrees Celsius, 77.70 degrees Fahrenheit
24.90 degrees Celsius, 76.82 degrees Fahrenheit
24.41 degrees Celsius, 75.95 degrees Fahrenheit

 

Example 2 : DHt11 Example

 

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
 
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
 
#define DHTPIN 4 // Pin which is connected to the DHT sensor.
#define DHTTYPE DHT11 // DHT 11 
#define ledPin 13
 
DHT_Unified dht(DHTPIN, DHTTYPE);
 
uint32_t delayMS;
 
void setup() 
{
 Serial.begin(9600); 
 // Initialize device.
 dht.begin();
 Serial.println("DHTxx Unified Sensor Example");
}
 
void loop() 
{
 // Delay between measurements.
 delay(delayMS);
 // Get temperature event and print its value.
 sensors_event_t event; 
 dht.temperature().getEvent(&event);
 if (isnan(event.temperature)) 
 {
 Serial.println("Error reading temperature!");
 }
 else 
 {
 Serial.print("Temperature: ");
 Serial.print(event.temperature);
 Serial.println(" *C");
 if(event.temperature >25)
 {
 digitalWrite(ledPin,1);
 }
 else
 {
 digitalWrite(ledPin,0);
 }
 }
 delay(1000);
}

 

Testing, open the serial monitor and try and alter the temperature on the device (blow on it). Blue led should light

 

Share

Arduino Easy Module Shield v1

I spotted a couple of new shields when I was browsing some online shopping sites, so I though I would take a look at these. Initial impressions suggest these would be ideal for beginners.

Shield 1

This shield integrate various module functions and you can directly program to complete the experiment without welding and cables.

This shield can be fully compatible with the Arduino UNO R3 and it will never short circuit with the Arduino UNO USB interface, so this shield is very safe.

Details

Model: Easy Module shield V1

You can see from the image below that tehre are many features, none of tehse are overly difficult to work with the LEDs connect to 2 digital pins, the potentiometer and ldr are connected to analog pins and so on

multi-purpose-shield-v1

Board Features

The board has various features, these make it ideal for beginners who just want to plug in a shield and start coming up with various simple examples rather than dealing with cables, sensors and breadboards
1、Two channels key module
2、Two channels LED module
3、Full color LED module
4、Infrared receiving module
5、Luminance sensor module
6、LM35D temperature sensor module
7、Passive buzzer module
8、Rotate potentiometer module
9、DHT11 temperature and humidity sensor module
10、One I2C interface (A4 SDA, A5 SCL)
11、One TTL serial port
12、Two-way digital port (D7、D8)
13、Two channels analog ports (A3)
14、Reset button

 

Code

This example will show a basic usage of the LDR and pot

#define vrPin A0
#define ldrPin A1
 
void setup() 
{
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
 
void loop() 
{
  // read the variable resistor on analog pin 0:
  float vrValue = analogRead(vrPin);
  float ldrValue = analogRead(ldrPin);
  // Convert the analog reading to a voltage
  float vrVoltage = vrValue * (5.0 / 1023.0);
  float ldrVoltage = ldrValue * (5.0 / 1023.0);
 
  // print out the Variable resistor value you read:
  Serial.print("Variable resistor : ");
  Serial.println(vrVoltage);
  Serial.print("LDR value : ");
  Serial.println(ldrVoltage);
  delay(1000);
}

 

Testing

Open the serial monitor and adjust the pot and cover the LDR

Variable resistor : 0.57
LDR value : 4.35
Variable resistor : 0.57
LDR value : 4.05
Variable resistor : 2.10
LDR value : 4.34
Variable resistor : 1.72
LDR value : 3.29
Variable resistor : 1.72
LDR value : 2.89
Variable resistor : 1.54
LDR value : 1.60
Variable resistor : 0.78
LDR value : 4.33

 

Links

The shield comes in at about $8 which considering it has various parts such as a DHT11, LDR, LM35 and an RGB LED seems to be good value
keyestudio Multi-purpose Shield V1 for arduino starter

Share

Arduino MAG3110 magnetometer example

Freescale’s MAG3110 is a small, low-power, digital 3-axis magnetometer. The device can be used in conjunction with a 3-axis accelerometer to realize an orientation independent electronic compass that can provide accurate heading information. It features a standard I2C serial interface output and smart embedded functions.

The MAG3110 is capable of measuring magnetic fields with an output data rate (ODR) up to 80 Hz; these output data rates correspond to sample intervals from 12.5 ms to several seconds. The MAG3110 is available in a plastic DFN package and it is guaranteed to operate over the extended temperature range of -40°C to +85°C.

Again for ease to use its easier to buy a module with the device fitted to it, here is one that I purchased. You can see the MAG3110 in the middle of the picture

mag3110-module

I also found this schematic online of a similar module to the one pictured above. Looking at the schematic it looks very similar to the module

magsensor-module-schematic

Connection

 

Arduino Pin MAG3110 Pin
3v3 VCC
GND GND
D4 SDA
D5 SCL

Layout

An I2C device so easy to wire up as per the connections above

arduino-and-mag3110_bb

 

Code

This particular code example does not require any libraries

#include <Wire.h>
 
#define MAG_ADDR  0x0E //7-bit address for the MAG3110, doesn't change
 
void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  config();            // turn the MAG3110 on
}
 
void loop()
{
  print_values();
  delay(5);
}
 
void config(void)
{
  Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E
  Wire.write(0x11);             // cntrl register2
  Wire.write(0x80);             // write 0x80, enable auto resets
  Wire.endTransmission();       // stop transmitting
  delay(15); 
  Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E
  Wire.write(0x10);             // cntrl register1
  Wire.write(1);                // write 0x01, active mode
  Wire.endTransmission();       // stop transmitting
}
 
void print_values(void)
{
  Serial.print("x=");
  Serial.print(read_x());
  Serial.print(",");  
  Serial.print("y=");    
  Serial.print(read_y());
  Serial.print(",");       
  Serial.print("z=");    
  Serial.println(read_z());
}
 
int mag_read_register(int reg)
{
  int reg_val;
 
  Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E
  Wire.write(reg);              // x MSB reg
  Wire.endTransmission();       // stop transmitting
  delayMicroseconds(2); //needs at least 1.3us free time between start and stop
 
  Wire.requestFrom(MAG_ADDR, 1); // request 1 byte
  while(Wire.available())    // slave may write less than requested
  { 
    reg_val = Wire.read(); // read the byte
  }
 
  return reg_val;
}
 
int mag_read_value(int msb_reg, int lsb_reg)
{
  int val_low, val_high;  //define the MSB and LSB
  val_high = mag_read_register(msb_reg);
  delayMicroseconds(2); //needs at least 1.3us free time between start and stop
  val_low = mag_read_register(lsb_reg);
  int out = (val_low|(val_high << 8)); //concatenate the MSB and LSB
  return out;
}
 
int read_x(void)
{
  return mag_read_value(0x01, 0x02);
}
 
int read_y(void)
{
  return mag_read_value(0x03, 0x04);
}
 
int read_z(void)
{
  return mag_read_value(0x05, 0x06);
}

 

Testing

Open up the serial monitor

x=44,y=1138,z=1505
x=65175,y=580,z=2037
x=65117,y=745,z=1435
x=65145,y=1487,z=1814
x=64700,y=949,z=1912
x=64848,y=671,z=1921
x=65411,y=803,z=2218
x=64852,y=720,z=1644

 

Link
MAG3110 compass module three-axis electronic compass module magnetoresistive sensor magnetometer module

Share

Arduino and SHT31 module

SHT31 is the next generation of Sensirion’s temperature and humidity sensors. It builds on a new CMOSens® sensor chip that is at the heart of Sensirion’s new humidity and temperatureplatform.

The SHT3x-DIS has increased intelligence, reliability and improved accuracy specifications compared to its predecessor. Its functionality includes enhanced signal processing, two distinctive and user selectable I2C addresses and communication speeds of up to 1 MHz. The DFN package has a footprint of 2.5 x 2.5 mm2 while keeping a height of 0.9 mm.

This allows for integration of the SHT3x-DIS into a great variety of applications.

Features

Fully calibrated, linearized, and temperature compensated digital output
Wide supply voltage range, from 2.4 V to 5.5 V
I2C Interface with communication speeds up to 1 MHz and two user selectable addresses

I bought the following module

sht31

If you’re using an Arduino simply connect the VIN pin to the 5V voltage pin, GND to ground, SCL to I2C Clock (Analog 5) and SDA to I2C Data (Analog 4).

Here is a layout drawn up in fritzing to illustrate thsi

Layout

 

arduino-and-sht31_bb

Code

This example uses the adafruit sht31 library – https://github.com/adafruit/Adafruit_SHT31

#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_SHT31.h"
 
Adafruit_SHT31 sht31 = Adafruit_SHT31();
 
 
void setup() 
{
  Serial.begin(9600);
  if (! sht31.begin(0x44)) 
  {
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
  }
}
 
 
void loop() 
{
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();
 
  if (! isnan(t)) 
  {
    Serial.print("Temp *C = "); Serial.println(t);
  } 
  else 
  { 
    Serial.println("Failed to read temperature");
  }
 
  if (! isnan(h)) 
  {
    Serial.print("Hum. % = "); Serial.println(h);
  } 
  else 
  { 
    Serial.println("Failed to read humidity");
  }
  Serial.println();
  delay(1000);
}

 

Link
1PCS/LOT SHT31 Temperature & SHT31-D Humidity Sensor module Breakout Weather for Arduino

Share