Chipkit Max32 and Easy module Shield V1 temperature examples

We will now look at some more Easy module Shield V1 examples, this time looking at the DHT11 and LM35 temperature sensors

here is a picture of the shield

 

Sample Code

We are going to look at the two temperature sensors that are fitted to the shield in these examples

DHT11 example

Here is the connection for the DHT11 sensor

You need the following library installed https://github.com/winlinvip/SimpleDHT

[codesyntax lang=”cpp”]

#include <SimpleDHT.h>

int pinDHT11 = 4;
SimpleDHT11 dht11;

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{

  byte temperature = 0;
  byte humidity = 0;
  if (dht11.read(pinDHT11, &temperature, &humidity, NULL)) 
  {
    Serial.print("Read DHT11 failed.");
    return;
  }
  
  Serial.print((int)temperature); 
  Serial.print(" *C, "); 
  Serial.print((int)humidity); 
  Serial.println(" %");
  delay(1000);
}

[/codesyntax]

OPen the serial monitor and you should see something like this

24 *C, 18 %
24 *C, 18 %
24 *C, 18 %
24 *C, 18 %
24 *C, 18 %
24 *C, 18 %
25 *C, 17 %

 

LM 35 example

Here is the LM35 connection on the shield

[codesyntax lang=”cpp”]

//declare variables
float tempC;
int tempPin = 2;

void setup()
{
  Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}

void loop()
{
  tempC = analogRead(tempPin);           //read the value from the sensor
  tempC = (3.3 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
  Serial.print((byte)tempC);    
  Serial.println(" c");        
  delay(1000);                           
}

[/codesyntax]

Open the serial monitor

25 c
26 c
27 c
27 c
27 c

Temperature sensor comparison

In this example we will compare the LM35 and DHT11 sensors to see the differences in the readings

[codesyntax lang=”cpp”]

#include <SimpleDHT.h>

int pinDHT11 = 4;
float tempC;
int tempPin = 2;
byte temperature = 0;
byte humidity = 0;
SimpleDHT11 dht11;

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{

  tempC = analogRead(tempPin);           //read the value from the sensor
  tempC = (3.3* tempC * 100.0)/1024.0;  //convert the analog data to temperature
  if (dht11.read(pinDHT11, &temperature, &humidity, NULL)) 
  {
    Serial.print("Read DHT11 failed.");
    return;
  }
  Serial.print("DHT11 - ");
  Serial.print((int)temperature); 
  Serial.print(" *C, ");
  Serial.print("LM35 - "); 
  Serial.print((byte)tempC);
  Serial.println(" *C");
  delay(1000);
}

[/codesyntax]

Open the serial monitor and this is what you will see

DHT11 – 24 *C, LM35 – 25 *C
DHT11 – 24 *C, LM35 – 25 *C
DHT11 – 24 *C, LM35 – 25 *C
DHT11 – 24 *C, LM35 – 25 *C
DHT11 – 24 *C, LM35 – 25 *C
DHT11 – 24 *C, LM35 – 25 *C
DHT11 – 24 *C, LM35 – 25 *C

 

Link

$10 for one of these shields

keyestudio Multi-purpose Shield V1 for arduino starter

Related posts

Chipkit Max32 and ADXL335 accelerometer example

Chipkit Max32 and LSM303 Accelerometer example

Chipkit Max32 and LSM303 Magnetometer example

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More