element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Smart Security and Surveillance
  • Challenges & Projects
  • Design Challenges
  • Smart Security and Surveillance
  • More
  • Cancel
Smart Security and Surveillance
Forum Guardian Sentinel <Part 5> - Sensor & Motor
  • News
  • Projects
  • Forum
  • DC
  • Leaderboard
  • Files
  • Members
  • More
  • Cancel
  • New
Join Smart Security and Surveillance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 3 replies
  • Subscribers 50 subscribers
  • Views 138 views
  • Users 0 members are here
  • sht40
  • analog-devices
  • sgp30
  • design-challenge
  • sensor
  • MAX32630FTHR#
Related

Guardian Sentinel <Part 5> - Sensor & Motor

meera_hussien
meera_hussien 25 days ago

Guardian Sentinel - Sensor & Motor 

<Part 5>

The sensor that i planned to use in this design is the SGP30 and SHT40 sensor. 

What is SGP30 sensor?

The SGP30 is a digital multi-pixel gas sensor developed for simple integration into air purifiers, demand-controlled ventilation systems, and IoT-based applications. Sensirion’s CMOSens® technology combines a complete sensor system into a single chip, including a digital I²C interface, a temperature-controlled micro hotplate, and two preprocessed indoor air quality output signals. As one of the first metal-oxide gas sensors with multiple sensing elements integrated on a single chip, the SGP30 can provide more comprehensive information about indoor air quality.

Here is the simple infographic about the sensor

image

The one which i am using is from Seeedstudio. A grove based sensor

imageimage

The sensor is connected to the 

What is SHT40 sensor?

The Grove SHT40 digital sensor is built around Sensirion’s proven humidity and temperature sensing technology. It delivers reliable temperature and humidity measurements across a wide measurement range. With the Grove connector system, the SHT40 sensor can be easily connected and used with a wide range of microcontrollers, making it suitable for quick plug-and-play prototyping.

Here is the simple infographic about the sensor

image

imageimage

Both the sensor is interfaced to the FTHR-PMD-INTZ Feather-to-PMOD via i2C. Figure below shows how the pinout for the i2C connection. 

image

 At the top we connect the SGP30 sensor and at the bottom we connect the SHT40 sensor as shown in the image below

image image image

Once the sensor are connected, we re-run the i2c scanner code to ensure that the sensor are detected by the MAX32630FTHR and also to get respective i2C address. 

#include <Wire.h>

void setup() {
  Serial.begin(115200);
  while (!Serial);

  Serial.println("MAX32630FTHR I2C Scanner");
  Wire.begin();
}

void loop() {
  byte error, address;
  int devices = 0;

  Serial.println("Scanning I2C bus...");

  for (address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) Serial.print("0");
      Serial.println(address, HEX);
      devices++;
    }
  }

  if (devices == 0) {
    Serial.println("No I2C devices found.");
  } else {
    Serial.print("Total devices found: ");
    Serial.println(devices);
  }

  Serial.println();
  delay(3000);
}

The serial output shows the sensor are detected and also the i2C address as well

image

Once we have the i2C address, we can now write the code the read both the sensor values

 

#include <Wire.h>
#include <Adafruit_SGP30.h>
#include <Adafruit_SHT4x.h>
#include <Adafruit_Sensor.h>

// Sensor objects
Adafruit_SGP30 sgp30;
Adafruit_SHT4x sht40 = Adafruit_SHT4x();

// I2C addresses
#define SGP30_ADDR 0x58
#define SHT40_ADDR 0x44

unsigned long lastReadTime = 0;
const unsigned long readInterval = 2000; // Read every 2 seconds

// Function to calculate absolute humidity for SGP30 compensation
// Input: temperature in Celsius, relative humidity in %
// Output: absolute humidity in mg/m^3
uint32_t getAbsoluteHumidity(float temperature, float humidity) {
  const float absoluteHumidity =
    216.7f *
    ((humidity / 100.0f) * 6.112f *
    exp((17.62f * temperature) / (243.12f + temperature)) /
    (273.15f + temperature));

  return (uint32_t)(absoluteHumidity * 1000.0f);
}

void setup() {
  Serial.begin(115200);
  delay(2000);

  Serial.println();
  Serial.println("SGP30 + SHT40 Sensor Test");
  Serial.println("-------------------------");

  Wire.begin();

  // Start SHT40
  if (!sht40.begin(&Wire)) {
    Serial.println("SHT40 not detected at address 0x44.");
    Serial.println("Check wiring and I2C connection.");
    while (1);
  }

  Serial.println("SHT40 detected at address 0x44.");

  // Optional SHT40 settings
  sht40.setPrecision(SHT4X_HIGH_PRECISION);
  sht40.setHeater(SHT4X_NO_HEATER);

  // Start SGP30
  if (!sgp30.begin(&Wire)) {
    Serial.println("SGP30 not detected at address 0x58.");
    Serial.println("Check wiring and I2C connection.");
    while (1);
  }

  Serial.println("SGP30 detected at address 0x58.");

  Serial.print("SGP30 serial number: ");
  Serial.print(sgp30.serialnumber[0], HEX);
  Serial.print(sgp30.serialnumber[1], HEX);
  Serial.println(sgp30.serialnumber[2], HEX);

  Serial.println();
  Serial.println("Allow the SGP30 to warm up for stable readings.");
  Serial.println();
}

