Last active
May 7, 2019 10:04
-
-
Save JimishF/779dd24bfc960d01d3d43b98002fb9f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ProxSensor = A0; | |
int inputVal = 0; | |
void setup() | |
{ | |
pinMode(13, OUTPUT); // Pin 13 has an LED connected on most Arduino boards: | |
pinMode(ProxSensor,INPUT); // Pin 2 is connected to the output of proximity sensor | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
inputVal = analogRead(ProxSensor); // Analog value will very from 0-1023 | |
Serial.println(inputVal); | |
if( inputVal > 500 ){ | |
digitalWrite(13, HIGH); // set the LED on | |
} | |
else{ | |
digitalWrite(13, LOW); // set the LED off | |
} | |
delay(500); // wait for half of a second | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ProxSensor=2; | |
int inputVal = 0; | |
void setup() | |
{ | |
pinMode(13, OUTPUT); // Pin 13 has an LED connected on most Arduino boards: | |
pinMode(ProxSensor,INPUT); //Pin 2 is connected to the output of proximity sensor | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
inputVal = digitalRead(ProxSensor); | |
Serial.println(inputVal); | |
if( inputVal == HIGH ){ | |
//Check the sensor output | |
digitalWrite(13, HIGH); // set the LED on | |
} | |
else{ | |
digitalWrite(13, LOW); // set the LED off | |
} | |
delay(500); // wait for half of a second | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <LiquidCrystal_PCF8574.h> | |
// creating lcd object | |
LiquidCrystal_PCF8574 lcd(0x27); | |
void setup() | |
{ | |
// LCD Error check | |
int error; | |
Wire.begin(); | |
Wire.beginTransmission(0x27); | |
error = Wire.endTransmission(); | |
if (error == 0) { | |
Serial.println(": LCD found."); | |
} else { | |
Serial.println(": LCD not found."); | |
} | |
lcd.begin(16, 2); // initialize the lcd as 16 cols, 2 rows | |
lcd.setBacklight(255); // Turn backLight ON | |
} | |
void loop() | |
{ | |
lcd.clear(); // clear the LCD | |
lcd.home(); // puts cursor to 0,0 | |
// You can also use lcd.setCursor(0, 0); to put cursor at a specific position | |
lcd.print("Hello LCD"); | |
delay(2000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ThingSpeak.h" | |
#include <ESP8266WiFi.h> | |
int keyIndex = 0; | |
WiFiClient client; | |
char ssid[] = "Your SSID Here"; | |
char pass[] = "Your Password Here"; | |
unsigned long myChannelNumber = 123456; | |
const char * myWriteAPIKey = "XXXXXXXXXXX"; | |
long int calculate( long int data){ | |
/* Wait for 5 seconds before calculating new data */ | |
delay( 5000 ); | |
/* Start Writing code from here, | |
* make sure whatever value you want to upload, | |
* must be assigned to variable 'data' | |
*/ | |
data = analogRead( 0 ); | |
/*returned 'data' will be uploiaded to the Thingspeak channel */ | |
return data; | |
} | |
int number = 0; | |
void setup() { | |
Serial.begin(115200); // Initialize serial | |
WiFi.mode(WIFI_STA); | |
ThingSpeak.begin(client); // Initialize ThingSpeak | |
// Connect or reconnect to WiFi | |
if(WiFi.status() != WL_CONNECTED){ | |
Serial.println("Attempting to connect to SSID: "+ String(ssid) ); | |
while(WiFi.status() != WL_CONNECTED){ | |
// Connect to WIFI (WPA/WPA2 network | |
WiFi.begin(ssid, pass); | |
Serial.print("."); | |
delay(3000); | |
} | |
Serial.println("\nConnected."); | |
} | |
} | |
long int data = 0; | |
void loop() { | |
/* Write data to ThingSpeak. There are up to 8 fields in a channel, | |
* allowing you to store up to 8 different pieces of information in a channel. | |
* Here, we write to field 1 | |
*/ | |
data = calculate( data ); | |
int field = 1; | |
int responseCode = ThingSpeak.writeField(myChannelNumber, field , data , myWriteAPIKey); | |
if ( responseCode == 200 ){ | |
Serial.println("Channel update successful."); | |
} | |
else { | |
Serial.println("Problem updating channel. HTTP error code " + String(x)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int trigPin = 9; | |
int echoPin = 10; | |
// defines variables | |
long duration; | |
int distance; | |
void setup() { | |
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output | |
pinMode(echoPin, INPUT); // Sets the echoPin as an Input | |
Serial.begin(9600); // Starts the serial communication | |
} | |
void loop() { | |
// Clears the trigPin | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); | |
// Sets the trigPin on HIGH state for 10 micro seconds | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigPin, LOW); | |
// Reads the echoPin, returns the sound wave travel time in microseconds | |
duration = pulseIn(echoPin, HIGH); | |
distance= duration*0.034/2; // Calculating the distance | |
// Prints the distance on the Serial Monitor | |
Serial.print("Distance: "); | |
Serial.println(distance); | |
// Wait for 300ms | |
delay(300); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment