IIot Test Bed Using Maixduino

Published  November 12, 2024   0
IIot Test Bed Using Maixduino

The main idea of this project is to develop a test bed for Industrial Internet of Things to monitor parameters like temperature, humidity, light level, DC motor RPM and its power consumption. Sipeed Maixduino board act as the processing unit to measure, process and display the parameters in the LCD. Further the data is transferred to a host PC to feed the data to Adafruit IO platform.

Components Used:

1.    Sipeed Maixduino Kit for RISC-V AI + IoT
2.    DHT 11 temperature and humidity sensor
3.    BH1750 Light sensor
4.    1000 RPM DC motor
5.    L298N dual H-Bridge motor driver
6.    Opto-interrupter sensor or IR LED sensor module
7.    INA219 current sensor module
8.    30 slot rotary encoder disc mechanism and arrangement to hold the motor.
9.    12 V 5 A DC power adopter for DC motor

To see the full demonstration video, click on the YouTube Video below.

<

Project Description:

This prototype could be used as a IIoT test bed for data collection, processing and to upload data to cloud platform. DC motor RPM and its power consumption measurement is vital in predicting faults and analyzing the motor life in industrial applications. In this prototype 30 slot rotating disc mechanism and holder for DC motor is developed using 3D printing. Used any cubic Kobra2 neo printer and PETG material for making the mechanism. The mechanism holds the motor as well as the opto interrupter as shown in Fig 1 below.
 

Encoder Disc

Fig 1: 3D printed 30 slot encoder disc and motor holding mechanism.

Whenever the DC motor is enabled with defined duty cycle, 30 slot encoder disc mechanism mounter with the DC motor starts rotating, further the opto-interrupter starts to detect the number of ticks per slot detected and increments the counter value up to 30 counts in this setup since the encoder disc has 30 slots.  One complete rotation takes 30 count value. Based on the slot counted for defined interval motor speed is computed. Along with this current and power consumption of the motor also measured using the INA 219 current sensor module. DHT11 sensor is used to measure the Ambient temperature and relative humidity of the test environment. Light sensor BH1750 is used to measure the light intensity. Opto interrupter sensor is used to detect the disc rotation to compute the motor speed. Below Fig2 shows the working setup of the developed system.

Developed System Working Setup

Circuit Description:

BH1750 and INA219 sensor modules are I2C compatible and their SDA and SCL lines are connected to the Maixduino SDA and SCL pins respectively for data communication. DHT11 sensor supports onewire interface and it’s connected to PIN3 of Maixduino. Opto interrupter sensor output is connected to the PIN2 of Maixduino. L298N H-Bridge motor driver is used to control the speed of 1000 RPM DC motor. ENA pin of motor driver is connected to PIN6, Motor input IN1 and IN2 are connected to PIN8 and PIN9 of Maixduino. DC motor connected with OUT1 terminals of motor driver module. To measure the current and power consumption of DC motor, motor drive module is power with a 12V 5A DC power adopter through the INA219 module. Circuit diagram of the developed system is shown in Fig 3. Maixduino detects and computes the motor speed, current and power consumed, temperature and relative humidity and light level. Further the computed data are transferred to the host PC via serial communication and onboard LCD display of Maixduino. 
 

Developed system working setup Schematics

Fig 3: circuit diagram of the developed system

Software description:

Arduino IDE is used for the code development. The code utilizes wire.h, for I2C communication and BH1750.h for reading data from BH1750 sensor, INA219.h for reading data from current sensor module. DHT11.h is used for reading temperature and humidity data. Sipeed_ST7789.h is used for the display utilization.

Below are the few functions created:

