A collection of examples for getting started in the Internet of Things (IoT). This includes code, wiring diagrams and documentation. In the description of each example, we list supported/tested boards. The same code may work on other boards with no or minimal changes. Files are organized in the following manner:
admin
: Utilities for maintaining this repo.Arduino
: Projects on Arduino and Energia. Most examples are about Arduino Uno and TI LaunchPadF5529.NodeMCU
: Projects on NodeMCU including those that can be programmed via Arduino IDE.RaspberryPi
: Projects on mostly Raspberry Pi 2 or 3, although examples may work with other variants.
Examples using other platforms such as Intel Edison, Broadcom WICED or ARM mbed may be added in future.
ADXL345I2C | Interface to the ADXL345 accelerometer via I2C. |
ADXL345SPI | Interface to the ADXL345 accelerometer via SPI. |
Blink | Blink two LEDs alternatively. One LED is on the board and the other is connected externally. |
BuzzerPot | Using a potentiometer, drive a buzzer. We illustrate two variations: DIRECT : Buzzer is directly connected to potentiometer. WITH_PWM : Buzzer is sampled by microcontroller, which then uses PWM to drive the buzzer. |
DigitalRead | Investigate the effect of pressing a push button by reading the voltage as a digital value. The value is printed on the serial monitor but also used to light up an LED. |
FC04-SoundSensor | FC04 sound sensor is to read an analog value. Value is used to drive an LED array that is supposed to light up to indicate sound loudness. This sensor responds well to base sounds (low frequency bands). In any case, adjust the trimmer on the module to suit your application. |
HC05-AT-Cmds | Put the Bluetooth module in AT command mode. Run a bunch of commands to configure the module. Module must be forced to enter AT command mode by long pressing the reset button before powering it up. |
HC05-Bluetooth | Send commands from an Android device via Bluetooth to turn on/off or blink and LED. A suggested Android app is the Bluetooth SPP Tools Pro. |
HCSR04-Ultrasonic | Sense the distance of an object/obstacle using ultrasound. |
HallEffect3144 | Detect door open/close events using a hall effect sensor. Note that the orientation of the magnet (North pole or South pole) matters. This example shows how to write interrupt code. |
IR-Proximity-Detection | Use an IR LED and an IR photodiode to detect proximity of an obstable. An indicator LED glows in response to the proximity of the obstacle. This indicator can be programmed as a digital or an analog output. |
IR-RemoteControl | Use an IR receiver/decoder to decode and store commands from a household remote control. Use an IR LED to send the commands to the household gadget/appliance. |
LCD-2x16-Joystick | Read values from a joystick and display the same on a 2x16 line LCD module. LiquidCrystal library is used in this example. 4-pin mode is used for the LCD. Since RW pin is grounded, only write operation is possible. |
LDR | LDR is a light dependant resistor. Read the analog voltage across the LDR and derive the resistance. |
LM35 | Use analog input to read temperature measurement from LM35. |
LM35-7Segx3 | Use LM35 to sense temperature that is displayed. Use 74HC595 shift register to control 3 7-segment displays. |
LedMatrix | Drive an 8x8 LED matrix without any IC. |
LedMatrix-Max7219 | Drive one or more 8x8 LED matrices using MAX7219. SPI is is used for interfacing. Two variants are presented below: 0: From first principles. 1: Two 8x8 matrices using LedControl library. |
LedStrip-ULN2003 | Drive an LED strip using Darlington array ULN2003. PWM is used to control the colours. Hence, pins must be capable of PWM out. Two implementations are illustrated. |
MCP3008 | Use LM35 to sense temperature that is displayed. External ADC 10-bit MCP3008 is used and read by Arduino via SPI. |
MQ2-GasSensor | Use MQ2 gas sensor module and read analog values. The code also includes calibration. Since the mapping betweeen Rs and PPM is non-linear no conversion to PPM is done at the moment. No compensation has been included for current humidity and temperature. |
PIR-MotionDetector | Using a PIR module we detect motion. Debouncing is used in such a way that current motion has to stop for a minimum time interval before we record a new motion. |
RTC-IN1307 | Interface to Real-Time Clock (RTC) chip IN1307, which has an I2C interface. DS1307 is an equivalent chip but is not tested with this code. Code allows users to set the time via UART. RTClib is used in this code. |
ReedSwitch | Detect door open/close events using a reed switch. This example shows how to write interrupt code. |
RgbLed | Change colours on an RGB LED. PWM is used to control the colours. Hence, pins must be capable of PWM out. |
SerialCmds | Control an LED using commands "on" or "off" received on the serial port. This is a simple illustration of how we can control the system remotely using the serial interface. Implementation assumes characters are buffered and sent together as a single command. This is the case with Arduino and Energia serial monitors. This won't work in Fritzing serial monitor since characters are sent as soon as they are typed. |
ServoPushbutton | Control servo movement using push buttons. |
Tetris-FC16 | Tetris game is implemented. Display uses the MAX7219 FC16 module that cascades four 8x8 dot matrix displays. For user control, we use four pushbuttons. The displays should be powered by an independent power supply and not from the Arduino. |
UnipolarStepper | Drive the unipolar stepper motor 28-BYJ48 that has 5 wires. ULN2003 driver module is used for the purpose. It's also possible to use the ULN2003 chip directly without the dedicated module. There are different implementations in this code for illustration: 0: Using Stepper library. 1: Half-wave drive from first principles. 2: Using third-party AccelStepper library. 3: With acceleration using AccelStepper library. |
Blynk-Blink | Control an LED manually from the Blynk app. This code can be compiled and uploaded from Arduino IDE. Update the code with your token, Wi-Fi SSID and password. |
Blynk-LM35 | Send temperature readings from LM35 and display the same on the Blynk app. |
Blynk-RgbLed | Control an LED manually from the Blynk app. This code can be compiled and uploaded from Arduino IDE. Update the code with your token, Wi-Fi SSID and password. |
adxl345_i2c | Interface Raspberry Pi with ADXL345 accelerometer via I2C. We use the Adafruit Python ADXL345 for this purpose. This can installed with "sudo pip3 install adafruit-adxl345" See https://github.com/adafruit/Adafruit_Python_ADXL345 Ensure that I2C is enabled via raspi-config. Ensure that line i2c-dev is present in file /etc/modules |
blink_fade | Use RPi.GPIO module to blink or fade an LED. Fading uses software PWM since RPi.GPIO module does not support hardware PWM. Note that RPi.GPIO is available by default on Raspbian Jessie and Stretch. |
toggle_uart | Read commands from UART to control LED state. Use gpiozero module to control the LED. |
lcd_dashboard | We use tkinter package to display a GUI window on a 3.5" 480x320 LCD display from Waveshare. App shows current time, Devopedia logo, and the latest tech news. News is pulled via a free REST API service and it's use requires an API key. The key is expected to be defined in an environment variable NEWS_API_KEY. |
led_pushbutton | Use GPIO Zero module to control an LED. LED state toggles whenever a push button is pressed and released. |
lm35_adc | Interface Raspberry Pi with MCP3008 for ADC functionality. LM35 temperature sensor is connected to CH1 of MCP3008. MCP3008 is powered with 3.3V. If environment variable TS_API_KEY is set, data is sent to the ThingSpeak IoT cloud. REST API is used. |
lm35_adc_mqtt | Interface Raspberry Pi with MCP3008 for ADC functionality. LM35 temperature sensor is connected to CH1 of MCP3008. MCP3008 is powered with 3.3V. If environment variable TS_API_KEY is set, data is sent to the ThingSpeak IoT cloud. MQTT is used. |
ssd1306_bmp180 | Use BMP180 to obtain three sensor readings: temperature, barometric pressure and altitude. BMP180 uses an I2C interface. Show these readings on SSD1306 OLED display. This uses an SPI interface. RPI is used with the WaveShare Pioneer600 that contains both BM180 and SSD1306. Code is adapted from examples at https://www.waveshare.com/wiki/File:Pioneer600-Code.tar.gz For this example, install Python packages (via pip3): smbus, pillow |
WiringPi-PWM | Use WiringPi C library to fade an LED using hardware PWM. Compile as "gcc WiringPi-PWM.c -o pwm -Wall -lwiringPi" or use the Makefile, "make all" Run as "sudo ./pwm" |
wiringpi_pwm | Use WiringPi-Python binding of WiringPi C implementation. See https://github.com/WiringPi/WiringPi-Python This example shows HW PWM on GPIO18. To use HW PWM, run as "sudo python3 wiring_pwm.py" Code also shows the use of SW PWM, which is possible on any GPIO pin. To use SW PWM, run as "python3 wiring_pwm.py sw" |