0% found this document useful (0 votes)
1 views

5 A The Arduino board is shown below

The document provides various Arduino and Raspberry Pi programs for controlling components like buzzers, LEDs, and sensors. It includes code snippets for reading temperature and humidity, sending SMS, and using Bluetooth communication. Additionally, it covers GPIO setup and interactions with sensors like DHT11 and IR sensors.

Uploaded by

953622243097
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

5 A The Arduino board is shown below

The document provides various Arduino and Raspberry Pi programs for controlling components like buzzers, LEDs, and sensors. It includes code snippets for reading temperature and humidity, sending SMS, and using Bluetooth communication. Additionally, it covers GPIO setup and interactions with sensors like DHT11 and IR sensors.

Uploaded by

953622243097
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

5 A The Arduino board is shown below:

The components of Arduino UNO board are shown below:Let's discuss each
component in detail.
PROGRAM:

BUZZER:

int buzzerPin = 8; //Assign Pin 8 to the


relay control/signal pin void setup() {
// put your setup code here, to run once:
pinMode(buzzerPin, OUTPUT); //Setting the Relay pin as an Output Pin
}
void loop() {
digitalWrite(buzzerPin, HIGH); //Turn the
relay ON for 1 second delay(1000);
digitalWrite(buzzerPin,LOW); //Turn the
relay OFF for 1 second delay(1000);

LED BLINKING:

void setup() {

pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as


an output.

void loop() {

digitalWrite(LED_BUILTIN, HIGH); // turn the LED on

(HIGH is the voltage level) delay(1000); // wait for a second

digitalWrite(LED_BUILTIN, LOW); // turn the LED off by

making the voltage LOW delay(1000); // wait for a second

}
CIRCUIT DIAGRAM:
CODE:

#include
"DHT.h"
#define
DHTPIN 2
#define DHTTYPE DHT11 // Other possibilities DHT21,
DHT22 DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
float temp =
dht.readTemperature(); float
humidity =
dht.readHumidity(); if
(isnan(temp) ||
isnan(humidity))
{
Serial.println("Failed to read from DHT11");
}
else
{
Serial.print("Temperat
ure: ");
Serial.print(temp);
Serial.print(" °C, ");
Serial.print("Humidity
: ");
Serial.print(humidity);
Serial.println(" %");
}
delay(5000);
}
PROGRAM:

#define ledPin 12

int data = 0;

void setup()

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

Serial.begin(9600);

void loop()

if (Serial.available() > 0)

data = Serial.read();

if (data == '0')

digitalWrite(ledPin, LOW);

Serial.println("LED: OFF");

else if (data == '1')

digitalWrite(ledPin, HIGH);

Serial.println("LED: ON");

}
PROGRAM :

#include "SoftwareSerial.h"

SoftwareSerial XBee(2, 3);

int BUTTON = 5;

boolean toggle = false; // This variable keeps track of alternative click of the button

void setup()

Serial.begin(9600);

pinMode(BUTTON, INPUT_PULLUP);

XBee.begin(9600);

void loop()

// When button is pressed (GPIO pulled low), send '1'

if (digitalRead(BUTTON) == LOW && toggle)

Serial.println("Turn on LED");

toggle = false;

XBee.write('1');

delay(1000);

// When button is pressed a second time (GPIO pulled low), send '0'

else if (digitalRead(BUTTON) == LOW && !toggle)

Serial.println("Turn off LED");

toggle = true;
XBee.write('0');

delay(1000);

}
PROGRAM:

#include <SoftwareSerial.h>

int led = 6;

int received = 0;

int i;

// For communicating with Zigbee

SoftwareSerial zigbee(2, 3);

void setup()

Serial.begin(9600);

zigbee.begin(9600);

pinMode(led, OUTPUT);

void loop()

// Check if data is received

if (zigbee.available() > 0)

received = zigbee.read();

// If the data is '0', turn off the LED

if (received == '0')

Serial.println("Turning off LED");

digitalWrite(led, LOW);

}
// If the data is '1', turn on the LED

else if (received == '1')

Serial.println("Turning on LED");

digitalWrite(led, HIGH);

}
Program:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);