1.    title() – This function, initializes the display and print project title on the display 
2.    motorinit() – This function, initializes the motor settings (ENA to control speed, IN1 & IN2 for direction and motor control.
3.    motoroff() – This function turns off the motor
4.    motoronforward() – This function, moves the motor in forward direction
5.    motoronbackward() – This function, moves the motor in backward direction
6.    RPM_speed(int a) – This function, get the duty cycle value for the motor speed
7.    readlight() – This function, reads the light value and update the value display and send it to serial port
8.    readrpm() – This function computes the RPM and update the value in display and send it to serial port
9.    readINA() – This function reads the current and power consumption data and update the value in display and send it to serial port
10.    temphumi() – This function reads the temperature and humidity values and update the values in display and send it to serial port

The code initializes required settings in the void setup() and void loop() has the function calls to read the sensor data and update the display and transfer the data over serial communication to host PC.

Results:

Below Fig 4 & Fig 5 shows the display of measurement parameters during Motor OFF and Motor ON state.  Fig 6 shows the measurement data collected on the serial port of the host PC.

Measurement Data on Display During Motor OFF

Fig 4: Measurement data on display during Motor OFF

Data on Display During Motor On

Fig 5: Measurement data on display during Motor ON

Serial Port Of Host PC

Fig 6A: Measurement data collected on the serial port of the host PC

Python Script

Fig 6B: measurement of data with python script to read the serial data on the host PC

Future enhancement:

At its present status, the developed system is not having IIoT enablement. In future, host PC can forward data or from the Maixduino through Wi-Fi communication can send data to Adafruit IO or similar cloud platforms to have the IoT connectivity, through the IoT platform further motor speed could be controlled and monitored for motor fault analysis and prediction of motor life which enables the complete IIoT system. Initially it was planned to measure the motor speed through the on-board camera on Maixduino, in future it will also been carried out to enable machine vision capability. In connection to this work, dashboard is created with Adafruit IO for the IIoT enablement as shown in Fig 7.

Adafruit IO dashboard

Fig 7: Adafruit IO dashboard view for the developed system

To view the code and schematics of the project, please click on the GitHub icon below.

Iiot Test Bed Using Maixduino CodeIiot Test Bed Using Maixduino Zip File

Code

/*
This code is tested working with Sipeed Maixduino
it measures following parameters:
1. light intensity (BH1750 sensor),
2. temperature & Humidity (DHT11 sensor), 
3. current and power consumption of DC motor (INA219 module)
4. DC Motor Rotation per minute (Opto interruptor sensor reads DC motor rotation through the 30 slot mechanism. DC motor connected with L293N module)  
all the measured parameters values are updated in the Sipeed ST7789 display and transferred via serial port at 115200 baud rate.
Modified and updated by K. Vairamani on 08/11/2024
*/
#include <Sipeed_ST7789.h>
#include<BH1750.h>
#include<Wire.h>
#include "INA219.h"
#include <DHT11.h>
DHT11 dht11(3);
INA219 INA(0x41);
BH1750 lightMeter;
unsigned long start_time = 0;
unsigned long end_time = 0;
int steps=0;
float steps_old=0;
float temp=0;
float RPS=0;
float RPM = 0;
int counter = 2; //opto interruptor pin 
unsigned long millisBefore;
volatile int slotcount;

int temperature = 0;
int humidity = 0;

SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD
Sipeed_ST7789 lcd(320, 240, spi_);
//L298N pin connections
int PWM_EN = 6; //Connected to enable pin for L298N module
int M1 = 8; // Connected to IN1 of L298N module
int M2 = 9; // Connected to IN2 of L298N module

//funtion protypes
void title();
void motorinit();
void motoroff();
void motoronforward();
void motoronbackward();
void RPM_speed(int a);
void readlight();
void readrpm();
void readINA();
void temphumi();

void setup()
{
   Wire.begin();
   Serial.begin(115200);
   motorinit();
   motoroff(); 
   pinMode(counter, INPUT_PULLUP);
   lightMeter.begin();
   if (!INA.begin() )
   {
       Serial.println("Could not connect to INA219. Fix and Reboot");
   }
   INA.setMaxCurrentShunt(5, 0.002);
   delay(1000);
   lcd.begin(15000000, COLOR_BLUE);    
   lcd.setRotation(0);

}

void loop() {
 title();
 readlight();  
 temphumi();
 RPM_speed(255); //Duty Cycle 100%
 motoronforward();
 readINA();
 readrpm();
//  motoroff();
 delay(1000);
}

 

void motorinit()
{
 // Set all the motor control pins to outputs
    pinMode(PWM_EN, OUTPUT);
    pinMode(M1, OUTPUT);
    pinMode(M2, OUTPUT);
}
void motoroff()
{    
    // Turn off motors
    digitalWrite(M1, LOW);
    digitalWrite(M2, LOW);
}
void motoronforward()
{
 // Turn ON motors Forward rotation
    digitalWrite(M1, HIGH);
    digitalWrite(M2, LOW);
}
void motoronbackward()
{
 // Turn ON motors backward rotation
    digitalWrite(M1, LOW);
    digitalWrite(M2, HIGH);
}
void RPM_speed(int a)
{
 analogWrite(PWM_EN, a);
}
void readrpm()
{
 //lcd.print("RPM m/s: ");
 start_time=millis();
 end_time=start_time+1000;
 while(millis()<end_time)
 {
   if(digitalRead(counter))
   {
     steps=steps+1; 
     while(digitalRead(counter));
  }
 }
 temp=steps-steps_old;
 steps_old=steps;
 RPS=(temp/30); //change yoursRevolution encoder slot here Example: 30
 RPM=(RPS*60);
 Serial.print("RPM:");
 Serial.println(RPM);
 lcd.setCursor(1,190);
 lcd.print("Motor RPM:");
 lcd.setCursor(180,190);
 lcd.println(RPM);
}
void readlight()
{
 float lux = lightMeter.readLightLevel();
 Serial.print("Light lx:");
 Serial.print(lux,2);
 Serial.print(',');
 lcd.setCursor(1,70);
 lcd.print("Light lx: ");
 lcd.setCursor(180,70);
 lcd.println(lux);
 
}
void title()
{
   lcd.fillScreen(COLOR_BLUE);
   lcd.setTextSize(2);
   lcd.setTextColor(COLOR_WHITE);
   lcd.setCursor(60,10);
   lcd.println("Sipeed MAIXDUINO");
   lcd.setCursor(60,40);
   lcd.println("IIoT test bed");
}
void readINA()
{
 lcd.setCursor(1,130);
 lcd.print("Shunt mV: ");
 lcd.setCursor(180,130);
 lcd.print(INA.getShuntVoltage_mV(), 2);
 lcd.setCursor(1,150);
 lcd.print("Current mA");
 lcd.setCursor(180,150);
 lcd.print(INA.getCurrent_mA(), 2);
 lcd.setCursor(1,170);
 lcd.print("Power mW:");
 lcd.setCursor(180,170);
 lcd.print(INA.getPower_mW(), 2);
 Serial.print("Current mA:");
 Serial.print(INA.getCurrent_mA(), 2);
 Serial.print(",");
 Serial.print("Power mW:");
 Serial.print(INA.getPower_mW(), 2);
 Serial.print(",");
}
void temphumi()
{
     // Attempt to read the temperature and humidity values from the DHT11 sensor.
   int result = dht11.readTemperatureHumidity(temperature, humidity);
   // Check the results of the readings.
   // If the reading is successful, print the temperature and humidity values.
   // If there are errors, print the appropriate error messages.
   if (result == 0) {
       Serial.print("Temperature °C: ");
       Serial.print(temperature);
       Serial.print(',');
       Serial.print("Humidity %:");
       Serial.print(humidity);
       Serial.print(',');
       lcd.setCursor(1,90);
       lcd.print("Temperature C: ");
       lcd.setCursor(180,90);
       lcd.println(temperature);
       lcd.setCursor(1,110);
       lcd.print("Humidity %: ");
       lcd.setCursor(180,110);
       lcd.println(humidity);

   } else {
       // Print error message based on the error code.
       Serial.println(DHT11::getErrorString(result));
   }
}

Have any question realated to this Article?

Ask Our Community Members