void loop() {
  if (millis() - lastReadTime >= readInterval) {
    lastReadTime = millis();

    sensors_event_t humidityEvent;
    sensors_event_t temperatureEvent;

    // Read SHT40 temperature and humidity
    sht40.getEvent(&humidityEvent, &temperatureEvent);

    float temperature = temperatureEvent.temperature;
    float humidity = humidityEvent.relative_humidity;

    // Calculate absolute humidity for SGP30 compensation
    uint32_t absoluteHumidity = getAbsoluteHumidity(temperature, humidity);

    // Send humidity compensation to SGP30
    sgp30.setHumidity(absoluteHumidity);

    // Read SGP30 air quality values
    if (!sgp30.IAQmeasure()) {
      Serial.println("Failed to read SGP30.");
      return;
    }

    Serial.println("===== Sensor Readings =====");

    Serial.print("SHT40 Temperature : ");
    Serial.print(temperature);
    Serial.println(" °C");

    Serial.print("SHT40 Humidity    : ");
    Serial.print(humidity);
    Serial.println(" %RH");

    Serial.print("SGP30 TVOC        : ");
    Serial.print(sgp30.TVOC);
    Serial.println(" ppb");

    Serial.print("SGP30 eCO2        : ");
    Serial.print(sgp30.eCO2);
    Serial.println(" ppm");

    Serial.print("Abs Humidity      : ");
    Serial.print(absoluteHumidity);
    Serial.println(" mg/m3");

    Serial.println("===========================");
    Serial.println();
  }
}

The output

image

Next we shall see how to interface the stepper motor. Below is the stepper motor i use in this project and the wiring diagram. I am using the stepper motor as shown in image below


image

The connection between the stepper FeatherWing and the stepper motor is done as shown in the image below


imageimage

Coil 1 from stepper motor is connected to M3 and coil 2 is connected to M4. Since the FeatherWing has two port, please ensure you are connecting which port. Port 1 is connected with M1 and M2 and Port 2 is connected to M3 and M4. In my case i am using the Port 2. Once the wiring for the motor is complete, connect the external power to power up the stepper motor. And i run the code below to test if everything works fine.

#include <Wire.h>
#include <Adafruit_MotorShield.h>

#define MOTOR_ADDR 0x60
#define STEPPER_PORT 2
#define STEPS_PER_REV 200

Adafruit_MotorShield AFMS = Adafruit_MotorShield(MOTOR_ADDR);
Adafruit_StepperMotor *myMotor = AFMS.getStepper(STEPS_PER_REV, STEPPER_PORT);

void setup() {
  Serial.begin(115200);
  delay(2000);

  Serial.println("Stepper Smooth Test - M3/M4");

  Wire.begin();

  if (!AFMS.begin()) {
    Serial.println("Motor FeatherWing not found at 0x60.");
    while (1);
  }

  Serial.println("Motor FeatherWing found.");
  Serial.println("Using Port 2: M3/M4");

  myMotor->setSpeed(5);  // Try 5, 10, 20
}

void loop() {
  Serial.println("Forward MICROSTEP...");
  myMotor->step(200, FORWARD, MICROSTEP);
  delay(1000);

  Serial.println("Backward MICROSTEP...");
  myMotor->step(200, BACKWARD, MICROSTEP);
  delay(1000);
}

And the video below is the working demo

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Now all are working fine. Next is the integration. 

  • Sign in to reply
  • Cancel

Top Replies

  • saramic
    saramic 24 days ago +1
    cool thanks for sharing some of the sensors I had not heard of and was curious of a CO2 parts per million sensor for another project. Your images don't seem to be showing but you seem to be using a The…
  • saramic
    saramic 24 days ago

    cool thanks for sharing some of the sensors I had not heard of and was curious of a CO2 parts per million sensor for another project. Your images don't seem to be showing but you seem to be using a

    The SGP30 is a digital multi-pixel metal-oxide (MOX) gas sensor from Sensirion designed for air quality monitoring in smart home, IoT, and purification applications. It combines multiple sensing elements on a single chip to provide detailed signals for Total Volatile Organic Compounds (TVOC) and equivalent CO₂ (eCO₂) over an I²C interface

    nice to see how easy using

    #include <Adafruit_MotorShield.h>

    is, as I am using LPSDK it seems I have to write my own stepper motor tables to fire the correct coils and I am getting some interesting results - post coming soon

    good luck Fingers crossedTada 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • DAB
    DAB 24 days ago

    A lot of the images did not display.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • kmikemoo
    kmikemoo 23 days ago in reply to DAB

    It's the first 3 images for me, both last night and today.  The others came up.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube