Anda di halaman 1dari 49

ARDUINO

Arduino is an open-source computer hardware and software company, project and user
community that designs and manufactures microcontroller-based kits for building digital
devices and interactive objects that can sense and control objects in the physical world.
The project is based on microcontroller board designs, manufactured by several vendors,
using various microcontrollers. These systems provide sets of digital and analog I/O pins that
can be interfaced to various expansion boards ("shields") and other circuits. The boards
feature serial communications interfaces, including USB on some models, for loading
programs from personal computers. For programming the microcontrollers, the Arduino
project provides an integrated development environment (IDE) based on
the Processing project, which includes support for the C and C++ programming languages.
ARDUINO PIN DESCRIPTION
Technical specifications:

Microcontroller ATmega328P

Operating Voltage 5V

Input Voltage (recommended) 7-12V

Input Voltage (limit) 6-20V

Digital I/O Pins 14 (of which 6 provide PWM output)

PWM Digital I/O Pins 6

Analog Input Pins 6

DC Current per I/O Pin 20 mA

DC Current for 3.3V Pin 50 mA

32 KB (ATmega328P)
Flash Memory
of which 0.5 KB used by bootloader

SRAM 2 KB (ATmega328P)

EEPROM 1 KB (ATmega328P)

Clock Speed 16 MHz

Length 68.6 mm

Width 53.4 mm

Weight 25 g
ARDUINO COMMANDS
Classification:
digitalWrite()

digitalRead()

analogRead()

analogWrite()

Ifstatements ( )/Boolean

Serialcommunication

DIGITAL COMMANDS

• digitalWrite(pin, HIGH/LOW);

ex: digitalWrite(13, HIGH); // set 13 pin to 5Volts

• digitalRead(pin);

ex: int val = digitalRead(3);

ANALOG COMMANDS

• analogWrite(pwm pin,value );

ex: analogWrite(9, 255); // set 9 pin to 255

• anlogRead(n);

ex: int val = anlogRead(0);


SERIAL COMMANDS

• Serial.begin(baudrate);

• ex: Serial.begin(9600);

• Serial.read();

• ex: Char c = Serial.read();

• Serial.print();

• ex: Serial.print(“arduino”); // print arduino

• // NOTE: -> commands are CASE-sensitive

GENERAL COMMANDS

• pinMode(pin, INPUT/OUTPUT);

• ex: pinMode(13, OUTPUT);

• map(val, fromLow, fromHigh, toLow, toHigh) ;

• ex: val = map(val, 0, 1023, 0, 255);

• constrain(val, min, max) ;

• ex: val = constrain(val, 0, 180);

• delay(time_ms);

• ex: delay(2500); // delay of 2.5 sec.

• // NOTE: -> commands are CASE-sensitive


LED BLINK
Aim: To Blink the LED ON and OFF for every 1 Second interval.
Circuit Diagram:

Components Required:
1. LED
2. 220𝜴 Resistor
3. Jumper Wires
4. Bread Board
5. Arduino Uno
6. Arduino Uno Cable
Program:
int led = 13;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
PUSH BUTTON
Aim: To turn on the LED when the Push Button is Pressed.
Circuit Diagram:

Components Required:
1. Arduino Uno
2. LED
3. 10K𝜴 Resistor
4. Jumper Wires
5. Push Button
6. Bread Board
Code:
const int buttonPin = 7;
const int ledPin = 13;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
LIGHT DEPENDENT RESISTOR
Aim: To observe the Analog Value of LDR in Serial Monitor of Arduino IDE
Circuit Diagram:

Components Required:
1. Arduino Uno
2. Bread Board
3. LDR
4. Jumper Wires
5. 10K𝜴 Resistor
Code:
int sensorPin = A2;
int sensorValue = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
delay(1000);
}
SERVO MOTOR INTERFACING WITH POTENTIOMETER
Aim: To interface the Servo Motor and Potentiometer with Arduino Uno
Circuit Diagram:

Components Required:
1. Arduino Uno
2. 10K𝜴 POT
3. Servo Motor
4. Jumper Wires
5. Bread Board
Code:
#include <Servo.h>
Servo myservo;
int potpin = A0;
int val;
void setup()
{
myservo.attach(9);
}
void loop()
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);
}
BLIND STICK
Aim: To design a Real time Application called Blind Stick using Arduino Uno
Circuit Diagram:

Components Required:
1. Arduino Uno
2. Ultrasonic Sensor
3. Buzzer
4. Bread Board
5. Jumper Wires
6. Connecting Cable
Code:
#define trigPin 13
#define echoPin 12
#define motor 7

void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motor, OUTPUT);
}

void loop()
{
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 70)// This is where checking the distanceyou can change the value
{
digitalWrite(motor,HIGH); // When the the distance below 100cm
}
else
{
digitalWrite(motor,LOW);// when greater than 100cm
} delay(500);
}
OBSTACLE DETECTION ROBOT
Aim: To stop the robot whenever an Obstacle is detected.
Circuit Diagram:

Components Required:
1. Arduino Uno
2. L293D Motor Driver
3. DC Motors – 2
4. Ultrasonic Sensor
5. Bread Board
6. Jumper Wires
7. Arduino Connecting Cable
Code:
const int trigPin = 12;
const int echoPin = 13;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
if(distance<=10)
{
Serial.println("STOP");
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}
if(distance>=11)
{
Serial.println("FORWARD");
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);

}
}
BLUETOOTH CONTROLLED ROBOT
Aim: To control the Robot using Bluetooth through Android Phones
Circuit Diagram:

Components Required:
1. Arduino Uno
2. L293D Motor Driver
3. DC Motor – 2
4. Jumper Wires
5. Bread Board
6. Arduino Connecting Cable
7. Bluetooth Module
Android App Link:
https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en

Code:
int state;
void setup() {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600);
}

