0% found this document useful (0 votes)
54 views10 pages

Arduino Programs

The document provides Arduino code examples for connecting and reading various sensors including an LED, relay, DC motor, current sensor, voltage sensor, LCD display, potentiometer, and PT100 temperature sensor. For each sensor, a circuit diagram and code is shown to demonstrate how to interface the sensor with an Arduino board and read/display the sensor values.

Uploaded by

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

Arduino Programs

The document provides Arduino code examples for connecting and reading various sensors including an LED, relay, DC motor, current sensor, voltage sensor, LCD display, potentiometer, and PT100 temperature sensor. For each sensor, a circuit diagram and code is shown to demonstrate how to interface the sensor with an Arduino board and read/display the sensor values.

Uploaded by

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

47014

Name = Muhammad muddussir


raza
Class = 1st year et
47014

➢ARDUINO WITH LED (Blinking with 5s)


Follow the circuit diagram and hook up the components on the
breadboard as shown in the image given below.

ARDUINO CODE
void setup() {
pinMode(2, OUTPUT);
}
void loop() {
digitalWrite(2, HIGH);
delay(5000); // wait for a second
Page 1 of 10
47014

digitalWrite(2, LOW);
delay(5000);
}

➢ARDUINO WITH RELAY


Follow the circuit diagram and hook up the components on the
breadboard as shown in the image given below.

ARDUINO CODE
const int RELAY_PIN = 3;
void setup() {
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
digitalWrite(RELAY_PIN, HIGH);
Page 2 of 10
47014

delay(500);
digitalWrite(RELAY_PIN, LOW);
delay(500);
}

➢ARDUINO WITH DC MOTOR


Follow the circuit diagram and hook up the components on the
breadboard as shown in the image given below.

ARDUINO CODE
int motorPin = 3;
void setup() {
}
void loop() {
digitalWrite(motorPin, HIGH);

➢ ARDUINO WITH CURRENT SENSOR

Page 3 of 10
47014

Follow the circuit diagram and hook up the components on the


breadboard as shown in the image given below.

ARDUINO CODE
float average_current;
void setup() {
Serial.begin(9600);
}
void loop() {
for(int i=0;i<SAMPLES;i++){
int sensorValue = analogRead(A0);
float volt = sensorValue * 5;
volt = volt / 1023;
float current = volt / 185;
current = current / 1000;
average_current += current;
Page 4 of 10
47014

delay(1);
}
average_current = average_current / SAMPLES;
Serial.print("Current: ");
Serial.println(average_current);
delay(100);
}

➢ARDUINO WITH VOLTAGE SENSOR


Follow the circuit diagram and hook up the components on the
breadboard as shown in the image given below.

ARDUINO CODE
float input_volt = 0.0;
float temp=0.0;
float r1=10000.0;

Page 5 of 10
47014

float r2=100000.0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int analogvalue = analogRead(A0);
temp = (analogvalue * 5.0) / 1024.0;
input_volt = temp / (r2/(r1+r2));
if (input_volt < 0.1)
{
input_volt=0.0;
}
Serial.print("Voltage= ");
Serial.print(input_volt);
Serial.println(" Volts");
delay(1000);
}

➢ARDUINO WITH LCD


Follow the circuit diagram and hook up the components on the
breadboard as shown in the image given below.

Page 6 of 10
47014

ARDUINO CODE
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
lcd.print("hello, world!");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}

➢ARDUINO WITH POTENTIO METER

Page 7 of 10
47014

Follow the circuit diagram and hook up the components on the


breadboard as shown in the image given below.

ARDUINO CODE
float floatMap(float x, float in_min, float in_max, float out_min, float
out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) +
out_min;
}
void setup() {
Serial.begin(9600);
}
void loop() {
int analogValue = analogRead(A0);

Page 8 of 10
47014

float voltage = floatMap(analogValue, 0, 1023, 0, 5);


Serial.print("Analog: ");
Serial.print(analogValue);
Serial.print(", Voltage: ");
Serial.println(voltage);
delay(1000);
}

➢ARDUINO WITH PT100 TEMPERATURE SENSOR


Follow the circuit diagram and hook up the components on the
breadboard as shown in the image given below.

ARDUINO CODE
void setup() {
Serial.begin(9600);

Page 9 of 10
47014

pinMode (A0, INPUT); this pin


}
void loop()
{ float offset = 6.4762;
float sensitivity=1.9971;
int AnalogValue = analogRead(A0);
Serial.print("Analog Value: ");
Serial.println(AnalogValue);
delay(1000);
float DigitalValue = (AnalogValue * 5) / (1023);
Serial.print("Digital value: ");
Serial.println(DigitalValue);
float temp = (AnalogValue - offset)/sensitivity;
Serial.print("Temperature value: ");
Serial.println(temp);
delay(5000);
}

Page 10 of 10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy