Last active
July 17, 2018 06:57
-
-
Save Eyakub/78c1eae3b9b0fcb3224ae2129024a5d8 to your computer and use it in GitHub Desktop.
Here I'll be adding some basic adruino basic code.
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
.. |
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
// the setup function runs once when you press reset or power the board | |
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 | |
} |
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
// the setup function runs once when you press reset or power the board | |
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) | |
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW | |
} |
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 state = 0; | |
int fading = 15; | |
int brightness = 0; | |
int ledOut = 5; | |
int val; | |
int value; | |
void setup() { | |
Serial.begin(9600); | |
// put your setup code here, to run once: | |
pinMode(ledOut, OUTPUT); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
val = Serial.read(); | |
val=Serial.parseInt(); | |
Serial.println(val); | |
//value = val; | |
//value = Serial.parseInt(); | |
if(val == 1){ | |
digitalWrite(ledOut, HIGH); | |
delay(200); | |
digitalWrite(ledOut, LOW); | |
delay(200); | |
} | |
else{ | |
analogWrite(ledOut, brightness); | |
brightness = brightness + fading; | |
if(brightness <= 0 || brightness >= 255){ | |
fading = -fading; | |
} | |
delay(30); | |
} | |
} |
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
void setup() { | |
Serial.begin(9600); | |
pinMode(8,OUTPUT); | |
pinMode(A0,INPUT); | |
// put your setup code here, to run once: | |
} | |
void loop() { | |
int value=analogRead(A0); | |
Serial.println(value); | |
if(value>100){ | |
digitalWrite(8,LOW); | |
}else{ | |
digitalWrite(8,HIGH); | |
} | |
// put your main code here, to run repeatedly: | |
} |
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 ledPin = 13; // LED connected to digital pin 13 | |
int fadePin = 3; | |
unsigned long nextBlink, nextFade; | |
int fadeBrightness = 0; | |
char ledState = LOW, fadeDir = 10; | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); // sets the digital pin as output | |
pinMode(fadePin, OUTPUT); | |
ledState = LOW; | |
nextBlink = millis(); | |
nextFade = millis(); | |
} | |
/* | |
* This checks whether it's time to change the state of the LED, and | |
* does the write if so. But it doesn't execute delay(), so in either | |
* case it takes essentially no time to execute. | |
*/ | |
void blink(void) | |
{ | |
unsigned long now; | |
now = millis(); | |
if (now >= nextBlink) { | |
nextBlink = now + 1000; // Next change in one second | |
if (ledState == LOW) { | |
digitalWrite(ledPin, HIGH); | |
ledState = HIGH; | |
} | |
else { | |
digitalWrite(ledPin, LOW); | |
ledState = LOW; | |
} | |
} | |
} | |
void fade(void) | |
{ | |
unsigned long now; | |
now = millis(); | |
if (now >= nextFade) { | |
nextFade = now + 200; // Next change in one second | |
if (fadeDir > 0) { | |
if (fadeBrightness > (255 - fadeDir)) { | |
fadeDir = - fadeDir; | |
} | |
} | |
else { | |
if (fadeBrightness < (-fadeDir)) { | |
fadeDir = - fadeDir; | |
} | |
} | |
fadeBrightness += fadeDir; | |
analogWrite(fadePin, fadeBrightness); | |
} | |
} | |
void loop() | |
{ | |
blink(); | |
fade(); | |
} |
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 val = 0; // variable for reading the pin status | |
void setup() { | |
pinMode(8, OUTPUT); // declare LED as output | |
pinMode(2, INPUT); // declare sensor as input | |
Serial.begin(9600); | |
} | |
void loop(){ | |
val = digitalRead(2); // read input value | |
if(val == 1){ | |
//pirState = HIGH; | |
//Serial.print("Motion detected"); | |
digitalWrite(8, HIGH); | |
} | |
else{ | |
pirState = LOW; | |
digitalWrite(8, LOW); | |
} | |
} |
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<LiquidCrystal.h> | |
const int rs = 10, en = 12, rw = 11, d0 = 2, d1 = 3, d2 = 4, d3 = 5; | |
LiquidCrystal lcd(rs, en, rw, d0, d1, d2, d3); | |
int backLight = 13; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(backLight, OUTPUT); | |
digitalWrite(backLight, HIGH); | |
lcd.begin(16, 2); | |
lcd.clear(); | |
lcd.setCursor(0, 0); | |
lcd.print("Hello "); | |
lcd.setCursor(0, 1); | |
lcd.print("Wrold"); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} |
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 tempPin = A0; // the output pin of LM35 | |
//int fan1 = 4; // the pin where fan is | |
//int fan2 = 8; // led pin | |
int temp; | |
int tempMin = 20; // the temperature to start the fan | |
int tempMax = 50; // the maximum temperature when fan is at 100% | |
//int fanSpeed; | |
void setup() { | |
pinMode(fan1, OUTPUT); | |
pinMode(fan2, OUTPUT); | |
pinMode(tempPin, INPUT); | |
analogReference(INTERNAL); | |
Serial.begin(9600); | |
} | |
void loop() { | |
temp = readTemp(); // get the temperature | |
if(temp < tempMin) { // if temp is lower than minimum temp | |
//fanSpeed = 0; // fan is not spinning | |
digitalWrite(8, LOW); | |
digitalWrite(4, HIGH); | |
} | |
else{ | |
digitalWrite(4, LOW); | |
digitalWrite(8, HIGH); | |
} | |
Serial.print("TEMP = "); | |
Serial.print(temp); | |
Serial.println("DEG C"); | |
} | |
int readTemp() { // get the temperature and convert it to celsius | |
temp = analogRead(tempPin); | |
return temp * 0.4888; | |
} |
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; | |
long duration; | |
int distance; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(trigPin, OUTPUT); | |
pinMode(echoPin, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); | |
//sets the trigPin on high state for 10micro seconds | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
//reads the echoPin, returns the sound wave travel time in microseconds | |
duration = pulseIn(echoPin, HIGH); | |
//calculating the distance onthe serial monitor | |
distance = duration * 0.034/2; | |
Serial.print("Distance: "); | |
Serial.println(distance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment