Arduino / Raspberry Pi Lab Manual
7. Introduction to Arduino Platform and Programming
Objective:
To understand the Arduino development platform, upload a basic program to blink an LED.
Components Required:
- Arduino Uno board
- USB cable
- LED
- 220-ohm resistor
- Breadboard & jumper wires
Procedure:
1. Connect the LED anode to pin 13 through a resistor and cathode to GND.
2. Install Arduino IDE.
3. Connect Arduino via USB.
Sample Code:
void setup() {
pinMode(13, OUTPUT);
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
Expected Output:
LED connected to pin 13 blinks at 1-second intervals.
Arduino / Raspberry Pi Lab Manual
8. Communicate Between Arduino and Raspberry Pi Using Any Wireless Medium (Bluetooth)
Objective:
Establish serial communication between Arduino and Raspberry Pi using Bluetooth.
Components Required:
- Arduino Uno
- Raspberry Pi
- HC-05 Bluetooth module
- Jumper wires
Circuit Connections:
- HC-05 TX -> Arduino RX
- HC-05 RX -> Arduino TX (via voltage divider)
- VCC -> 5V
- GND -> GND
Arduino Code:
void setup() {
Serial.begin(9600);
void loop() {
Serial.println("Hello from Arduino");
delay(1000);
Raspberry Pi Python Code:
import serial
bluetooth = serial.Serial("/dev/rfcomm0", baudrate=9600)
while True:
data = bluetooth.readline()
Arduino / Raspberry Pi Lab Manual
print("Received:", data.decode())
Expected Output:
Raspberry Pi receives and displays "Hello from Arduino".
9. Displaying Time over 4-Digit 7-Segment Display using Raspberry Pi
Objective:
Display the current time on a 4-digit 7-segment display.
Components Required:
- Raspberry Pi
- 4-digit 7-segment display module (TM1637)
- Jumper wires
Connections:
- CLK -> GPIO 21
- DIO -> GPIO 20
- VCC -> 3.3V
- GND -> GND
Python Code:
from tm1637 import TM1637
from time import sleep, strftime, localtime
import RPi.GPIO as GPIO
display = TM1637(clk=21, dio=20)
while True:
t = strftime("%H%M", localtime())
display.numbers(int(t[:2]), int(t[2:]))
sleep(1)
Arduino / Raspberry Pi Lab Manual
Expected Output:
7-segment display shows the real-time clock in HHMM format.
10. Raspberry Pi Based Oscilloscope
Objective:
Use Raspberry Pi and an ADC to visualize analog signals.
Components Required:
- Raspberry Pi
- MCP3008 ADC
- Potentiometer or signal source
- Jumper wires
Connections:
- Connect MCP3008 to SPI pins on Raspberry Pi
- Potentiometer output to CH0 of MCP3008
Python Code:
import spidev
import time
import matplotlib.pyplot as plt
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = 1350000
def read_channel(channel):
adc = spi.xfer2([1, (8+channel)<<4, 0])
data = ((adc[1]&3) << 8) + adc[2]
Arduino / Raspberry Pi Lab Manual
return data
x = []
y = []
for i in range(100):
x.append(i)
y.append(read_channel(0))
time.sleep(0.05)
plt.plot(x, y)
plt.title("Oscilloscope Output")
plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.show()
Expected Output:
Simple graph showing voltage variation from potentiometer.
11. Controlling Raspberry Pi with WhatsApp
Objective:
Control GPIOs of Raspberry Pi using WhatsApp messages via Twilio.
Components Required:
- Raspberry Pi with internet
- Twilio WhatsApp API account
- LED
Steps:
1. Set up Twilio account and WhatsApp sandbox.
2. Write a Flask app to receive messages and control GPIO.
Arduino / Raspberry Pi Lab Manual
Python Code:
from flask import Flask, request
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
app = Flask(__name__)
@app.route("/whatsapp", methods=['POST'])
def whatsapp():
msg = request.values.get('Body', '').lower()
if 'on' in msg:
GPIO.output(18, GPIO.HIGH)
elif 'off' in msg:
GPIO.output(18, GPIO.LOW)
return 'OK'
app.run(host='0.0.0.0', port=5000)
Expected Output:
Sending "on" via WhatsApp turns on LED, "off" turns it off.
12. Setting up Wireless Access Point using Raspberry Pi
Objective:
Configure Raspberry Pi as a Wi-Fi access point.
Components Required:
- Raspberry Pi with built-in Wi-Fi
Arduino / Raspberry Pi Lab Manual
- SD card with Raspberry Pi OS
- Internet via Ethernet or USB
Steps:
1. Install required packages:
sudo apt install hostapd dnsmasq
2. Configure /etc/dhcpcd.conf, /etc/dnsmasq.conf, and /etc/hostapd/hostapd.conf.
hostapd.conf Example:
interface=wlan0
driver=nl80211
ssid=PiAccessPoint
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=raspberry123
wpa_key_mgmt=WPA-PSK
Start Services:
sudo systemctl start hostapd
sudo systemctl start dnsmasq
Expected Output:
Other devices can see and connect to Raspberry Pi's Wi-Fi network.