Things used in this project

Hardware components:
09590 01
LED (generic)
×3
10988 01
Temperature Sensor
×1
51gzz5eu9pl. sx425
HC-SR04
×1
A000066 iso both
Arduino UNO & Genuino UNO
×1
Software apps and online services:
ARTe (Arduino Real-Time extension)

Schematics

Circuit Diagram
Electronic circuit of the components used. This schema has been designed to work properly with the implemented Arduino code. If the layout of the components is changed, you must change the pin statement in the Arduino code.
circuitdiagram_WWyvXhbDQZ.fzz

Code

Multitasking and Real-Time Arduino ProcessingArduino
This simple project shows how Arduino can be used with a real time operating system (Erika). A special version of Arduino called ARTe was used for software development ( http://retis.sssup.it/?q=arte ).
ARTe (Arduino Real-Time extension) is an extension to the Arduino framework that supports multitasking and real-time preemptive scheduling. Thanks to ARTe, the user can easily specify and run multiple concurrent loops at differents rates, in addition to the single execution cycle provided by the standard Arduino framework. Today ARTE supports the most popular platforms: Arduino UNO and Arduino DUE. In addition to the single loop present in the standard Arduino approach, the user can easily specify a number of concurrent loops to be executed at specific rates. Concurrency and real-time scheduling is provided by the ERIKA Enterprise (http://erika.tuxfamily.org/drupal/) open-source real-time kernel. Loops can use the standard Arduino libraries, which have been enhanced to guarantee mutual exclusion in the access of shared data structures. The impact of ARTe in terms of footprint and runtime overhead has beed evaluated by extensive tests and resulted to be negligible.
In this project was used to run 3 periodic processes that handle different activities. A process for managing every 3 seconds the acquisition of the distance through the sensor HC-SR04. Another process for flashing a LED every 7 seconds. A final process to read the temperature returned by the LM35 sensor expressed in degrees Celsius is executed every 11 seconds. All processes are managed in real time mode.
//Pin definition
static int trigger = 9; // Pin HC-SR04
static int echo = 8; // Pin HC-SR04
static int led_HC = 10; // Pin HC-SR04
static int led_pulsed = 13; // Timed pulsed led
static int led_temperature = 12; // Led to temperature overflow
static int LM35_analogPin = 0; // analog pin for temperature sensor


// Variables for calculating the distance with sensor HC-SR04
long duration; // Flight time of signal
long distance;  // Calculated distance 
float temp_C; // temperature variable (Celsius degrees)

void setup() {
  //Serial communication
  Serial.begin(9600);

  //Pin setup
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(led_HC, OUTPUT);
  pinMode(led_pulsed, OUTPUT);
  pinMode(led_temperature, OUTPUT);

  digitalWrite(echo, LOW);
  digitalWrite(trigger, LOW);
  digitalWrite(led_HC, LOW);
  digitalWrite(led_pulsed, LOW);
  digitalWrite(led_temperature, LOW);

  //Analog input
  analogReference(INTERNAL); // prendo la misura analogica di riferimento di Arduino a 1.1V

  //Variable initialization of the distance
  duration = 0;
  distance = 0;
}

void loop() {
}

void loop1(3000) {
  //Send a HIGH pulse to the trigger pin
  digitalWrite(trigger, HIGH);
  //I leave it to the HIGH value for 10 microseconds
  delayMicroseconds(10);
  //I carry it back to the LOW state
  digitalWrite(trigger, LOW);

  //I get the number of microseconds for which the echo PIN is left in HIGH state
  duration = pulseIn(echo, HIGH);

  /*Sound velocity is 340 meters per second, or 29 microseconds per cent.
    Our impulse travels back and forth, so to calculate the distance
   Between the sensor and our obstacle we need to do:*/
  distance = duration / 29 / 2;

  // Turn on the led if there is an obstacle at a distance of less than 10 cm
  if (distance < 10) {
    digitalWrite(led_HC, HIGH);
  }
  else {
    digitalWrite(led_HC, LOW);
  }
  // Print on the serial buffer
  Serial.print("duration : ");
  Serial.print(duration);
  Serial.print(" - distance : ");
  Serial.println(distance);
}

void loop2(7000) {
  int i;
  Serial.println("Pulsed LED");
  // Code for the flashing of the led
  for (i = 0; i < 5; i++)
  {
    digitalWrite(led_pulsed, HIGH);
    delay(500);
    digitalWrite(led_pulsed, LOW);
    delay(500);
  }
}

void loop3(11000) {
  float sum_temp = 0;
  float average_temp = 0;
  /* Acquire 3 values from the sensor every 500 milliseconds.
     Through an appropriate conversion I get the measure in degrees Celsius.
     Calculate the average of subsequent measurements.*/
  for (int i = 0; i < 3; i++){  
    delay(500);
    temp_C = (1.1 * analogRead(LM35_analogPin) * 100.0) / 1024;
    sum_temp += temp_C;
  }
  average_temp = sum_temp / 3;
  // If the temperature is greater than 23 degrees, turn on the led
  if (average_temp > 23) {
    digitalWrite(led_temperature, HIGH);
  }
  else {
    digitalWrite(led_temperature, LOW);
  }
  Serial.print("Temperature : ");
  Serial.println(average_temp);
}
Multitasking-RealTime-Arduino-System
This simple project shows how Arduino can be used with a real time operating system (Erika). A special version of Arduino called ARTe was used for software development ( http://retis.sssup.it/?q=arte ). ARTe (Arduino Real-Time extension) is an extension to the Arduino framework that supports multitasking and real-time preemptive scheduling. Thanks to ARTe, the user can easily specify and run multiple concurrent loops at differents rates, in addition to the single execution cycle provided by the standard Arduino framework. Today ARTE supports the most popular platforms: Arduino UNO and Arduino DUE. In addition to the single loop present in the standard Arduino approach, the user can easily specify a number of concurrent loops to be executed at specific rates. Concurrency and real-time scheduling is provided by the ERIKA Enterprise (http://erika.tuxfamily.org/drupal/) open-source real-time kernel. Loops can use the standard Arduino libraries, which have been enhanced to guarantee mutual exclusion in the access of shared data structures. The impact of ARTe in terms of footprint and runtime overhead has beed evaluated by extensive tests and resulted to be negligible. In this project was used to run 3 periodic processes that handle different activities. A process for managing every 3 seconds the acquisition of the distance through the sensor HC-SR04. Another process for flashing a LED every 7 seconds. A final process to read the temperature returned by the LM35 sensor expressed in degrees Celsius is executed every 11 seconds. All processes are managed in real time mode.

Credits

10584066 10204278356307954 447257766737252888 n mthzqqyscl
Melvin Mancini

I'm a student at the Faculty of Computer Science and Automation at the Computer and Automation Engineering at Marche Polytechnic University.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Smart Garden
Intermediate
  • 1,073
  • 12

Smart Garden is plant environmental monitoring system.

Control RGB LED by Dragging – Arduino 101 & App Inventor
Intermediate
  • 233
  • 4

Full instructions

This topic will teach you how to control a RGB LED on an Arduino 101 board with an Android device (MIT App Inventor).

Arduino Bike Blink Lights
Intermediate
  • 483
  • 8

Protip

Arduino Nano bike bag signals, controlled by a wireless (RF) RC attached to front handle.

WiDC: Wi-Fi-Controlled FPV Robot
Intermediate
  • 5,107
  • 32

Full instructions

What about using a Wi-Fi remote-controlled robot for exploring your surroundings, reaching inaccessible places, spying and take pictures?

Sienci Mill One - Simple and Affordable Desktop CNC
Intermediate
  • 7,826
  • 37

Full instructions

The Sienci Mill One is a powerful, open source desktop CNC machine to turn your digital 3D designs into real physical objects.

MPU9250-Data-Visualization
Intermediate
  • 343
  • 6

Protip

A useful tool to visualize at real time data of the MPU9250 sent through a COM port.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback