Project

Implementation of RTOS to control and Check the Temperature and Pressure using Binary Semaphore

AIM: To Calculate and Check the Pressure and Temperature in an Atmosphere using Temperature sensor, Pressure sensor and Arduino by using Binary Semaphore in FreeRTOS.

Requirements:

1. Arduino Uno

2. Temperature Sensor

3. Pressure Sensor

4. Connecting wires

5. USB cable

CODE:

#include
#include "Arduino_SensorKit.h"
#include "semphr.h"

SemaphoreHandle_t xBinarySemaphore;


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

while(!Serial);

xBinarySemaphore = xSemaphoreCreateBinary();
xTaskCreate(Temperature, "Task-1",100,NULL,2,NULL);
xTaskCreate(Pressure1, "Task-2", 100,NULL,1,NULL);
xSemaphoreGive(xBinarySemaphore);
}


void loop(){ }


void Temperature(void *pvParameters)
{
while(1)
{
xSemaphoreTake(xBinarySemaphore,portMAX_DELAY);
Serial.println(" Task-1 Acquired the Semaphore");
Serial.print("Temp: ");
Serial.print(Pressure.readTemperature());
Serial.println("C");
delay(1000);

Serial.println(" Task-1 releasing the semaphore");
xSemaphoreGive(xBinarySemaphore);
vTaskDelay(1);
}
}


void Pressure1(void *pvParameters)
{
while(1)
{
xSemaphoreTake(xBinarySemaphore,portMAX_DELAY);
Serial.println(" Task-2 Acquired the Semaphore");
Serial.print("Pressure1: ");

Serial.print(Pressure.readPressure());
Serial.println("Pa");
delay(1000);

Serial.println(" Task-2 releasing the semaphore");
xSemaphoreGive(xBinarySemaphore);
vTaskDelay(1);
}


}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.