Ahmed Abdulhai
Published © MIT

Greenhouse Control Room using Hexabitz Platform

In this project, we will control the temperature and humidity of an agricultural space using a PID controller and Hexabitz modules

IntermediateFull instructions provided5 hours417
Greenhouse Control Room using Hexabitz Platform

Things used in this project

Story

Read more

Schematics

H0AR9 Factsheet

Hexabitz H3BR6x 6 digit seven segment interface module Hardware Design

H3BR6x Factsheet

Hexabitz H01R0x smart RGB LED module Hardware Design

Hexabitz H0FR1x compact mechanical DC relay module hardware

Haxbitz H0FR6x compact solid state relay (SSR) module Hardware Design

H0FR6 Factsheet

H01R0x Factsheet

H0FR1 Factsheet

Hexabitz H0AR9x Sensor Hub Module Hardware Design

Code

Greenhouse Control Room using Hexabitz Platform

C/C++
/*
 BitzOS (BOS) V0.2.9 - Copyright (C) 2017-2023 Hexabitz
 All rights reserved

 File Name     : main.c
 Description   : Main program body.
 */
/* Includes ------------------------------------------------------------------*/
#include "BOS.h"

/* Private variables ---------------------------------------------------------*/

float temper;
float humidity;

double Kp =20.0;
double Ki =0.01;
float setpoint =24.5; // We set the desired temperature value in Celsius
float dt =0.1; // Sampling time for the control loop
double pid_output;
float error;
/* Private function prototypes -----------------------------------------------*/
uint8_t pid_controller(float setpoint,float temper);

uint8_t pid_controller(float setpoint,float temper){
	float integral_error, mx_val;
	
	// Calculate error
	error =setpoint - temper;
	
	// Calculate integral error
	integral_error +=error * dt;
	// saturation for integral_error
	mx_val =50;
	if(integral_error > mx_val)
		integral_error =mx_val;
	if(integral_error < -mx_val)
		integral_error =-mx_val;
	
	// Calculate PID output
	pid_output =Kp * error + Ki * integral_error;
	// saturation for output PID we set a maximum value 100% and minimum value 0%
	if(pid_output > 100){
		pid_output =100;
	}
	
	if(pid_output <= 0){
		pid_output =0;
	}
	return pid_output;
}
/* Main function ------------------------------------------------------------*/

int main(void){
	
	Module_Init();		//Initialize Module &  BitzOS
	
	//Don't place your code here.
	for(;;){
	}
}

/*-----------------------------------------------------------*/

/* User Task */
void UserTask(void *argument){
// Welcome Message on seven segment
	messageParams[0] =17;
	memcpy(&messageParams[1],&"Hexabitz platform",sizeof("Hexabitz platform"));
	SendMessageToModule(5,CODE_H3BR6_SevenDisplayMovingSentence,18);
	Delay_ms(5000);
	
	// put your code here, to run repeatedly.
	while(1){
		
// sampling reading from sensors
		SampleHumidity(&humidity);
		
		SampleTemperature(&temper);
		
		if(pid_controller(setpoint,temper) == 0){
			SendMessageToModule(4,CODE_H0FR6_OFF,0);
			
			messageParams[0] =0;
			messageParams[1] =BLUE;
			messageParams[2] =100;
			SendMessageToModule(1,CODE_H01R0_COLOR,3);
		}
		else{
			
			// setting a percent value to moudel H0FR6x (SSR) from output pid
			messageParams[0] =pid_controller(setpoint,temper);
			SendMessageToModule(4,CODE_H0FR6_PWM,1);
			
			messageParams[0] =0;
			messageParams[1] =GREEN;
			messageParams[2] =pid_controller(setpoint,temper);
			SendMessageToModule(1,CODE_H01R0_COLOR,3);
			
		}
		// on and off moudel H0FR1x (SPDT) relay
		if((temper >= 30 && pid_controller(setpoint,temper) == 0) || (humidity >= 75 && humidity <= 95)){
			
			float timeout =0xFFFFFFFF;
			memcpy(&messageParams[0],&timeout,4);
			SendMessageToModule(3,CODE_H0FR1_ON,4);
		}
		else{
			SendMessageToModule(3,CODE_H0FR1_OFF,0);
		}
		//    printing value of temperature and humidity on seven segment
		
		memcpy(&messageParams[0],&temper,4);
		messageParams[4] =3;
		messageParams[5] ='c';
		messageParams[6] =0;
		SendMessageToModule(5,CODE_H3BR6_SevenDisplayQuantities,7);
		Delay_ms(700);
		
		memcpy(&messageParams[0],&humidity,4);
		messageParams[4] =3;
		messageParams[5] ='H';
		messageParams[6] =0;
		SendMessageToModule(5,CODE_H3BR6_SevenDisplayQuantities,7);
		Delay_ms(700);
	}
}

/*-----------------------------------------------------------*/

H0AR91-Greenhouse Control Room using Hexabitz Platform

C/C++
No preview (download only).

H0FR1-Greenhouse Control Room using Hexabitz Platform

C/C++
No preview (download only).

H0FR6-Greenhouse Control Room using Hexabitz Platform

C/C++
No preview (download only).

H01R0x-Greenhouse Control Room using Hexabitz Platform

C/C++
No preview (download only).

H3BR6-Greenhouse Control Room using Hexabitz Platform

C/C++
No preview (download only).

Haxbitz H0FR6x compact solid state relay (SSR) module firmware

Hexabitz Sensor Hub (Temperature, Humidity, Ambient Light, Color, Sound, Motion) Module Firmware

Hexabitz H01R0x smart RGB LED module firmware

Hexabitz H0FR1x compact mechanical DC relay module firmware

Hexabitz H3BR6x 6 digit seven segment interface module firmware

Credits

Ahmed Abdulhai
3 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.