Professional Documents
Culture Documents
PIN Assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
Code :
// Required libraries will be imported
#include <OneWire.h>
#include <DallasTemperature.h>
void setup() {
// Sensor is initialized
sensors.begin();
}
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
Code:
int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
void setup ()
{
pinMode (Led, OUTPUT) ; // Initialize output pin
pinMode (Sensor, INPUT) ; // Initialize sensor pin
digitalWrite(Sensor, HIGH) ; // Activate internal pull-up resistor
}
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor
is read out
Pr Jarou Tarik
TP de l’informatique industrielle
{
digitalWrite (Led, LOW);
}
else
{
digitalWrite (Led, HIGH);
}
}
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage:
Code:
int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
void setup ()
{
pinMode (Led, OUTPUT) ; // Initialize output pin
pinMode (Sensor, INPUT) ; // Initialize sensor pin
Pr Jarou Tarik
TP de l’informatique industrielle
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor
is read out
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage:
Code:
int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
void setup ()
{
Pr Jarou Tarik
TP de l’informatique industrielle
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor
is read out
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage:
Code:
int Led = 3;
void setup ()
{
pinMode (Led, OUTPUT); // Initialize output pin for the LED
Pr Jarou Tarik
TP de l’informatique industrielle
}
void loop () //Main program loop
{
digitalWrite (Led, HIGH); // LED is switched on
delay (4000); // Wait mode for 4 seconds
digitalWrite (Led, LOW); // LED is switched off
delay (2000); // Wait mode for another two seconds during which
the LED is switched off
}
PIN Assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
Code:
int buzzer = 8 ; // Declaration of the buzzer output pin
void setup ()
{
pinMode (buzzer, OUTPUT) ;// Initialize as output pin
}
void loop ()
{
unsigned char i;
while (1)
{
// In this program, the buzzer is controlled alternately with
two different frequencies.
// The signal consists of a square wave voltage.
Pr Jarou Tarik
TP de l’informatique industrielle
//Frequency 1
for (i = 0; i <80; i++)
{
digitalWrite (buzzer, HIGH) ;
delay (1) ;
digitalWrite (buzzer, LOW) ;
delay (1) ;
}
//Frequency 2
for (i = 0; i <100; i++)
{
digitalWrite (buzzer, HIGH) ;
delay (2) ;
digitalWrite (buzzer, LOW) ;
delay (2) ;
}
}
}
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage:
Code:
int Led_Red = 10;
int Led_Green = 11;
int Led_Blue = 12;
void setup ()
Pr Jarou Tarik
TP de l’informatique industrielle
{
// Initialize output pins for the LEDs
pinMode (Led_Red, OUTPUT);
pinMode (Led_Green, OUTPUT);
pinMode (Led_Blue, OUTPUT);
}
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
Code:
int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
void setup ()
{
pinMode (Led, OUTPUT) ; // Initialize output pin
pinMode (Sensor, INPUT) ; // Initialize sensor pin
digitalWrite(Sensor, HIGH) ; // Activate internal pull-up resistor
}
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor
is read out
Pr Jarou Tarik
TP de l’informatique industrielle
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
ARDUINO SENSOR
Pin 10 LED GREEN
Pin 11 LED RED
Ground GND
ARDUINO SENSOR
Pin 13 LED+
ground LED-
Code:
This code example shows how the integrated LEDs can be changed alternately, every 3 seconds,
by means of a definable output pin.
int Led_Red = 10;
int Led_Green = 11;
void setup ()
{
// Initialize output pins for the LEDs
pinMode (Led_Red, OUTPUT);
pinMode (Led_Green, OUTPUT);
Pr Jarou Tarik
TP de l’informatique industrielle
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
ARDUINO SENSOR
Pin 13 LED+
ground LED-
ARDUINO SENSOR
pin 10 signal
5V +V
ground GND
Code:
This is a sample program that lights up an LED when a signal is detected at the sensor. The
modules KY-011, KY-016 or KY-029 can also be used as LEDs, for example.
int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
void setup ()
{
pinMode (Led, OUTPUT) ; // Initialize output pin
pinMode (Sensor, INPUT) ; // Initialize sensor pin
digitalWrite(Sensor, HIGH) ; // Activate internal pull-up resistor
Pr Jarou Tarik
TP de l’informatique industrielle
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor
is read out
Pr Jarou Tarik
TP de l’informatique industrielle
PIN assignment:
Montage :
ARDUINO SENSOR
A0 (KY-053 ADC) Signal
5V +V
Masse GND
Pr Jarou Tarik
TP de l’informatique industrielle
ARDUINO KY-053
5V +V
Masse GND
A5 SCL
A4 SDA
Code :
For the following code example an additional library is needed:
Adafruit_ADS1x15 by Adafruit | published under the BSD License.
The example below uses this said library - for this we recommend downloading it from Github,
unzipping it and copying it in the Arduino library folder, which by default is located at
(C:\User[username]\Documents\Arduino\libraries), so that it is available for this code example
and following projects. Alternatively, this is also included in the download package below as
well.
The program measures the current voltage value at the NTC, calculates the temperature and
translates the result to °C for serial output
#include <Adafruit_ADS1015.h>
#include <math.h>
Adafruit_ADS1115 ads;
void setup(void)
{
Serial.begin(9600);
Pr Jarou Tarik
TP de l’informatique industrielle
ads.begin();
}
void loop(void)
Pr Jarou Tarik
TP de l’informatique industrielle
PIN assignment:
Montage :
ARDUINO SENSOR
Pin D2 Signal
5V +V
Ground GND
Pr Jarou Tarik
TP de l’informatique industrielle
void setup()
{
Serial.begin(9600);
Serial.println("KY-015 test - temperature and humidity test:");
// Measurement is started
dht.begin();
}
Pr Jarou Tarik
TP de l’informatique industrielle
// Humidity is measured
float h = dht.readHumidity();
// temperature is measured
float t = dht.readTemperature();
Pr Jarou Tarik
TP de l’informatique industrielle
Montage :
ARDUINO SENSOR
Pin 10 LED Red
Ground GND
Code:
This code example shows how the integrated LEDs can be changed alternately, in 3 second
cycles, by means of a definable output pin.
int Led_Red = 10;
int Led_Green = 11;
int Led_Blue = 12;
void setup ()
{
// Initialize output pins for the LEDs
pinMode (Led_Red, OUTPUT);
Pr Jarou Tarik
TP de l’informatique industrielle
Pr Jarou Tarik
TP de l’informatique industrielle
PIN assignment:
Montage :
ARDUINO SENSOR
pin 10 signal
5V +V
ground GND
ARDUINO SENSOR
Pin 13 LED +
ground LED -
Pr Jarou Tarik
TP de l’informatique industrielle
Code :
This is a sample program that lights up an LED when a signal is detected at the sensor. The
modules KY-011, KY-016 or KY-029 can also be used as LEDs, for example.
int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
void setup ()
{
pinMode (Led, OUTPUT) ; // Initialize output pin
pinMode (Sensor, INPUT) ; // Initialize sensor pin
}
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor
is read out
Pr Jarou Tarik
TP de l’informatique industrielle
Montage :
ARDUINO SENSOR
pin A5 signal
5V +V
ground GND
Pr Jarou Tarik
TP de l’informatique industrielle
Code :
The program measures the current voltage value at the sensor, calculates the current resistance
value of the sensor from this and the known series resistance and outputs the results on the serial
output.
int sensorPin = A5; // Declare the input pin here
void loop()
Pr Jarou Tarik
TP de l’informatique industrielle
{
// Current voltage value is measured...
int rawValue = analogRead(sensorPin);
float voltage = rawValue * (5.0/1023) * 1000;
delay(500);
}
Pr Jarou Tarik
TP de l’informatique industrielle
Montage :
ARDUINO SENSOR
pin 10 signal
5V +V
ground GND
Code:
The program simulates a blinker - it switches the relay in predefined time (delayTime) between
the two states (or output terminals).
int relay = 10; // Declares the pin to which the relay is connected
void setup ()
{
pinMode (relay, OUTPUT); // The pin is declared as output
}
Pr Jarou Tarik
TP de l’informatique industrielle
PIN assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
This is an example program which lights up a LED when a signal is detected at the sensor. The
modules KY-011, KY-016 or KY-029 can also be used as LEDs, for example.
Code:
int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
void setup ()
{
pinMode (Led, OUTPUT) ; // Initialize output pin
pinMode (Sensor, INPUT) ; // Initialize sensor pin
}
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor
is read out
Pr Jarou Tarik
TP de l’informatique industrielle
{
digitalWrite (Led, LOW);
}
else
{
digitalWrite (Led, HIGH);
}
}
PIN assignment:
Montage :
Pr Jarou Tarik
TP de l’informatique industrielle
This is an example program which lights up a LED when a signal is detected at the sensor. The
modules KY-011, KY-016 or KY-029 can also be used as LEDs, for example.
Code:
int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
void setup ()
{
pinMode (Led, OUTPUT) ; // Initialize output pin
pinMode (Sensor, INPUT) ; // Initialize sensor pin
}
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor
is read out
Pr Jarou Tarik
TP de l’informatique industrielle
Montage :
Pr Jarou Tarik
TP de l’informatique industrielle
Code:
/*
* SimpleReceiver.cpp
*
* Demonstriert den Empfang von NEC-IR-Codes mit IRrecv
*
* Copyright (C) 2020-2021 Armin Joachimsmeyer
* armin.joachimsmeyer@gmail.com
*
* Diese Datei ist Teil von Arduino-IRremote
https://github.com/Arduino-IRremote/Arduino-IRremote.
*
* MIT-Lizenz
*/
/*
* Geben Sie an, welche(s) Protokoll(e) für die Dekodierung
verwendet werden soll(en).
* * Wenn kein Protokoll definiert ist, sind alle Protokolle aktiv.
*/
//#define DECODE_DENON // Enthält Sharp
//#define DECODE_JVC
//#define DECODE_KASEIKYO
//#define DECODE_PANASONIC // dasselbe wie DECODE_KASEIKYO
//#define DECODE_LG
#define DECODE_NEC // Beinhaltet Apple und Onkyo
//#define DECODE_SAMSUNG
Pr Jarou Tarik
TP de l’informatique industrielle
//#define DECODE_SONY
//#define DECODE_RC5
//#define DECODE_RC6
//#define DECODE_BOSEWAVE
//#define DECODE_LEGO_PF
//#define DECODE_MAGIQUEST
//#define DECODE_WHYNTER
#include <Arduino.h>
/*
* Makros für Eingangs- und Ausgangspin definieren etc.
*/
#include "PinDefinitionsAndMore.h"
#include <IRremote.h>
void setup() {
Serial.begin(115200);
// Nur um zu wissen, welches Programm auf meinem Arduino läuft
Serial.println(F("START " __FILE__ " von " __DATE__ "\r\nUsing
library version " VERSION_IRREMOTE));
/*
* Starten des Empfängers, Aktivieren der Feedback-LED und
Abgreifen des LED-Feedback-Pins von der internen Kartendefinition
Pr Jarou Tarik
TP de l’informatique industrielle
*/
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK,
USE_DEFAULT_FEEDBACK_LED_PIN);
void loop() {
/*
* Prüfen, ob empfangene Daten vorhanden sind und wenn ja,
versuchen, diese zu dekodieren.
* Dekodiertes Ergebnis steht in der Struktur
IrReceiver.decodedIRData.
*
* Z.B. Befehl ist in IrReceiver.decodedIRData.command
* Adresse ist in Befehl ist in IrReceiver.decodedIRData.address
* und bis zu 32 Bit Rohdaten in
IrReceiver.decodedIRData.decodedRawData
*/
if (IrReceiver.decode()) {
Pr Jarou Tarik
TP de l’informatique industrielle
/*
* !!!Wichtig!!! Aktivieren Sie den Empfang des nächsten
Wertes,
* da der Empfang nach dem Ende des aktuell empfangenen
Datenpakets gestoppt wurde.
*/
IrReceiver.resume(); // Empfang des nächsten Wertes
freigeben
/*
* Abschließend prüfen Sie die empfangenen Daten und führen
Aktionen entsprechend dem empfangenen Befehl aus
*/
if (IrReceiver.decodedIRData.command == 0x34) {
Serial.println("Signal empfangen");
} else if (IrReceiver.decodedIRData.command == 0x36) {
Serial.println("Signal empfangen und dieses Mal ist es
ein anderes");
} else {
Serial.println("Signal empfangen, aber leider nicht das
richtige");
}
}
}
Pr Jarou Tarik
TP de l’informatique industrielle
In the idle state, the potentiometer is in the middle, so that resistor1=resistor2, with which also
the applied voltage distributes itself equally on both - e.g. measured value At +V=5V -> 2.5V.
If now the position of the e.g. X-axis is changed, the respective resistors change depending on
the current position - e.g. if it goes in one direction, resistor 1 becomes smaller and resistor 2
larger, if it goes in the other direction, resistor 1 becomes larger and resistor 2 smaller.
Depending on how the resistors are distributed among each other, this results in a respective
voltage value that can be measured between the resistors (in the case of the potentiometer, so-
called sliders) and thus the position of the axis can be determined.
PIN assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage :
The program reads the current values of the input pins, converts them to a voltage (0-1023 ->
0V-5V) and outputs it on the serial output.
Code:
// Declaration and initialization of the input pins
int JoyStick_X = A0; // X-axis signal
int JoyStick_Y = A1; // Y-axis signal
int Button = 3; // Button
void setup ()
{
pinMode (JoyStick_X, INPUT);
pinMode (JoyStick_Y, INPUT);
pinMode (Button, INPUT);
Pr Jarou Tarik
TP de l’informatique industrielle
if(button==1)
{
Serial.println (" not pressed");
}
else
{
Pr Jarou Tarik
TP de l’informatique industrielle
PIN assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage :
The program reads the current voltage value which can be measured at the analog output and
outputs it to the serial interface.
In addition, the state of the digital pin is also indicated in the console, which means whether the
value has fallen below the limit or not.
Code:
// Declaration and initialization of the input pins
int Analog_Input = A0; // Analog output of the sensor
int Digital_Input = 3; // Digital output of the sensor
void setup ()
{
pinMode (Analog_Input, INPUT);
pinMode (Digital_Input, INPUT);
Pr Jarou Tarik
TP de l’informatique industrielle
if(Digital==1)
{
Serial.println (" reached");
}
else
{
Serial.println (" not yet reached");
}
Serial.println ("-------------------------------------------------
---------------");
delay (200);
}
Pr Jarou Tarik
TP de l’informatique industrielle
Montage :
Pr Jarou Tarik
TP de l’informatique industrielle
The program reads the current voltage value which can be measured at the analog output and
outputs it to the serial interface.
In addition, the state of the digital pin is also indicated in the console, which means whether the
value has fallen below the limit or not.
Code:
// Declaration and initialization of the input pins
int Analog_Input = A0; // Analog output of the sensor
int Digital_Input = 3; // Digital output of the sensor
void setup ()
{
pinMode (Analog_Input, INPUT);
pinMode (Digital_Input, INPUT);
Pr Jarou Tarik
TP de l’informatique industrielle
if(Digital==1)
{
Serial.println (" reached");
}
else
{
Serial.println (" not yet reached");
}
Serial.println ("-------------------------------------------------
---------------");
delay (200);
}
Pr Jarou Tarik
TP de l’informatique industrielle
Pin assignment:
Montage :
The program reads the current voltage value which can be measured at the analog output and
outputs it to the serial interface.
In addition, the state of the digital pin is also indicated in the console, which means whether the
value has fallen below the limit or not.
Code:
// Declaration and initialization of the input pins
int Analog_Input = A0; // Analog output of the sensor
Pr Jarou Tarik
TP de l’informatique industrielle
void setup ()
{
pinMode (Analog_Input, INPUT);
pinMode (Digital_Input, INPUT);
if(Digital==1)
{
Serial.println (" reached");
}
Pr Jarou Tarik
TP de l’informatique industrielle
else
{
Serial.println (" not yet reached");
}
Serial.println ("-------------------------------------------------
---------------");
delay (200);
}
Pin assignment:
Montage :
Pr Jarou Tarik
TP de l’informatique industrielle
Code:
This code example shows how the integrated LEDs can be changed alternately, in 3 second
cycles, by means of a definable output pin.
int Led_Red = 10;
int Led_Green = 11;
int Led_Blue = 12;
void setup ()
{
// Initialize output pins for the LEDs
pinMode (Led_Red, OUTPUT);
pinMode (Led_Green, OUTPUT);
pinMode (Led_Blue, OUTPUT);
}
Pr Jarou Tarik
TP de l’informatique industrielle
delay (3000); // Wait mode for another three seconds in which the
LEDs are then switched over
}
PIN Assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
Code:
The program reads the current voltage value, which can be measured at the analog output, and
outputs it on the serial port.
In addition, the status of the digital pin in the console is also indicated, which means whether
the limit has been exceeded or not.
// Declaration and initialization of input pins
int Analog_Input = A0; // Analog output of the sensor
int Digital_Input = 3; // Digital output of the sensor
void setup ( )
Pr Jarou Tarik
TP de l’informatique industrielle
{
pinMode (Analog_In, INPUT);
pinMode (Digital_Inbox, INPUT);
if (Digital==1)
{
Serial.println (“reached”);
}
else
{
Serial.println (“not reached yet”);
Pr Jarou Tarik
TP de l’informatique industrielle
}
Serial.println ( " ----------------------------------------------
------------------") ;
delay (200) ;
}
PIN Assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage :
The program reads the current voltage value which can be measured at the analog output and
outputs it to the serial interface.
In addition, the state of the digital pin is also indicated in the console, which means whether the
value has fallen below the limit or not.
Pr Jarou Tarik
TP de l’informatique industrielle
Code:
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage:
Pr Jarou Tarik
TP de l’informatique industrielle
This code example shows how the integrated LEDs can be changed alternately, every 3 seconds,
by means of a definable output pin.
Code:
PIN Assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
This is an example program that makes an LED light up when a signal is detected on the sensor.
For example, the modules KY-011, KY-016 or KY-029 can be used as LEDs.
Pr Jarou Tarik
TP de l’informatique industrielle
Code:
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage:
Pr Jarou Tarik
TP de l’informatique industrielle
The program reads the current state of the sensor pins and displays in the serial console whether
the obstacle detector is currently in front of an obstacle or not.
Code:
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage :
Pr Jarou Tarik
TP de l’informatique industrielle
The program reads the current state of the sensor pin and displays in the serial console whether
the line tracker is currently on the line or not
Code:
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage :
Pr Jarou Tarik
TP de l’informatique industrielle
This code example shows how an LED can be switched on for four seconds and then switched
off for two seconds by means of a definable output spin.
Code:
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage :
Pr Jarou Tarik
TP de l’informatique industrielle
The program measures the current voltage value on the sensor, calculates the current resistance
value of the sensor from this and the known series resistor, and outputs the results on the serial
output.
Code:
Pr Jarou Tarik
TP de l’informatique industrielle
Pin assignment:
Montage :
Pr Jarou Tarik
TP de l’informatique industrielle
The program reads the current voltage value, which can be measured at the analog output, and
outputs it on the serial port.
In addition, the status of the digital pin in the console is also indicated, which means whether
the limit has been exceeded or not.
Code:
Pr Jarou Tarik
TP de l’informatique industrielle
PIN assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
Code:
The program reads the current voltage value, which can be measured at the analog output, and
outputs it on the serial port.
In addition, the status of the digital pin in the console is also indicated, which means whether
the limit has been exceeded or not.
// Declaration and initialization of input pins
int Analog_Input = A0; // Analog output of the sensor
int Digital_Input = 3; // Digital output of the sensor
void setup ( )
{
pinMode (Analog_In, INPUT);
pinMode (Digital_Input, INPUT);
Pr Jarou Tarik
TP de l’informatique industrielle
if (Digital==1)
{
Serial.println (“reached”);
}
else
{
Serial.println (" not yet reached");
}
Serial.println ( " ----------------------------------------------
------------------") ;
delay (200) ;
}
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
Montage:
Pr Jarou Tarik
TP de l’informatique industrielle
Code:
////////////////////////////////////////////////////
//////////////////////
/// Copyright (c) 2015 Dan Truong
/// Permission is granted to use this software under the MIT
/// license, with my name and copyright kept in source code
/// http: // http: //opensource.org/licenses/MIT
///
/// KY039 Arduino Heartrate Monitor V1.0 (April 02, 2015)
////////////////////////////////////////////////////
//////////////////////
////////////////////////////////////////////////////
//////////////////////
/// @param [in] IRSensorPin Analog PI to which the sensor is
connected
/// @param [in] delay (msec) The delay between calling up the
sampling function.
Pr Jarou Tarik
TP de l’informatique industrielle
// You get the best results when you scan 5 times per heartbeat.
/// Not slower than 150mSec for e.g. 70 BPM pulse
/// 60 mSec would be better for e.g. up to a pulse of 200 BPM.
///
/// @ short description
/// This code represents a so-called peak detection.
/// No heartbeat history is recorded, but it
/// a search is made for "peaks" within the recorded data,
/// and indicated by LED. By means of the well-known delay
intervals, you can
/// the pulse can be roughly calculated.
////////////////////////////////////////////////////
//////////////////////
int rawValue;
// Should the current value deviate too far from the last maximum
value
Pr Jarou Tarik
TP de l’informatique industrielle
Pr Jarou Tarik
TP de l’informatique industrielle
////////////////////////////////////////////////////
//////////////////////
// Arduino main code
////////////////////////////////////////////////////
//////////////////////
int ledPin = 13;
int analogPin = 0;
void setup ()
{
// The built-in Arduino LED (Digital 13) is used here for output
pinMode (ledPin, OUTPUT);
void loop ()
{
static int beatMsec = 0;
int heartRateBPM = 0;
if (heartbeatDetected (analogPin, delayMsec)) {
heartRateBPM = 60000 / beatMsec;
// LED output at heartbeat
Pr Jarou Tarik
TP de l’informatique industrielle
beatMsec = 0;
} else {
digitalWrite (ledPin, 0);
}
delay (delayMsec);
beatMsec + = delayMsec;
}
PIN Assignment:
Pr Jarou Tarik
TP de l’informatique industrielle
Montage:
If the pin status has changed, the program checks which of the two pins changed first, which
indicates the direction of rotation. This information is obtained by comparing one of the two
pin values from a previous run with the value of the current run.
After the direction has been determined, the steps from the starting position are counted and
output. Pressing the rotary encoder button resets the current position.
** For the serial output: baud rate = 115200 **
Code:
// Initialization of the required variables
int counter = 0;
boolean direction;
int Pin_clk_Last;
Pr Jarou Tarik
TP de l’informatique industrielle
int Pin_clk_Aktuell;
void setup ()
{
// input pins are initialized ...
pinMode (pin_clk, INPUT);
pinMode (pin_dt, INPUT);
pinMode (button_pin, INPUT);
// If the pin status has changed, the program checks which of the
two
// Pins changed first, which indicates the direction of rotation.
// This information is obtained by taking one of the two pin values
from a previous
// Compare pass with the value of the current pass.
Pr Jarou Tarik
TP de l’informatique industrielle
// After the direction has been determined, the steps are counted
and output from the start position.
// Pressing the rotary encoder button resets the current position.
void loop ()
{
// Read out the current status
Pin_clk_Aktuell = digitalRead (pin_clk);
else
{// Otherwise, Pin_DT changed first
Direction = false;
Counter--;
}
Serial.println ("Rotation detected:");
Serial.print ("Direction of rotation:");
if (direction)
{
Pr Jarou Tarik
TP de l’informatique industrielle
Serial.println ("clockwise");
}
else
{
Serial.println ("counterclockwise");
}
Pr Jarou Tarik
TP de l’informatique industrielle
Technical specifications :
PIN Assignment:
Montage:
Pr Jarou Tarik
TP de l’informatique industrielle
The example program activates the distance measurement according to the above principle and
measures the time with the help of the Arduino function pulseIn how long the ultrasonic signal
is in the air. This time is then used as the basis for converting the distance - the result is then
output in the serial output. If the signal is outside the measuring range, a corresponding error
message is issued.
Code:
#define Echo_EingangsPin 7 // Echo input pin
#define Trigger_AusgangsPin 8 // Trigger output pin
void setup () {
pinMode (Trigger_AusgangsPin, OUTPUT);
pinMode (Echo_EingangsPin, INPUT);
Serial.begin (9600);
}
Pr Jarou Tarik
TP de l’informatique industrielle
void loop () {
// Now we wait at the echo input until the signal has been
activated
// and then the time measured how long it remains activated
Duration = pulseIn (Echo_EingangsPin, HIGH);
else
{
// The calculated distance is output in the serial output
Serial.print ("The distance is:");
Serial.print (distance);
Pr Jarou Tarik
TP de l’informatique industrielle
Serial.println ("cm");
Serial.println ("-----------------------------------");
}
// Pause between the individual measurements
delay (500);
}
PIN Assignment:
The pin assignment is printed on the module board.
The signals at the inputs / outputs A1-A4 and B1-B4 are shifted to the respective voltage level
(VCCa -> A1-A4 | VCCb -> B1-B4)
Pr Jarou Tarik
TP de l’informatique industrielle
Please make sure that both systems are connected to the same GND (ground) - OE does not
have to be connected with this module.
Pr Jarou Tarik
TP de l’informatique industrielle
Please make sure that both systems are connected to the same GND (ground) - OE does not have to
be connected to this module. A breakout board is recommended to connect the Micro: Bit.
A corresponding library is required for this module - see code examples below.
Pr Jarou Tarik
TP de l’informatique industrielle
TECHNICAL SPECIFICATIONS:
PIN Assignment:
This sensor allows it to be connected to and operated on both 5V and 3.3V systems. Please note
that only one of the respective power supply pins is connected; suitable for the voltage level of
the system used - see the examples below for connecting the Arduino (5V) or the Rasperry Pi
(3.3V).
Montage:
Pr Jarou Tarik
TP de l’informatique industrielle
This sensor does not output its measurement result as a signal on an output pin, but
communicates it via the I2C bus. This can be used to control the sensor and to start and evaluate
the respective measurements for pressure and temperature.
There are several ways to control this sensor module - the Adafruit_BMP280 library has proven
to be particularly accessible, which is provided by Adafruit published under the OpenSource
BSD license.
Code:
/ *************************************************
**************************
This is a library for the BMP280 humidity, temperature & pressure
sensor
Pr Jarou Tarik
TP de l’informatique industrielle
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
void setup () {
Serial.begin (9600);
Serial.println (F ("BMP280 test"));
if (! bmp.begin ()) {
Serial.println (F ("Could not find a valid BMP280 sensor, check
wiring!"));
while (1);
Pr Jarou Tarik
TP de l’informatique industrielle
}
}
void loop () {
Serial.print (F ("Temperature ="));
Serial.print (bmp.readTemperature ());
Serial.println ("* C");
Serial.println ();
delay (2000);
}
Pr Jarou Tarik
TP de l’informatique industrielle
PIN Assignment:
The pin assignment is printed on the module board
Montage:
Pr Jarou Tarik
TP de l’informatique industrielle
The Arduino boards have a 10-bit ADC with 6 channels. However, if you need more channels
or higher accuracy, you can expand the Arduino by 4 ADC channels with 12-bit accuracy using
the KY-053 Analog Digital Converter Module, which is connected to the Arduino via I2C.
Code:
#include "ADS1x15.h"
#include <math.h>
Pr Jarou Tarik
TP de l’informatique industrielle
ads.begin ();
}
Pr Jarou Tarik
TP de l’informatique industrielle
Pr Jarou Tarik
TP de l’informatique industrielle
delay (1000);
}
Pr Jarou Tarik