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

Arduini Codes

Uploaded by

Anju James
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Arduini Codes

Uploaded by

Anju James
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Exp 1a – Blink Inbuilt LED

Aim-

void setup()
{
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
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
}
Exp 1b – Blink External LED

Aim-
Circuit Diagram
int LED = 8;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Exp 2 A – Arduino based Voltage measurement – Analog input within 5 V

// C++ code
//
/*
AnalogReadSerial
Reads an analog input (potentiometer) on pin 0,
prints the result to the serial monitor.

OPEN THE SERIAL MONITOR TO VIEW THE OUTPUT FROM


THE POTENTIOMETER >>

Attach the center pin of a potentiometer to pin


A0, and the outside pins to +5V and ground.

This example code is in the public domain.


*/

int sensorValue = 0;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);

void loop()
{
// read the input on analog pin 0:
sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(10); // Delay a little bit to improve simulation performance
}

Exp 2 B – Arduino based Voltage measurement – Analog input range 0-12 V

Aim-
Circuit Diagram
int value = 0;
float voltage;
float R1 = 47000.0;
float R2 = 33000.0;

void setup(){
pinMode(A0, INPUT);
Serial.begin(9600);
}

void loop(){
value = analogRead(A0);
voltage = value * (5.0/1024)*((R1 + R2)/R2);
Serial.print("Voltage =");
Serial.println(voltage);
delay(500);
}

You might also like