30‑Day IoT for SAP Course Tutorial By Sanjay Chatterjee!
Table of Contents
Introduction & Course Overview1.1. Course Objectives and Outcomes
1.2. Target Audience and Prerequisites
1.3. Hardware, Software, and SAP Environment Setup
1.4. Overview of SAP BTP, SAP IoT, and Business Use Cases Part I: Raspberry Pi 5 – Days 1 to 15
2.1. Days 1–3: Introduction, Setup, Linux & Fundamentals
2.2. Days 4–7: Sensor Interfacing on Raspberry Pi (DHT22, IR, HC‑SR04, PIR)
2.3. Days 8–10: Advanced Programming, Concurrency, and Actuator Control (Stepper & Servo)
2.4. Days 11–15: Data Logging, Node.js Integration, and SAP Connectivity
2.5. Capstone Project – Unified Raspberry Pi Dashboard Part II: Arduino with Wi‑Fi – Days 16 to 30
3.1. Days 16–18: Arduino Fundamentals & Basic Sensor Interfacing
3.2. Days 19–22: Advanced Sensor Modules & Actuator Control (PIR, LoRa, Flow & Turbidity, Stepper & Servo)
3.3. Days 23–27: Cloud Connectivity and SAP Integration with Arduino (Direct & via Node.js Middleware)
3.4. Days 28–30: End‑to‑End Integration, Capstone Project Development, and Final Presentation SAP BTP, SAP IoT, and Business Use Cases in Depth
4.1. SAP BTP Overview and Its Core Components
4.2. SAP IoT Services and Device Management
4.3. SAP API Management and Messaging (MQTT/Event Mesh)
4.4. Business Use Cases: Predictive Maintenance, Smart Manufacturing, and Supply Chain Optimization Final Integration, Testing & Capstone Projects
5.1. Unified System Architecture and Data Flow
5.2. Testing, Troubleshooting, and Optimization
5.3. Final Presentation Guidelines and Certification Appendices
6.1. Detailed Datasheets and Wiring Diagrams
6.2. Full Code Listings with Explanatory Comments
6.3. Lab Worksheets and Troubleshooting Guides
6.4. Additional Reading and Resources
Chapter 1: Introduction & Course Overview
1.1 Course Objectives and Outcomes
Objectives: Develop a deep understanding of IoT fundamentals and their application in enterprise systems. Gain hands‑on experience with sensor and actuator interfacing using Raspberry Pi 5 ( /Node.js) and Arduino (C/C++). Learn how to integrate sensor data into SAP S/4HANA via SAP BTP using REST APIs, messaging services, and API management. Explore real‑world business use cases, such as predictive maintenance, smart manufacturing, and supply chain optimization. Outcomes: Build a full‑scale IoT prototype that collects and processes data from various sensors, controls actuators, and integrates with SAP systems. Acquire skills necessary to design, develop, deploy, and troubleshoot IoT solutions in enterprise settings.1.2 Target Audience and Prerequisites
Target Audience: Engineers, developers, and IT professionals with a basic background in programming and electronics. Prerequisites: Basic programming in , JavaScript (Node.js), and C/C++ (for Arduino). Familiarity with electronics fundamentals and circuit design. Basic understanding of networking and IoT communication protocols. Introductory knowledge of SAP S/4HANA and SAP BTP (pre‑reading materials provided).1.3 Hardware, Software, and SAP Environment Setup
Hardware: Raspberry Pi 5 (with Raspberry Pi OS installed) Arduino Board with Wi‑Fi (e.g., Arduino MKR1000) Sensors and Actuators: Temperature & Humidity sensor (DHT22) Infrared sensor Ultrasonic sensor (HC‑SR04) Motion sensor (PIR) LoRaWAN module Flow meter Turbidity meter Stepper motor kit (with driver such as ULN2003 for 28BYJ‑48) Servo motor Software: 3 with libraries (RPi.GPIO, Adafruit_DHT, spidev) Node.js with Express for API development Arduino IDE with required libraries (DHT, NewPing, LoRa, Servo, Stepper) SAP Environment: Access to SAP BTP (Business Technology Platform) with IoT and API Management services enabled. Pre‑configured SAP S/4HANA demo or test environment for integration.1.4 Overview of SAP BTP, SAP IoT, and Business Use Cases
SAP BTP Overview: A cloud platform that integrates data management, analytics, and application development. Provides services to extend SAP S/4HANA capabilities with IoT data. SAP IoT Services: Enable device connectivity, data ingestion, real‑time analytics, and management of IoT devices. Allow integration of sensor data with enterprise applications. Business Use Cases: Predictive Maintenance: Use sensor data (temperature, vibration, flow) to anticipate equipment failures. Smart Manufacturing: Monitor production lines and quality control in real‑time. Supply Chain Optimization: Use live sensor data for inventory tracking and logistics improvements.Chapter 2: Part I – Raspberry Pi 5 (Days 1 to 15)
Each day’s lesson is planned for a 2‑hour session divided into lecture, lab, and discussion segments. The following sections include detailed sample code with line‑by‑line explanations, wiring diagrams (to be inserted), and expected outputs.
2.1 Days 1–3: Introduction, Setup, Linux & Fundamentals
Day 1: Introduction & Raspberry Pi Setup
Lecture Topics: Overview of the course, IoT trends, and the role of IoT in enterprise digital transformation. Introduction to Raspberry Pi hardware: CPU, memory, GPIO, and connectivity options. Basic Linux commands and terminal navigation. Lab Activity: Boot the Raspberry Pi, connect a keyboard/monitor or use SSH, and execute basic commands (e.g., ls, pwd, ifconfig). Discussion: How a Linux-based platform like Raspberry Pi is ideal for IoT applications. Expected Outcome: Students will be comfortable using the terminal and managing the Raspberry Pi’s operating system.Day 2: OS Installation, Network Configuration & Environment
Lecture Topics: Step‑by‑step OS installation (using NOOBS or imaging the SD card). Configuring network settings and enabling SSH for remote access. Installing 3, pip, and an IDE (Thonny/VS Code). Lab Activity: Write and run a simple “Hello World” script.Sample Code:
# Hello World script for Raspberry Pi
print("Hello, IoT World!")
Explanation:
This script prints a welcome message. It verifies the environment is correctly set up. Discussion: Importance of a stable development environment in IoT projects.Day 3: IoT Protocols & GPIO Basics
Lecture Topics: Introduction to IoT communication protocols: MQTT, HTTP, REST APIs. Overview of Raspberry Pi GPIO pins and their usage. Lab Activity: Build a simple LED blinking circuit using a resistor, LED, and GPIO wiring.Sample Code:
import RPi.GPIO as GPIO
import time
# Use Broadcom pin numbering
GPIO.setmode(GPIO.BCM)
# Define LED pin
LED_PIN = 18
GPIO.setup(LED_PIN, GPIO.OUT)
try:
while True:
GPIO.output(LED_PIN, True) # Turn on LED
time.sleep(1)
GPIO.output(LED_PIN, False) # Turn off LED
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
Detailed Explanation:
GPIO.setmode(GPIO.BCM): Selects the Broadcom numbering scheme. GPIO.setup(LED_PIN, GPIO.OUT): Configures pin 18 as an output. Main Loop: The LED is turned on and off every second; a try‑except block ensures cleanup. Discussion: How basic GPIO control forms the foundation for sensor and actuator interfacing.2.2 Days 4–7: Sensor Interfacing on Raspberry Pi
Day 4: Temperature & Humidity Sensor (DHT22)
Lecture Topics: How the DHT22 sensor measures temperature and humidity. Sensor calibration, error rates, and optimal placement. Detailed Sample Code with Explanation:
import Adafruit_DHT
import time
# Set sensor type and GPIO pin number
sensor = Adafruit_DHT.DHT22
pin = 4 # Connect DHT22 data pin to GPIO4
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
# Check if the sensor returned valid data
if humidity is not None and temperature is not None:
# Format and print the readings with one decimal place
print(f"Temp = {temperature:0.1f}°C, Humidity = {humidity:0.1f}%")
else:
print("Failed to get reading. Try again!")
time.sleep(2) # Wait 2 seconds before next reading
Line‑by‑Line Explanation:
Import Libraries: Loads Adafruit_DHT for sensor interfacing and time for delays. Sensor Setup: Specifies DHT22 and assigns GPIO pin 4. read_retry(): Attempts to read sensor data several times, improving reliability. Conditional Check: Ensures valid readings before printing. Output: Prints formatted temperature and humidity values every 2 seconds. Lab Activity: Assemble the circuit according to the wiring diagram (to be provided) and run the code. Expected Output: “Temp = 24.5°C, Humidity = 55.2%” every 2 seconds. Diagrams: Include a wiring diagram for DHT22 connection.Day 5: Infrared Sensor Interfacing
Lecture Topics: Principles of infrared (IR) sensors: how they emit and detect IR light. Applications in motion detection and proximity sensing. Detailed Sample Code with Explanation:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
IR_PIN = 17 # Connect the IR sensor digital output to GPIO17
GPIO.setup(IR_PIN, GPIO.IN)
try:
while True:
# Read the digital value from the sensor: HIGH means object detected
if GPIO.input(IR_PIN):
print("IR Sensor: Object detected!")
else:
print("IR Sensor: No object detected.")
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
Explanation:
Sets up GPIO pin 17 as input. The loop prints a message based on the sensor’s digital output. A delay of 1 second ensures the output is updated periodically. Lab Activity: Connect the IR sensor per the wiring diagram and run the code. Expected Output: Alternates between “IR Sensor: Object detected!” and “No object detected” based on sensor input.Day 6: Ultrasonic Sensor (HC‑SR04) Interfacing
Lecture Topics: How ultrasonic sensors work by emitting a pulse and measuring the echo. Explanation of TRIG and ECHO pins. Detailed Sample Code with Explanation:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
TRIG = 23 # GPIO pin connected to TRIG
ECHO = 24 # GPIO pin connected to ECHO
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
def measure_distance():
# Ensure the TRIG pin is low
GPIO.output(TRIG, False)
time.sleep(0.5)
# Send a 10-microsecond pulse to TRIG
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
# Measure the time the ECHO pin is high
while GPIO.input(ECHO) == 0:
pulse_start = time.time()
while GPIO.input(ECHO) == 1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
# Calculate distance (speed of sound = 34300 cm/s, divided by 2)
distance = pulse_duration * 17150
return distance
try:
while True:
dist = measure_distance()
print(f"Distance: {dist:.2f} cm")
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
Explanation:
TRIG pin sends a 10‑microsecond pulse to initiate measurement. The ECHO pin’s high duration is measured and converted to distance. Output is printed every second. Lab Activity: Build the ultrasonic sensor circuit as shown in the diagram and run the code. Expected Output: A printed distance value (e.g., “Distance: 12.34 cm”).Day 7: Motion Sensor (PIR) Interfacing
Lecture Topics: How Passive Infrared (PIR) sensors detect motion based on infrared radiation changes. Detailed Sample Code with Explanation:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
PIR_PIN = 27 # Connect PIR sensor output to GPIO27
GPIO.setup(PIR_PIN, GPIO.IN)
try:
while True:
if GPIO.input(PIR_PIN):
print("Motion detected!")
else:
print("No motion.")
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
Explanation:
Sets GPIO pin 27 as input for the PIR sensor. Continuously polls the sensor and prints motion status. Uses a 1‑second delay between readings. Lab Activity: Connect the PIR sensor and simulate motion to observe changes. Expected Output: “Motion detected!” when movement is present, “No motion.” otherwise.2.3 Days 8–10: Advanced Programming & Actuator Control on Raspberry Pi
Day 8: Running Multiple Sensors Concurrently
Lecture Topics: Methods of achieving concurrency in (threads vs. async I/O). Techniques for aggregating data from multiple sensors in real‑time. Lab Activity: Write a program that concurrently reads data from the DHT22 and HC‑SR04 sensors.Sample Code (using threading):
import threading
import Adafruit_DHT
import RPi.GPIO as GPIO
import time
# Sensor configuration for DHT22
DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4
# Ultrasonic sensor pins
TRIG = 23
ECHO = 24
GPIO.setmode(GPIO.BCM)
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
def read_dht():
while True:
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if humidity and temperature:
print(f"[DHT22] Temp: {temperature:0.1f}°C, Humidity: {humidity:0.1f}%")
else:
print("[DHT22] Sensor error")
time.sleep(2)
def read_ultrasonic():
def measure_distance():
GPIO.output(TRIG, False)
time.sleep(0.5)
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO) == 0:
pulse_start = time.time()
while GPIO.input(ECHO) == 1:
pulse_end = time.time()
return (pulse_end - pulse_start) * 17150
while True:
distance = measure_distance()
print(f"[Ultrasonic] Distance: {distance:.2f} cm")
time.sleep(1)
# Create threads for each sensor
thread_dht = threading.Thread(target=read_dht)
thread_ultra = threading.Thread(target=read_ultrasonic)
thread_dht.start()
thread_ultra.start()
Explanation:
Two threads are created: one for the DHT22 and one for the HC‑SR04. Each thread runs its sensor reading loop independently. Discussion: Pros and cons of threading in resource‑limited environments.Day 9: Stepper Motor Control with Raspberry Pi
Lecture Topics: Overview of stepper motor operation and the role of drivers (e.g., ULN2003). Timing requirements and step sequence explanation. Detailed Sample Code with Explanation:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# Define GPIO pins connected to the driver inputs
pins = [5, 6, 13, 19]
for pin in pins:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
# Define an 8-step sequence for the motor
step_seq = [
[1, 0, 0, 1],
[1, 0, 0, 0],
[1, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 1, 1],
[0, 0, 0, 1]
]
try:
while True:
for step in step_seq:
for pin, val in zip(pins, step):
GPIO.output(pin, val)
time.sleep(0.005)
except KeyboardInterrupt:
GPIO.cleanup()
Explanation:
The code sets four GPIO pins as outputs and defines an 8‑step sequence that energizes the motor coils in order. The loop cycles through the sequence with a brief delay to ensure smooth motion. Lab Activity: Wire the stepper motor circuit per the provided schematic and run the code. Expected Outcome: The motor rotates continuously in one direction.Day 10: Servo Motor Control with Raspberry Pi
Lecture Topics: How servo motors use PWM signals to set angular positions. Detailed Sample Code with Explanation:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
servo_pin = 18 # Connect the servo signal to GPIO18
GPIO.setup(servo_pin, GPIO.OUT)
# Initialize PWM on the servo pin at 50 Hz
pwm = GPIO.PWM(servo_pin, 50)
pwm.start(7.5) # Neutral position (~90°)
try:
while True:
pwm.ChangeDutyCycle(5) # Approximately 0° position
time.sleep(1)
pwm.ChangeDutyCycle(7.5) # Back to 90°
time.sleep(1)
pwm.ChangeDutyCycle(10) # Approximately 180° position
time.sleep(1)
except KeyboardInterrupt:
pwm.stop()
GPIO.cleanup()
Explanation:
Sets up a PWM signal on GPIO18 with a frequency of 50 Hz. Changing the duty cycle moves the servo to different positions. Lab Activity: Connect the servo as per diagram, run the code, and observe the sweep. Expected Outcome: The servo rotates between roughly 0°, 90°, and 180°.2.4 Days 11–15: Data Logging, Node.js Integration & SAP Connectivity
Day 11: Data Logging & Local Storage on Raspberry Pi
Lecture Topics: Methods of logging sensor data locally using CSV files or SQLite databases. Ensuring data integrity and timestamping. Detailed Sample Code (CSV Logging):
import csv
import time
import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
pin = 4
# Open CSV file in append mode
with open('sensor_data.csv', 'a', newline='') as csvfile:
fieldnames = ['timestamp', 'temperature', 'humidity']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity and temperature:
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
writer.writerow({'timestamp': timestamp,
'temperature': f"{temperature:0.1f}",
'humidity': f"{humidity:0.1f}"})
print(f"Logged data at {timestamp}")
else:
print("Sensor error")
time.sleep(2)
Explanation:
Opens (or creates) a CSV file and writes headers. Reads sensor data, timestamps it, and appends it to the file. Lab Activity: Implement and verify that the CSV file is updated with sensor readings.Day 12: Introduction to Node.js on Raspberry Pi for IoT
Lecture Topics: Overview of Node.js architecture and its advantages for handling asynchronous I/O. Setting up an Express server to receive and display sensor data. Detailed Sample Code with Explanation (Express Server):javascript
const express = require('express');
const app = express();
app.use(express.json());
// Create POST endpoint to receive sensor data
app.post('/sensor-data', (req, res) => {
console.log('Received sensor data:', req.body);
// Data processing and forwarding logic can be added here
res.status(200).send('Data received');
});
app.listen(3000, () => console.log('Server running on port 3000'));
Explanation:
Sets up a basic Express server listening on port 3000. The /sensor-data endpoint logs incoming JSON data and returns a confirmation response. Lab Activity: Deploy the Node.js server on the Pi and test it using tools like Postman.Day 13: SAP BTP & IoT Integration Overview
Lecture Topics: Detailed explanation of SAP BTP’s architecture. In‑depth look at SAP IoT services, device management, API Management, and messaging via MQTT/Event Mesh. Lab Activity: Guided tour of the SAP BTP cockpit (using demo accounts or screenshots). Review sample SAP IoT API endpoints. Supplementary Materials: Case studies and whitepapers on SAP IoT implementations.Day 14: Integrating Raspberry Pi Data with SAP via Node.js
Lecture Topics: Methods to forward sensor data from Raspberry Pi to SAP endpoints using REST APIs. Detailed Sample Code ( Sending Data):
import requests
# Replace with your SAP API endpoint
url = "http://<sap_endpoint>/api/sensor-data"
data = {"temperature": 25, "humidity": 60}
response = requests.post(url, json=data)
print("Data sent, response:", response.status_code)
Explanation:
Uses the requests library to post a JSON payload to an SAP API. Prints the HTTP status code for confirmation. Lab Activity: Modify the sensor logger code to send data to the SAP endpoint via the Node.js middleware.Day 15: Raspberry Pi Capstone – Unified Sensor Dashboard
Lecture Topics: Overview of the capstone project that integrates sensor readings, actuator controls, local logging, and cloud connectivity. Discussion on troubleshooting, performance optimization, and data security. Lab Activity: Combine modules from Days 4–14 into a unified application. Develop a dashboard (using Node.js for the web interface) to display real‑time data. Project Deliverable: A fully integrated Raspberry Pi system that collects, logs, and transmits sensor data.Chapter 3: Part II – Arduino with Wi‑Fi (Days 16 to 30)
Each Arduino session includes detailed code explanations, wiring diagrams, and lab exercises to build an end‑to‑end solution that forwards sensor data to SAP (directly or via Node.js middleware).
3.1 Days 16–18: Arduino Fundamentals & Basic Sensor Interfacing
Day 16: Arduino Fundamentals & Environment Setup
Lecture Topics: Overview of Arduino boards and microcontroller architecture. Installing and configuring the Arduino IDE. Lab Activity: Upload the “Blink” sketch to verify board functionality.Sample Code (Blink):
cpp
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // Turn LED on
delay(1000);
digitalWrite(13, LOW); // Turn LED off
delay(1000);
}
Explanation:
Sets pin 13 (onboard LED) as an output and toggles it every second.Day 17: Sensor Interfacing – Temperature & Humidity (DHT22)
Lecture Topics: DHT22 sensor operation on Arduino, library usage, and wiring. Detailed Sample Code with Explanation:cpp
#include "DHT.h"
#define DHTPIN 2 // Connect DHT22 data pin to digital pin 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\tTemperature: ");
Serial.print(temperature);
Serial.println(" *C");
}
delay(2000);
}
Explanation:
Includes the DHT library, initializes sensor on pin 2, reads values, and prints them every 2 seconds. Lab Activity: Wire the DHT22 to the Arduino and verify readings on the Serial Monitor.Day 18: Sensor Interfacing – Infrared and Ultrasonic Sensors
Lecture Topics: Overview of IR and ultrasonic sensor interfacing on Arduino. Detailed Sample Code for IR Sensor:cpp
const int irPin = 3;
void setup() {
pinMode(irPin, INPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = digitalRead(irPin);
if (sensorValue == HIGH) {
Serial.println("IR Sensor: Object detected!");
} else {
Serial.println("IR Sensor: No object detected.");
}
delay(1000);
}
Explanation:
Reads digital input from IR sensor connected to pin 3 and outputs detection status. Detailed Sample Code for Ultrasonic Sensor (HC‑SR04):cpp
const int trigPin = 9;
const int echoPin = 10;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
long duration;
int distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000);
}
Explanation:
Sends a pulse from TRIG, measures echo time from ECHO, and calculates distance. Lab Activity: Test each sensor individually and then combine both into one sketch.3.2 Days 19–22: Advanced Sensor Modules & Actuator Control on Arduino
Day 19: Sensor Interfacing – Motion Sensor (PIR)
Lecture Topics: How PIR sensors work on Arduino. Detailed Sample Code with Explanation:cpp
const int pirPin = 4;
void setup() {
pinMode(pirPin, INPUT);
Serial.begin(9600);
}
void loop() {
int motion = digitalRead(pirPin);
if (motion == HIGH) {
Serial.println("Motion detected!");
} else {
Serial.println("No motion.");
}
delay(1000);
}
Explanation:
Configures pin 4 for PIR sensor and prints motion status. Lab Activity: Connect PIR sensor and test output.Day 20: Advanced Sensor – LoRaWAN Module
Lecture Topics: Overview of LoRaWAN technology and long‑range communication. Detailed Sample Code with Explanation:cpp
#include <SPI.h>
#include <LoRa.h>
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Sender");
if (!LoRa.begin(868E6)) { // Set frequency to 868 MHz
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
Serial.println("Sending packet...");
LoRa.beginPacket();
LoRa.print("Temperature:25, Humidity:60");
LoRa.endPacket();
delay(10000);
}
Explanation:
Initializes the LoRa module at 868 MHz and sends a payload every 10 seconds. Lab Activity: Connect the LoRa module and test the transmission.Day 21: Sensor Interfacing – Flow Meter and Turbidity Meter
Lecture Topics: Using interrupts on Arduino to count pulses from a flow meter. Reading analog sensor values from a turbidity meter. Detailed Sample Code for Flow Meter:cpp
volatile int pulseCount = 0;
const int flowPin = 5;
void pulseCounter() {
pulseCount++;
}
void setup() {
Serial.begin(9600);
pinMode(flowPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(flowPin), pulseCounter, FALLING);
}
void loop() {
pulseCount = 0;
interrupts();
delay(5000); // Count pulses for 5 seconds
noInterrupts();
float flowRate = pulseCount / 5.0;
Serial.print("Flow rate: ");
Serial.print(flowRate);
Serial.println(" pulses/sec");
}
Explanation:
Uses an interrupt to count pulses; calculates pulses per second. Detailed Sample Code for Turbidity Meter:cpp
const int turbidityPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(turbidityPin);
Serial.print("Turbidity value: ");
Serial.println(sensorValue);
delay(1000);
}
Explanation:
Reads analog value from the turbidity sensor on pin A0 and prints it. Lab Activity: Test both sensors individually, then integrate their code.Day 22: Actuator Control – Stepper Motor on Arduino
Lecture Topics: Understanding the Arduino Stepper library and its use for controlling stepper motors. Detailed Sample Code with Explanation:cpp
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
Serial.begin(9600);
myStepper.setSpeed(60); // 60 RPM
}
void loop() {
Serial.println("Clockwise rotation");
myStepper.step(stepsPerRevolution);
delay(500);
Serial.println("Counterclockwise rotation");
myStepper.step(-stepsPerRevolution);
delay(500);
}
Explanation:
Initializes the stepper motor on pins 8–11 and rotates it in both directions. Lab Activity: Wire the stepper motor and verify the rotations.Day 23: Actuator Control – Servo Motor on Arduino
Lecture Topics: Controlling a servo motor using the Arduino Servo library. Detailed Sample Code with Explanation:cpp
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(6); // Attach servo signal to pin 6
Serial.begin(9600);
}
void loop() {
// Sweep from 0° to 180°
for (int pos = 0; pos <= 180; pos++) {
myservo.write(pos);
delay(15);
}
// Sweep back from 180° to 0°
for (int pos = 180; pos >= 0; pos--) {
myservo.write(pos);
delay(15);
}
}
Explanation:
Uses a for‑loop to gradually move the servo from 0° to 180° and back. Lab Activity: Connect the servo and observe smooth motion.3.3 Days 24–27: Cloud Connectivity & SAP Integration with Arduino
Day 24: Data Aggregation & Cloud Connectivity on Arduino
Lecture Topics: Aggregating sensor readings on Arduino and preparing data for transmission. Overview of Wi‑Fi connectivity on Arduino (using an Arduino Wi‑Fi shield or board with built‑in Wi‑Fi). Lab Activity: Write a sketch that reads data from multiple sensors and formats it as a JSON string. Explanation: Discuss memory constraints on Arduino and best practices for string formatting.Day 25: SAP BTP & IoT – Deep Dive (Arduino Focus)
Lecture Topics: Detailed review of SAP BTP components for IoT, focusing on how low‑power devices (like Arduino) can connect via cloud gateways. Explore SAP IoT services, device management, and API management. Lab Activity: Guided walkthrough of SAP BTP cockpit and configuration of a sample IoT device. Supplementary Materials: Case studies on integrating low‑power IoT devices with SAP.Day 26: Integrating Arduino Data with SAP – Direct Transmission
Lecture Topics: How to use Arduino Wi‑Fi libraries (e.g., WiFiNINA) to send HTTP requests. Pseudo‑Code Explanation: Build a JSON payload from sensor data and send via HTTP POST.Pseudo‑Code Sample:
cpp
// Pseudo-code using WiFiClient and HTTPClient libraries
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h>
// Setup WiFi and server details...
// In loop, create JSON string and send HTTP POST request to SAP endpoint.
Lab Activity: Develop and test the sketch; monitor confirmation on the Serial Monitor.Day 27: Integrating Arduino Data with SAP – Via Node.js Middleware
Lecture Topics: How Node.js middleware can act as a bridge between Arduino and SAP. Overview of an Express app that receives Arduino data. Detailed Sample Code (Node.js Middleware):javascript
const express = require('express');
const app = express();
app.use(express.json());
app.post('/arduino-data', (req, res) => {
console.log('Received Arduino data:', req.body);
// Forward data to SAP or process as needed.
res.status(200).send('Data received');
});
app.listen(3000, () => console.log('Middleware server running on port 3000'));
Explanation:
Similar to the Raspberry Pi middleware example, this endpoint logs incoming data. Lab Activity: Test the middleware by sending sample data from Arduino.3.4 Days 28–30: End‑to‑End Integration, Capstone Project & Final Presentation
Day 28: End‑to‑End IoT Integration – Project Planning
Lecture Topics: Overview of the unified system architecture combining Raspberry Pi and Arduino devices. How sensor data flows from edge devices to Node.js middleware and into SAP. Lab Activity: Create system architecture diagrams, wiring diagrams, and data flow charts. Draft a project plan outlining the integration steps. Discussion: Best practices for scaling, security, and fault tolerance.Day 29: Capstone Development Session
Lecture Topics: Intensive coding and integration session. Lab Activity: Combine all modules from previous days into one integrated project. Develop a unified dashboard (using Node.js for the web interface) that displays real‑time data from both Raspberry Pi and Arduino devices. Test connectivity from devices to SAP via middleware. Discussion: Iterative debugging, performance optimization, and documentation.Day 30: Final Project Demonstration & Course Wrap‑Up
Lecture Topics: Final project presentations. Review of key learnings, troubleshooting techniques, and future directions. Lab Activity: Each group or individual demonstrates their fully integrated IoT solution. Q&A session, feedback, and certification guidelines. Deliverables: Final project report including system architecture, code documentation, and test results.Chapter 4: SAP BTP, SAP IoT, and Business Use Cases in Depth
4.1 SAP BTP Overview and Its Core Components
Content: Detailed description of SAP BTP’s architecture, including database services, integration services, and application development tools. Explanation of how SAP BTP serves as a foundation for extending SAP S/4HANA with IoT data. Diagrams: Include architectural diagrams of SAP BTP and data flow examples.4.2 SAP IoT Services and Device Management
Content: Overview of SAP IoT services: connecting devices, ingesting data, real‑time analytics. Step‑by‑step guide to setting up device management in SAP BTP. Best practices and security considerations.4.3 SAP API Management and Messaging Services
Content: Detailed explanation of how to expose, secure, and manage REST APIs. Overview of messaging services (MQTT, Event Mesh) and how they facilitate real‑time communication. Code examples showing how API endpoints are consumed by IoT devices.4.4 Business Use Cases in Depth
Case Study 1: Predictive Maintenance Detailed workflow: Sensor data (temperature, vibration, flow) is collected, transmitted, and analyzed to predict equipment failures. Diagrams, KPIs, and discussion of the ROI. Case Study 2: Smart Manufacturing How real‑time sensor data improves production quality, reduces downtime, and optimizes operations. Examples of dashboard visualizations and key performance indicators. Case Study 3: Supply Chain Optimization Using IoT data for inventory tracking and logistics optimization. Integration of sensor data into SAP S/4HANA to improve decision making.Chapter 5: Final Integration, Testing & Capstone Projects
5.1 Unified System Architecture and Data Flow
Content: Comprehensive architecture diagram showing sensor nodes (Raspberry Pi and Arduino), Node.js middleware, and SAP BTP connectivity. Explanation of each component’s role and how data flows from the edge to enterprise systems.5.2 Testing, Troubleshooting, and Performance Optimization
Content: Strategies for testing IoT systems (unit tests, integration tests, and field testing). Common pitfalls, debugging checklists, and performance tuning techniques. Lab worksheets and troubleshooting flowcharts.5.3 Final Presentation Guidelines and Certification
Content: Guidelines for preparing the final project presentation. Evaluation rubrics and criteria for certification. Discussion on documentation, future work, and professional development.Chapter 6: Appendices
6.1 Detailed Datasheets and Wiring Diagrams
Content: Complete datasheets for each sensor and actuator. Wiring diagrams for Raspberry Pi and Arduino circuits (include photos and schematic diagrams).6.2 Full Code Listings with Explanatory Comments
Content: Consolidated code for all sample programs ( , Arduino sketches, Node.js) with detailed inline comments.6.3 Lab Worksheets and Troubleshooting Guides
Content: Step‑by‑step lab instructions for each session. Troubleshooting guides and FAQs for common issues.6.4 Additional Reading and Resources
Content: Recommended books, articles, and online courses. Links to SAP documentation, IoT case studies, and community forums.Final Remarks
This final extended tutorial is structured to be a complete training manual for a 30‑day, 2‑hour‑per‑day course. It covers:
All core IoT topics from basic Linux and /Arduino programming to advanced sensor integration and actuator control. Detailed sample code with step‑by‑step explanations and expected outputs. In‑depth coverage of SAP BTP, SAP IoT services, API Management, and real‑world business use cases. A comprehensive capstone project that unifies all the learned skills into a fully integrated IoT solution ready for SAP S/4HANA environments.