void setup()

mySerial.begin(9600); // Setting the baud rate of GSM Module

Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)

delay(100);

void loop()

if (Serial.available() > 0)

switch (Serial.read())

case 's':

SendMessage();

break;

case 'd':

DialCall();

break;

if (mySerial.available() > 0)

{
Serial.write(mySerial.read());

void SendMessage()

mySerial.println("AT+CMGF=1"); // Sets the GSM Module in Text Mode

delay(1000); // Delay of 1000 milliseconds or 1 second

mySerial.println("AT+CMGS=\"+xxxxxxxxxxx\"\r"); // Replace x with mobile number

delay(1000);

mySerial.println("I am SMS from GSM Module"); // The SMS text you want to send

delay(100);

mySerial.println((char)26); // ASCII code of CTRL+Z

delay(1000);

void DialCall()

mySerial.println("ATD+xxxxxxxxxxxx;"); // ATDxxxxxxxxxx; -- watch out here for semicolon at the


end!!

delay(100);

}
PIN DIAGRAM:
PROGRAM ;

import RPi.GPIO as GPIO

import time

# Set the GPIO mode to BCM

GPIO.setmode(GPIO.BCM)

# Set the GPIO pin to an output

LED_PIN = 17

GPIO.setup(LED_PIN, GPIO.OUT)

try:

while True:

# Turn the LED on

GPIO.output(LED_PIN, GPIO.HIGH)

time.sleep(1) # 1 second delay

# Turn the LED off

GPIO.output(LED_PIN, GPIO.LOW)

time.sleep(1) # 1 second delay

except KeyboardInterrupt:

GPIO.cleanup() # Clean up GPIO settings on keyboard interrupt


PROGRAM :

import time
import board
import adafruit_dht

# Initialize the DHT11 sensor on GPIO4 (Raspberry Pi 4 - gpio4)


dhtDevice = adafruit_dht.DHT11(board.D4, use_pulseio=False)

while True:
try:
# Read the temperature and humidity from the sensor
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity

# Print the values to the serial port


print("Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(temperature_f, temperature_c, humidity))

except RuntimeError as error:


# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue

except Exception as error:


# Handle other exceptions and clean up
dhtDevice.exit()
raise error

time.sleep(2.0)

OUTPUT :
PROGRAM FOR IR SENSOR:
import RPi.GPIO as gpio

from time import sleep

# Set up the GPIO mode to BOARD (physical pin numbering)

gpio.setmode(gpio.BOARD)

# Set GPIO pin 36 (Raspberry Pi 4 - GPIO16) as an input

gpio.setup(36, gpio.IN)

while True:

# Read the sensor input

sensor = gpio.input(36)

if sensor == 1:

print("Not detected")

sleep(0.1)

elif sensor == 0:

print("Detected")

OUTPUT :
Arduino Program:

int led = 13;

void setup()

pinMode(led, OUTPUT);

Serial.begin(9600); // Default baud rate for Bluetooth: 38400

void loop()

if (Serial.available())

int a = Serial.parseInt();

Serial.println(a);

if (a == 1)

digitalWrite(led, HIGH);

if (a == 0)

digitalWrite(led, LOW);

}
}

Raspberry Pi Bluetooth Program:

import serial

import time

bluetooth = serial.Serial("/dev/rfcomm7", 9600)

while True:

a = input("Enter: ")

string = 'X{0}'.format(a)

bluetooth.write(string.encode("utf-8"))
Program :

import httplib

import urllib

import time

key = "XXXXXXXXXXXXXXXX" # Put your API Key here

def thermometer():

while True:

# Calculate CPU temperature of Raspberry Pi in Degrees C

temp = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1e3 # Get Raspberry Pi


CPU temperature

params = urllib.urlencode({'field1': temp, 'key': key})

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

conn = httplib.HTTPConnection("api.thingspeak.com:80")

try:

conn.request("POST", "/update", params, headers)

response = conn.getresponse()

print temp

print response.status, response.reason

data = response.read()

conn.close()

except:

print("Connection failed")

break

if __name__ == "__main__":

while True:
thermometer()

output

You might also like