void loop() {
if(Serial.available() > 0)
{
state=Serial.read();
Serial.println(state);
}
if(state == '0')
{
Serial.println("STOP");
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
if(state == '1')
{
Serial.println("FORWARD");
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
if(state == '2')
{
Serial.println("REVERSE");
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
if(state == '3')
{
Serial.println("RIGHT");
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
if(state == '4')
{
Serial.println("LEFT");
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
}
BLUETOOTH CONTROLLED OBSTACLE DETECTION ROBOT.
Aim: To control the Robot using Bluetooth and avoiding obstacles through ultrasonic sensor.
Circuit Diagram:

Components Required:
1. Arduino Uno
2. L293D Motor Driver
3. Bluetooth Module
4. Ultrasonic Sensor
5. Bread Board
6. Jumper Wires
7. Arduino Connecting Cable
8. DC Motors – 2
Code:
const int trigPin = 12;
const int echoPin = 13;
long duration;
int distance;
int state;
int measure;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600);
}

void loop() {

state=Serial.read();
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
measure = distance;

if(distance<=10)
{
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}

if(state == '0')
{
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
if(state == '1')
{
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
if(state == '2')
{
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
if(state == '3')
{
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
if(state == '4')
{
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
}
DHT11 INTERFACING WITH NODEMCU
Aim: To interface DHT11 with Nodemcu and Upload values to Thingspeak
Circuit Diagram:

Components Required:
1. Nodemcu
2. DHT11 Sensor
3. Jumper Wires
4. Bread Board
5. Connecting Cable
Code:
#include <ESP8266WiFi.h>;
#include <WiFiClient.h>;
#include <ThingSpeak.h>;

const char* ssid = "Krishna"; //Your Network SSID


const char* password = "1234567890"; //Your Network Password
WiFiClient client;
unsigned long myChannelNumber = 843662; //Your Channel Number (Without Brackets)
const char * myWriteAPIKey = "IGTT7X97EIUDTCVI"; //Your Write API Key
#include <SimpleDHT.h>

int pinDHT11 = 0;
SimpleDHT11 dht11(pinDHT11);

void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
ThingSpeak.begin(client);
}

void loop() {
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
return;
}

Serial.print(temperature); Serial.print(" *C, ");


Serial.print(humidity); Serial.println(" H");

ThingSpeak.writeField(myChannelNumber, 1,temperature, myWriteAPIKey);


ThingSpeak.writeField(myChannelNumber, 2,humidity, myWriteAPIKey);
// DHT11 sampling rate is 1HZ.
delay(1500);
}
SEVEN SEGMENT DISPLAY USING ARDUINO
Aim: To design a digital dice using Seven Segment and Arduino Uno
Circuit Diagram:

Components Required:
1. Seven Segment Display
2. Arduino Uno
3. Push Buttons – 2
4. 220𝜴 Resistor
5. Bread Board
6. Jumper Wires
7. Connecting Cable
Code:
int randNumber;
const int buttonPin = 10;

byte seven_seg_digits[10][7] =
{
{ 1,1,1,1,1,1,0 }, // = 0
{ 0,1,1,0,0,0,0 }, // = 1
{ 1,1,0,1,1,0,1 }, // = 2
{ 1,1,1,1,0,0,1 }, // = 3
{ 0,1,1,0,0,1,1 }, // = 4
{ 1,0,1,1,0,1,1 }, // = 5
{ 1,0,1,1,1,1,1 }, // = 6
{ 1,1,1,0,0,0,0 }, // = 7
{ 1,1,1,1,1,1,1 }, // = 8
{ 1,1,1,0,0,1,1 } // = 9
};

int buttonState = 0;

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}

void sevenSegWrite(byte digit) {


byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}

void loop() {
// print number from 9 to 1
// for (byte count = 10; count > 0; --count) {
// delay(1000);
// sevenSegWrite(count - 1);

// print a random number from 1 to 6


buttonState = digitalRead(buttonPin);
if(buttonState == '1')
{
randNumber = random(1, 7);
Serial.println(randNumber);
sevenSegWrite(randNumber);

delay(1000);
}
}
GSM MODULE INTERTFACING WITH ARDUINO UNO
Aim: Sending Message and Call through Sim900A GSM Module with Arduino Uno
Circuit Diagram:

Components Required:
1. SIM900A GSM Module
2. Arduino Uno
3. Jumper Wires
4. Bread Board
5. 12V 2A Adapter
6. Connecting Cable
Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10); // RX, TX
char msg;
char call;

void setup() {
// put your setup code here, to run once:
mySerial.begin(9600);
Serial.begin(9600);
Serial.println("GSM SIM900A BEGIN");
Serial.println("Enter character for control option:");
Serial.println("s : to send message");
Serial.println("c : to make a call");
Serial.println();
delay(100);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0)
switch(Serial.read())
{
case 's':
SendMessage();
break;
case 'c':
MakeCall();
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 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+918712328848\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("Hello Vamsi");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}

void MakeCall()
{
mySerial.println("ATD+918712328848;"); // ATDxxxxxxxxxx; -- watch out here for
semicolon at the end!!
Serial.println("Calling "); // print response over serial port
delay(1000);
}
GLOBAL POSITIONING SYSTEM
Aim: Interfacing GPS Module with Arduino Uno
Circuit Diagram:

Components Required:
1. Arduino Uno
2. Bread Board
3. NEO-6M GPS Module
4. Jumper Wires
5. Connecting Cable
Code:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/* Create object named bt of the class SoftwareSerial */
SoftwareSerial GPS_SoftSerial(4, 3);/* (Rx, Tx) */
/* Create an object named gps of the class TinyGPSPlus */
TinyGPSPlus gps;

volatile float minutes, seconds;


volatile int degree, secs, mins;
void setup() {
Serial.begin(9600); /* Define baud rate for serial communication */
GPS_SoftSerial.begin(9600); /* Define baud rate for software serial communication */
}

void loop() {
smartDelay(1000); /* Generate precise delay of 1ms */
unsigned long start;
double lat_val, lng_val, alt_m_val;
uint8_t hr_val, min_val, sec_val;
bool loc_valid, alt_valid, time_valid;
lat_val = gps.location.lat(); /* Get latitude data */
loc_valid = gps.location.isValid(); /* Check if valid location data is available */
lng_val = gps.location.lng(); /* Get longtitude data */
alt_m_val = gps.altitude.meters(); /* Get altitude data in meters */
alt_valid = gps.altitude.isValid(); /* Check if valid altitude data is available */
hr_val = gps.time.hour(); /* Get hour */
min_val = gps.time.minute(); /* Get minutes */
sec_val = gps.time.second(); /* Get seconds */
time_valid = gps.time.isValid(); /* Check if valid time data is available */
if (!loc_valid)
{

}
else
{
Serial.print("lat");
Serial.println(lat_val, 6);
Serial.print("long");
Serial.println(lng_val, 6);

static void smartDelay(unsigned long ms)


{
unsigned long start = millis();
do
{
while (GPS_SoftSerial.available()) /* Encode data read from GPS while data is available on
serial port */
gps.encode(GPS_SoftSerial.read());
/* Encode basically is used to parse the string received by the GPS and to store it in a buffer
so that information can be extracted from it */
} while (millis() - start < ms);
}
void DegMinSec( double tot_val) /* Convert data in decimal degrees into degrees minutes
seconds form */
{
degree = (int)tot_val;
minutes = tot_val - degree;
seconds = 60 * minutes;
minutes = (int)seconds;
mins = (int)minutes;
seconds = seconds - minutes;
seconds = 60 * seconds;
secs = (int)seconds;
}
ULTRASONIC SENSOR WITH NODEMCU AND THINGSPEAK
Aim: Interface Ultrasonic sensor with Nodemcu and Upload the Values to the Cloud of
Thingspeak
Circuit Diagram:

Components Required:
1. Nodemcu
2. Ultrasonic Sensor
3. Jumper Wires
4. Bread Board
5. Connecting Cable
Code:
#include <ESP8266WiFi.h>;
#include <WiFiClient.h>;
#include <ThingSpeak.h>;
const char* ssid = "WifiName"; //Your Network SSID
const char* password = "WifiPassword"; //Your Network Password
const int trigPin = 2;
const int echoPin = 0;
long duration;
int distance;
WiFiClient client;
unsigned long myChannelNumber = 843662; //Your Channel Number (Without Brackets)
const char * myWriteAPIKey = "D63IB7CQ1M107PG0"; //Your Write API Key
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
delay(10);
WiFi.begin(ssid, password);
ThingSpeak.begin(client);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
ThingSpeak.writeField(myChannelNumber, 1,distance, myWriteAPIKey);
delay(15000);
}
TRAFFIC LIGHT CONTROLLER
Aim: To Program the LED’s into a Real time Traffic Light Controller using Arduino Uno
Circuit Diagram:

Components Required:
1. Red LED’s – 4
2. Green LED’s – 4
3. Yellow LED’s – 4
4. Arduino Uno
5. Bread Board
6. Jumper Wires
7. Arduino Cable
Code:

int Lane1[] = {13,12,11}; // Lane 1 Red, Yellow and Green

int Lane2[] = {10,9,8};// Lane 2 Red, Yellow and Green

int Lane3[] = {7,6,5};// Lane 3 Red, Yellow and Green

int Lane4[] = {4,3,2};// Lane 4 Red, Yellow and Green

void setup()

{
for (int i = 0; i < 3; i++)

pinMode(Lane1[i], OUTPUT);

pinMode(Lane2[i], OUTPUT);

pinMode(Lane3[i], OUTPUT);

pinMode(Lane4[i], OUTPUT);

for (int i = 0; i < 3; i++){

digitalWrite(Lane1[i], LOW);

digitalWrite(Lane2[i], LOW);

digitalWrite(Lane3[i], LOW);

digitalWrite(Lane4[i], LOW);

void loop()

digitalWrite(Lane1[2], HIGH);

digitalWrite(Lane3[0], HIGH);

digitalWrite(Lane4[0], HIGH);

digitalWrite(Lane2[0], HIGH);

delay(7000);

digitalWrite(Lane1[2], LOW);

digitalWrite(Lane3[0], LOW);

digitalWrite(Lane1[1], HIGH);
digitalWrite(Lane3[1], HIGH);

delay(3000);

digitalWrite(Lane1[1], LOW);

digitalWrite(Lane3[1], LOW);

digitalWrite(Lane1[0], HIGH);

digitalWrite(Lane3[2], HIGH);

delay(7000);

digitalWrite(Lane3[2], LOW);

digitalWrite(Lane4[0], LOW);

digitalWrite(Lane3[1], HIGH);

digitalWrite(Lane4[1], HIGH);

delay(3000);

digitalWrite(Lane3[1], LOW);

digitalWrite(Lane4[1], LOW);

digitalWrite(Lane3[0], HIGH);

digitalWrite(Lane4[2], HIGH);

delay(7000);

digitalWrite(Lane4[2], LOW);

digitalWrite(Lane2[0], LOW);

digitalWrite(Lane4[1], HIGH);

digitalWrite(Lane2[1], HIGH);

delay(3000);

digitalWrite(Lane4[1], LOW);

digitalWrite(Lane2[1], LOW);

digitalWrite(Lane4[0], HIGH);

digitalWrite(Lane2[2], HIGH);
delay(7000);

digitalWrite(Lane1[0], LOW);

digitalWrite(Lane2[2], LOW);

digitalWrite(Lane1[1], HIGH);

digitalWrite(Lane2[1], HIGH);

delay(3000);

digitalWrite(Lane2[1], LOW);

digitalWrite(Lane1[1], LOW);}
HOME AUTOMATION USING IOT
Aim: To build a Real Time Application on Home Automation using Nodemcu
Circuit Diagram:

Components Required:
1. Nodemcu
2. Relay Module
3. LED’s – 2
4. DC Motor – 2
5. Jumper Wires
6. Bread Board
7. Connecting Cable
Android App Link:
https://play.google.com/store/apps/details?id=cc.blynk&hl=en

Code:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.


// Go to the Project Settings (nut icon).
char auth[] = "auth token";

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "ssid";
char pass[] = "pwd";

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}

void loop()
{
Blynk.run();
}
SOIL MOISTURE INTERFACING WITH NODEMCU
Aim: Interfacing Soil Moisture with Nodemcu and getting Values from the ThingSpeak Cloud
Circuit Diagram:

Components Required:
1. Nodemcu
2. Soil moisture Sensor
3. Jumper Wires
4. Bread Board
5. Connecting Cable
Android App Link:
https://play.google.com/store/apps/details?id=com.cinetica_tech.thingview&hl=en

Code:
#include <ESP8266WiFi.h>;
#include <WiFiClient.h>;
#include <ThingSpeak.h>;
const char* ssid = "Krishna"; //Your Network SSID
const char* password = "1234567890"; //Your Network Password

int sensorpin = A0;


int sensorvalue = 0;

WiFiClient client;
unsigned long myChannelNumber = 711370; //Your Channel Number (Without Brackets)
const char * myWriteAPIKey = "Y8MTZ0AVFLE7QZRO"; //Your Write API Key

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
WiFi.begin(ssid, password);
ThingSpeak.begin(client);
}

void loop() {
// put your main code here, to run repeatedly:
sensorvalue = analogRead(sensorpin);
Serial.println(sensorvalue);
ThingSpeak.writeField(myChannelNumber, 1,sensorvalue, myWriteAPIKey);
delay(10000);
}
SUN TRACKING SOLAR PANEL.
Aim: To design Real Time Application on Single Axis Solar Tracker using Arduino
Circuit Diagram:

Components Required:
1. Servo Motor
2. Arduino Uno
3. LDR – 2
4. 10K Resistor
5. Bread Board
6. Jumper Wires
7. Connecting Cables
Code:
#include <Servo.h>

Servo myservo;
int pos = 90; // initial position
int sens1 = A0; // LRD 1 pin
int sens2 = A1; //LDR 2 pin
int tolerance = 2;

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(sens1, INPUT);
pinMode(sens2, INPUT);
myservo.write(pos);
delay(2000); // a 2 seconds delay while we position the solar panel
}

void loop()
{
int val1 = analogRead(sens1); // read the value of sensor 1
int val2 = analogRead(sens2); // read the value of sensor 2

if((abs(val1 - val2) <= tolerance) || (abs(val2 - val1) <= tolerance)) {


//do nothing if the difference between values is within the tolerance limit
} else {
if(val1 > val2)
{
pos = --pos;
}
if(val1 < val2)
{
pos = ++pos;
}
}
if(pos > 180) { pos = 180; } // reset to 180 if it goes higher
if(pos < 0) { pos = 0; } // reset to 0 if it goes lower

myservo.write(pos); // write the position to servo


delay(50);
}
INTERFACING PIR SENSOR WITH ARDUINO UNO
Aim: Interfacing PIR Sensor with Arduino Uno to detect the Motion.
Circuit Diagram:

Components Required:
1. Arduino Uno
2. PIR Sensor
3. Bread Board
4. Jumper Wires
5. 10K𝜴 Resistor
6. Connecting Cable
Code:
const int buttonPin = 2; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600); // initialize serial communication
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.println(“motion detected”);
}
else {
Serial.println(“sorry try once”);
}
}

Anda mungkin juga menyukai